Skip to content

Commit ebe5938

Browse files
committed
Merge branch '492-console-wide-account' of github.com:eth-cscs/firecrest-ui into 492-console-wide-account
2 parents be11632 + 922fff9 commit ebe5938

File tree

7 files changed

+114
-284
lines changed

7 files changed

+114
-284
lines changed

app/modules/filesystem/components/dialogs/DownloadDialog.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { postLocalTransferDownload } from '~/apis/filesystem-api'
2222
interface DownloadDialogProps {
2323
system: string
2424
file: File
25+
accountName: string
2526
currentPath?: string
2627
open: boolean
2728
onClose: () => void
@@ -30,6 +31,7 @@ interface DownloadDialogProps {
3031
const DownloadDialog: React.FC<DownloadDialogProps> = ({
3132
system,
3233
file,
34+
accountName,
3335
currentPath = undefined,
3436
open,
3537
onClose,
@@ -40,7 +42,7 @@ const DownloadDialog: React.FC<DownloadDialogProps> = ({
4042
const [downloadError, setDownloadError] = useState<string | null>(null)
4143
const [loading, setLoading] = useState<boolean>(false)
4244
const [formValues, setFormValues] = useState({
43-
account: '',
45+
account: accountName,
4446
})
4547

4648
useEffect(() => {
@@ -105,8 +107,10 @@ const DownloadDialog: React.FC<DownloadDialogProps> = ({
105107
<input
106108
type='text'
107109
name='account'
110+
value={formValues.account}
108111
onChange={(e) => setFormValues({ ...formValues, account: e.target.value })}
109-
className='flex-1 border-gray-300 focus:border-blue-300 focus:ring-blue-300 rounded-md border py-2 px-3 shadow-sm sm:text-sm focus:outline-none'
112+
disabled
113+
className='flex-1 border-gray-300 focus:border-blue-300 focus:ring-blue-300 rounded-md border py-2 px-3 shadow-sm sm:text-sm focus:outline-none disabled:bg-gray-100 disabled:text-gray-500 disabled:cursor-not-allowed'
110114
/>
111115
</div>
112116
)}

app/modules/filesystem/components/views/FileListView.tsx

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import {
2626
buildFileSystemSelection,
2727
buildFileSystemSelectionPath,
2828
splitFileSystemSelection,
29-
buildFileSystemNavigationPath,
3029
buildBreadcrumbNavigation,
30+
buildFileSystemNavigationPath,
3131
} from '~/modules/filesystem/helpers/filesystem-helper'
3232
import { formatDateTime } from '~/helpers/date-helper'
3333
import { FileTableSortableColumn } from '~/helpers/ui-table-helper'
@@ -62,7 +62,6 @@ import LoadingButton from '~/components/buttons/LoadingButton'
6262
import SimplePanel from '~/components/panels/SimplePanel'
6363
// views
6464
import SimpleView, { SimpleViewSize } from '~/components/views/SimpleView'
65-
import { showInputValidation } from '~/components/forms/validations/ValidationForm'
6665

6766
const copyToClipboard = (file: File, fileSystem: FileSystem) => {
6867
const path = `${fileSystem.path}/${file.name}`
@@ -74,9 +73,16 @@ interface FileItemProps {
7473
currentPath: string
7574
fileSystem: FileSystem
7675
system: System
76+
accountName: string
7777
}
7878

79-
const FileItem: React.FC<FileItemProps> = ({ file, currentPath, fileSystem, system }) => {
79+
const FileItem: React.FC<FileItemProps> = ({
80+
file,
81+
currentPath,
82+
fileSystem,
83+
system,
84+
accountName,
85+
}) => {
8086
const [changeOwnershipDialogOpen, setChangeOwnershipDialogOpen] = useState(false)
8187
const [changePermissionDialogDialogOpen, setChangePermissionDialogDialogOpen] = useState(false)
8288
const [checksumDialogOpen, setChecksumDialogOpen] = useState(false)
@@ -148,6 +154,7 @@ const FileItem: React.FC<FileItemProps> = ({ file, currentPath, fileSystem, syst
148154
system={system.name}
149155
file={file}
150156
currentPath={currentPath}
157+
accountName={accountName}
151158
open={downloadkDialogOpen}
152159
onClose={() => setDownloadDialogOpen(false)}
153160
/>
@@ -303,9 +310,16 @@ interface DirectoryItemProps {
303310
currentPath: string
304311
fileSystem: FileSystem
305312
system: System
313+
accountName: string
306314
}
307315

308-
const DirectoryItem: React.FC<DirectoryItemProps> = ({ file, currentPath, fileSystem, system }) => {
316+
const DirectoryItem: React.FC<DirectoryItemProps> = ({
317+
file,
318+
currentPath,
319+
fileSystem,
320+
system,
321+
accountName,
322+
}) => {
309323
const [changeOwnershipDialogOpen, setChangeOwnershipDialogOpen] = useState(false)
310324
const [changePermissionDialogDialogOpen, setChangePermissionDialogDialogOpen] = useState(false)
311325
const [copyDialogOpen, setCopyDialogOpen] = useState(false)
@@ -316,7 +330,7 @@ const DirectoryItem: React.FC<DirectoryItemProps> = ({ file, currentPath, fileSy
316330
const [removeDialogOpen, setRemoveDialogOpen] = useState(false)
317331
const { name } = file
318332

319-
const navigationPath = buildFileSystemNavigationPath(system.name, currentPath, name)
333+
const navigationPath = buildFileSystemNavigationPath(system.name, currentPath, accountName, name)
320334
return (
321335
<tr className='even:bg-blue-50'>
322336
<td className='px-4 py-3 font-medium'>
@@ -493,14 +507,21 @@ interface BreadcrumbNavigationProps {
493507
currentPath: string
494508
system: System
495509
fileSystem: FileSystem
510+
accountName: string
496511
}
497512

498513
const BreadcrumbNavigation: React.FC<BreadcrumbNavigationProps> = ({
499514
currentPath,
500515
system,
501516
fileSystem,
517+
accountName,
502518
}) => {
503-
const navigationData = buildBreadcrumbNavigation(currentPath, fileSystem.path, system.name)
519+
const navigationData = buildBreadcrumbNavigation(
520+
currentPath,
521+
fileSystem.path,
522+
system.name,
523+
accountName,
524+
)
504525
return (
505526
<>
506527
<nav className='flex rounded-md p-2 mb-4 border border-gray-200' aria-label='Breadcrumb'>
@@ -540,6 +561,7 @@ interface FileSystemSelectionData {
540561
system: System
541562
systems: System[]
542563
username: string
564+
accountName: string
543565
}
544566

545567
const FileSystemSelection: React.FC<FileSystemSelectionData> = ({
@@ -548,11 +570,12 @@ const FileSystemSelection: React.FC<FileSystemSelectionData> = ({
548570
system,
549571
systems,
550572
username,
573+
accountName,
551574
}) => {
552575
const onChangeHandler = (event: any) => {
553576
const selectedValue = event.target.value
554577
const { systemName, fileSystemPath } = splitFileSystemSelection(selectedValue)
555-
const newNavigationPath = buildFileSystemNavigationPath(systemName, fileSystemPath)
578+
const newNavigationPath = buildFileSystemNavigationPath(systemName, fileSystemPath, accountName)
556579
window.location.href = newNavigationPath
557580
}
558581

@@ -618,13 +641,15 @@ interface FileListTableProps {
618641
currentPath: string
619642
fileSystem: FileSystem
620643
system: System
644+
accountName: string
621645
}
622646

623647
const FileListTable: React.FC<FileListTableProps> = ({
624648
files,
625649
currentPath,
626650
fileSystem,
627651
system,
652+
accountName,
628653
}) => {
629654
const [sortableColumns, setSortableColumns] = useState<FileTableSortableColumn[]>([])
630655
const [fileSystemList, setFileSystemList] = useState<any[]>([])
@@ -655,6 +680,7 @@ const FileListTable: React.FC<FileListTableProps> = ({
655680
currentPath={currentPath}
656681
fileSystem={fileSystem}
657682
system={system}
683+
accountName={accountName}
658684
/>
659685
) : (
660686
<FileItem
@@ -663,6 +689,7 @@ const FileListTable: React.FC<FileListTableProps> = ({
663689
currentPath={currentPath}
664690
fileSystem={fileSystem}
665691
system={system}
692+
accountName={accountName}
666693
/>
667694
),
668695
)}
@@ -687,7 +714,7 @@ const FileTransferInfo: React.FC<any> = ({ file, uploadLimit }) => {
687714
}
688715

689716
// TODO: Code refactoring and improvements (remove duplication, create ad-hoc components, ...)
690-
const FileUpload: React.FC<any> = ({ system, currentPath, fileUploadLimit }) => {
717+
const FileUpload: React.FC<any> = ({ system, currentPath, fileUploadLimit, accountName }) => {
691718
const [uploading, setUploading] = useState(false)
692719
const [fileToUploadSelected, setFileToUploadSelected] = useState<any | null>(null)
693720
const [fileTransferUploadResult, setFileTransferUploadResult] = useState<any | null>(null)
@@ -696,7 +723,7 @@ const FileUpload: React.FC<any> = ({ system, currentPath, fileUploadLimit }) =>
696723
const [uploadError, setUploadError] = useState<HttpErrorResponse | null>(null)
697724
const singleDraggableFileUploadRef = useRef<any>(null)
698725
const [formValues, setFormValues] = useState({
699-
account: '',
726+
account: accountName,
700727
})
701728

702729
const isFileSizeOk = (file: any) => {
@@ -805,8 +832,9 @@ const FileUpload: React.FC<any> = ({ system, currentPath, fileUploadLimit }) =>
805832
type='text'
806833
name='account'
807834
value={formValues.account}
835+
disabled
808836
onChange={(e) => setFormValues({ ...formValues, account: e.target.value })}
809-
className='border-gray-300 focus:border-blue-300 focus:ring-blue-300 mt-1 block w-full rounded-md border py-2 px-3 shadow-sm sm:text-sm focus:outline-none'
837+
className='border-gray-300 focus:border-blue-300 focus:ring-blue-300 mt-1 block w-full rounded-md border py-2 px-3 shadow-sm sm:text-sm focus:outline-none disabled:bg-gray-100 disabled:text-gray-500 disabled:cursor-not-allowed'
810838
/>
811839
{/* {showInputValidation({
812840
fieldName: 'name',
@@ -895,6 +923,8 @@ const FileListView: React.FC<FileListViewProps> = ({
895923
</div>
896924
)
897925

926+
console.log('Account Name:', accountName)
927+
898928
return (
899929
<SimpleView title='File Manager' size={SimpleViewSize.FULL}>
900930
<SimplePanel title={'Filesystem'} className='mb-[330px]' actionsButtons={actionsButtons}>
@@ -912,19 +942,22 @@ const FileListView: React.FC<FileListViewProps> = ({
912942
system={system}
913943
systems={systems}
914944
username={username}
945+
accountName={accountName}
915946
/>
916947
</div>
917948
<BreadcrumbNavigation
918949
currentPath={currentPath}
919950
system={system}
920951
fileSystem={fileSystem}
952+
accountName={accountName}
921953
/>
922954
{remoteFsError == null && (
923955
<FileUpload
924956
system={system}
925957
currentPath={currentPath}
926958
setLocalError={setLocalError}
927959
fileUploadLimit={fileUploadLimit}
960+
accountName={accountName}
928961
/>
929962
)}
930963

@@ -937,6 +970,7 @@ const FileListView: React.FC<FileListViewProps> = ({
937970
currentPath={currentPath}
938971
fileSystem={fileSystem}
939972
system={system}
973+
accountName={accountName}
940974
/>
941975
)}
942976
{!fileList ||

app/modules/filesystem/helpers/filesystem-helper.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,20 @@ export const buildFileSystemSelectionPath = (fileSystem: FileSystem, username: s
3939
export const buildFileSystemNavigationPath = (
4040
systemName: string,
4141
currentPath: string,
42+
accountName: string,
4243
additionalPath: string | null = null,
4344
) => {
4445
if (additionalPath === null || _.isEmpty(additionalPath)) {
45-
return `/filesystems/${systemName}/?targetPath=${currentPath}`
46+
return `/filesystems/systems/${systemName}/accounts/${accountName}/?targetPath=${currentPath}`
4647
}
47-
return `/filesystems/${systemName}/?targetPath=${currentPath}/${additionalPath}`
48+
return `/filesystems/systems/${systemName}/accounts/${accountName}/?targetPath=${currentPath}/${additionalPath}`
4849
}
4950

5051
export const buildBreadcrumbNavigation = (
5152
currentPath: string,
5253
fileSystemPath: string,
5354
systemName: string,
55+
accountName: string,
5456
) => {
5557
if (!currentPath || currentPath.trim() === '') {
5658
return []
@@ -64,7 +66,7 @@ export const buildBreadcrumbNavigation = (
6466
dirName: pathSegment,
6567
path: path,
6668
isBasePath: path === fileSystemPath,
67-
navUrl: buildFileSystemNavigationPath(systemName, path),
69+
navUrl: buildFileSystemNavigationPath(systemName, path, accountName),
6870
})
6971
})
7072
return navigationStructure

app/modules/status/helpers/system-helper.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,54 @@ import _ from 'lodash'
99
// types
1010
import { FileSystemDataType, FileSystem, System } from '~/types/api-status'
1111

12+
type ResolvedFileSystem = {
13+
fileSystem: FileSystem
14+
path: string
15+
}
16+
17+
export const getFileSystemByTargetPath = (
18+
system: System,
19+
targetPath: string | null | undefined,
20+
username: string,
21+
): ResolvedFileSystem => {
22+
if (!system) {
23+
throw new Error('Filesystem(s) configuration error: system is missing')
24+
}
25+
26+
// If no target path, resolve from default
27+
if (targetPath == null || _.isEmpty(targetPath)) {
28+
const fileSystem = getDefaultFileSystemFromSystem(system)
29+
30+
if (!fileSystem) {
31+
throw new Error('Filesystem(s) configuration error: no default filesystem')
32+
}
33+
34+
let path = fileSystem.path
35+
36+
if (fileSystem.defaultWorkDir) {
37+
path = `${fileSystem.path}/${username}`
38+
}
39+
40+
return { fileSystem, path }
41+
}
42+
43+
// If target path is provided, search in the system
44+
const fileSystem = searchFileSystemByPath(system.fileSystems, targetPath, false)
45+
46+
if (!fileSystem) {
47+
throw new Error(`Filesystem(s) configuration error: no filesystem for path "${targetPath}"`)
48+
}
49+
50+
return { fileSystem, path: targetPath }
51+
}
52+
1253
export const searchSystemByName = (systems: System[], name: string, defaultValue: any = null) => {
1354
const system = systems.find((system: System) => {
1455
return system.name == name
1556
})
1657
return system || defaultValue
1758
}
1859

19-
2060
export const searchFileSystemByPath = (
2161
fileSystems: FileSystem[],
2262
path: string,
@@ -47,14 +87,14 @@ export const getDefaultFileSystemFromSystem = (system: System | null) => {
4787
if (system === null) {
4888
return null
4989
}
50-
if (system.fileSystems.length == 0){
90+
if (system.fileSystems.length == 0) {
5191
return null
5292
}
5393
const fileSystem = system.fileSystems.find((fileSystem: FileSystem) => {
5494
return fileSystem.defaultWorkDir == true
5595
})
56-
if (fileSystem === null){
57-
return system.fileSystems[0]
96+
if (fileSystem === null) {
97+
return system.fileSystems[0]
5898
}
5999
return fileSystem
60100
}

0 commit comments

Comments
 (0)