Skip to content

Commit

Permalink
Fix Form component config
Browse files Browse the repository at this point in the history
  • Loading branch information
mlqn committed Jan 28, 2025
1 parent 51e4a2b commit 86637a4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 63 deletions.
1 change: 0 additions & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,6 @@
"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.preselectedOptionIndex_button": "Plassering av forhåndsvalgt verdi (indeks)",
"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
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ export const FormComponentConfig = ({
key={propertyKey}
/>
))}

{/** Custom logic for custom file endings */}
{hasCustomFileEndings && (
<>
<EditBooleanValue
propertyKey='hasCustomFileEndings'
component={component}
defaultValue={hasCustomFileEndings.default}
handleComponentChange={(updatedComponent: FormComponent) => {
if (!updatedComponent.hasCustomFileEndings) {
handleComponentUpdate({
...updatedComponent,
validFileEndings: undefined,
});
return;
}
handleComponentUpdate(updatedComponent);
}}
/>
{component['hasCustomFileEndings'] && (
<EditStringValue
component={component}
handleComponentChange={handleComponentUpdate}
propertyKey='validFileEndings'
/>
)}
</>
)}

{showOtherComponents &&
restOfBooleanKeys.map((propertyKey) => (
<EditBooleanValue
Expand All @@ -144,6 +173,7 @@ export const FormComponentConfig = ({
key={propertyKey}
/>
))}

{restOfBooleanKeys.length > 0 && (
<StudioProperty.Button
className={classes.button}
Expand All @@ -152,6 +182,7 @@ export const FormComponentConfig = ({
property={rendertext}
/>
)}

{grid && (
<>
{showGrid ? (
Expand Down Expand Up @@ -188,13 +219,11 @@ export const FormComponentConfig = ({
)}
</>
)}

{/** String properties */}
{stringPropertyKeys.map((propertyKey) => {
return (
<CollapsiblePropertyEditor
key={propertyKey}
label={t(`ux_editor.component_properties.${propertyKey}` as TranslationKey)}
>
<CollapsiblePropertyEditor key={propertyKey} label={componentPropertyLabel(propertyKey)}>
<EditStringValue
component={component}
handleComponentChange={handleComponentUpdate}
Expand All @@ -204,77 +233,42 @@ export const FormComponentConfig = ({
</CollapsiblePropertyEditor>
);
})}
{/** Array properties with enum values) */}
{arrayPropertyKeys.map((propertyKey) => {
const isShowValidations = propertyKey === 'showValidations';
const commonProps = {
component,
handleComponentChange: handleComponentUpdate,
propertyKey,
key: propertyKey,
enumValues: properties[propertyKey]?.items?.enum,
multiple: true,
};
return isShowValidations ? (
<CollapsiblePropertyEditor
key={propertyKey}
label={t('ux_editor.component_properties.showValidations')}
>
<EditStringValue {...commonProps} />
</CollapsiblePropertyEditor>
) : (
<EditStringValue {...commonProps} />
);
})}

{/** Number properties (number and integer types) */}
{numberPropertyKeys.map((propertyKey) => {
const isPreselectedOptionIndex = propertyKey === 'preselectedOptionIndex';
const commonProps = {
component,
handleComponentChange: handleComponentUpdate,
propertyKey,
key: propertyKey,
enumValues: properties[propertyKey]?.enum,
};
return isPreselectedOptionIndex ? (
return (
<CollapsiblePropertyEditor
key={propertyKey}
label={t('ux_editor.component_properties.preselectedOptionIndex_button')}
label={componentPropertyLabel(
`${propertyKey}${propertyKey === 'preselectedOptionIndex' ? '_button' : ''}`,
)}
>
<EditNumberValue {...commonProps} />
<EditNumberValue
component={component}
handleComponentChange={handleComponentUpdate}
propertyKey={propertyKey}
key={propertyKey}
enumValues={properties[propertyKey]?.enum}
/>
</CollapsiblePropertyEditor>
) : (
<EditNumberValue {...commonProps} />
);
})}

{/** Custom logic for custom file endings */}
{hasCustomFileEndings && (
<>
<EditBooleanValue
propertyKey='hasCustomFileEndings'
component={component}
defaultValue={hasCustomFileEndings.default}
handleComponentChange={(updatedComponent: FormComponent) => {
if (!updatedComponent.hasCustomFileEndings) {
handleComponentUpdate({
...updatedComponent,
validFileEndings: undefined,
});
return;
}
handleComponentUpdate(updatedComponent);
}}
/>
{component['hasCustomFileEndings'] && (
{/** Array properties with enum values) */}
{arrayPropertyKeys.map((propertyKey) => {
return (
<CollapsiblePropertyEditor key={propertyKey} label={componentPropertyLabel(propertyKey)}>
<EditStringValue
component={component}
handleComponentChange={handleComponentUpdate}
propertyKey='validFileEndings'
propertyKey={propertyKey}
key={propertyKey}
enumValues={properties[propertyKey]?.items?.enum}
multiple={true}
/>
)}
</>
)}
</CollapsiblePropertyEditor>
);
})}

{/** Object properties */}
{objectPropertyKeys.map((propertyKey) => {
Expand Down

0 comments on commit 86637a4

Please sign in to comment.