From 2e3fa7c851745047f18f23c016bbcb3ba0fd572e Mon Sep 17 00:00:00 2001 From: German Saracca Date: Mon, 1 Apr 2024 09:01:45 -0300 Subject: [PATCH 1/9] feature(plugin-react-hooks): Install package and configure --- .eslintrc.json | 1 + package-lock.json | 13 +++++++++++++ package.json | 1 + 3 files changed, 15 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index dbdefa329..dfba7a0aa 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 700647615..0d0adffef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -79,6 +79,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", @@ -22276,6 +22277,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 d6cd25938..a3e152174 100644 --- a/package.json +++ b/package.json @@ -143,6 +143,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", From c76aafd177a05cd8ec5ee072cf51019be00ce955 Mon Sep 17 00:00:00 2001 From: German Saracca Date: Mon, 1 Apr 2024 10:29:02 -0300 Subject: [PATCH 2/9] fix(plugin-react-hooks): Fix errors from calling react hooks conditionally --- .../edit-dataset-menu/DeaccessionDatasetButton.tsx | 3 ++- .../edit-dataset-menu/DeleteDatasetButton.tsx | 3 ++- .../edit-dataset-menu/EditDatasetMenu.tsx | 5 +++-- .../EditDatasetPermissionsMenu.tsx | 14 +++++++------- .../publish-dataset-menu/PublishDatasetMenu.tsx | 5 +++-- .../SubmitForReviewButton.tsx | 3 ++- 6 files changed, 19 insertions(+), 14 deletions(-) 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/EditDatasetMenu.tsx b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.tsx index 03faf3cd1..3f3a9e09a 100644 --- a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.tsx +++ b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.tsx @@ -13,12 +13,13 @@ interface EditDatasetMenuProps { export function EditDatasetMenu({ dataset }: EditDatasetMenuProps) { const { user } = useSession() + const { showModal } = useNotImplementedModal() + const { t } = useTranslation('dataset') if (!user || !dataset.permissions.canUpdateDataset) { return <> } - const { showModal } = useNotImplementedModal() - const { t } = useTranslation('dataset') + 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 (