Skip to content

Commit

Permalink
Merge pull request #433 from bento-platform/refact/rm-defaultprops
Browse files Browse the repository at this point in the history
refact: remove use of deprecated defaultProps
  • Loading branch information
davidlougheed authored Aug 28, 2024
2 parents 1ce25f2 + 9c02602 commit d4ad12b
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 45 deletions.
10 changes: 4 additions & 6 deletions src/components/ForbiddenContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<Layout>
<Layout.Content style={LAYOUT_CONTENT_STYLE}>
<Result status="error" title="Forbidden" subTitle={message} />
<Result status="error" title="Forbidden" subTitle={message ?? DEFAULT_MESSAGE} />
</Layout.Content>
</Layout>
);

ForbiddenContent.defaultProps = {
message: "You do not have permission to view this content.",
};

export default ForbiddenContent;
6 changes: 1 addition & 5 deletions src/components/datasets/DatasetFormModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,8 @@ const DatasetFormModal = ({ project, mode, initialValue, onCancel, onOk, open })
);
};

DatasetFormModal.defaultProps = {
mode: FORM_MODE_ADD,
};

DatasetFormModal.propTypes = {
mode: propTypesFormMode,
mode: propTypesFormMode.isRequired,
initialValue: datasetPropTypesShape,

onOk: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ const LinkedFieldSetModal = ({ dataset, linkedFieldSetIndex, linkedFieldSet, mod
</Modal>
);
};
LinkedFieldSetModal.defaultProps = {
mode: FORM_MODE_ADD,
};
LinkedFieldSetModal.propTypes = {
mode: propTypesFormMode,
mode: propTypesFormMode.isRequired,
open: PropTypes.bool,
dataset: datasetPropTypesShape,
onSubmit: PropTypes.func,
Expand Down
6 changes: 1 addition & 5 deletions src/components/explorer/OntologyTerm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 2 additions & 5 deletions src/components/manager/DatasetTitleDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import MonospaceText from "@/components/common/MonospaceText";

export type DatasetTitleDisplayProps = {
datasetID: string;
link: boolean;
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);

Expand All @@ -30,8 +30,5 @@ const DatasetTitleDisplay = ({ datasetID, link }: DatasetTitleDisplayProps) => {
if (!link) return title;
return <Link to={`/data/manager/projects/${project}#dataset-${datasetID}`}>{title}</Link>;
};
DatasetTitleDisplay.defaultProps = {
link: false,
};

export default DatasetTitleDisplay;
6 changes: 1 addition & 5 deletions src/components/manager/DatasetTreeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,11 @@ const DatasetTreeSelect = forwardRef(({ value, onChange, style, idFormat }, ref)
);
});

DatasetTreeSelect.defaultProps = {
idFormat: ID_FORMAT_PROJECT_DATASET,
};

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;
6 changes: 1 addition & 5 deletions src/components/manager/DropBoxTreeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -67,8 +67,4 @@ DropBoxTreeSelect.propTypes = {
basePrefix: PropTypes.string,
};

DropBoxTreeSelect.defaultProps = {
folderMode: false,
};

export default DropBoxTreeSelect;
6 changes: 1 addition & 5 deletions src/components/manager/ProjectTitleDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useProjects } from "@/modules/metadata/hooks";

export type ProjectTitleDisplayProps = {
projectID: string;
link: boolean;
link?: boolean;
};

const ProjectTitleDisplay = ({ projectID, link }: ProjectTitleDisplayProps) => {
Expand All @@ -28,8 +28,4 @@ const ProjectTitleDisplay = ({ projectID, link }: ProjectTitleDisplayProps) => {
return <Link to={`/data/manager/projects/${projectID}`}>{title}</Link>;
};

ProjectTitleDisplay.defaultProps = {
link: false,
};

export default ProjectTitleDisplay;
6 changes: 1 addition & 5 deletions src/components/manager/projects/ProjectJsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CODE_STYLE = {
borderRadius: "3px",
};

export const ExtraPropertiesCode = ({ tooltip }) => {
export const ExtraPropertiesCode = ({ tooltip = false }) => {
if (tooltip) {
return <span style={CODE_STYLE}>extra_properties</span>;
}
Expand All @@ -33,10 +33,6 @@ ExtraPropertiesCode.propTypes = {
tooltip: PropTypes.bool,
};

ExtraPropertiesCode.defaultProps = {
tooltip: false,
};

const ProjectJsonSchema = ({ projectSchema }) => {
const dispatch = useDispatch();

Expand Down

0 comments on commit d4ad12b

Please sign in to comment.