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
dd27f66d
Commit
dd27f66d
authored
Sep 01, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add/remove input fields recursively
parent
22f1dac7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
93 deletions
+63
-93
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+4
-6
workspace.ts
libs/remix-ui/workspace/src/lib/actions/workspace.ts
+13
-13
workspace.ts
libs/remix-ui/workspace/src/lib/reducers/workspace.ts
+46
-74
No files found.
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
dd27f66d
...
@@ -253,20 +253,18 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -253,20 +253,18 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const
deletePath
=
async
(
path
:
string
|
string
[])
=>
{
const
deletePath
=
async
(
path
:
string
|
string
[])
=>
{
// const filesProvider = fileSystem.provider.provider
if
(
global
.
fs
.
readonly
)
return
toast
(
'cannot delete file. '
+
name
+
' is a read only explorer'
)
if
(
!
Array
.
isArray
(
path
))
path
=
[
path
]
if
(
!
Array
.
isArray
(
path
))
path
=
[
path
]
for
(
const
p
of
path
)
{
if
(
filesProvider
.
isReadOnly
(
p
))
{
return
toast
(
'cannot delete file. '
+
name
+
' is a read only explorer'
)
}
}
global
.
modal
(
`Delete
${
path
.
length
>
1
?
'items'
:
'item'
}
`
,
deleteMessage
(
path
),
'OK'
,
async
()
=>
{
global
.
modal
(
`Delete
${
path
.
length
>
1
?
'items'
:
'item'
}
`
,
deleteMessage
(
path
),
'OK'
,
async
()
=>
{
const
fileManager
=
state
.
fileManager
const
fileManager
=
state
.
fileManager
for
(
const
p
of
path
)
{
for
(
const
p
of
path
)
{
try
{
try
{
await
fileManager
.
remove
(
p
)
await
fileManager
.
remove
(
p
)
}
catch
(
e
)
{
}
catch
(
e
)
{
const
isDir
=
await
state
.
fileManager
.
isDirectory
(
p
)
const
isDir
=
await
state
.
fileManager
.
isDirectory
(
p
)
toast
(
`Failed to remove
${
isDir
?
'folder'
:
'file'
}
${
p
}
.`
)
toast
(
`Failed to remove
${
isDir
?
'folder'
:
'file'
}
${
p
}
.`
)
}
}
}
}
...
...
libs/remix-ui/workspace/src/lib/actions/workspace.ts
View file @
dd27f66d
...
@@ -413,12 +413,12 @@ const fileRemoved = async (removePath: string) => {
...
@@ -413,12 +413,12 @@ const fileRemoved = async (removePath: string) => {
await
dispatch
(
fileRemovedSuccess
(
removePath
))
await
dispatch
(
fileRemovedSuccess
(
removePath
))
}
}
//
const fileRenamed = async (oldPath: string) => {
const
fileRenamed
=
async
(
oldPath
:
string
)
=>
{
//
const path = extractParentFromKey(oldPath) || provider.workspace || provider.type || ''
const
path
=
extractParentFromKey
(
oldPath
)
||
provider
.
workspace
||
provider
.
type
||
''
//
const data = await fetchDirectoryContent(provider, path)
const
data
=
await
fetchDirectoryContent
(
provider
,
path
)
//
await dispatch(fileRenamedSuccess(path, oldPath, data))
await
dispatch
(
fileRenamedSuccess
(
path
,
oldPath
,
data
))
//
}
}
const
rootFolderChanged
=
async
(
path
)
=>
{
const
rootFolderChanged
=
async
(
path
)
=>
{
await
dispatch
(
rootFolderChangedSuccess
(
path
))
await
dispatch
(
rootFolderChangedSuccess
(
path
))
...
@@ -460,15 +460,15 @@ const executeEvent = async (eventName: 'fileAdded' | 'folderAdded' | 'fileRemove
...
@@ -460,15 +460,15 @@ const executeEvent = async (eventName: 'fileAdded' | 'folderAdded' | 'fileRemove
}
}
break
break
//
case 'fileRenamed':
case
'fileRenamed'
:
//
await fileRenamed(path)
await
fileRenamed
(
path
)
//
delete pendingEvents[eventName + path]
delete
pendingEvents
[
eventName
+
path
]
//
if (queuedEvents.length) {
if
(
queuedEvents
.
length
)
{
//
const next = queuedEvents.pop()
const
next
=
queuedEvents
.
pop
()
//
await executeEvent(next.eventName, next.path)
await
executeEvent
(
next
.
eventName
,
next
.
path
)
//
}
}
//
break
break
case
'rootFolderChanged'
:
case
'rootFolderChanged'
:
await
rootFolderChanged
(
path
)
await
rootFolderChanged
(
path
)
...
...
libs/remix-ui/workspace/src/lib/reducers/workspace.ts
View file @
dd27f66d
...
@@ -225,12 +225,12 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...
@@ -225,12 +225,12 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
browser
:
{
browser
:
{
...
state
.
browser
,
...
state
.
browser
,
files
:
state
.
mode
===
'browser'
?
fileRemoved
(
state
,
payload
)
:
state
.
browser
.
files
,
files
:
state
.
mode
===
'browser'
?
fileRemoved
(
state
,
payload
)
:
state
.
browser
.
files
,
expandPath
:
state
.
mode
===
'browser'
?
[...
new
Set
([...
state
.
browser
.
expandPath
,
payload
]
)]
:
state
.
browser
.
expandPath
expandPath
:
state
.
mode
===
'browser'
?
[...
(
state
.
browser
.
expandPath
.
filter
(
path
=>
path
!==
payload
)
)]
:
state
.
browser
.
expandPath
},
},
localhost
:
{
localhost
:
{
...
state
.
localhost
,
...
state
.
localhost
,
files
:
state
.
mode
===
'localhost'
?
fileRemoved
(
state
,
payload
)
:
state
.
localhost
.
files
,
files
:
state
.
mode
===
'localhost'
?
fileRemoved
(
state
,
payload
)
:
state
.
localhost
.
files
,
expandPath
:
state
.
mode
===
'localhost'
?
[...
new
Set
([...
state
.
localhost
.
expandPath
,
payload
]
)]
:
state
.
localhost
.
expandPath
expandPath
:
state
.
mode
===
'localhost'
?
[...
(
state
.
browser
.
expandPath
.
filter
(
path
=>
path
!==
payload
)
)]
:
state
.
localhost
.
expandPath
}
}
}
}
}
}
...
@@ -254,11 +254,11 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...
@@ -254,11 +254,11 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...
state
,
...
state
,
browser
:
{
browser
:
{
...
state
.
browser
,
...
state
.
browser
,
files
:
state
.
mode
===
'browser'
?
fetchDirectoryContent
(
state
,
payload
,
true
)
:
state
.
browser
.
files
files
:
state
.
mode
===
'browser'
?
fetchDirectoryContent
(
state
,
payload
)
:
state
.
browser
.
files
},
},
localhost
:
{
localhost
:
{
...
state
.
localhost
,
...
state
.
localhost
,
files
:
state
.
mode
===
'localhost'
?
fetchDirectoryContent
(
state
,
payload
,
true
)
:
state
.
localhost
.
files
files
:
state
.
mode
===
'localhost'
?
fetchDirectoryContent
(
state
,
payload
)
:
state
.
localhost
.
files
}
}
}
}
}
}
...
@@ -270,11 +270,11 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...
@@ -270,11 +270,11 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...
state
,
...
state
,
browser
:
{
browser
:
{
...
state
.
browser
,
...
state
.
browser
,
files
:
state
.
mode
===
'browser'
?
removeInputField
(
state
,
payload
)
:
state
.
browser
.
files
files
:
state
.
mode
===
'browser'
?
fetchDirectoryContent
(
state
,
payload
,
payload
.
path
+
'/'
+
'blank'
)
:
state
.
browser
.
files
},
},
localhost
:
{
localhost
:
{
...
state
.
localhost
,
...
state
.
localhost
,
files
:
state
.
mode
===
'localhost'
?
removeInputField
(
state
,
payload
)
:
state
.
localhost
.
files
files
:
state
.
mode
===
'localhost'
?
fetchDirectoryContent
(
state
,
payload
,
payload
.
path
+
'/'
+
'blank'
)
:
state
.
localhost
.
files
}
}
}
}
}
}
...
@@ -293,12 +293,48 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...
@@ -293,12 +293,48 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
}
}
}
const
fetchDirectoryContent
=
(
state
:
BrowserState
,
payload
:
{
fileTree
,
path
:
string
,
type
?:
'file'
|
'folder'
})
=>
{
const
fileAdded
=
(
state
:
BrowserState
,
path
:
string
):
{
[
x
:
string
]:
Record
<
string
,
File
>
}
=>
{
let
files
=
state
.
mode
===
'browser'
?
state
.
browser
.
files
:
state
.
localhost
.
files
const
_path
=
splitPath
(
state
,
path
)
files
=
_
.
set
(
files
,
_path
,
{
path
:
path
,
name
:
extractNameFromKey
(
path
),
isDirectory
:
false
,
type
:
'file'
})
return
files
}
const
folderAdded
=
(
state
:
BrowserState
,
path
:
string
):
{
[
x
:
string
]:
Record
<
string
,
File
>
}
=>
{
let
files
=
state
.
mode
===
'browser'
?
state
.
browser
.
files
:
state
.
localhost
.
files
const
_path
=
splitPath
(
state
,
path
)
files
=
_
.
set
(
files
,
_path
,
{
path
:
path
,
name
:
extractNameFromKey
(
path
),
isDirectory
:
true
,
type
:
'folder'
})
return
files
}
const
fileRemoved
=
(
state
:
BrowserState
,
path
:
string
):
{
[
x
:
string
]:
Record
<
string
,
File
>
}
=>
{
const
files
=
state
.
mode
===
'browser'
?
state
.
browser
.
files
:
state
.
localhost
.
files
const
_path
=
splitPath
(
state
,
path
)
_
.
unset
(
files
,
_path
)
return
files
}
// IDEA: Modify function to remove blank input field without fetching content
const
fetchDirectoryContent
=
(
state
:
BrowserState
,
payload
:
{
fileTree
,
path
:
string
,
type
?:
'file'
|
'folder'
},
deletePath
?:
string
)
=>
{
if
(
state
.
mode
===
'browser'
)
{
if
(
state
.
mode
===
'browser'
)
{
if
(
payload
.
path
===
state
.
browser
.
currentWorkspace
)
{
if
(
payload
.
path
===
state
.
browser
.
currentWorkspace
)
{
let
files
=
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
)
let
files
=
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
)
files
=
_
.
merge
(
files
,
state
.
browser
.
files
[
state
.
browser
.
currentWorkspace
])
files
=
_
.
merge
(
files
,
state
.
browser
.
files
[
state
.
browser
.
currentWorkspace
])
if
(
deletePath
)
delete
files
[
deletePath
]
return
{
[
state
.
browser
.
currentWorkspace
]:
files
}
return
{
[
state
.
browser
.
currentWorkspace
]:
files
}
}
else
{
}
else
{
let
files
=
state
.
browser
.
files
let
files
=
state
.
browser
.
files
...
@@ -306,6 +342,7 @@ const fetchDirectoryContent = (state: BrowserState, payload: { fileTree, path: s
...
@@ -306,6 +342,7 @@ const fetchDirectoryContent = (state: BrowserState, payload: { fileTree, path: s
const
prevFiles
=
_
.
get
(
files
,
_path
)
const
prevFiles
=
_
.
get
(
files
,
_path
)
prevFiles
.
child
=
_
.
merge
(
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
),
prevFiles
.
child
)
prevFiles
.
child
=
_
.
merge
(
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
),
prevFiles
.
child
)
if
(
deletePath
)
delete
prevFiles
.
child
[
deletePath
]
files
=
_
.
set
(
files
,
_path
,
prevFiles
)
files
=
_
.
set
(
files
,
_path
,
prevFiles
)
return
files
return
files
}
}
...
@@ -314,6 +351,7 @@ const fetchDirectoryContent = (state: BrowserState, payload: { fileTree, path: s
...
@@ -314,6 +351,7 @@ const fetchDirectoryContent = (state: BrowserState, payload: { fileTree, path: s
let
files
=
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
)
let
files
=
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
)
files
=
_
.
merge
(
files
,
state
[
state
.
mode
].
files
[
state
.
mode
])
files
=
_
.
merge
(
files
,
state
[
state
.
mode
].
files
[
state
.
mode
])
if
(
deletePath
)
delete
files
[
deletePath
]
return
{
[
state
.
mode
]:
files
}
return
{
[
state
.
mode
]:
files
}
}
else
{
}
else
{
let
files
=
state
.
localhost
.
files
let
files
=
state
.
localhost
.
files
...
@@ -321,6 +359,7 @@ const fetchDirectoryContent = (state: BrowserState, payload: { fileTree, path: s
...
@@ -321,6 +359,7 @@ const fetchDirectoryContent = (state: BrowserState, payload: { fileTree, path: s
const
prevFiles
=
_
.
get
(
files
,
_path
)
const
prevFiles
=
_
.
get
(
files
,
_path
)
prevFiles
.
child
=
_
.
merge
(
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
),
prevFiles
.
child
)
prevFiles
.
child
=
_
.
merge
(
normalize
(
payload
.
fileTree
,
payload
.
path
,
payload
.
type
),
prevFiles
.
child
)
if
(
deletePath
)
delete
prevFiles
.
child
[
deletePath
]
files
=
_
.
set
(
files
,
_path
,
prevFiles
)
files
=
_
.
set
(
files
,
_path
,
prevFiles
)
return
files
return
files
}
}
...
@@ -376,75 +415,8 @@ const normalize = (filesList, directory?: string, newInputType?: 'folder' | 'fil
...
@@ -376,75 +415,8 @@ const normalize = (filesList, directory?: string, newInputType?: 'folder' | 'fil
return
Object
.
assign
({},
folders
,
files
)
return
Object
.
assign
({},
folders
,
files
)
}
}
const
fileAdded
=
(
state
:
BrowserState
,
path
:
string
):
{
[
x
:
string
]:
Record
<
string
,
File
>
}
=>
{
let
files
=
state
.
mode
===
'browser'
?
state
.
browser
.
files
:
state
.
localhost
.
files
const
_path
=
splitPath
(
state
,
path
)
files
=
_
.
set
(
files
,
_path
,
null
)
return
files
}
const
folderAdded
=
(
state
:
BrowserState
,
path
:
string
):
{
[
x
:
string
]:
Record
<
string
,
File
>
}
=>
{
let
files
=
state
.
mode
===
'browser'
?
state
.
browser
.
files
:
state
.
localhost
.
files
const
_path
=
splitPath
(
state
,
path
)
files
=
_
.
set
(
files
,
_path
,
null
)
return
files
}
const
fileRemoved
=
(
state
:
BrowserState
,
path
:
string
):
{
[
x
:
string
]:
Record
<
string
,
File
>
}
=>
{
let
files
=
state
.
mode
===
'browser'
?
state
.
browser
.
files
:
state
.
localhost
.
files
const
_path
=
splitPath
(
state
,
path
)
// files = _.unset(files, _path)
return
files
}
const
removeInputField
=
(
state
:
BrowserState
,
payload
:
{
path
:
string
,
fileTree
})
=>
{
if
(
state
.
mode
===
'browser'
)
{
if
(
payload
.
path
===
state
.
browser
.
currentWorkspace
)
{
const
files
=
state
.
browser
.
files
delete
files
[
state
.
browser
.
currentWorkspace
][
payload
.
path
+
'/'
+
'blank'
]
return
files
}
return
fetchDirectoryContent
(
state
,
payload
)
}
else
{
if
(
payload
.
path
===
state
.
mode
)
{
const
files
=
state
[
state
.
mode
].
files
delete
files
[
state
.
mode
][
payload
.
path
+
'/'
+
'blank'
]
return
files
}
return
fetchDirectoryContent
(
state
,
payload
)
}
}
// IDEA: pass new parameter to fetchDirectoryContent for delete Path option.
const
removePath
=
(
state
:
BrowserState
,
path
:
string
,
pathName
,
files
)
=>
{
const
pathArr
:
string
[]
=
path
.
split
(
'/'
).
filter
(
value
=>
value
)
if
(
pathArr
[
0
]
!==
root
)
pathArr
.
unshift
(
root
)
const
_path
=
pathArr
.
map
((
key
,
index
)
=>
index
>
1
?
[
'child'
,
key
]
:
key
).
reduce
((
acc
:
string
[],
cur
)
=>
{
return
Array
.
isArray
(
cur
)
?
[...
acc
,
...
cur
]
:
[...
acc
,
cur
]
},
[])
const
prevFiles
=
_
.
get
(
files
,
_path
)
if
(
prevFiles
)
{
prevFiles
.
child
&&
prevFiles
.
child
[
pathName
]
&&
delete
prevFiles
.
child
[
pathName
]
files
=
_
.
set
(
files
,
_path
,
{
isDirectory
:
true
,
path
,
name
:
extractNameFromKey
(
path
).
indexOf
(
'gist-'
)
===
0
?
extractNameFromKey
(
path
).
split
(
'-'
)[
1
]
:
extractNameFromKey
(
path
),
type
:
extractNameFromKey
(
path
).
indexOf
(
'gist-'
)
===
0
?
'gist'
:
'folder'
,
child
:
prevFiles
?
prevFiles
.
child
:
{}
})
}
return
files
}
const
splitPath
=
(
state
:
BrowserState
,
path
:
string
):
string
[]
|
string
=>
{
const
splitPath
=
(
state
:
BrowserState
,
path
:
string
):
string
[]
|
string
=>
{
const
root
=
state
.
mode
===
'browser'
?
state
.
browser
.
currentWorkspace
:
'localhost'
const
root
=
state
.
mode
===
'browser'
?
state
.
browser
.
currentWorkspace
:
'localhost'
const
pathArr
:
string
[]
=
path
.
split
(
'/'
).
filter
(
value
=>
value
)
const
pathArr
:
string
[]
=
path
.
split
(
'/'
).
filter
(
value
=>
value
)
if
(
pathArr
[
0
]
!==
root
)
pathArr
.
unshift
(
root
)
if
(
pathArr
[
0
]
!==
root
)
pathArr
.
unshift
(
root
)
...
...
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