From 166445ec8675b4b5f05eac20f1fe9d2678b4b25d Mon Sep 17 00:00:00 2001 From: Sal Tijerina Date: Thu, 27 Feb 2025 15:30:11 -0600 Subject: [PATCH] use system path util --- .../components/CreateMapModal/CreateMapModal.tsx | 13 ++++++------- .../ManageMapProjectPanel/SaveTabContent.tsx | 14 ++++++++++++-- react/src/utils/fileUtils.ts | 10 ++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/react/src/components/CreateMapModal/CreateMapModal.tsx b/react/src/components/CreateMapModal/CreateMapModal.tsx index c726c23e..11896925 100644 --- a/react/src/components/CreateMapModal/CreateMapModal.tsx +++ b/react/src/components/CreateMapModal/CreateMapModal.tsx @@ -18,6 +18,7 @@ import { useAuthenticatedUser, useCreateProject } from '@hazmapper/hooks'; import { ProjectRequest } from '@hazmapper/types'; import { FileListing } from '@hazmapper/components/Files'; import { truncateMiddle } from '@hazmapper/utils/truncateMiddle'; +import { renderFilePathLabel } from '@hazmapper/utils/fileUtils'; import styles from './CreateMapModal.module.css'; type CreateMapModalProps = { @@ -99,13 +100,11 @@ const CreateMapModal = ({ isOpen, closeModal }: CreateMapModalProps) => { const handleDirectoryChange = (directory: string) => { const systemId = getValues('systemId'); - const saveLocationDisplay = - systemId === 'designsafe.storage.default' - ? directory.replace( - new RegExp(`^${userData?.username}(/)?`), - 'My Data/' - ) - : directory.replace(new RegExp(`^(/)?`), 'Project Root/'); + const saveLocationDisplay = renderFilePathLabel( + directory, + userData?.username || '', + systemId + ); setValue('saveLocationDisplay', saveLocationDisplay); setValue('systemPath', directory); }; diff --git a/react/src/components/ManageMapProjectPanel/SaveTabContent.tsx b/react/src/components/ManageMapProjectPanel/SaveTabContent.tsx index 2083cba6..c9360f19 100644 --- a/react/src/components/ManageMapProjectPanel/SaveTabContent.tsx +++ b/react/src/components/ManageMapProjectPanel/SaveTabContent.tsx @@ -2,7 +2,12 @@ import React, { useMemo } from 'react'; import { Project } from '@hazmapper/types'; import { List, Button } from 'antd'; import { LoadingSpinner, SectionMessage } from '@tacc/core-components'; -import { useAppConfiguration, useDesignSafeProjects } from '@hazmapper/hooks'; +import { + useAppConfiguration, + useDesignSafeProjects, + useAuthenticatedUser, +} from '@hazmapper/hooks'; +import { renderFilePathLabel } from '@hazmapper/utils/fileUtils'; interface SaveTabProps { project: Project; @@ -16,6 +21,7 @@ const SaveTabContent: React.FC = ({ project }) => { isLoading, error, } = useDesignSafeProjects(); + const { data: userData } = useAuthenticatedUser(); const dsDataDepotUrl = `${config.designsafePortalUrl}/data/browser/`; const dsProj = designSafeProjects?.result?.find( (ds_project) => @@ -79,7 +85,11 @@ const SaveTabContent: React.FC = ({ project }) => { rel="noreferrer" style={{ padding: 0 }} > - {project.system_path} + {renderFilePathLabel( + project.system_path, + userData?.username || '', + project.system_id + )} } diff --git a/react/src/utils/fileUtils.ts b/react/src/utils/fileUtils.ts index 5f0d9518..ad149368 100644 --- a/react/src/utils/fileUtils.ts +++ b/react/src/utils/fileUtils.ts @@ -59,3 +59,13 @@ export const convertFilesToTapisPaths = (files: File[]): TapisFilePath[] => { }; }); }; + +export const renderFilePathLabel = ( + path: string, + username: string, + systemId: string +) => { + return systemId === 'designsafe.storage.default' + ? path.replace(new RegExp(`^${username}(/)?`), 'My Data/') + : path.replace(new RegExp(`^(/)?`), 'Project Root/'); +};