Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
3c4606ff
Commit
3c4606ff
authored
Apr 12, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template files
parent
b4a44693
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
2 deletions
+106
-2
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
+86
-0
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+2
-0
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
+5
-2
notification.ts
libs/remix-ui/file-explorer/src/lib/reducers/notification.ts
+0
-0
index.ts
libs/remix-ui/file-explorer/src/lib/utils/index.ts
+13
-0
No files found.
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
0 → 100644
View file @
3c4606ff
import
React
from
'react'
import
{
File
}
from
'../types'
import
{
extractNameFromKey
,
extractParentFromKey
}
from
'../utils'
const
globalRegistry
=
require
(
'../../../../../../apps/remix-ide/src/global/registry'
)
const
fileProviders
=
globalRegistry
.
get
(
'fileproviders'
).
api
const
browser
=
fileProviders
.
browser
// eslint-disable-line
const
workspace
=
fileProviders
.
workspace
const
localhost
=
fileProviders
.
localhost
// eslint-disable-line
export
const
fetchDirectoryError
=
(
error
:
any
)
=>
{
return
{
type
:
'FETCH_DIRECTORY_ERROR'
,
payload
:
error
}
}
export
const
fetchDirectoryRequest
=
(
promise
:
Promise
<
any
>
)
=>
{
return
{
type
:
'FETCH_DIRECTORY_REQUEST'
,
payload
:
promise
}
}
export
const
fetchDirectorySuccess
=
(
path
:
string
,
files
:
File
[])
=>
{
return
{
type
:
'FETCH_DIRECTORY_SUCCESS'
,
payload
:
{
path
,
files
}
}
}
export
const
fileSystemReset
=
()
=>
{
return
{
type
:
'FILESYSTEM_RESET'
}
}
const
normalize
=
(
filesList
):
File
[]
=>
{
const
folders
=
[]
const
files
=
[]
Object
.
keys
(
filesList
||
{}).
forEach
(
key
=>
{
key
=
key
.
replace
(
/^
\/
|
\/
$/g
,
''
)
// remove first and last slash
let
path
=
key
path
=
path
.
replace
(
/^
\/
|
\/
$/g
,
''
)
// remove first and last slash
if
(
filesList
[
key
].
isDirectory
)
{
folders
.
push
({
path
,
name
:
extractNameFromKey
(
path
),
isDirectory
:
filesList
[
key
].
isDirectory
})
}
else
{
files
.
push
({
path
,
name
:
extractNameFromKey
(
path
),
isDirectory
:
filesList
[
key
].
isDirectory
})
}
})
return
[...
folders
,
...
files
]
}
const
fetchDirectoryContent
=
async
(
folderPath
:
string
):
Promise
<
File
[]
>
=>
{
return
new
Promise
((
resolve
)
=>
{
workspace
.
resolveDirectory
(
folderPath
,
(
error
,
fileTree
)
=>
{
if
(
error
)
console
.
error
(
error
)
const
files
=
normalize
(
fileTree
)
resolve
(
files
)
})
})
}
export
const
fetchDirectory
=
(
path
:
string
)
=>
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
const
promise
=
fetchDirectoryContent
(
path
)
dispatch
(
fetchDirectoryRequest
(
promise
))
promise
.
then
((
files
)
=>
{
dispatch
(
fetchDirectorySuccess
(
path
,
files
))
}).
catch
((
error
)
=>
{
dispatch
(
fetchDirectoryError
({
error
}))
})
return
promise
}
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
3c4606ff
...
@@ -260,10 +260,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -260,10 +260,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const
fetchDirectoryContent
=
async
(
folderPath
:
string
):
Promise
<
File
[]
>
=>
{
const
fetchDirectoryContent
=
async
(
folderPath
:
string
):
Promise
<
File
[]
>
=>
{
console
.
log
(
'folderPath: '
,
folderPath
)
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
((
resolve
)
=>
{
filesProvider
.
resolveDirectory
(
folderPath
,
(
_error
,
fileTree
)
=>
{
filesProvider
.
resolveDirectory
(
folderPath
,
(
_error
,
fileTree
)
=>
{
const
files
=
normalize
(
fileTree
)
const
files
=
normalize
(
fileTree
)
console
.
log
(
'files: '
,
files
)
resolve
(
files
)
resolve
(
files
)
})
})
})
})
...
...
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
View file @
3c4606ff
import
{
extractNameFromKey
,
extractParentFromKey
}
from
'../utils'
interface
Action
{
interface
Action
{
type
:
string
;
type
:
string
;
payload
:
Record
<
string
,
string
|
number
|
boolean
>
;
payload
:
Record
<
string
,
any
>
;
}
}
export
const
initialState
=
{
export
const
initialState
=
{
files
:
[],
files
:
[],
expandPath
:
[],
isRequesting
:
false
,
isRequesting
:
false
,
isSuccessful
:
false
,
isSuccessful
:
false
,
hasError
:
null
hasError
:
null
...
@@ -22,7 +24,8 @@ export const reducer = (state = initialState, action: Action) => {
...
@@ -22,7 +24,8 @@ export const reducer = (state = initialState, action: Action) => {
}
}
case
'FETCH_DIRECTORY_SUCCESS'
:
{
case
'FETCH_DIRECTORY_SUCCESS'
:
{
return
{
return
{
files
:
[],
files
:
action
.
payload
.
files
,
expandPath
:
[...
action
.
payload
.
path
],
isRequesting
:
false
,
isRequesting
:
false
,
isSuccessful
:
true
,
isSuccessful
:
true
,
hasError
:
null
hasError
:
null
...
...
libs/remix-ui/file-explorer/src/lib/reducers/notification.ts
0 → 100644
View file @
3c4606ff
libs/remix-ui/file-explorer/src/lib/utils/index.ts
0 → 100644
View file @
3c4606ff
export
const
extractNameFromKey
=
(
key
:
string
):
string
=>
{
const
keyPath
=
key
.
split
(
'/'
)
return
keyPath
[
keyPath
.
length
-
1
]
}
export
const
extractParentFromKey
=
(
key
:
string
):
string
=>
{
if
(
!
key
)
return
const
keyPath
=
key
.
split
(
'/'
)
keyPath
.
pop
()
return
keyPath
.
join
(
'/'
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment