Skip to content

Commit

Permalink
feat: CQDG-617 add tooltip on disable buttons on data explo (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulous authored Mar 7, 2024
1 parent 9c938ed commit f8abacf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 55 deletions.
23 changes: 13 additions & 10 deletions src/components/reports/DownloadClinicalDataDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import intl from 'react-intl-universal';
import { useDispatch } from 'react-redux';
import { DownloadOutlined } from '@ant-design/icons';
import { ISqonGroupFilter } from '@ferlab/ui/core/data/sqon/types';
import { Button, Dropdown } from 'antd';
import { Button, Dropdown, Tooltip } from 'antd';
import { INDEXES } from 'graphql/constants';
import { generateSelectionSqon } from 'views/DataExploration/utils/selectionSqon';

Expand All @@ -24,6 +24,7 @@ const DownloadClinicalDataDropdown = ({

const getCurrentSqon = (): any =>
sqon || generateSelectionSqon(INDEXES.PARTICIPANT, participantIds);
const isDisabled = !sqon?.content?.length && !participantIds.length;

const MenuProps = {
onClick: (e: { key: string }) =>
Expand All @@ -49,16 +50,18 @@ const DownloadClinicalDataDropdown = ({
};

return (
<Dropdown
key="actionDropdown"
disabled={!sqon?.content?.length && !participantIds.length}
menu={MenuProps}
placement="bottomLeft"
<Tooltip
title={intl.get('screen.dataExploration.youMustSelect')}
trigger={isDisabled ? 'hover' : 'none'}
>
<Button type={type} icon={<DownloadOutlined />}>
{intl.get('api.report.clinicalData.download')}
</Button>
</Dropdown>
{/** need a empty div below to show tooltip when Dropdown is disabled */}
<div />
<Dropdown disabled={isDisabled} key="actionDropdown" menu={MenuProps} placement="bottomLeft">
<Button type={type} icon={<DownloadOutlined />}>
{intl.get('api.report.clinicalData.download')}
</Button>
</Dropdown>
</Tooltip>
);
};

Expand Down
9 changes: 6 additions & 3 deletions src/components/reports/DownloadFileManifestModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import intl from 'react-intl-universal';
import { useDispatch } from 'react-redux';
import { DownloadOutlined } from '@ant-design/icons';
import { ISyntheticSqon } from '@ferlab/ui/core/data/sqon/types';
import { Button, Checkbox, Modal } from 'antd';
import { Button, Checkbox, Modal, Tooltip } from 'antd';

import TooMuchFilesAlert from 'components/reports/TooMuchFilesAlert';
import { ReportType } from 'services/api/reports/models';
Expand Down Expand Up @@ -34,7 +34,10 @@ const DownloadFileManifestModal = ({
const [isFamilyChecked, setIsFamilyChecked] = useState(false);

return (
<>
<Tooltip
title={intl.get('screen.dataExploration.youMustSelect')}
trigger={isDisabled ? 'hover' : 'none'}
>
<Button
icon={<DownloadOutlined />}
onClick={() => setIsModalVisible(true)}
Expand Down Expand Up @@ -76,7 +79,7 @@ const DownloadFileManifestModal = ({
{hasTooManyFiles && <TooMuchFilesAlert />}
{!hasTooManyFiles && isModalVisible && <FilesTable sqon={sqon} />}
</Modal>
</>
</Tooltip>
);
};

Expand Down
9 changes: 6 additions & 3 deletions src/components/reports/DownloadRequestAccessModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDispatch } from 'react-redux';
import { DownloadOutlined } from '@ant-design/icons';
import ExternalLink from '@ferlab/ui/core/components/ExternalLink';
import { ISyntheticSqon } from '@ferlab/ui/core/data/sqon/types';
import { Button, Checkbox, Modal } from 'antd';
import { Button, Checkbox, Modal, Tooltip } from 'antd';
import EnvVariables from 'helpers/EnvVariables';

import RestrictedStudyAlert from 'components/reports/RestrictedStudyAlert';
Expand Down Expand Up @@ -43,7 +43,10 @@ const DownloadRequestAccessModal = ({
)}/docs/faire-une-demande-daccès-aux-données-du-cqdg`;

return (
<>
<Tooltip
title={intl.get('screen.dataExploration.youMustSelect')}
trigger={isDisabled ? 'hover' : 'none'}
>
<Button
icon={<DownloadOutlined />}
onClick={() => setIsModalVisible(true)}
Expand Down Expand Up @@ -98,7 +101,7 @@ const DownloadRequestAccessModal = ({
{!withoutFiles && hasTooManyFiles && <TooMuchFilesAlert />}
{isRestricted && <RestrictedStudyAlert />}
</Modal>
</>
</Tooltip>
);
};

Expand Down
36 changes: 18 additions & 18 deletions src/components/reports/DownloadSamplelDataButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import intl from 'react-intl-universal';
import { useDispatch } from 'react-redux';
import { DownloadOutlined } from '@ant-design/icons';
import { ISqonGroupFilter } from '@ferlab/ui/core/data/sqon/types';
import { Button } from 'antd';
import { Button, Tooltip } from 'antd';
import { INDEXES } from 'graphql/constants';
import { generateSelectionSqon } from 'views/DataExploration/utils/selectionSqon';

Expand All @@ -19,26 +19,26 @@ const DownloadSampleDataButton = ({ sampleIds, sqon, type = 'default' }: OwnProp
const dispatch = useDispatch();

const getCurrentSqon = (): any => sqon || generateSelectionSqon(INDEXES.BIOSPECIMEN, sampleIds);
const isDisabled = !sampleIds.length;

return (
<Button
key={1}
icon={<DownloadOutlined />}
onClick={() =>
dispatch(
fetchReport({
data: {
sqon: getCurrentSqon(),
name: ReportType.BIOSPECIMEN_DATA,
},
}),
)
}
disabled={!sampleIds.length}
type={type}
<Tooltip
title={intl.get('screen.dataExploration.youMustSelect')}
trigger={isDisabled ? 'hover' : 'none'}
>
{intl.get('api.report.sampleData.download')}
</Button>
<Button
disabled={isDisabled}
type={type}
icon={<DownloadOutlined />}
onClick={() =>
dispatch(
fetchReport({ data: { sqon: getCurrentSqon(), name: ReportType.BIOSPECIMEN_DATA } }),
)
}
>
{intl.get('api.report.sampleData.download')}
</Button>
</Tooltip>
);
};

Expand Down
44 changes: 26 additions & 18 deletions src/components/uiKit/SetsManagementDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const SetsManagementDropdown = ({
const [isEditDisabled, setIsEditDisabled] = useState(true);
const [modal, setModal] = useState<ModalState>(modals.hideAll);
const { savedSets, isLoading, fetchingError } = useSavedSet();
const isDisabled = !selectedKeys?.length;

useEffect(() => {
if (savedSets && !isLoading && !fetchingError && sqon) {
Expand Down Expand Up @@ -251,25 +252,32 @@ const SetsManagementDropdown = ({
type={type}
/>
)}
<Dropdown
disabled={!selectedKeys?.length}
menu={getMenuProps({
participantCount: getSetCount(selectedKeys || [], results.total, selectedAllResults),
onClick: onClick,
isEditDisabled: isEditDisabled,
type,
})}
placement="bottomLeft"
trigger={['click']}
getPopupContainer={() =>
document.getElementById(`${type}-set-dropdown-container`) as HTMLElement
}
<Tooltip
title={intl.get('screen.dataExploration.youMustSelect')}
trigger={isDisabled ? 'hover' : 'none'}
>
<Button className={'save-set-btn'} onClick={(e) => e.preventDefault()}>
{getTitle(type)}
<DownOutlined />
</Button>
</Dropdown>
{/** need a empty div below to show tooltip when Dropdown is disabled */}
<div />
<Dropdown
disabled={isDisabled}
menu={getMenuProps({
participantCount: getSetCount(selectedKeys || [], results.total, selectedAllResults),
onClick: onClick,
isEditDisabled: isEditDisabled,
type,
})}
placement="bottomLeft"
trigger={['click']}
getPopupContainer={() =>
document.getElementById(`${type}-set-dropdown-container`) as HTMLElement
}
>
<Button className={'save-set-btn'} onClick={(e) => e.preventDefault()}>
{getTitle(type)}
<DownOutlined />
</Button>
</Dropdown>
</Tooltip>
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ const en = {
removeTypeSet: 'Remove from a {type} set',
set: 'Set',
chooseSet: 'Choose a set',
youMustSelect: 'You must select at least 1 item',
},
},
// this facets object is also used by Ferlab-ui to override the values in the facets
Expand Down
7 changes: 4 additions & 3 deletions src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ const fr = {
results: 'Résultats',
noResults: 'Aucun résultat',
of: 'de',
selected: 'élément selectionné',
selectedPlural: 'éléments selectionnés',
selectAllResults: 'Selectionner tous les résultats',
selected: 'élément sélectionné',
selectedPlural: 'éléments sélectionnés',
selectAllResults: 'Sélectionner tous les résultats',
clear: 'Effacer',
tableExport: 'Exporter en TSV',
reset: 'Réinitialiser',
Expand Down Expand Up @@ -1127,6 +1127,7 @@ const fr = {
removeTypeSet: "Retirer de l'ensemble de {type}",
set: 'Ensemble',
chooseSet: 'Choisissez un ensemble',
youMustSelect: 'Sélectionnez au moins un élément',
},
},
// this facets object is also used by Ferlab-ui to override the values in the facets
Expand Down

0 comments on commit f8abacf

Please sign in to comment.