From d5a51463ffca15915d543e9f8d7e1c16155ab50c Mon Sep 17 00:00:00 2001 From: Joon Kyoung Date: Thu, 4 Jan 2024 22:32:21 +0900 Subject: [PATCH] fix: use JavaScript default parameters instead React's defaultProps (#9453) --- src/core/components/errors.jsx | 6 +----- src/core/components/highlight-code.jsx | 6 +----- src/core/components/providers/markdown.jsx | 6 +----- src/core/plugins/icons/components/arrow-down.jsx | 8 +------- src/core/plugins/icons/components/arrow-up.jsx | 8 +------- src/core/plugins/icons/components/arrow.jsx | 8 +------- src/core/plugins/icons/components/close.jsx | 8 +------- src/core/plugins/icons/components/copy.jsx | 8 +------- src/core/plugins/icons/components/lock.jsx | 8 +------- src/core/plugins/icons/components/unlock.jsx | 8 +------- .../components/Accordion/Accordion.jsx | 6 +----- .../components/JSONSchema/JSONSchema.jsx | 8 +------- .../components/keywords/Title/Title.jsx | 6 +----- .../json-schema-2020-12/components/keywords/Type.jsx | 6 +----- src/core/plugins/oas3/wrap-components/markdown.jsx | 6 +----- .../keywords/Discriminator/DiscriminatorMapping.jsx | 4 ---- 16 files changed, 15 insertions(+), 95 deletions(-) diff --git a/src/core/components/errors.jsx b/src/core/components/errors.jsx index 2b99e33d..afe2baaf 100644 --- a/src/core/components/errors.jsx +++ b/src/core/components/errors.jsx @@ -84,7 +84,7 @@ const ThrownErrorItem = ( { error, jumpToLine } ) => { ) } -const SpecErrorItem = ( { error, jumpToLine } ) => { +const SpecErrorItem = ( { error, jumpToLine = null } ) => { let locationMessage = null if(error.get("path")) { @@ -126,10 +126,6 @@ ThrownErrorItem.propTypes = { jumpToLine: PropTypes.func } -ThrownErrorItem.defaultProps = { - jumpToLine: null -} - SpecErrorItem.propTypes = { error: PropTypes.object.isRequired, jumpToLine: PropTypes.func diff --git a/src/core/components/highlight-code.jsx b/src/core/components/highlight-code.jsx index 35d90a10..29f075e3 100644 --- a/src/core/components/highlight-code.jsx +++ b/src/core/components/highlight-code.jsx @@ -7,7 +7,7 @@ import isFunction from "lodash/isFunction" import saveAs from "js-file-download" import { CopyToClipboard } from "react-copy-to-clipboard" -const HighlightCode = ({value, fileName, className, downloadable, getConfigs, canCopy, language}) => { +const HighlightCode = ({value, fileName = "response.txt", className, downloadable, getConfigs, canCopy, language}) => { const config = isFunction(getConfigs) ? getConfigs() : null const canSyntaxHighlight = get(config, "syntaxHighlight") !== false && get(config, "syntaxHighlight.activated", true) const rootRef = useRef(null) @@ -82,8 +82,4 @@ HighlightCode.propTypes = { canCopy: PropTypes.bool } -HighlightCode.defaultProps = { - fileName: "response.txt" -} - export default HighlightCode diff --git a/src/core/components/providers/markdown.jsx b/src/core/components/providers/markdown.jsx index 4da26ef0..4a08d791 100644 --- a/src/core/components/providers/markdown.jsx +++ b/src/core/components/providers/markdown.jsx @@ -18,7 +18,7 @@ if (DomPurify.addHook) { }) } -function Markdown({ source, className = "", getConfigs }) { +function Markdown({ source, className = "", getConfigs = () => ({ useUnsafeMarkdown: false }) }) { if (typeof source !== "string") { return null } @@ -51,10 +51,6 @@ Markdown.propTypes = { getConfigs: PropTypes.func, } -Markdown.defaultProps = { - getConfigs: () => ({ useUnsafeMarkdown: false }), -} - export default Markdown export function sanitizer(str, { useUnsafeMarkdown = false } = {}) { diff --git a/src/core/plugins/icons/components/arrow-down.jsx b/src/core/plugins/icons/components/arrow-down.jsx index 8dff9423..46011d2b 100644 --- a/src/core/plugins/icons/components/arrow-down.jsx +++ b/src/core/plugins/icons/components/arrow-down.jsx @@ -4,7 +4,7 @@ import React from "react" import PropTypes from "prop-types" -const ArrowDown = ({ className, width, height, ...rest }) => ( +const ArrowDown = ({ className = null, width = 20, height = 20, ...rest }) => ( ( +const ArrowUp = ({ className = null, width = 20, height = 20, ...rest }) => ( ( +const Arrow = ({ className = null, width = 20, height = 20, ...rest }) => ( ( +const Close = ({ className = null, width = 20, height = 20, ...rest }) => ( ( +const Copy = ({ className = null, width = 15, height = 16, ...rest }) => ( ( +const Lock = ({ className = null, width = 20, height = 20, ...rest }) => ( ( +const Unlock = ({ className = null, width = 20, height = 20, ...rest }) => ( { +const Accordion = ({ expanded = false, children, onChange }) => { const ChevronRightIcon = useComponent("ChevronRightIcon") const handleExpansion = useCallback( @@ -42,8 +42,4 @@ Accordion.propTypes = { onChange: PropTypes.func.isRequired, } -Accordion.defaultProps = { - expanded: false, -} - export default Accordion diff --git a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx index 0b9c92b7..2d3c25a3 100644 --- a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx +++ b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx @@ -23,7 +23,7 @@ import { } from "../../context" const JSONSchema = forwardRef( - ({ schema, name, dependentRequired, onExpand }, ref) => { + ({ schema, name = "", dependentRequired = [], onExpand = () => {} }, ref) => { const fn = useFn() const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() @@ -215,10 +215,4 @@ JSONSchema.propTypes = { onExpand: PropTypes.func, } -JSONSchema.defaultProps = { - name: "", - dependentRequired: [], - onExpand: () => {}, -} - export default JSONSchema diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Title/Title.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Title/Title.jsx index 675185b9..ce416ac5 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/Title/Title.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Title/Title.jsx @@ -7,7 +7,7 @@ import PropTypes from "prop-types" import { schema } from "../../../prop-types" import { useFn } from "../../../hooks" -const Title = ({ title, schema }) => { +const Title = ({ title = "", schema }) => { const fn = useFn() const renderedTitle = title || fn.getTitle(schema) @@ -25,8 +25,4 @@ Title.propTypes = { schema: schema.isRequired, } -Title.defaultProps = { - title: "", -} - export default Title diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Type.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Type.jsx index 251280d5..8b51557c 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/Type.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Type.jsx @@ -7,7 +7,7 @@ import PropTypes from "prop-types" import { schema } from "../../prop-types" import { useFn } from "../../hooks" -const Type = ({ schema, isCircular }) => { +const Type = ({ schema, isCircular = false }) => { const fn = useFn() const type = fn.getType(schema) const circularSuffix = isCircular ? " [circular]" : "" @@ -24,8 +24,4 @@ Type.propTypes = { isCircular: PropTypes.bool, } -Type.defaultProps = { - isCircular: false, -} - export default Type diff --git a/src/core/plugins/oas3/wrap-components/markdown.jsx b/src/core/plugins/oas3/wrap-components/markdown.jsx index a7510e72..95ca2f4b 100644 --- a/src/core/plugins/oas3/wrap-components/markdown.jsx +++ b/src/core/plugins/oas3/wrap-components/markdown.jsx @@ -9,7 +9,7 @@ const parser = new Remarkable("commonmark") parser.block.ruler.enable(["table"]) parser.set({ linkTarget: "_blank" }) -export const Markdown = ({ source, className = "", getConfigs }) => { +export const Markdown = ({ source, className = "", getConfigs = () => ({ useUnsafeMarkdown: false }) }) => { if(typeof source !== "string") { return null } @@ -42,8 +42,4 @@ Markdown.propTypes = { getConfigs: PropTypes.func, } -Markdown.defaultProps = { - getConfigs: () => ({ useUnsafeMarkdown: false }), -} - export default OAS3ComponentWrapFactory(Markdown) diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/DiscriminatorMapping.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/DiscriminatorMapping.jsx index e71105ea..effdfec6 100644 --- a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/DiscriminatorMapping.jsx +++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/DiscriminatorMapping.jsx @@ -29,8 +29,4 @@ DiscriminatorMapping.propTypes = { }), } -DiscriminatorMapping.defaultProps = { - mapping: undefined, -} - export default DiscriminatorMapping