Skip to content

Commit

Permalink
use system path util (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina authored Mar 3, 2025
1 parent 3b52c30 commit d423351
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
13 changes: 6 additions & 7 deletions react/src/components/CreateMapModal/CreateMapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
};
Expand Down
14 changes: 12 additions & 2 deletions react/src/components/ManageMapProjectPanel/SaveTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +21,7 @@ const SaveTabContent: React.FC<SaveTabProps> = ({ project }) => {
isLoading,
error,
} = useDesignSafeProjects();
const { data: userData } = useAuthenticatedUser();
const dsDataDepotUrl = `${config.designsafePortalUrl}/data/browser/`;
const dsProj = designSafeProjects?.result?.find(
(ds_project) =>
Expand Down Expand Up @@ -79,7 +85,11 @@ const SaveTabContent: React.FC<SaveTabProps> = ({ project }) => {
rel="noreferrer"
style={{ padding: 0 }}
>
{project.system_path}
{renderFilePathLabel(
project.system_path,
userData?.username || '',
project.system_id
)}
</Button>
</>
}
Expand Down
10 changes: 10 additions & 0 deletions react/src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,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/');
};

0 comments on commit d423351

Please sign in to comment.