Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Retrieving help texts from nb.json instead of JSON schemas #14420

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -185,7 +185,6 @@ export const FormComponentConfig = ({
component={component}
handleComponentChange={handleComponentUpdate}
propertyKey='validFileEndings'
helpText={validFileEndings?.description}
/>
)}
</>
Expand All @@ -199,7 +198,6 @@ export const FormComponentConfig = ({
handleComponentChange={handleComponentUpdate}
propertyKey={propertyKey}
key={propertyKey}
helpText={properties[propertyKey]?.description}
enumValues={properties[propertyKey]?.enum || properties[propertyKey]?.examples}
/>
);
Expand All @@ -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}
/>
);
Expand All @@ -227,7 +224,6 @@ export const FormComponentConfig = ({
handleComponentChange={handleComponentUpdate}
propertyKey={propertyKey}
key={propertyKey}
helpText={properties[propertyKey]?.description}
enumValues={properties[propertyKey]?.items?.enum}
multiple={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +31,6 @@ export type EditBindingProps = {
export const EditBinding = ({
bindingKey,
component,
helpText,
label,
handleComponentChange,
onSetDataModelSelectVisible,
Expand Down Expand Up @@ -102,7 +100,6 @@ export const EditBinding = ({
internalBindingFormat={internalBindingFormat}
handleBindingChange={handleBindingChange}
bindingKey={bindingKey}
helpText={helpText}
componentType={component.type}
/>
<EditBindingButtons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import { StudioNativeSelect } from '@studio/components';
import { useValidDataModels } from '@altinn/ux-editor/hooks/useValidDataModels';
import type { ComponentType } from 'app-shared/types/ComponentType';
import classes from './SelectDataFieldBinding.module.css';
import { useComponentPropertyHelpText } from '../../../../../hooks';

type SelectDataFieldProps = {
internalBindingFormat: InternalBindingFormat;
handleBindingChange: (dataModelBindings: InternalBindingFormat) => void;
bindingKey: string;
helpText: string;
componentType: ComponentType;
};

export const SelectDataFieldBinding = ({
internalBindingFormat,
handleBindingChange,
bindingKey,
helpText,
componentType,
}: SelectDataFieldProps): React.JSX.Element => {
const { t } = useTranslation();
Expand All @@ -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;
Expand All @@ -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 }) => (
<StudioNativeSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const defaultEditDataModelingBinding: EditDataModelBindingProps<any> = {
returnValue: 'returnValue',
key: 'key',
},
helpText: 'helpText',
};

type renderEditDataModelBinding = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ export interface EditDataModelBindingProps<T extends ComponentType>
returnValue?: any;
key?: string;
};
helpText?: string;
}

export const EditDataModelBinding = <T extends ComponentType>({
component,
handleComponentChange,
renderOptions,
helpText,
}: EditDataModelBindingProps<T>) => {
const { key, label } = renderOptions || {};
const bindingKey = key || 'simpleBinding';
Expand All @@ -46,7 +44,6 @@ export const EditDataModelBinding = <T extends ComponentType>({
<EditBinding
bindingKey={bindingKey}
component={component}
helpText={helpText}
label={labelSpecificText}
handleComponentChange={handleComponentChange}
onSetDataModelSelectVisible={setDataModelSelectVisible}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { StudioDecimalInput, StudioNativeSelect } from '@studio/components';
import type { ComponentType } from 'app-shared/types/ComponentType';
import type { FormItem } from '../../../types/FormItem';
import type { FilterKeysOfType } from 'app-shared/types/FilterKeysOfType';
import { useComponentPropertyLabel, useAppContext } from '../../../hooks';
import {
useComponentPropertyLabel,
useAppContext,
useComponentPropertyHelpText,
} from '../../../hooks';
import type { KeyValuePairs } from 'app-shared/types/KeyValuePairs';
import { useTranslation } from 'react-i18next';

Expand All @@ -15,20 +19,19 @@ type NumberKeys<ObjectType extends KeyValuePairs> = FilterKeysOfType<ObjectType,
export interface EditNumberValueProps<T extends ComponentType, K extends NumberKeys<FormItem<T>>>
extends IGenericEditComponent<T> {
propertyKey: K;
helpText?: string;
enumValues?: number[];
}

export const EditNumberValue = <T extends ComponentType, K extends NumberKeys<FormItem<T>>>({
component,
handleComponentChange,
propertyKey,
helpText,
enumValues,
}: EditNumberValueProps<T, K>) => {
const { t } = useTranslation();
const componentPropertyLabel = useComponentPropertyLabel();
const { selectedFormLayoutSetName, updateLayoutsForPreview } = useAppContext();
const componentPropertyHelpText = useComponentPropertyHelpText();

const handleValueChange = async (newValue: number) => {
handleComponentChange(setComponentProperty<T, number, K>(component, propertyKey, newValue), {
Expand All @@ -45,7 +48,7 @@ export const EditNumberValue = <T extends ComponentType, K extends NumberKeys<Fo
value={component[propertyKey]}
onChange={handleValueChange}
propertyPath={component.propertyPath}
helpText={helpText}
helpText={componentPropertyHelpText(String(propertyKey))}
renderField={({ fieldProps }) =>
enumValues ? (
<StudioNativeSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { Combobox, Textfield } from '@digdir/designsystemet-react';
import { useComponentPropertyLabel } from '../../../hooks/useComponentPropertyLabel';
import { useComponentPropertyEnumValue } from '@altinn/ux-editor/hooks/useComponentPropertyEnumValue';
import { StudioNativeSelect } from '@studio/components';
import { useComponentPropertyHelpText } from '../../../hooks';

const NO_VALUE_SELECTED_IN_NATIVE_SELECT: string = 'NO_VALUE';

export interface EditStringValueProps extends IGenericEditComponent {
propertyKey: string;
helpText?: string;
enumValues?: string[];
multiple?: boolean;
}
Expand All @@ -20,13 +20,13 @@ export const EditStringValue = ({
component,
handleComponentChange,
propertyKey,
helpText,
enumValues,
multiple,
}: EditStringValueProps): ReactElement => {
const { t } = useTranslation();
const componentPropertyLabel = useComponentPropertyLabel();
const componentEnumValue = useComponentPropertyEnumValue();
const componentPropertyHelpText = useComponentPropertyHelpText();

const handleValueChange = (newValue): void => {
handleComponentChange({
Expand All @@ -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');
Expand Down
Loading