Skip to content

Commit

Permalink
- Disables import of multiple assets for one feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sophia-massie committed Feb 14, 2025
1 parent cece066 commit eac0164
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
9 changes: 3 additions & 6 deletions react/src/components/AssetDetail/AssetButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ const AssetButton: React.FC<AssetButtonProps> = ({
/* Uncomment when WG-422 polling is merged
const notification = useNotification();*/
const featureId = selectedFeature.id;
const {
mutate: importFeatureAsset,
isPending: isImporting,
isSuccess: isImportingSuccess,
} = useImportFeatureAsset(projectId, featureId);
const { mutate: importFeatureAsset, isPending: isImporting } =
useImportFeatureAsset(projectId, featureId);

const handleSubmit = (files: TapisFilePath[]) => {
for (const file of files) {
Expand Down Expand Up @@ -82,7 +79,7 @@ const AssetButton: React.FC<AssetButtonProps> = ({
type="primary"
onClick={() => setIsModalOpen(true)}
isLoading={isImporting}
disabled={isImportingSuccess}
disabled={isImporting}
>
Add Asset from DesignSafe
</Button>
Expand Down
27 changes: 25 additions & 2 deletions react/src/components/FileBrowserModal/FileBrowserModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState } from 'react';
import React, { useState, useMemo } from 'react';
import { Modal, Button, Layout, Typography } from 'antd';
import { FileListing } from '../Files';
import { File, TapisFilePath } from '@hazmapper/types';
import { convertFilesToTapisPaths } from '@hazmapper/utils/fileUtils';
import { IMPORTABLE_FEATURE_ASSET_TYPES } from '@hazmapper/utils/fileUtils';
import { SectionMessage } from '@tacc/core-components';

type FileBrowserModalProps = {
isOpen: boolean;
Expand All @@ -21,6 +23,15 @@ const FileBrowserModal = ({
allowedFileExtensions = [],
}: FileBrowserModalProps) => {
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
const [isMultiSelectError, setIsMultiSelectError] = useState<boolean>(false);

Check failure on line 26 in react/src/components/FileBrowserModal/FileBrowserModal.tsx

View workflow job for this annotation

GitHub Actions / React-Linting

'isMultiSelectError' is assigned a value but never used
const isSingleSelectMode = useMemo(() => {
return (
JSON.stringify(allowedFileExtensions.sort()) ===
JSON.stringify(IMPORTABLE_FEATURE_ASSET_TYPES.sort())
);
}, [allowedFileExtensions]);

console.log(isSingleSelectMode);

const handleClose = () => {
parentToggle();
Expand All @@ -31,6 +42,10 @@ const FileBrowserModal = ({
};

const handleImport = () => {
setIsMultiSelectError(false);
if (isSingleSelectMode && selectedFiles.length > 1) {
setIsMultiSelectError(true);
}
if (onImported) {
const tapisFilePaths = convertFilesToTapisPaths(selectedFiles);
onImported(tapisFilePaths);
Expand All @@ -45,6 +60,11 @@ const FileBrowserModal = ({
onCancel={handleClose}
footer={[
<Text key="fileCount" type="secondary" style={{ marginRight: 16 }}>
{isSingleSelectMode && selectedFiles.length > 1 && (
<SectionMessage type="error">
Adding multiple asset to a feature is not supported.
</SectionMessage>
)}
{selectedFiles.length > 0 && `${selectedFiles.length} files selected`}
</Text>,
<Button key="closeModalButton" onClick={handleClose}>
Expand All @@ -55,7 +75,10 @@ const FileBrowserModal = ({
htmlType="submit"
type="primary"
onClick={handleImport}
disabled={selectedFiles.length === 0} // Disable if no files are selected
disabled={
selectedFiles.length === 0 ||
(isSingleSelectMode && selectedFiles.length > 1)
} // Disable if no files are selected. If single select mode, disable if multiple files are selected
>
Import
</Button>,
Expand Down

0 comments on commit eac0164

Please sign in to comment.