Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task/WG-439, task/WG-437: Use system path util #338

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { 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 @@ -88,7 +89,7 @@
trigger('systemFile');
oldSystemFilename.current = systemFilename;
}
}, [getValues, mapName, setValue]);

Check warning on line 92 in react/src/components/CreateMapModal/CreateMapModal.tsx

View workflow job for this annotation

GitHub Actions / React-Linting

React Hook useEffect has a missing dependency: 'trigger'. Either include it or remove the dependency array

const handleClose = () => {
setErrorMessage('');
Expand All @@ -99,13 +100,11 @@

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/');
};
Loading