diff --git a/.eslintrc.json b/.eslintrc.json index 258d855ee..e3d490836 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,6 +18,7 @@ "extends": [ "eslint:recommended", "plugin:react/recommended", + "plugin:react-hooks/recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended-requiring-type-checking", diff --git a/package-lock.json b/package-lock.json index d7ebbda2a..2a6c42ad2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -80,6 +80,7 @@ "eslint-plugin-import": "2.27.5", "eslint-plugin-prettier": "4.2.1", "eslint-plugin-react": "7.32.2", + "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-simple-import-sort": "10.0.0", "eslint-plugin-storybook": "0.6.11", "eslint-plugin-unused-imports": "2.0.0", @@ -22245,6 +22246,18 @@ "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" } }, + "node_modules/eslint-plugin-react-hooks": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz", + "integrity": "sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==", + "dev": true, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" + } + }, "node_modules/eslint-plugin-react/node_modules/doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", diff --git a/package.json b/package.json index 242d98253..2470686e9 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,7 @@ "eslint-plugin-import": "2.27.5", "eslint-plugin-prettier": "4.2.1", "eslint-plugin-react": "7.32.2", + "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-simple-import-sort": "10.0.0", "eslint-plugin-storybook": "0.6.11", "eslint-plugin-unused-imports": "2.0.0", diff --git a/src/sections/collection/datasets-list/DatasetsList.tsx b/src/sections/collection/datasets-list/DatasetsList.tsx index cd44c661a..a72202af2 100644 --- a/src/sections/collection/datasets-list/DatasetsList.tsx +++ b/src/sections/collection/datasets-list/DatasetsList.tsx @@ -32,7 +32,7 @@ export function DatasetsList({ datasetRepository, page, collectionId }: Datasets useEffect(() => { setIsLoading(isLoading) - }, [isLoading]) + }, [isLoading, setIsLoading]) if (isLoading) { return diff --git a/src/sections/collection/datasets-list/DatasetsListWithInfiniteScroll.tsx b/src/sections/collection/datasets-list/DatasetsListWithInfiniteScroll.tsx index dd962ddeb..d757ccbb4 100644 --- a/src/sections/collection/datasets-list/DatasetsListWithInfiniteScroll.tsx +++ b/src/sections/collection/datasets-list/DatasetsListWithInfiniteScroll.tsx @@ -52,7 +52,7 @@ export function DatasetsListWithInfiniteScroll({ useEffect(() => { setIsLoading(isLoading) - }, [isLoading]) + }, [isLoading, setIsLoading]) useEffect(() => { const updatePaginationTotalItems = () => { diff --git a/src/sections/create-dataset/useGetMetadataBlocksInfo.tsx b/src/sections/create-dataset/useGetMetadataBlocksInfo.tsx index 203c2fe7e..4ee7eab4f 100644 --- a/src/sections/create-dataset/useGetMetadataBlocksInfo.tsx +++ b/src/sections/create-dataset/useGetMetadataBlocksInfo.tsx @@ -49,7 +49,7 @@ export const useGetMetadataBlocksInfo = ({ } } void handleGetDatasetMetadataBlockFields() - }, []) + }, [collectionId, metadataBlockInfoRepository]) return { metadataBlocks, diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index 8acd6dd59..6cc83be9c 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -38,7 +38,7 @@ export function Dataset({ fileRepository, created }: DatasetProps) { } useEffect(() => { setIsLoading(isLoading) - }, [isLoading]) + }, [isLoading, setIsLoading]) if (isLoading) { return diff --git a/src/sections/dataset/DatasetFactory.tsx b/src/sections/dataset/DatasetFactory.tsx index c80597b45..cafed8de4 100644 --- a/src/sections/dataset/DatasetFactory.tsx +++ b/src/sections/dataset/DatasetFactory.tsx @@ -54,7 +54,7 @@ function DatasetWithSearchParams() { useEffect(() => { if (privateUrlToken) setAnonymizedView(true) - }, [privateUrlToken]) + }, [privateUrlToken, setAnonymizedView]) if (privateUrlToken) { return ( diff --git a/src/sections/dataset/DatasetProvider.tsx b/src/sections/dataset/DatasetProvider.tsx index 41ebd2504..e121485aa 100644 --- a/src/sections/dataset/DatasetProvider.tsx +++ b/src/sections/dataset/DatasetProvider.tsx @@ -1,4 +1,4 @@ -import { PropsWithChildren, useEffect, useState } from 'react' +import { PropsWithChildren, useCallback, useEffect, useState } from 'react' import { DatasetContext } from './DatasetContext' import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository' import { Dataset } from '../../dataset/domain/models/Dataset' @@ -20,7 +20,8 @@ export function DatasetProvider({ }: PropsWithChildren) { const [dataset, setDataset] = useState() const [isLoading, setIsLoading] = useState(true) - const getDataset = () => { + + const getDataset = useCallback(() => { if (searchParams.persistentId) { return getDatasetByPersistentId(repository, searchParams.persistentId, searchParams.version) } @@ -28,7 +29,7 @@ export function DatasetProvider({ return getDatasetByPrivateUrlToken(repository, searchParams.privateUrlToken) } return Promise.resolve(undefined) - } + }, [repository, searchParams]) useEffect(() => { setIsLoading(true) @@ -42,7 +43,7 @@ export function DatasetProvider({ console.error('There was an error getting the dataset', error) setIsLoading(false) }) - }, [repository, searchParams]) + }, [repository, searchParams, getDataset]) return ( {children} diff --git a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx index 18527ffb5..00f1e68f6 100644 --- a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx @@ -6,6 +6,8 @@ interface DeaccessionDatasetButtonProps { dataset: Dataset } export function DeaccessionDatasetButton({ dataset }: DeaccessionDatasetButtonProps) { + const { t } = useTranslation('dataset') + if ( !dataset.version.someDatasetVersionHasBeenReleased || !dataset.permissions.canPublishDataset @@ -13,7 +15,6 @@ export function DeaccessionDatasetButton({ dataset }: DeaccessionDatasetButtonPr return <> } - const { t } = useTranslation('dataset') return ( <> diff --git a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx index 9a1eaf9f7..1e2b4a632 100644 --- a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx @@ -6,6 +6,8 @@ interface DeleteDatasetButtonProps { dataset: Dataset } export function DeleteDatasetButton({ dataset }: DeleteDatasetButtonProps) { + const { t } = useTranslation('dataset') + if ( !dataset.permissions.canDeleteDataset || dataset.version.latestVersionPublishingStatus !== DatasetPublishingStatus.DRAFT @@ -13,7 +15,6 @@ export function DeleteDatasetButton({ dataset }: DeleteDatasetButtonProps) { return <> } - const { t } = useTranslation('dataset') return ( <> diff --git a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.tsx b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.tsx index 7ef7f3282..5fccf6009 100644 --- a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.tsx +++ b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.tsx @@ -10,13 +10,6 @@ interface EditDatasetPermissionsMenuProps { dataset: Dataset } export function EditDatasetPermissionsMenu({ dataset }: EditDatasetPermissionsMenuProps) { - if ( - !dataset.permissions.canManageDatasetPermissions && - !dataset.permissions.canManageFilesPermissions - ) { - return <> - } - const { t } = useTranslation('dataset') const { getSettingByName } = useSettings() const [hasPublicStore, setHasPublicStore] = useState(false) @@ -31,6 +24,13 @@ export function EditDatasetPermissionsMenu({ dataset }: EditDatasetPermissionsMe }) }, [getSettingByName]) + if ( + !dataset.permissions.canManageDatasetPermissions && + !dataset.permissions.canManageFilesPermissions + ) { + return <> + } + if (hasPublicStore) { return ( diff --git a/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx b/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx index 6ea678467..b96fff849 100644 --- a/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx +++ b/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx @@ -11,6 +11,9 @@ interface PublishDatasetMenuProps { export function PublishDatasetMenu({ dataset }: PublishDatasetMenuProps) { const { user } = useSession() + const { t } = useTranslation('dataset') + const { showModal } = useNotImplementedModal() + if ( !dataset.version.isLatest || dataset.version.publishingStatus !== DatasetPublishingStatus.DRAFT || @@ -20,12 +23,10 @@ export function PublishDatasetMenu({ dataset }: PublishDatasetMenuProps) { return <> } - const { t } = useTranslation('dataset') const handleSelect = () => { // TODO - Implement upload files showModal() } - const { showModal } = useNotImplementedModal() return ( } - const { t } = useTranslation('dataset') return (