Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 9549068

Browse files
authored
Tweaked FileBrowserContentPanel to allow better setting of nesting directory (#9444)
In the studio, we want to let people go to other projects through the file browser, while in other situations we do not want to let them go above the level they start at, e.g. projects/<projectName> or /recordings/<recordingID>. Added a new prop to the panel component to optionally set a nesting directory. Tweaked the breadcrumbs logic to not show anything higher than the nesting directory.
1 parent 42b4bb5 commit 9549068

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

packages/client-core/src/admin/components/Project/ProjectFilesDrawer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const ProjectFilesDrawer = ({ open, selectedProject, onClose }: Props) => {
6666
disableDnD
6767
selectedFile={selectedProject.name}
6868
onSelectionChanged={onSelectionChanged}
69+
nestingDirectory={selectedProject.name}
6970
/>
7071
</Box>
7172
<Box sx={{ flexGrow: 1 }}>

packages/client-core/src/admin/components/Recordings/RecordingsDrawer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const RecordingFilesDrawer = ({ open, onClose, selectedRecordingId }: Props) =>
7373
selectedFile={selectedRecordingId}
7474
onSelectionChanged={onSelectionChanged}
7575
folderName="recordings"
76+
nestingDirectory={selectedRecordingId}
7677
/>
7778
)}
7879
</Box>

packages/editor/src/components/assets/FileBrowserContentPanel.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type FileBrowserContentPanelProps = {
119119
disableDnD?: boolean
120120
selectedFile?: string
121121
folderName?: string
122+
nestingDirectory?: string
122123
}
123124

124125
type DnDFileType = {
@@ -153,7 +154,7 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (props)
153154

154155
const originalPath = `/${props.folderName || 'projects'}/${props.selectedFile ? props.selectedFile + '/' : ''}`
155156
const selectedDirectory = useHookstate(originalPath)
156-
const nestingDirectory = useHookstate('projects')
157+
const nestingDirectory = useHookstate(props.nestingDirectory || 'projects')
157158
const fileProperties = useHookstate<FileType | null>(null)
158159
const isLoading = useHookstate(true)
159160

@@ -196,10 +197,6 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (props)
196197
refreshDirectory()
197198
}, [selectedDirectory, activeScene])
198199

199-
useEffect(() => {
200-
FileBrowserService.getNestingDirectory().then((directory) => nestingDirectory.set(directory))
201-
}, [])
202-
203200
const refreshDirectory = async () => {
204201
await FileBrowserService.fetchFiles(selectedDirectory.value, page)
205202
}
@@ -359,17 +356,13 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (props)
359356
}
360357
changeDirectoryByPath(newPath)
361358
}
359+
let breadcrumbDirectoryFiles = selectedDirectory.value.slice(1, -1).split('/')
362360

363-
let nestingDirectoryFiles = nestingDirectory.value.split('/')
364-
let breadcrumbDirectoryFiles = selectedDirectory.value
365-
.slice(1, -1)
366-
.split('/')
367-
.filter((file, idx) => {
368-
if (idx < nestingDirectoryFiles.length && file === nestingDirectoryFiles[idx]) {
369-
return false
370-
}
371-
return true
372-
})
361+
const nestedIndex = breadcrumbDirectoryFiles.indexOf(nestingDirectory.value)
362+
363+
breadcrumbDirectoryFiles = breadcrumbDirectoryFiles.filter((file, idx) => {
364+
return idx >= nestedIndex
365+
})
373366

374367
return (
375368
<Breadcrumbs

0 commit comments

Comments
 (0)