Skip to content

Commit

Permalink
Make select option value of default taskId an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondyr committed Jan 28, 2025
1 parent 66c2e70 commit 1bd1b19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { app, org } from '@studio/testing/testids';
import {
layoutSet1NameMock,
layoutSet2NameMock,
layoutSetsExtendedMock,
layoutSetsMock,
} from '../../../testing/layoutSetsMock';
import { layout1NameMock, layoutMock } from '../../../testing/layoutMock';
Expand Down Expand Up @@ -83,6 +84,7 @@ const render = (component: FormItem) => {
[layout1NameMock]: layoutMock,
});
queryClient.setQueryData([QueryKey.LayoutSets, org, app], layoutSetsMock);
queryClient.setQueryData([QueryKey.LayoutSetsExtended, org, app], layoutSetsExtendedMock);
renderWithProviders(
<ComponentMainConfig component={component} handleComponentChange={handleComponentChange} />,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ describe('Summary2ComponentTargetSelector', () => {
render();

const select = targetTaskIdSelect();
expect(select).toHaveValue(layoutSetsMock.sets[0].tasks[0]);
expect(select).toHaveValue('');
expect(select).toHaveTextContent(layoutSetsMock.sets[0].id);
});

it('should select the task id from the target when the task id of the target is defined', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ import { useTranslation } from 'react-i18next';
import { useAppContext, useComponentTitle } from '../../../../../hooks';
import { useFormLayoutsQuery } from '../../../../../hooks/queries/useFormLayoutsQuery';
import { useTargetTypes } from './useTargetTypes';
import { useLayoutSetsQuery } from 'app-shared/hooks/queries/useLayoutSetsQuery';
import { getComponentOptions, getLayoutSetOptions, getPageOptions } from './targetUtils';
import {
getComponentOptions,
getLayoutSetOptions,
getPageOptions,
getTargetLayoutSetName,
} from './targetUtils';
import { useLayoutSetsExtendedQuery } from 'app-shared/hooks/queries/useLayoutSetsExtendedQuery';

type Summary2TargetProps = {
target: Summary2TargetConfig;
Expand All @@ -28,10 +33,12 @@ export const Summary2Target = ({ target, onChange }: Summary2TargetProps) => {
const { t } = useTranslation();
const { org, app } = useStudioEnvironmentParams();
const { selectedFormLayoutSetName, selectedFormLayoutName } = useAppContext();
const { data: layoutSets } = useLayoutSetsQuery(org, app);
const selectedLayoutSetTargetName = target.taskId
? layoutSets?.sets?.find((set) => set.tasks?.[0] === target.taskId).id
: selectedFormLayoutSetName;
const { data: layoutSets } = useLayoutSetsExtendedQuery(org, app);
const selectedLayoutSetTargetName = getTargetLayoutSetName({
target,
layoutSets,
selectedFormLayoutSetName,
});
const { data: formLayoutsData } = useFormLayoutsQuery(org, app, selectedLayoutSetTargetName);
const getComponentTitle = useComponentTitle();
const targetTypes = useTargetTypes();
Expand Down Expand Up @@ -74,7 +81,10 @@ export const Summary2Target = ({ target, onChange }: Summary2TargetProps) => {
onChange={(e) => handleLayoutSetChange(e.target.value)}
>
{layoutSetOptions.map((layoutSet) => (
<option key={layoutSet.id} value={layoutSet.tasks[0]}>
<option
key={layoutSet.id}
value={layoutSet.id === selectedFormLayoutSetName ? '' : layoutSet.task.id}
>
{layoutSet.id}
</option>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { IFormLayouts, IInternalLayout } from '@altinn/ux-editor/types/glob
import type { FormComponent } from '@altinn/ux-editor/types/FormComponent';
import { getAllLayoutComponents } from '../../../../../utils/formLayoutUtils';
import { ComponentType } from 'app-shared/types/ComponentType';
import type { LayoutSet, LayoutSets } from 'app-shared/types/api/LayoutSetsResponse';
import type { Summary2TargetConfig } from 'app-shared/types/ComponentSpecificConfig';
import type { LayoutSetsModel } from 'app-shared/types/api/dto/LayoutSetsModel';
import type { LayoutSetModel } from 'app-shared/types/api/dto/LayoutSetModel';

const excludedComponents = [
ComponentType.ActionButton,
Expand Down Expand Up @@ -81,6 +81,6 @@ export const getPageOptions = (formLayoutsData: IFormLayouts): TargetProps[] =>
: [];
};

export const getLayoutSetOptions = (layoutSets: LayoutSets): LayoutSet[] => {
return layoutSets?.sets.filter((set: LayoutSet) => set.tasks?.length > 0);
export const getLayoutSetOptions = (layoutSets: LayoutSetsModel): LayoutSetModel[] => {
return layoutSets?.sets.filter((set) => set.task);
};

0 comments on commit 1bd1b19

Please sign in to comment.