Skip to content

Commit

Permalink
[maykinmedia/open-producten#24] remove product attribute from product…
Browse files Browse the repository at this point in the history
… price component
  • Loading branch information
Floris272 committed Oct 9, 2024
1 parent c768a2d commit dc37eb3
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 94 deletions.
2 changes: 0 additions & 2 deletions .storybook/decorators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
DEFAULT_FILE_TYPES,
DEFAULT_PREFILL_ATTRIBUTES,
DEFAULT_PREFILL_PLUGINS,
DEFAULT_PRODUCTS,
DEFAULT_REGISTRATION_ATTRIBUTES,
DEFAULT_VALIDATOR_PLUGINS,
sleep,
Expand Down Expand Up @@ -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,
}}
>
<Story />
Expand Down
10 changes: 0 additions & 10 deletions i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,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",
Expand Down Expand Up @@ -1429,11 +1424,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",
Expand Down
11 changes: 0 additions & 11 deletions i18n/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,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",
Expand Down Expand Up @@ -1449,12 +1444,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",
Expand Down
13 changes: 0 additions & 13 deletions src/components/ComponentConfiguration.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
DEFAULT_COLORS,
DEFAULT_DOCUMENT_TYPES,
DEFAULT_FILE_TYPES,
DEFAULT_PRODUCTS,
} from '@/tests/sharedUtils';
import {AnyComponentSchema} from '@/types';

Expand Down Expand Up @@ -110,7 +109,6 @@ const Template: StoryFn<TemplateArgs> = ({
getDocumentTypes={async () => DEFAULT_DOCUMENT_TYPES}
getConfidentialityLevels={async () => CONFIDENTIALITY_LEVELS}
getAuthPlugins={async () => DEFAULT_AUTH_PLUGINS}
getProducts={async () => DEFAULT_PRODUCTS}
component={component}
isNew={isNew}
builderInfo={builderInfo}
Expand Down Expand Up @@ -2291,7 +2289,6 @@ export const ProductPrice: Story = {
type: 'productPrice',
key: 'productPrice',
label: 'A productPrice field',
product: '123',
},

builderInfo: {
Expand Down Expand Up @@ -2334,16 +2331,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();
Expand Down
2 changes: 0 additions & 2 deletions src/components/ComponentConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const ComponentConfiguration: React.FC<ComponentConfigurationProps> = ({
getDocumentTypes,
getConfidentialityLevels,
getAuthPlugins,
getProducts,
isNew,
component,
builderInfo,
Expand Down Expand Up @@ -72,7 +71,6 @@ const ComponentConfiguration: React.FC<ComponentConfigurationProps> = ({
getDocumentTypes,
getConfidentialityLevels,
getAuthPlugins,
getProducts,
}}
>
<ComponentEditForm
Expand Down
1 change: 0 additions & 1 deletion src/components/ComponentPreview.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,6 @@ export const ProductPrice: Story = {
label: 'Product price preview',
description: 'A preview of the product price Formio component',
hidden: true, // must be ignored
product: '123',
},
},

Expand Down
2 changes: 0 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export interface BuilderContextType {
getDocumentTypes: () => Promise<Array<DocumentTypeOption>>;
getConfidentialityLevels: () => Promise<SelectOption[]>;
getAuthPlugins: () => Promise<AuthPluginOption[]>;
getProducts: () => Promise<SelectOption[]>;
}

const BuilderContext = React.createContext<BuilderContextType>({
Expand All @@ -66,7 +65,6 @@ const BuilderContext = React.createContext<BuilderContextType>({
getDocumentTypes: async () => [],
getConfidentialityLevels: async () => [],
getAuthPlugins: async () => [],
getProducts: async () => [],
});

BuilderContext.displayName = 'BuilderContext';
Expand Down
43 changes: 4 additions & 39 deletions src/registry/productPrice/edit.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand All @@ -42,16 +39,14 @@ const EditForm: EditFormDefinition<ProductPriceComponentSchema> = () => {
<BuilderTabs.Basic
hasErrors={hasAnyError(
'label',
'key',
'description',
'tooltip',
'showInSummary',
'showInEmail',
'showInPDF',
'hidden',
'clearOnHide',
'isSensitiveData',
'product'
'isSensitiveData'
)}
/>
<BuilderTabs.Advanced hasErrors={hasAnyError('conditional')} />
Expand All @@ -70,7 +65,6 @@ const EditForm: EditFormDefinition<ProductPriceComponentSchema> = () => {
<Hidden />
<ClearOnHide />
<IsSensitiveData />
<Product />
</TabPanel>

{/* Advanced tab */}
Expand Down Expand Up @@ -107,7 +101,7 @@ const EditForm: EditFormDefinition<ProductPriceComponentSchema> = () => {
EditForm.defaultValues = {
// basic tab
label: '',
key: '',
key: 'priceOption',
description: '',
tooltip: '',
showInSummary: true,
Expand All @@ -116,7 +110,6 @@ EditForm.defaultValues = {
hidden: false,
clearOnHide: true,
isSensitiveData: false,
product: '',
// Advanced tab
conditional: {
show: undefined,
Expand All @@ -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 (
<Select
name="product"
label={
<FormattedMessage
description="Label for 'product' builder field"
defaultMessage="Product"
/>
}
options={options}
isLoading={loading}
tooltip={tooltip}
/>
);
};

export default EditForm;
11 changes: 0 additions & 11 deletions src/tests/sharedUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,6 @@ export const DEFAULT_COLORS: ColorOption[] = [
},
];

export const DEFAULT_PRODUCTS: SelectOption[] = [
{
label: 'product 1',
value: '1234',
},
{
label: 'product 2',
value: '5678',
},
];

export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
3 changes: 0 additions & 3 deletions src/tests/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
DEFAULT_FILE_TYPES,
DEFAULT_PREFILL_ATTRIBUTES,
DEFAULT_PREFILL_PLUGINS,
DEFAULT_PRODUCTS,
DEFAULT_REGISTRATION_ATTRIBUTES,
DEFAULT_VALIDATOR_PLUGINS,
sleep,
Expand Down Expand Up @@ -94,7 +93,6 @@ const contextRender = (
getConfidentialityLevels: async () =>
builderOptions.confidentialityLevels || CONFIDENTIALITY_LEVELS,
getAuthPlugins: async () => DEFAULT_AUTH_PLUGINS,
getProducts: async () => DEFAULT_PRODUCTS,
}}
>
{children}
Expand Down Expand Up @@ -174,7 +172,6 @@ const dummyBuilderContext = {
getDocumentTypes: async () => [],
getConfidentialityLevels: async () => [],
getAuthPlugins: async () => [],
getProducts: async () => [],
} satisfies BuilderContextType;

// re-export everything (see https://testing-library.com/docs/react-testing-library/setup/#custom-render)
Expand Down

0 comments on commit dc37eb3

Please sign in to comment.