From fa182e66fa7304137d9dc96daf65d2521465f803 Mon Sep 17 00:00:00 2001 From: Harel M Date: Thu, 21 Dec 2023 23:46:56 +0200 Subject: [PATCH] Migration of jsx files to tsx 1 (#848) In this PR I have changed some of the jsx files to tsx file. I'm starting off with the "leafs" so that migration of the rest will be easier, hopefully. What I'm basically doing is taking a jsx file, copy paste it into: https://mskelton.dev/ratchet And after that I'm fixing the types as needed. It's not a very long process. Hopefully more PRs will follow and this will be over soon. I don't plan to migrate the storybook as I generally don't understand why is it useful, I'll open an issue to see if anyone thinks differently. --- cypress/e2e/modals.cy.ts | 7 + package-lock.json | 114 ++++++++++++++ package.json | 8 + src/components/{Block.jsx => Block.tsx} | 56 +++---- src/components/{Doc.jsx => Doc.tsx} | 40 +++-- src/components/FieldArray.jsx | 21 --- src/components/FieldArray.tsx | 19 +++ src/components/FieldColor.jsx | 20 --- src/components/FieldColor.tsx | 21 +++ .../{FieldDocLabel.jsx => FieldDocLabel.tsx} | 26 ++-- src/components/FieldEnum.jsx | 20 --- src/components/FieldEnum.tsx | 20 +++ src/components/{FieldId.jsx => FieldId.tsx} | 15 +- src/components/FieldJson.jsx | 16 -- src/components/FieldJson.tsx | 13 ++ .../{FieldMaxZoom.jsx => FieldMaxZoom.tsx} | 13 +- .../{FieldMinZoom.jsx => FieldMinZoom.tsx} | 13 +- src/components/FieldMultiInput.jsx | 21 --- src/components/FieldMultiInput.tsx | 20 +++ src/components/FieldNumber.jsx | 19 --- src/components/FieldNumber.tsx | 20 +++ src/components/FieldSelect.jsx | 20 --- src/components/FieldSelect.tsx | 22 +++ src/components/FieldString.jsx | 20 --- src/components/FieldString.tsx | 19 +++ .../{FieldType.jsx => FieldType.tsx} | 17 +-- src/components/FieldUrl.jsx | 22 --- src/components/FieldUrl.tsx | 23 +++ src/components/{Fieldset.jsx => Fieldset.tsx} | 26 ++-- ...rEditorBlock.jsx => FilterEditorBlock.tsx} | 10 +- ...{IconBackground.jsx => IconBackground.tsx} | 0 .../{IconCircle.jsx => IconCircle.tsx} | 0 src/components/{IconFill.jsx => IconFill.tsx} | 0 .../{IconLayer.jsx => IconLayer.tsx} | 23 ++- src/components/{IconLine.jsx => IconLine.tsx} | 0 .../{IconMissing.jsx => IconMissing.tsx} | 0 .../{IconSymbol.jsx => IconSymbol.tsx} | 0 .../{InputArray.jsx => InputArray.tsx} | 47 +++--- ...Autocomplete.jsx => InputAutocomplete.tsx} | 28 ++-- .../{InputButton.jsx => InputButton.tsx} | 30 ++-- .../{InputCheckbox.jsx => InputCheckbox.tsx} | 16 +- .../{InputColor.jsx => InputColor.tsx} | 47 +++--- ...DynamicArray.jsx => InputDynamicArray.tsx} | 60 ++++---- .../{InputEnum.jsx => InputEnum.tsx} | 31 ++-- .../{InputFont.jsx => InputFont.tsx} | 24 +-- .../{InputJson.jsx => InputJson.tsx} | 92 ++++++------ ...nputMultiInput.jsx => InputMultiInput.tsx} | 19 ++- .../{InputNumber.jsx => InputNumber.tsx} | 85 ++++++----- .../{InputSelect.jsx => InputSelect.tsx} | 26 ++-- src/components/InputSpec.jsx | 139 ------------------ src/components/InputSpec.tsx | 126 ++++++++++++++++ .../{InputString.jsx => InputString.tsx} | 46 +++--- src/components/{InputUrl.jsx => InputUrl.tsx} | 45 +++--- src/components/{Modal.jsx => Modal.tsx} | 26 ++-- .../{ModalLoading.jsx => ModalLoading.tsx} | 22 +-- .../{ModalOpen.jsx => ModalOpen.tsx} | 70 +++++---- .../{ModalSettings.jsx => ModalSettings.tsx} | 47 +++--- ...{ModalShortcuts.jsx => ModalShortcuts.tsx} | 12 +- .../{ModalSurvey.jsx => ModalSurvey.tsx} | 12 +- src/components/ScrollContainer.jsx | 15 -- src/components/ScrollContainer.tsx | 14 ++ ...ilterEditor.jsx => SingleFilterEditor.tsx} | 38 +++-- .../{SmallError.jsx => SmallError.tsx} | 13 +- .../{SpecField.jsx => SpecField.tsx} | 14 +- 64 files changed, 1009 insertions(+), 859 deletions(-) rename src/components/{Block.jsx => Block.tsx} (70%) rename src/components/{Doc.jsx => Doc.tsx} (77%) delete mode 100644 src/components/FieldArray.jsx create mode 100644 src/components/FieldArray.tsx delete mode 100644 src/components/FieldColor.jsx create mode 100644 src/components/FieldColor.tsx rename src/components/{FieldDocLabel.jsx => FieldDocLabel.tsx} (73%) delete mode 100644 src/components/FieldEnum.jsx create mode 100644 src/components/FieldEnum.tsx rename src/components/{FieldId.jsx => FieldId.tsx} (60%) delete mode 100644 src/components/FieldJson.jsx create mode 100644 src/components/FieldJson.tsx rename src/components/{FieldMaxZoom.jsx => FieldMaxZoom.tsx} (72%) rename src/components/{FieldMinZoom.jsx => FieldMinZoom.tsx} (72%) delete mode 100644 src/components/FieldMultiInput.jsx create mode 100644 src/components/FieldMultiInput.tsx delete mode 100644 src/components/FieldNumber.jsx create mode 100644 src/components/FieldNumber.tsx delete mode 100644 src/components/FieldSelect.jsx create mode 100644 src/components/FieldSelect.tsx delete mode 100644 src/components/FieldString.jsx create mode 100644 src/components/FieldString.tsx rename src/components/{FieldType.jsx => FieldType.tsx} (78%) delete mode 100644 src/components/FieldUrl.jsx create mode 100644 src/components/FieldUrl.tsx rename src/components/{Fieldset.jsx => Fieldset.tsx} (72%) rename src/components/{FilterEditorBlock.jsx => FilterEditorBlock.tsx} (73%) rename src/components/{IconBackground.jsx => IconBackground.tsx} (100%) rename src/components/{IconCircle.jsx => IconCircle.tsx} (100%) rename src/components/{IconFill.jsx => IconFill.tsx} (100%) rename src/components/{IconLayer.jsx => IconLayer.tsx} (62%) rename src/components/{IconLine.jsx => IconLine.tsx} (100%) rename src/components/{IconMissing.jsx => IconMissing.tsx} (100%) rename src/components/{IconSymbol.jsx => IconSymbol.tsx} (100%) rename src/components/{InputArray.jsx => InputArray.tsx} (67%) rename src/components/{InputAutocomplete.jsx => InputAutocomplete.tsx} (80%) rename src/components/{InputButton.jsx => InputButton.tsx} (53%) rename src/components/{InputCheckbox.jsx => InputCheckbox.tsx} (77%) rename src/components/{InputColor.jsx => InputColor.tsx} (79%) rename src/components/{InputDynamicArray.jsx => InputDynamicArray.tsx} (70%) rename src/components/{InputEnum.jsx => InputEnum.tsx} (58%) rename src/components/{InputFont.jsx => InputFont.tsx} (72%) rename src/components/{InputJson.jsx => InputJson.tsx} (64%) rename src/components/{InputMultiInput.jsx => InputMultiInput.tsx} (67%) rename src/components/{InputNumber.jsx => InputNumber.tsx} (74%) rename src/components/{InputSelect.jsx => InputSelect.tsx} (53%) delete mode 100644 src/components/InputSpec.jsx create mode 100644 src/components/InputSpec.tsx rename src/components/{InputString.jsx => InputString.tsx} (62%) rename src/components/{InputUrl.jsx => InputUrl.tsx} (68%) rename src/components/{Modal.jsx => Modal.tsx} (77%) rename src/components/{ModalLoading.jsx => ModalLoading.tsx} (64%) rename src/components/{ModalOpen.jsx => ModalOpen.tsx} (82%) rename src/components/{ModalSettings.jsx => ModalSettings.tsx} (85%) rename src/components/{ModalShortcuts.jsx => ModalShortcuts.tsx} (93%) rename src/components/{ModalSurvey.jsx => ModalSurvey.tsx} (85%) delete mode 100644 src/components/ScrollContainer.jsx create mode 100644 src/components/ScrollContainer.tsx rename src/components/{SingleFilterEditor.jsx => SingleFilterEditor.tsx} (61%) rename src/components/{SmallError.jsx => SmallError.tsx} (54%) rename src/components/{SpecField.jsx => SpecField.tsx} (71%) diff --git a/cypress/e2e/modals.cy.ts b/cypress/e2e/modals.cy.ts index e5fd505f..911deef6 100644 --- a/cypress/e2e/modals.cy.ts +++ b/cypress/e2e/modals.cy.ts @@ -77,11 +77,18 @@ describe("modals", () => { }); it("name", () => { + when.click("field-doc-button-Name"); + + should.containText("spec-field-doc", "name for the style"); + }); + + it("show name specifications", () => { when.setValue(get.dataAttribute("modal:settings.name"), "foobar"); when.click("modal:settings.owner"); should.equalStyleStore((obj) => obj.name, "foobar"); }); + it("owner", () => { when.setValue(get.dataAttribute("modal:settings.owner"), "foobar"); when.click("modal:settings.name"); diff --git a/package-lock.json b/package-lock.json index 3eada999..24fa6919 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,11 +67,19 @@ "@storybook/react": "^7.6.5", "@storybook/react-vite": "^7.6.5", "@storybook/theming": "^7.6.5", + "@types/codemirror": "^5.60.15", + "@types/color": "^3.0.6", "@types/cors": "^2.8.17", + "@types/lodash.capitalize": "^4.2.9", "@types/lodash.isequal": "^4.5.8", "@types/lodash.throttle": "^4.1.9", "@types/react": "^16.14.52", + "@types/react-aria-modal": "^4.0.9", + "@types/react-autocomplete": "^1.8.9", + "@types/react-color": "^3.0.10", "@types/react-dom": "^16.9.24", + "@types/react-file-reader-input": "^2.0.4", + "@types/react-icon-base": "^2.1.6", "@types/uuid": "^9.0.7", "@vitejs/plugin-react": "^4.2.0", "cors": "^2.8.5", @@ -4583,6 +4591,39 @@ "@types/chai": "*" } }, + "node_modules/@types/codemirror": { + "version": "5.60.15", + "resolved": "https://registry.npmjs.org/@types/codemirror/-/codemirror-5.60.15.tgz", + "integrity": "sha512-dTOvwEQ+ouKJ/rE9LT1Ue2hmP6H1mZv5+CCnNWu2qtiOe2LQa9lCprEY20HxiDmV/Bxh+dXjywmy5aKvoGjULA==", + "dev": true, + "dependencies": { + "@types/tern": "*" + } + }, + "node_modules/@types/color": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@types/color/-/color-3.0.6.tgz", + "integrity": "sha512-NMiNcZFRUAiUUCCf7zkAelY8eV3aKqfbzyFQlXpPIEeoNDbsEHGpb854V3gzTsGKYj830I5zPuOwU/TP5/cW6A==", + "dev": true, + "dependencies": { + "@types/color-convert": "*" + } + }, + "node_modules/@types/color-convert": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@types/color-convert/-/color-convert-2.0.3.tgz", + "integrity": "sha512-2Q6wzrNiuEvYxVQqhh7sXM2mhIhvZR/Paq4FdsQkOMgWsCIkKvSGj8Le1/XalulrmgOzPMqNa0ix+ePY4hTrfg==", + "dev": true, + "dependencies": { + "@types/color-name": "*" + } + }, + "node_modules/@types/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-87W6MJCKZYDhLAx/J1ikW8niMvmGRyY+rpUxWpL1cO7F8Uu5CHuQoFv+R0/L5pgNdW4jTyda42kv60uwVIPjLw==", + "dev": true + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -4703,6 +4744,15 @@ "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", "dev": true }, + "node_modules/@types/lodash.capitalize": { + "version": "4.2.9", + "resolved": "https://registry.npmjs.org/@types/lodash.capitalize/-/lodash.capitalize-4.2.9.tgz", + "integrity": "sha512-SV1dav/WbuI816SVig4trFz8ID/m5maVzC8I/E/DejPvmlXvIhw7Y0GWxJ03UhU6qaZOj6qQnR1xxC0mP7ZXoQ==", + "dev": true, + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/lodash.isequal": { "version": "4.5.8", "resolved": "https://registry.npmjs.org/@types/lodash.isequal/-/lodash.isequal-4.5.8.tgz", @@ -4831,6 +4881,34 @@ "csstype": "^3.0.2" } }, + "node_modules/@types/react-aria-modal": { + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@types/react-aria-modal/-/react-aria-modal-4.0.9.tgz", + "integrity": "sha512-H8SU5QoB+1ldMGYRHNm1MXfzD5oD+ZdYTrwVzT+KEiFrkTqQG2QdwVc6Ro4/RixnU4LNtMpvF5HKAIfzzGJGjw==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/react-autocomplete": { + "version": "1.8.9", + "resolved": "https://registry.npmjs.org/@types/react-autocomplete/-/react-autocomplete-1.8.9.tgz", + "integrity": "sha512-Il8qJEKvPU0uW+HOPiRHIKxGF61RM6cM5tEnZDmM5ek78OK5kfv04AZbNyqdPsuTnwp8HIRgBnQH2RhgKILjcg==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/react-color": { + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/@types/react-color/-/react-color-3.0.10.tgz", + "integrity": "sha512-6K5BAn3zyd8lW8UbckIAVeXGxR82Za9jyGD2DBEynsa7fKaguLDVtjfypzs7fgEV7bULgs7uhds8A8v1wABTvQ==", + "dev": true, + "dependencies": { + "@types/react": "*", + "@types/reactcss": "*" + } + }, "node_modules/@types/react-dom": { "version": "16.9.24", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.24.tgz", @@ -4840,6 +4918,33 @@ "@types/react": "^16" } }, + "node_modules/@types/react-file-reader-input": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/react-file-reader-input/-/react-file-reader-input-2.0.4.tgz", + "integrity": "sha512-Jqrfn+w42j8t8Q3npMXXKPdk+reIM0UHLKVc3ykrA7q7bN3Z62SGhsClZX0+Edlqm66lcKwmDQl+WMm+Xor7Xg==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/react-icon-base": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@types/react-icon-base/-/react-icon-base-2.1.6.tgz", + "integrity": "sha512-ebbN1JjCm6RxBd3HdI1+8VCdiOI4qMjnl9DIHWJFrB/eYLF4mzIgdL34PIqCJBLY3vlwil9v6IHQvzsa8vgMsg==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/reactcss": { + "version": "1.2.11", + "resolved": "https://registry.npmjs.org/@types/reactcss/-/reactcss-1.2.11.tgz", + "integrity": "sha512-0fFy0ubuPlhksId8r9V8nsLcxBAPQnn15g/ERAElgE9L6rOquMj2CapsxqfyBuHlkp0/ndEUVnkYI7MkTtkGpw==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/resolve": { "version": "1.20.6", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.6.tgz", @@ -4891,6 +4996,15 @@ "integrity": "sha512-0vWLNK2D5MT9dg0iOo8GlKguPAU02QjmZitPEsXRuJXU/OGIOt9vT9Fc26wtYuavLxtO45v9PGleoL9Z0k1LHg==", "dev": true }, + "node_modules/@types/tern": { + "version": "0.23.9", + "resolved": "https://registry.npmjs.org/@types/tern/-/tern-0.23.9.tgz", + "integrity": "sha512-ypzHFE/wBzh+BlH6rrBgS5I/Z7RD21pGhZ2rltb/+ZrVM1awdZwjx7hE5XfuYgHWk9uvV5HLZN3SloevCAp3Bw==", + "dev": true, + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/@types/uuid": { "version": "9.0.7", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.7.tgz", diff --git a/package.json b/package.json index 75b11d12..fd9e9624 100644 --- a/package.json +++ b/package.json @@ -96,11 +96,19 @@ "@storybook/react": "^7.6.5", "@storybook/react-vite": "^7.6.5", "@storybook/theming": "^7.6.5", + "@types/codemirror": "^5.60.15", + "@types/color": "^3.0.6", "@types/cors": "^2.8.17", + "@types/lodash.capitalize": "^4.2.9", "@types/lodash.isequal": "^4.5.8", "@types/lodash.throttle": "^4.1.9", "@types/react": "^16.14.52", + "@types/react-aria-modal": "^4.0.9", + "@types/react-autocomplete": "^1.8.9", + "@types/react-color": "^3.0.10", "@types/react-dom": "^16.9.24", + "@types/react-file-reader-input": "^2.0.4", + "@types/react-icon-base": "^2.1.6", "@types/uuid": "^9.0.7", "@vitejs/plugin-react": "^4.2.0", "cors": "^2.8.5", diff --git a/src/components/Block.jsx b/src/components/Block.tsx similarity index 70% rename from src/components/Block.jsx rename to src/components/Block.tsx index d3a2bfff..d7fe3709 100644 --- a/src/components/Block.jsx +++ b/src/components/Block.tsx @@ -1,40 +1,43 @@ -import React from 'react' -import PropTypes from 'prop-types' +import React, {SyntheticEvent} from 'react' import classnames from 'classnames' import FieldDocLabel from './FieldDocLabel' import Doc from './Doc' -/** Wrap a component with a label */ -export default class Block extends React.Component { - static propTypes = { - "data-wd-key": PropTypes.string, - label: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.element, - ]), - action: PropTypes.element, - children: PropTypes.node.isRequired, - style: PropTypes.object, - onChange: PropTypes.func, - fieldSpec: PropTypes.object, - wideMode: PropTypes.bool, - error: PropTypes.array, - } +type BlockProps = { + "data-wd-key"?: string + label?: string + action?: React.ReactElement + style?: object + onChange?(...args: unknown[]): unknown + fieldSpec?: object + wideMode?: boolean + error?: unknown[] +}; - constructor (props) { +type BlockState = { + showDoc: boolean +}; + +/** Wrap a component with a label */ +export default class Block extends React.Component { + _blockEl: HTMLDivElement | null = null; + + constructor (props: BlockProps) { super(props); this.state = { showDoc: false, } } - onChange(e) { + onChange(e: React.BaseSyntheticEvent) { const value = e.target.value - return this.props.onChange(value === "" ? undefined : value) + if (this.props.onChange) { + return this.props.onChange(value === "" ? undefined : value) + } } - onToggleDoc = (val) => { + onToggleDoc = (val: boolean) => { this.setState({ showDoc: val }); @@ -46,20 +49,17 @@ export default class Block extends React.Component { * causing the picker to reopen. This causes a scenario where the picker can * never be closed once open. */ - onLabelClick = (event) => { + onLabelClick = (event: SyntheticEvent) => { const el = event.nativeEvent.target; - const nativeEvent = event.nativeEvent; - const contains = this._blockEl.contains(el); + const contains = this._blockEl?.contains(el); if (event.nativeEvent.target.nodeName !== "INPUT" && !contains) { event.stopPropagation(); } - event.preventDefault(); + event.preventDefault(); } render() { - const errors = [].concat(this.props.error || []); - return