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
7033c200
Commit
7033c200
authored
Apr 24, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed file/folder removed bug
parent
7deedbad
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
33 deletions
+47
-33
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
+7
-17
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+7
-4
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
+33
-12
No files found.
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
View file @
7033c200
...
@@ -165,10 +165,10 @@ export const folderAddedSuccess = (path: string, files) => {
...
@@ -165,10 +165,10 @@ export const folderAddedSuccess = (path: string, files) => {
}
}
}
}
export
const
fileRemovedSuccess
=
(
path
:
string
,
removePath
:
string
,
files
)
=>
{
export
const
fileRemovedSuccess
=
(
path
:
string
,
removePath
:
string
)
=>
{
return
{
return
{
type
:
'FILE_REMOVED'
,
type
:
'FILE_REMOVED'
,
payload
:
{
path
,
removePath
,
files
}
payload
:
{
path
,
removePath
}
}
}
}
}
...
@@ -184,15 +184,12 @@ export const setProvider = (provider, workspaceName) => (dispatch: React.Dispatc
...
@@ -184,15 +184,12 @@ export const setProvider = (provider, workspaceName) => (dispatch: React.Dispatc
const
path
=
extractParentFromKey
(
folderPath
)
||
workspaceName
const
path
=
extractParentFromKey
(
folderPath
)
||
workspaceName
const
data
=
await
fetchDirectoryContent
(
provider
,
path
)
const
data
=
await
fetchDirectoryContent
(
provider
,
path
)
console
.
log
(
'data: '
,
data
)
dispatch
(
folderAddedSuccess
(
path
,
data
))
dispatch
(
folderAddedSuccess
(
path
,
data
))
})
})
provider
.
event
.
register
(
'fileRemoved'
,
async
(
removePath
)
=>
{
provider
.
event
.
register
(
'fileRemoved'
,
async
(
removePath
)
=>
{
const
path
=
extractParentFromKey
(
removePath
)
||
workspaceName
const
path
=
extractParentFromKey
(
removePath
)
||
workspaceName
const
data
=
await
fetchDirectoryContent
(
provider
,
path
)
dispatch
(
fileRemovedSuccess
(
path
,
removePath
,
data
))
dispatch
(
fileRemovedSuccess
(
path
,
removePath
))
})
})
provider
.
event
.
register
(
'fileRenamed'
,
async
()
=>
{
provider
.
event
.
register
(
'fileRenamed'
,
async
()
=>
{
...
@@ -229,20 +226,13 @@ export const addInputField = (provider, type: string, path: string) => (dispatch
...
@@ -229,20 +226,13 @@ export const addInputField = (provider, type: string, path: string) => (dispatch
return
promise
return
promise
}
}
export
const
removeInputFieldSuccess
=
(
path
:
string
,
files
:
File
[]
)
=>
{
export
const
removeInputFieldSuccess
=
(
path
:
string
)
=>
{
return
{
return
{
type
:
'REMOVE_INPUT_FIELD'
,
type
:
'REMOVE_INPUT_FIELD'
,
payload
:
{
path
,
files
}
payload
:
{
path
}
}
}
}
}
export
const
removeInputField
=
(
provider
,
path
:
string
)
=>
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
export
const
removeInputField
=
(
path
:
string
)
=>
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
const
promise
=
fetchDirectoryContent
(
provider
,
path
)
return
dispatch
(
removeInputFieldSuccess
(
path
))
promise
.
then
((
files
)
=>
{
dispatch
(
removeInputFieldSuccess
(
path
,
files
))
}).
catch
((
error
)
=>
{
console
.
error
(
error
)
})
return
promise
}
}
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
7033c200
...
@@ -654,7 +654,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -654,7 +654,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
if
(
!
content
||
(
content
.
trim
()
===
''
))
{
if
(
!
content
||
(
content
.
trim
()
===
''
))
{
if
(
state
.
focusEdit
.
isNew
)
{
if
(
state
.
focusEdit
.
isNew
)
{
removeInputField
(
fileSystem
.
provider
.
provider
,
parentFolder
)(
dispatch
)
removeInputField
(
parentFolder
)(
dispatch
)
setState
(
prevState
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
focusEdit
:
{
element
:
null
,
isNew
:
false
,
type
:
''
,
lastEdit
:
''
}
}
return
{
...
prevState
,
focusEdit
:
{
element
:
null
,
isNew
:
false
,
type
:
''
,
lastEdit
:
''
}
}
})
})
...
@@ -679,7 +679,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -679,7 +679,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
else
{
}
else
{
if
(
state
.
focusEdit
.
isNew
)
{
if
(
state
.
focusEdit
.
isNew
)
{
state
.
focusEdit
.
type
===
'file'
?
createNewFile
(
joinPath
(
parentFolder
,
content
))
:
createNewFolder
(
joinPath
(
parentFolder
,
content
))
state
.
focusEdit
.
type
===
'file'
?
createNewFile
(
joinPath
(
parentFolder
,
content
))
:
createNewFolder
(
joinPath
(
parentFolder
,
content
))
removeInputField
(
fileSystem
.
provider
.
provider
,
parentFolder
)(
dispatch
)
removeInputField
(
parentFolder
)(
dispatch
)
}
else
{
}
else
{
const
oldPath
:
string
=
state
.
focusEdit
.
element
const
oldPath
:
string
=
state
.
focusEdit
.
element
// const oldName = extractNameFromKey(oldPath)
// const oldName = extractNameFromKey(oldPath)
...
@@ -768,6 +768,9 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -768,6 +768,9 @@ export const FileExplorer = (props: FileExplorerProps) => {
?
'bg-light border'
:
(
state
.
focusContext
.
element
===
file
.
path
)
&&
(
state
.
focusEdit
.
element
!==
file
.
path
)
?
'bg-light border'
:
(
state
.
focusContext
.
element
===
file
.
path
)
&&
(
state
.
focusEdit
.
element
!==
file
.
path
)
?
'bg-light border'
:
''
?
'bg-light border'
:
''
const
icon
=
helper
.
getPathIcon
(
file
.
path
)
const
icon
=
helper
.
getPathIcon
(
file
.
path
)
const
spreadProps
=
{
onClick
:
(
e
)
=>
e
.
stopPropagation
()
}
if
(
file
.
isDirectory
)
{
if
(
file
.
isDirectory
)
{
return
(
return
(
...
@@ -799,12 +802,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -799,12 +802,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
}
}
>
>
{
{
file
.
child
?
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
`treeView${file.path}`
}
>
{
file
.
child
?
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
`treeView${file.path}`
}
{
...
spreadProps
}
>
{
Object
.
keys
(
file
.
child
).
map
((
key
,
index
)
=>
{
Object
.
keys
(
file
.
child
).
map
((
key
,
index
)
=>
{
return
renderFiles
(
file
.
child
[
key
],
index
)
return
renderFiles
(
file
.
child
[
key
],
index
)
})
})
}
}
</
TreeView
>
:
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
`treeView${file.path}`
}
/>
</
TreeView
>
:
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
`treeView${file.path}`
}
{
...
spreadProps
}
/>
}
}
</
TreeViewItem
>
</
TreeViewItem
>
)
)
...
...
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
View file @
7033c200
...
@@ -153,7 +153,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
...
@@ -153,7 +153,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
...
state
,
...
state
,
files
:
{
files
:
{
...
state
.
files
,
...
state
.
files
,
files
:
removeInputField
(
state
.
files
.
workspaceName
,
state
.
files
.
blankPath
,
state
.
files
.
files
,
action
.
payload
.
files
),
files
:
removeInputField
(
state
.
files
.
workspaceName
,
state
.
files
.
blankPath
,
state
.
files
.
files
),
blankPath
:
null
,
blankPath
:
null
,
isRequesting
:
false
,
isRequesting
:
false
,
isSuccessful
:
true
,
isSuccessful
:
true
,
...
@@ -190,7 +190,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
...
@@ -190,7 +190,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
...
state
,
...
state
,
files
:
{
files
:
{
...
state
.
files
,
...
state
.
files
,
files
:
fileRemoved
(
state
.
files
.
workspaceName
,
action
.
payload
.
path
,
action
.
payload
.
removePath
,
state
.
files
.
files
,
action
.
payload
.
files
),
files
:
fileRemoved
(
state
.
files
.
workspaceName
,
action
.
payload
.
path
,
action
.
payload
.
removePath
,
state
.
files
.
files
),
isRequesting
:
false
,
isRequesting
:
false
,
isSuccessful
:
true
,
isSuccessful
:
true
,
error
:
null
error
:
null
...
@@ -211,29 +211,51 @@ const resolveDirectory = (root, path: string, files, content) => {
...
@@ -211,29 +211,51 @@ const resolveDirectory = (root, path: string, files, content) => {
return
Array
.
isArray
(
cur
)
?
[...
acc
,
...
cur
]
:
[...
acc
,
cur
]
return
Array
.
isArray
(
cur
)
?
[...
acc
,
...
cur
]
:
[...
acc
,
cur
]
},
[])
},
[])
const
prevFiles
=
_
.
get
(
files
,
_path
)
files
=
_
.
set
(
files
,
_path
,
{
isDirectory
:
true
,
path
,
name
:
extractNameFromKey
(
path
),
child
:
{
...
content
[
pathArr
[
pathArr
.
length
-
1
]],
...
prevFiles
.
child
}
})
return
files
}
const
removePath
=
(
root
,
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
)
pathName
&&
delete
prevFiles
.
child
[
pathName
]
files
=
_
.
set
(
files
,
_path
,
{
files
=
_
.
set
(
files
,
_path
,
{
isDirectory
:
true
,
isDirectory
:
true
,
path
,
path
,
name
:
extractNameFromKey
(
path
),
name
:
extractNameFromKey
(
path
),
child
:
{
...
content
[
pathArr
[
pathArr
.
length
-
1
]]
}
child
:
prevFiles
.
child
})
})
return
files
return
files
}
}
const
addInputField
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
const
addInputField
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
if
(
Object
.
keys
(
content
)[
0
]
===
root
)
return
{
[
Object
.
keys
(
content
)[
0
]]:
{
...
content
[
Object
.
keys
(
content
)[
0
]],
...
files
[
Object
.
keys
(
content
)[
0
]
]
}
}
if
(
path
===
root
)
return
{
[
root
]:
{
...
content
[
root
],
...
files
[
root
]
}
}
const
result
=
resolveDirectory
(
root
,
path
,
files
,
content
)
const
result
=
resolveDirectory
(
root
,
path
,
files
,
content
)
return
result
return
result
}
}
const
removeInputField
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
const
removeInputField
=
(
root
,
path
:
string
,
files
)
=>
{
if
(
Object
.
keys
(
content
)[
0
]
===
root
)
{
if
(
path
===
root
)
{
delete
files
[
root
][
path
+
'/'
+
'blank'
]
delete
files
[
root
][
path
+
'/'
+
'blank'
]
return
files
return
files
}
}
return
re
solveDirectory
(
root
,
path
,
files
,
content
)
return
re
movePath
(
root
,
path
,
path
+
'/'
+
'blank'
,
files
)
}
}
const
fileAdded
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
const
fileAdded
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
...
@@ -244,12 +266,11 @@ const folderAdded = (root, path: string, files, content) => {
...
@@ -244,12 +266,11 @@ const folderAdded = (root, path: string, files, content) => {
return
resolveDirectory
(
root
,
path
,
files
,
content
)
return
resolveDirectory
(
root
,
path
,
files
,
content
)
}
}
const
fileRemoved
=
(
root
,
path
:
string
,
removedPath
:
string
,
files
,
content
)
=>
{
const
fileRemoved
=
(
root
,
path
:
string
,
removedPath
:
string
,
files
)
=>
{
if
(
path
===
root
)
{
if
(
path
===
root
)
{
const
allFiles
=
{
[
root
]:
{
...
content
[
root
],
...
files
[
root
]
}
}
delete
files
[
root
][
removedPath
]
delete
allFiles
[
root
][
removedPath
]
return
files
return
allFiles
}
}
return
re
solveDirectory
(
root
,
path
,
files
,
content
)
return
re
movePath
(
root
,
path
,
extractNameFromKey
(
removedPath
),
files
)
}
}
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