From b9e1998360912fe3d19ea0fe9425f4af63eaba95 Mon Sep 17 00:00:00 2001 From: Michael Queyrichon Date: Tue, 14 Jan 2025 15:45:18 +0100 Subject: [PATCH] Retrieve help texts from nb.json instead of JSON schemas --- frontend/language/src/nb.json | 2 +- .../src/components/Properties/DataModelBindings.tsx | 1 - .../src/components/config/FormComponentConfig.tsx | 6 +----- .../EditBinding/EditBinding.test.tsx | 1 - .../EditDataModelBinding/EditBinding/EditBinding.tsx | 3 --- .../EditBinding/SelectDataFieldBinding.tsx | 6 +++--- .../EditDataModelBinding.test.tsx | 1 - .../EditDataModelBinding/EditDataModelBinding.tsx | 3 --- .../components/config/editModal/EditNumberValue.tsx | 11 +++++++---- .../components/config/editModal/EditStringValue.tsx | 6 +++--- 10 files changed, 15 insertions(+), 25 deletions(-) diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index c12a983f729..4f9f7952a64 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -1383,7 +1383,6 @@ "ux_editor.component_properties.pagination": "Sidenummerering", "ux_editor.component_properties.position": "Plassering av valuta", "ux_editor.component_properties.preselectedOptionIndex": "Angi det valget som skal være forhåndsvalgt.", - "ux_editor.component_properties.preselected_help_text": "Eksempel: Hvis du har 5 valg, kan du bruke tall fra 0-4.", "ux_editor.component_properties.queryParameters": "Parametere i spørringen", "ux_editor.component_properties.readOnly": "Feltet kan kun leses", "ux_editor.component_properties.receiver": "Den som mottar skjemaet", @@ -1488,6 +1487,7 @@ "ux_editor.component_properties_description.pageBreak": "Valgfri sideskift før eller etter komponenten i PDF", "ux_editor.component_properties_description.pagination": "Pagineringsvalg for repeterende gruppe", "ux_editor.component_properties_help_text.hidden": "Hvis du velger å skjule et felt, kan du sette betingelser for når det skal skjules under Valg for dynamikk.", + "ux_editor.component_properties_help_text.preselectedOptionIndex": "Eksempel: Hvis du har 5 valg, kan du bruke tall fra 0-4.", "ux_editor.component_title.Accordion": "Trekkspilliste", "ux_editor.component_title.AccordionGroup": "Nestet trekkspilliste", "ux_editor.component_title.ActionButton": "Handlingsknapp", diff --git a/frontend/packages/ux-editor/src/components/Properties/DataModelBindings.tsx b/frontend/packages/ux-editor/src/components/Properties/DataModelBindings.tsx index 10ef68cbbe0..0cd574b37c1 100644 --- a/frontend/packages/ux-editor/src/components/Properties/DataModelBindings.tsx +++ b/frontend/packages/ux-editor/src/components/Properties/DataModelBindings.tsx @@ -101,7 +101,6 @@ export const DataModelBindings = (): React.JSX.Element => { debounceSave(formItemId, updatedComponent, mutateOptions); }} editFormId={formItemId} - helpText={dataModelBindingsProperties[propertyKey]?.description} renderOptions={{ key: propertyKey, label: propertyKey !== 'simpleBinding' ? propertyKey : undefined, diff --git a/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx b/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx index 39f6c9a0155..7417695bb5a 100644 --- a/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx +++ b/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx @@ -45,7 +45,7 @@ export const FormComponentConfig = ({ if (!schema?.properties) return null; const { properties } = schema; - const { hasCustomFileEndings, validFileEndings, grid, layoutSet } = properties; + const { hasCustomFileEndings, grid, layoutSet } = properties; // Add any properties that have a custom implementation to this list so they are not duplicated in the generic view const customProperties = [ @@ -185,7 +185,6 @@ export const FormComponentConfig = ({ component={component} handleComponentChange={handleComponentUpdate} propertyKey='validFileEndings' - helpText={validFileEndings?.description} /> )} @@ -199,7 +198,6 @@ export const FormComponentConfig = ({ handleComponentChange={handleComponentUpdate} propertyKey={propertyKey} key={propertyKey} - helpText={properties[propertyKey]?.description} enumValues={properties[propertyKey]?.enum || properties[propertyKey]?.examples} /> ); @@ -213,7 +211,6 @@ export const FormComponentConfig = ({ handleComponentChange={handleComponentUpdate} propertyKey={propertyKey} key={propertyKey} - helpText={t('ux_editor.component_properties.preselected_help_text')} enumValues={properties[propertyKey]?.enum} /> ); @@ -227,7 +224,6 @@ export const FormComponentConfig = ({ handleComponentChange={handleComponentUpdate} propertyKey={propertyKey} key={propertyKey} - helpText={properties[propertyKey]?.description} enumValues={properties[propertyKey]?.items?.enum} multiple={true} /> diff --git a/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.test.tsx b/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.test.tsx index 98b5ff43d95..ff5dff822f4 100644 --- a/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.test.tsx +++ b/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.test.tsx @@ -24,7 +24,6 @@ const secondDataModel = 'secondModel'; const defaultEditBinding: EditBindingProps = { bindingKey: defaultBindingKey, component: componentMocks[ComponentType.Input], - helpText: undefined, label: defaultLabel, handleComponentChange: jest.fn(), onSetDataModelSelectVisible: jest.fn(), diff --git a/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.tsx b/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.tsx index 2c88efc3155..68ac789d9be 100644 --- a/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.tsx +++ b/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.tsx @@ -22,7 +22,6 @@ import { formItemConfigs } from '@altinn/ux-editor/data/formItemConfig'; export type EditBindingProps = { bindingKey: string; component: FormItem; - helpText: string; label: string; handleComponentChange: (component: FormItem, mutateOptions?: UpdateFormMutateOptions) => void; onSetDataModelSelectVisible: (visible: boolean) => void; @@ -32,7 +31,6 @@ export type EditBindingProps = { export const EditBinding = ({ bindingKey, component, - helpText, label, handleComponentChange, onSetDataModelSelectVisible, @@ -102,7 +100,6 @@ export const EditBinding = ({ internalBindingFormat={internalBindingFormat} handleBindingChange={handleBindingChange} bindingKey={bindingKey} - helpText={helpText} componentType={component.type} /> void; bindingKey: string; - helpText: string; componentType: ComponentType; }; @@ -23,7 +23,6 @@ export const SelectDataFieldBinding = ({ internalBindingFormat, handleBindingChange, bindingKey, - helpText, componentType, }: SelectDataFieldProps): React.JSX.Element => { const { t } = useTranslation(); @@ -35,6 +34,7 @@ export const SelectDataFieldBinding = ({ const dataModelFields = getDataModelFields({ componentType, bindingKey, dataModelMetadata }); const isDataModelFieldValid = validateSelectedDataField(currentDataModelField, dataModelFields); + const componentPropertyHelpText = useComponentPropertyHelpText(); // Validate datamodel as well: fallbacks to default if invalid, then user must update datafield const isBindingError = !isDataModelFieldValid || !isDataModelValid; @@ -57,7 +57,7 @@ export const SelectDataFieldBinding = ({ onChange={handleDataModelFieldChange} value={isBindingError ? '' : currentDataModelField} propertyPath={propertyPath} - helpText={helpText} + helpText={componentPropertyHelpText(`data_model_bindings.${bindingKey}`)} label={t('ux_editor.modal_properties_data_model_field_binding')} renderField={({ fieldProps }) => ( = { returnValue: 'returnValue', key: 'key', }, - helpText: 'helpText', }; type renderEditDataModelBinding = { diff --git a/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.tsx b/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.tsx index cf57b1763df..f813d5fd348 100644 --- a/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.tsx +++ b/frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.tsx @@ -15,14 +15,12 @@ export interface EditDataModelBindingProps returnValue?: any; key?: string; }; - helpText?: string; } export const EditDataModelBinding = ({ component, handleComponentChange, renderOptions, - helpText, }: EditDataModelBindingProps) => { const { key, label } = renderOptions || {}; const bindingKey = key || 'simpleBinding'; @@ -46,7 +44,6 @@ export const EditDataModelBinding = ({ = FilterKeysOfType>> extends IGenericEditComponent { propertyKey: K; - helpText?: string; enumValues?: number[]; } @@ -23,12 +26,12 @@ export const EditNumberValue = ) => { const { t } = useTranslation(); const componentPropertyLabel = useComponentPropertyLabel(); const { selectedFormLayoutSetName, updateLayoutsForPreview } = useAppContext(); + const componentPropertyHelpText = useComponentPropertyHelpText(); const handleValueChange = async (newValue: number) => { handleComponentChange(setComponentProperty(component, propertyKey, newValue), { @@ -45,7 +48,7 @@ export const EditNumberValue = enumValues ? ( { const { t } = useTranslation(); const componentPropertyLabel = useComponentPropertyLabel(); const componentEnumValue = useComponentPropertyEnumValue(); + const componentPropertyHelpText = useComponentPropertyHelpText(); const handleValueChange = (newValue): void => { handleComponentChange({ @@ -42,7 +42,7 @@ export const EditStringValue = ({ value={component[propertyKey]} onChange={handleValueChange} propertyPath={`${component.propertyPath}/properties/${propertyKey}`} - helpText={helpText} + helpText={componentPropertyHelpText(propertyKey)} customValidationMessages={(errorCode: string) => { if (errorCode === 'pattern') { return t('validation_errors.pattern');