From 1bc68ca9d554ea21df01cfdf4cef3db7050e9b58 Mon Sep 17 00:00:00 2001 From: Floris272 Date: Wed, 9 Oct 2024 17:25:46 +0200 Subject: [PATCH 1/3] [maykinmedia/open-producten#24] remove product attribute from product price component --- .storybook/decorators.tsx | 2 - i18n/messages/en.json | 10 ----- i18n/messages/nl.json | 11 ----- .../ComponentConfiguration.stories.tsx | 13 ------ src/components/ComponentConfiguration.tsx | 2 - src/components/ComponentPreview.stories.tsx | 1 - src/context.ts | 2 - src/registry/productPrice/edit.tsx | 43 ++----------------- src/tests/sharedUtils.tsx | 11 ----- src/tests/test-utils.tsx | 3 -- 10 files changed, 4 insertions(+), 94 deletions(-) diff --git a/.storybook/decorators.tsx b/.storybook/decorators.tsx index 7d807ed0..da0a0bd7 100644 --- a/.storybook/decorators.tsx +++ b/.storybook/decorators.tsx @@ -12,7 +12,6 @@ import { DEFAULT_FILE_TYPES, DEFAULT_PREFILL_ATTRIBUTES, DEFAULT_PREFILL_PLUGINS, - DEFAULT_PRODUCTS, DEFAULT_REGISTRATION_ATTRIBUTES, DEFAULT_VALIDATOR_PLUGINS, sleep, @@ -101,7 +100,6 @@ export const BuilderContextDecorator: Decorator = (Story, context) => { getDocumentTypes: async () => context?.args?.documentTypes || defaultdocumentTypes, getConfidentialityLevels: async () => CONFIDENTIALITY_LEVELS, getAuthPlugins: async () => DEFAULT_AUTH_PLUGINS, - getProducts: async () => DEFAULT_PRODUCTS, }} > diff --git a/i18n/messages/en.json b/i18n/messages/en.json index 2af642ab..1d1a24ed 100644 --- a/i18n/messages/en.json +++ b/i18n/messages/en.json @@ -604,11 +604,6 @@ "description": "File component 'fileMaxSize' validation error", "originalDefault": "Specify a positive, non-zero file size without decimals, e.g. 10MB." }, - "QXsAuR": { - "defaultMessage": "Product to fetch prices for", - "description": "Tooltip for 'product' builder field", - "originalDefault": "Product to fetch prices for" - }, "Qjl92W": { "defaultMessage": "Preview", "description": "Component preview card title", @@ -1439,11 +1434,6 @@ "description": "Tooltip for 'hideHeader' builder field", "originalDefault": "Do not display the configured label and top line as the header in the fieldset." }, - "uuKVtO": { - "defaultMessage": "Product", - "description": "Label for 'product' builder field", - "originalDefault": "Product" - }, "vRVMpe": { "defaultMessage": "Value", "description": "Translations: property column header", diff --git a/i18n/messages/nl.json b/i18n/messages/nl.json index 2824c045..506be98f 100644 --- a/i18n/messages/nl.json +++ b/i18n/messages/nl.json @@ -613,11 +613,6 @@ "description": "File component 'fileMaxSize' validation error", "originalDefault": "Specify a positive, non-zero file size without decimals, e.g. 10MB." }, - "QXsAuR": { - "defaultMessage": "Product waarvoor prijzen worden opgehaald", - "description": "Tooltip for 'product' builder field", - "originalDefault": "Product to fetch prices for" - }, "Qjl92W": { "defaultMessage": "Voorbeeld", "description": "Component preview card title", @@ -1459,12 +1454,6 @@ "description": "Tooltip for 'hideHeader' builder field", "originalDefault": "Do not display the configured label and top line as the header in the fieldset." }, - "uuKVtO": { - "defaultMessage": "Product", - "description": "Label for 'product' builder field", - "isTranslated": true, - "originalDefault": "Product" - }, "vRVMpe": { "defaultMessage": "(Standaard)tekst", "description": "Translations: property column header", diff --git a/src/components/ComponentConfiguration.stories.tsx b/src/components/ComponentConfiguration.stories.tsx index 5d87405f..a234e307 100644 --- a/src/components/ComponentConfiguration.stories.tsx +++ b/src/components/ComponentConfiguration.stories.tsx @@ -13,7 +13,6 @@ import { DEFAULT_COLORS, DEFAULT_DOCUMENT_TYPES, DEFAULT_FILE_TYPES, - DEFAULT_PRODUCTS, } from '@/tests/sharedUtils'; import {AnyComponentSchema} from '@/types'; @@ -114,7 +113,6 @@ const Template: StoryFn = ({ getDocumentTypes={async () => DEFAULT_DOCUMENT_TYPES} getConfidentialityLevels={async () => CONFIDENTIALITY_LEVELS} getAuthPlugins={async () => DEFAULT_AUTH_PLUGINS} - getProducts={async () => DEFAULT_PRODUCTS} component={component} isNew={isNew} builderInfo={builderInfo} @@ -2300,7 +2298,6 @@ export const ProductPrice: Story = { type: 'productPrice', key: 'productPrice', label: 'A productPrice field', - product: '123', }, builderInfo: { @@ -2343,16 +2340,6 @@ export const ProductPrice: Story = { await userEvent.type(canvas.getByLabelText('Label'), 'Other label', {delay: 50}); await expect(canvas.getByLabelText('Property Name')).toHaveDisplayValue('customKey'); - await step('Change Product', async () => { - canvas.getByLabelText('Product').focus(); - await userEvent.keyboard('[ArrowDown]'); - await waitFor(async () => { - const product1 = canvas.getByText('product 1'); - await expect(product1).toBeVisible(); - await userEvent.click(product1); - }); - }); - await step('Submit form', async () => { await userEvent.click(canvas.getByRole('button', {name: 'Save'})); await expect(args.onSubmit).toHaveBeenCalled(); diff --git a/src/components/ComponentConfiguration.tsx b/src/components/ComponentConfiguration.tsx index ab03bfbd..eca05a25 100644 --- a/src/components/ComponentConfiguration.tsx +++ b/src/components/ComponentConfiguration.tsx @@ -44,7 +44,6 @@ const ComponentConfiguration: React.FC = ({ getDocumentTypes, getConfidentialityLevels, getAuthPlugins, - getProducts, isNew, component, builderInfo, @@ -72,7 +71,6 @@ const ComponentConfiguration: React.FC = ({ getDocumentTypes, getConfidentialityLevels, getAuthPlugins, - getProducts, }} > Promise>; getConfidentialityLevels: () => Promise; getAuthPlugins: () => Promise; - getProducts: () => Promise; } const BuilderContext = React.createContext({ @@ -66,7 +65,6 @@ const BuilderContext = React.createContext({ getDocumentTypes: async () => [], getConfidentialityLevels: async () => [], getAuthPlugins: async () => [], - getProducts: async () => [], }); BuilderContext.displayName = 'BuilderContext'; diff --git a/src/registry/productPrice/edit.tsx b/src/registry/productPrice/edit.tsx index 6f3d6bdf..e4c88e33 100644 --- a/src/registry/productPrice/edit.tsx +++ b/src/registry/productPrice/edit.tsx @@ -1,7 +1,5 @@ import {ProductPriceComponentSchema} from '@open-formulieren/types'; -import {useContext} from 'react'; -import {FormattedMessage, useIntl} from 'react-intl'; -import useAsync from 'react-use/esm/useAsync'; +import {useIntl} from 'react-intl'; import { BuilderTabs, @@ -20,8 +18,7 @@ import { useDeriveComponentKey, } from '@/components/builder'; import {LABELS} from '@/components/builder/messages'; -import {Select, TabList, TabPanel, Tabs} from '@/components/formio'; -import {BuilderContext} from '@/context'; +import {TabList, TabPanel, Tabs} from '@/components/formio'; import {useErrorChecker} from '@/utils/errors'; import {EditFormDefinition} from '../types'; @@ -42,7 +39,6 @@ const EditForm: EditFormDefinition = () => { = () => { 'showInPDF', 'hidden', 'clearOnHide', - 'isSensitiveData', - 'product' + 'isSensitiveData' )} /> @@ -70,7 +65,6 @@ const EditForm: EditFormDefinition = () => { - {/* Advanced tab */} @@ -107,7 +101,7 @@ const EditForm: EditFormDefinition = () => { EditForm.defaultValues = { // basic tab label: '', - key: '', + key: 'priceOption', description: '', tooltip: '', showInSummary: true, @@ -116,7 +110,6 @@ EditForm.defaultValues = { hidden: false, clearOnHide: true, isSensitiveData: false, - product: '', // Advanced tab conditional: { show: undefined, @@ -134,32 +127,4 @@ EditForm.defaultValues = { }, }; -const Product: React.FC = () => { - const {getProducts} = useContext(BuilderContext); - const {value: options, loading, error} = useAsync(async () => await getProducts(), []); - if (error) { - throw error; - } - - const intl = useIntl(); - const tooltip = intl.formatMessage({ - description: "Tooltip for 'product' builder field", - defaultMessage: 'Product to fetch prices for', - }); - return ( -