Skip to content

Commit

Permalink
feat: Create datamodel for subform in config (#14138)
Browse files Browse the repository at this point in the history
Co-authored-by: Jamal Alabdullah <[email protected]>
Co-authored-by: Michael Queyrichon <[email protected]>
Co-authored-by: Jonas Dyrlie <[email protected]>
  • Loading branch information
4 people authored Dec 2, 2024
1 parent 844b3b1 commit ebfb78e
Show file tree
Hide file tree
Showing 31 changed files with 677 additions and 457 deletions.
3 changes: 3 additions & 0 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1373,11 +1373,14 @@
"ux_editor.component_properties.stickyHeader": "Fest tittelraden",
"ux_editor.component_properties.style": "Stil",
"ux_editor.component_properties.subdomains": "Subdomener (kommaseparert)",
"ux_editor.component_properties.subform.choose_data_model": "Velg datamodell...",
"ux_editor.component_properties.subform.choose_layout_set": "Velg et underskjema...",
"ux_editor.component_properties.subform.choose_layout_set_description": "Velg først underskjemaet du vil bruke i Tabell for underskjema. Deretter kan du sette opp egenskapene for komponenten.",
"ux_editor.component_properties.subform.choose_layout_set_header": "Velg underskjemaet du vil bruke",
"ux_editor.component_properties.subform.choose_layout_set_label": "Velg et underskjema",
"ux_editor.component_properties.subform.create_layout_set_button": "Opprett et nytt underskjema",
"ux_editor.component_properties.subform.create_new_data_model": "Lag ny datamodell",
"ux_editor.component_properties.subform.create_new_data_model_label": "Navn på ny datamodell",
"ux_editor.component_properties.subform.created_layout_set_name": "Navn på underskjema",
"ux_editor.component_properties.subform.data_model_binding_label": "Velg datamodellknytning",
"ux_editor.component_properties.subform.data_model_empty_messsage": "Ingen tilgjengelige datamodeller",
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/shared/src/types/AppsQueryKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum AppsQueryKey {
AppLayouts = 'formLayouts',
AppLayoutSets = 'fetchLayoutSets',
AppLayoutSettings = 'layoutSettings',
AppTextResources = 'fetchTextResources',
}
15 changes: 15 additions & 0 deletions frontend/packages/ux-editor/src/AppContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ describe('AppContext', () => {
);
});

it('invalidates layout sets query for Apps in preview', async () => {
const { queryClient } = renderAppContext(({ updateLayoutSetsForPreview }: AppContextProps) => (
<Button onClick={() => updateLayoutSetsForPreview()} />
));

await clickButton();

await waitFor(async () => expect(queryClient.invalidateQueries).toHaveBeenCalledTimes(1));
await waitFor(async () =>
expect(queryClient.invalidateQueries).toHaveBeenCalledWith({
queryKey: [AppsQueryKey.AppLayoutSets],
}),
);
});

it('invalidates layout settings query for Apps in preview', async () => {
const { queryClient } = renderAppContext(
({ updateLayoutSettingsForPreview, selectedFormLayoutSetName }: AppContextProps) => (
Expand Down
10 changes: 10 additions & 0 deletions frontend/packages/ux-editor/src/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface AppContextProps {
selectedFormLayoutName: string;
setSelectedFormLayoutName: (selectedFormLayoutName: string) => void;
updateLayoutsForPreview: (layoutSetName: string, resetQueries?: boolean) => Promise<void>;
updateLayoutSetsForPreview: (resetQueries?: boolean) => Promise<void>;
updateLayoutSettingsForPreview: (layoutSetName: string, resetQueries?: boolean) => Promise<void>;
updateTextsForPreview: (language: string, resetQueries?: boolean) => Promise<void>;
shouldReloadPreview: boolean;
Expand Down Expand Up @@ -75,6 +76,13 @@ export const AppContextProvider = ({
[refetch],
);

const updateLayoutSetsForPreview = useCallback(
async (resetQueries: boolean = false): Promise<void> => {
return await refetch([AppsQueryKey.AppLayoutSets], resetQueries);
},
[refetch],
);

const updateLayoutSettingsForPreview = useCallback(
async (layoutSetName: string, resetQueries: boolean = false): Promise<void> => {
return await refetch([AppsQueryKey.AppLayoutSettings, layoutSetName], resetQueries);
Expand All @@ -97,6 +105,7 @@ export const AppContextProvider = ({
selectedFormLayoutName,
setSelectedFormLayoutName,
updateLayoutsForPreview,
updateLayoutSetsForPreview,
updateLayoutSettingsForPreview,
updateTextsForPreview,
shouldReloadPreview,
Expand All @@ -109,6 +118,7 @@ export const AppContextProvider = ({
selectedFormLayoutName,
setSelectedFormLayoutName,
updateLayoutsForPreview,
updateLayoutSetsForPreview,
updateLayoutSettingsForPreview,
updateTextsForPreview,
shouldReloadPreview,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import classes from './CreateNewSubformButtons.module.css';
import { CheckmarkIcon, TrashIcon } from '@studio/icons';
import { StudioButton, StudioSpinner } from '@studio/components';
import { useTranslation } from 'react-i18next';

type CreateNewSubformButtonsProps = {
isPendingNewSubformMutation: boolean;
disableSaveButton: boolean;
displayCloseButton: boolean;
handleCloseButton: () => void;
};

export const CreateNewSubformButtons = ({
isPendingNewSubformMutation,
disableSaveButton,
displayCloseButton,
handleCloseButton,
}: CreateNewSubformButtonsProps) => {
const { t } = useTranslation();

const saveIcon = isPendingNewSubformMutation ? (
<StudioSpinner size='sm' spinnerTitle={t('general.loading')} />
) : (
<CheckmarkIcon />
);

return (
<div className={classes.buttonGroup}>
<StudioButton
icon={saveIcon}
type='submit'
title={t('general.save')}
disabled={disableSaveButton}
variant='secondary'
color='success'
/>
{displayCloseButton && (
<StudioButton
onClick={handleCloseButton}
title={t('general.close')}
icon={<TrashIcon />}
variant='secondary'
color='danger'
/>
)}
</div>
);
};
Loading

0 comments on commit ebfb78e

Please sign in to comment.