From 7c373dc2f9dad5315f94252cb917c150fee4b408 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 28 Aug 2024 11:39:05 -0400 Subject: [PATCH 1/5] refact: remove use of deprecated defaultProps --- src/components/ForbiddenContent.tsx | 10 ++++------ src/components/datasets/DatasetFormModal.js | 6 +----- .../linked_field_set/LinkedFieldSetModal.js | 13 +++++++++---- src/components/explorer/OntologyTerm.js | 6 +----- src/components/manager/DatasetTitleDisplay.tsx | 5 +---- src/components/manager/DatasetTreeSelect.js | 6 +----- src/components/manager/DropBoxTreeSelect.js | 6 +----- src/components/manager/ProjectTitleDisplay.tsx | 6 +----- .../manager/projects/ProjectJsonSchema.js | 6 +----- 9 files changed, 20 insertions(+), 44 deletions(-) diff --git a/src/components/ForbiddenContent.tsx b/src/components/ForbiddenContent.tsx index acc78f1ff..c79aaf5c7 100644 --- a/src/components/ForbiddenContent.tsx +++ b/src/components/ForbiddenContent.tsx @@ -2,18 +2,16 @@ import type { ReactNode } from "react"; import { Layout, Result } from "antd"; import { LAYOUT_CONTENT_STYLE } from "@/styles/layoutContent"; -export type ForbiddenContentProps = { message: ReactNode }; +export type ForbiddenContentProps = { message?: ReactNode }; + +const DEFAULT_MESSAGE = "You do not have permission to view this content."; const ForbiddenContent = ({ message }: ForbiddenContentProps) => ( - + ); -ForbiddenContent.defaultProps = { - message: "You do not have permission to view this content.", -}; - export default ForbiddenContent; diff --git a/src/components/datasets/DatasetFormModal.js b/src/components/datasets/DatasetFormModal.js index cfa24b1f5..85c147cbb 100644 --- a/src/components/datasets/DatasetFormModal.js +++ b/src/components/datasets/DatasetFormModal.js @@ -13,7 +13,7 @@ import { useProjects } from "@/modules/metadata/hooks"; import { datasetPropTypesShape, projectPropTypesShape, propTypesFormMode } from "@/propTypes"; import { nop } from "@/utils/misc"; -const DatasetFormModal = ({ project, mode, initialValue, onCancel, onOk, open }) => { +const DatasetFormModal = ({ project, mode = FORM_MODE_ADD, initialValue, onCancel, onOk, open }) => { const dispatch = useDispatch(); const { @@ -92,10 +92,6 @@ const DatasetFormModal = ({ project, mode, initialValue, onCancel, onOk, open }) ); }; -DatasetFormModal.defaultProps = { - mode: FORM_MODE_ADD, -}; - DatasetFormModal.propTypes = { mode: propTypesFormMode, initialValue: datasetPropTypesShape, diff --git a/src/components/datasets/linked_field_set/LinkedFieldSetModal.js b/src/components/datasets/linked_field_set/LinkedFieldSetModal.js index 3ff070c34..d23c48fff 100644 --- a/src/components/datasets/linked_field_set/LinkedFieldSetModal.js +++ b/src/components/datasets/linked_field_set/LinkedFieldSetModal.js @@ -11,7 +11,15 @@ import { addDatasetLinkedFieldSetIfPossible, saveDatasetLinkedFieldSetIfPossible import { datasetPropTypesShape, linkedFieldSetPropTypesShape, propTypesFormMode } from "@/propTypes"; import { nop } from "@/utils/misc"; -const LinkedFieldSetModal = ({ dataset, linkedFieldSetIndex, linkedFieldSet, mode, open, onCancel, onSubmit }) => { +const LinkedFieldSetModal = ({ + dataset, + linkedFieldSetIndex, + linkedFieldSet, + mode = FORM_MODE_ADD, + open, + onCancel, + onSubmit, +}) => { const dispatch = useDispatch(); const [form] = Form.useForm(); @@ -84,9 +92,6 @@ const LinkedFieldSetModal = ({ dataset, linkedFieldSetIndex, linkedFieldSet, mod ); }; -LinkedFieldSetModal.defaultProps = { - mode: FORM_MODE_ADD, -}; LinkedFieldSetModal.propTypes = { mode: propTypesFormMode, open: PropTypes.bool, diff --git a/src/components/explorer/OntologyTerm.js b/src/components/explorer/OntologyTerm.js index 23f82d931..8212e8940 100644 --- a/src/components/explorer/OntologyTerm.js +++ b/src/components/explorer/OntologyTerm.js @@ -19,7 +19,7 @@ export const conditionalOntologyRender = (field) => (_, record) => { return EM_DASH; }; -const OntologyTerm = memo(({ term, renderLabel, br }) => { +const OntologyTerm = memo(({ term, renderLabel = id, br = false }) => { const { resourcesTuple } = useContext(ExplorerIndividualContext); // TODO: perf: might be slow to generate this over and over @@ -76,10 +76,6 @@ OntologyTerm.propTypes = { renderLabel: PropTypes.func, br: PropTypes.bool, }; -OntologyTerm.defaultProps = { - renderLabel: id, - br: false, -}; export const OntologyTermList = (items) => { if (!Array.isArray(items)) { diff --git a/src/components/manager/DatasetTitleDisplay.tsx b/src/components/manager/DatasetTitleDisplay.tsx index f0e853391..85530f61e 100644 --- a/src/components/manager/DatasetTitleDisplay.tsx +++ b/src/components/manager/DatasetTitleDisplay.tsx @@ -10,7 +10,7 @@ export type DatasetTitleDisplayProps = { link: boolean; }; -const DatasetTitleDisplay = ({ datasetID, link }: DatasetTitleDisplayProps) => { +const DatasetTitleDisplay = ({ datasetID, link = false }: DatasetTitleDisplayProps) => { // @ts-expect-error We have not typed the state yet const datasetsByID = useSelector((state) => state.projects.datasetsByID); @@ -30,8 +30,5 @@ const DatasetTitleDisplay = ({ datasetID, link }: DatasetTitleDisplayProps) => { if (!link) return title; return {title}; }; -DatasetTitleDisplay.defaultProps = { - link: false, -}; export default DatasetTitleDisplay; diff --git a/src/components/manager/DatasetTreeSelect.js b/src/components/manager/DatasetTreeSelect.js index 5ce4911ee..00c49331e 100644 --- a/src/components/manager/DatasetTreeSelect.js +++ b/src/components/manager/DatasetTreeSelect.js @@ -8,7 +8,7 @@ import { useProjects } from "@/modules/metadata/hooks"; export const ID_FORMAT_PROJECT_DATASET = "project:dataset"; export const ID_FORMAT_DATASET = "dataset"; -const DatasetTreeSelect = forwardRef(({ value, onChange, style, idFormat }, ref) => { +const DatasetTreeSelect = forwardRef(({ value, onChange, style, idFormat = ID_FORMAT_PROJECT_DATASET }, ref) => { const { items: projectItems, isFetching: projectsFetching } = useProjects(); const servicesFetching = useSelector((state) => state.services.isFetchingAll); @@ -62,10 +62,6 @@ const DatasetTreeSelect = forwardRef(({ value, onChange, style, idFormat }, ref) ); }); -DatasetTreeSelect.defaultProps = { - idFormat: ID_FORMAT_PROJECT_DATASET, -}; - DatasetTreeSelect.propTypes = { style: PropTypes.object, value: PropTypes.string, diff --git a/src/components/manager/DropBoxTreeSelect.js b/src/components/manager/DropBoxTreeSelect.js index 18599571c..5ea343458 100644 --- a/src/components/manager/DropBoxTreeSelect.js +++ b/src/components/manager/DropBoxTreeSelect.js @@ -35,7 +35,7 @@ const generateFileTree = (directory, valid, folderMode, basePrefix) => }; }); -const DropBoxTreeSelect = forwardRef(({ folderMode, nodeEnabled, basePrefix, ...props }, ref) => { +const DropBoxTreeSelect = forwardRef(({ folderMode = false, nodeEnabled, basePrefix, ...props }, ref) => { const { tree } = useDropBox(); const fileTree = useMemo( @@ -67,8 +67,4 @@ DropBoxTreeSelect.propTypes = { basePrefix: PropTypes.string, }; -DropBoxTreeSelect.defaultProps = { - folderMode: false, -}; - export default DropBoxTreeSelect; diff --git a/src/components/manager/ProjectTitleDisplay.tsx b/src/components/manager/ProjectTitleDisplay.tsx index 7a9560007..e4bff3c60 100644 --- a/src/components/manager/ProjectTitleDisplay.tsx +++ b/src/components/manager/ProjectTitleDisplay.tsx @@ -7,7 +7,7 @@ import { useProjects } from "@/modules/metadata/hooks"; export type ProjectTitleDisplayProps = { projectID: string; - link: boolean; + link?: boolean; }; const ProjectTitleDisplay = ({ projectID, link }: ProjectTitleDisplayProps) => { @@ -28,8 +28,4 @@ const ProjectTitleDisplay = ({ projectID, link }: ProjectTitleDisplayProps) => { return {title}; }; -ProjectTitleDisplay.defaultProps = { - link: false, -}; - export default ProjectTitleDisplay; diff --git a/src/components/manager/projects/ProjectJsonSchema.js b/src/components/manager/projects/ProjectJsonSchema.js index 9b8609146..6efcaabf0 100644 --- a/src/components/manager/projects/ProjectJsonSchema.js +++ b/src/components/manager/projects/ProjectJsonSchema.js @@ -22,7 +22,7 @@ const CODE_STYLE = { borderRadius: "3px", }; -export const ExtraPropertiesCode = ({ tooltip }) => { +export const ExtraPropertiesCode = ({ tooltip = false }) => { if (tooltip) { return extra_properties; } @@ -33,10 +33,6 @@ ExtraPropertiesCode.propTypes = { tooltip: PropTypes.bool, }; -ExtraPropertiesCode.defaultProps = { - tooltip: false, -}; - const ProjectJsonSchema = ({ projectSchema }) => { const dispatch = useDispatch(); From a9de69756add26a9d865679546c83706c1afddfa Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 28 Aug 2024 11:55:51 -0400 Subject: [PATCH 2/5] fix: bad type for DatasetTitleDisplay --- src/components/manager/DatasetTitleDisplay.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/manager/DatasetTitleDisplay.tsx b/src/components/manager/DatasetTitleDisplay.tsx index 85530f61e..fcffe223e 100644 --- a/src/components/manager/DatasetTitleDisplay.tsx +++ b/src/components/manager/DatasetTitleDisplay.tsx @@ -7,7 +7,7 @@ import MonospaceText from "@/components/common/MonospaceText"; export type DatasetTitleDisplayProps = { datasetID: string; - link: boolean; + link?: boolean; }; const DatasetTitleDisplay = ({ datasetID, link = false }: DatasetTitleDisplayProps) => { From 43f3ec8137e8af4df68c0fb4bfa3bff7def9fb1f Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 28 Aug 2024 13:08:07 -0400 Subject: [PATCH 3/5] chore: form modes don't need default prop value --- src/components/datasets/DatasetFormModal.js | 4 ++-- .../datasets/linked_field_set/LinkedFieldSetModal.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/datasets/DatasetFormModal.js b/src/components/datasets/DatasetFormModal.js index 85c147cbb..3e6ba4e60 100644 --- a/src/components/datasets/DatasetFormModal.js +++ b/src/components/datasets/DatasetFormModal.js @@ -13,7 +13,7 @@ import { useProjects } from "@/modules/metadata/hooks"; import { datasetPropTypesShape, projectPropTypesShape, propTypesFormMode } from "@/propTypes"; import { nop } from "@/utils/misc"; -const DatasetFormModal = ({ project, mode = FORM_MODE_ADD, initialValue, onCancel, onOk, open }) => { +const DatasetFormModal = ({ project, mode, initialValue, onCancel, onOk, open }) => { const dispatch = useDispatch(); const { @@ -93,7 +93,7 @@ const DatasetFormModal = ({ project, mode = FORM_MODE_ADD, initialValue, onCance }; DatasetFormModal.propTypes = { - mode: propTypesFormMode, + mode: propTypesFormMode.isRequired, initialValue: datasetPropTypesShape, onOk: PropTypes.func, diff --git a/src/components/datasets/linked_field_set/LinkedFieldSetModal.js b/src/components/datasets/linked_field_set/LinkedFieldSetModal.js index d23c48fff..bdde13ece 100644 --- a/src/components/datasets/linked_field_set/LinkedFieldSetModal.js +++ b/src/components/datasets/linked_field_set/LinkedFieldSetModal.js @@ -15,7 +15,7 @@ const LinkedFieldSetModal = ({ dataset, linkedFieldSetIndex, linkedFieldSet, - mode = FORM_MODE_ADD, + mode, open, onCancel, onSubmit, @@ -93,7 +93,7 @@ const LinkedFieldSetModal = ({ ); }; LinkedFieldSetModal.propTypes = { - mode: propTypesFormMode, + mode: propTypesFormMode.isRequired, open: PropTypes.bool, dataset: datasetPropTypesShape, onSubmit: PropTypes.func, From 845c2d56b0a05190ba02bfce493c02d992800f2c Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 28 Aug 2024 13:17:02 -0400 Subject: [PATCH 4/5] chore(manager): rm un-needed default prop for DatasetTreeSelect --- src/components/manager/DatasetTreeSelect.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/manager/DatasetTreeSelect.js b/src/components/manager/DatasetTreeSelect.js index 00c49331e..97c47d43e 100644 --- a/src/components/manager/DatasetTreeSelect.js +++ b/src/components/manager/DatasetTreeSelect.js @@ -8,7 +8,7 @@ import { useProjects } from "@/modules/metadata/hooks"; export const ID_FORMAT_PROJECT_DATASET = "project:dataset"; export const ID_FORMAT_DATASET = "dataset"; -const DatasetTreeSelect = forwardRef(({ value, onChange, style, idFormat = ID_FORMAT_PROJECT_DATASET }, ref) => { +const DatasetTreeSelect = forwardRef(({ value, onChange, style, idFormat }, ref) => { const { items: projectItems, isFetching: projectsFetching } = useProjects(); const servicesFetching = useSelector((state) => state.services.isFetchingAll); @@ -66,7 +66,7 @@ DatasetTreeSelect.propTypes = { style: PropTypes.object, value: PropTypes.string, onChange: PropTypes.func, - idFormat: PropTypes.oneOf([ID_FORMAT_PROJECT_DATASET, ID_FORMAT_DATASET]), + idFormat: PropTypes.oneOf([ID_FORMAT_PROJECT_DATASET, ID_FORMAT_DATASET]).isRequired, }; export default DatasetTreeSelect; From 9c0260268d01a5b3de0f071b64f144e14f9340de Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 28 Aug 2024 13:17:20 -0400 Subject: [PATCH 5/5] lint --- .../datasets/linked_field_set/LinkedFieldSetModal.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/components/datasets/linked_field_set/LinkedFieldSetModal.js b/src/components/datasets/linked_field_set/LinkedFieldSetModal.js index bdde13ece..04850e83a 100644 --- a/src/components/datasets/linked_field_set/LinkedFieldSetModal.js +++ b/src/components/datasets/linked_field_set/LinkedFieldSetModal.js @@ -11,15 +11,7 @@ import { addDatasetLinkedFieldSetIfPossible, saveDatasetLinkedFieldSetIfPossible import { datasetPropTypesShape, linkedFieldSetPropTypesShape, propTypesFormMode } from "@/propTypes"; import { nop } from "@/utils/misc"; -const LinkedFieldSetModal = ({ - dataset, - linkedFieldSetIndex, - linkedFieldSet, - mode, - open, - onCancel, - onSubmit, -}) => { +const LinkedFieldSetModal = ({ dataset, linkedFieldSetIndex, linkedFieldSet, mode, open, onCancel, onSubmit }) => { const dispatch = useDispatch(); const [form] = Form.useForm();