Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from '@storybook/react-vite';

import { ConditionalWrapper } from './ConditionalWrapper';

const meta = {
title: 'AppComponents/ConditionalWrapper',
component: ConditionalWrapper,
args: {
condition: true,
wrapper: (children) => <div style={{ border: '2px solid blue', padding: 8 }}>{children}</div>,
children: <p>Wrapped content</p>,
},
} satisfies Meta<typeof ConditionalWrapper>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Wrapped: Story = {};

export const Unwrapped: Story = {
args: {
condition: false,
},
};

export const Otherwise: Story = {
args: {
condition: false,
otherwise: (children) => <div style={{ border: '2px solid orange', padding: 8 }}>{children}</div>,
},
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';

import { screen } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { renderWithAppComponentsProvider } from 'src/app-components/test/renderWithAppComponentsProvider';
import { ConditionalWrapper } from './ConditionalWrapper';

describe('ConditionalWrapper', () => {
it('should pass children to wrapper callback when condition is true', () => {
const wrapperCb = jest.fn((children: React.ReactNode) => <div data-testid='conditional-wrapper'>{children}</div>);
render({
const wrapperCb = vi.fn((children: React.ReactNode) => <div data-testid='conditional-wrapper'>{children}</div>);
renderComponent({
condition: true,
wrapper: wrapperCb,
});
Expand All @@ -19,8 +19,8 @@ describe('ConditionalWrapper', () => {
});

it('should not pass children to wrapper callback when condition is false', () => {
const wrapperCb = jest.fn((children: React.ReactNode) => <div data-testid='conditional-wrapper'>{children}</div>);
render({
const wrapperCb = vi.fn((children: React.ReactNode) => <div data-testid='conditional-wrapper'>{children}</div>);
renderComponent({
condition: false,
wrapper: wrapperCb,
});
Expand All @@ -29,19 +29,32 @@ describe('ConditionalWrapper', () => {
expect(screen.queryByTestId('conditional-wrapper')).not.toBeInTheDocument();
expect(screen.getByTestId('children')).toBeInTheDocument();
});

it('should pass children to otherwise callback when condition is false', () => {
const otherwiseCb = vi.fn((children: React.ReactNode) => <div data-testid='otherwise-wrapper'>{children}</div>);
renderComponent({
condition: false,
otherwise: otherwiseCb,
});

expect(otherwiseCb).toHaveBeenCalledWith(<div data-testid='children'>Children</div>);
expect(screen.getByTestId('otherwise-wrapper')).toBeInTheDocument();
expect(screen.getByTestId('children')).toBeInTheDocument();
});
});

const render = (overridingProps: {
const renderComponent = (overridingProps: {
condition?: boolean;
wrapper?: (children: React.ReactNode) => React.JSX.Element;
otherwise?: (children: React.ReactNode) => React.JSX.Element;
}) => {
const allProps: Parameters<typeof ConditionalWrapper>[0] = {
condition: false,
wrapper: (children) => <div data-testid='conditional-wrapper'>{children}</div>,
...overridingProps,
};

return renderWithAppComponentsProvider(
return render(
<ConditionalWrapper {...allProps}>
<div data-testid='children'>Children</div>
</ConditionalWrapper>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ConditionalWrapper } from './ConditionalWrapper';
1 change: 1 addition & 0 deletions libs/form-component/src/app-components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './AccordionItem';
export * from './ConditionalWrapper';
export * from './Button';
export * from './Card';
export * from './Datepicker';
Expand Down
6 changes: 6 additions & 0 deletions src/App/frontend/monorepo-changed-paths.txt
Copy link
Copy Markdown
Contributor

@walldenfilippa walldenfilippa May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lurte litt på hvorfor disse ble lagt til her? Om dem heller skal være i en annen PR?

src/app-components/TimePicker/TimeSegment/TimeSegment.tsx
src/features/instantiate/containers/UnknownError.module.css
src/features/instantiate/containers/UnknownErrorDetails.module.css
src/features/instantiate/containers/UnknownErrorDetails.tsx
src/layout/SigningDocumentList/api.test.ts

Copy link
Copy Markdown
Contributor Author

@JamalAlabdullah JamalAlabdullah May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vi oppdaterer den for hver PR hvor vi flytter en komponent slik at vi får opp en advarsel i legacy repoet om man gjør endringer der det er gjort noe i minorepo, vi følger de here:

Instructions

  1. The task is to migrate @../../../src/App/frontend/src/app-components/$ARGUMENTS[0] to @../../../libs/form-component/src/app-components
  2. Ask the user any clarifying questions you have
  3. checkout a new branch called refactor/move-$ARGUMENTS[0]-to-app
  4. Make a plan to move
  5. Move the component
  6. Fix any imports using the component
  7. Remove forwardRef if in use in the component
  8. Add unit tests for the component if they don't exist
  9. Add a suitable storybook story for the component
  10. Go to @../../../src/App/frontend and run npx tsx scripts/compare-frontend-repos.ts update
  11. Output a PR description based on this format ../../../.github/pull_request_template.md. Keep it short and simple, keep the checkboxes, tick the relevant boxes

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ src/__mocks__/getOrgsMock.ts
src/app-components/Accordion/
src/app-components/Button/Button.tsx
src/app-components/Card/
src/app-components/ConditionalWrapper/
src/app-components/Date/
src/app-components/Datepicker/
src/app-components/Flex/
src/app-components/Text/DisplayText.tsx
src/app-components/TimePicker/TimeSegment/TimeSegment.tsx
src/app-components/loading/Spinner/Spinner.tsx
src/codegen/schemas/layout-sets.schema.v1.ts
src/components/presentation/Header.tsx
Expand Down Expand Up @@ -48,6 +50,9 @@ src/features/form/rules/RulesContext.tsx
src/features/formData/LegacyRules.ts
src/features/instance/instanceUtils.ts
src/features/instantiate/containers/InstantiateContainer.tsx
src/features/instantiate/containers/UnknownError.module.css
src/features/instantiate/containers/UnknownErrorDetails.module.css
src/features/instantiate/containers/UnknownErrorDetails.tsx
src/features/instantiate/useInstantiation.tsx
src/features/language/LangDataSourcesProvider.tsx
src/features/language/LangToolsStore.tsx
Expand All @@ -73,6 +78,7 @@ src/layout/Group/SummaryGroupComponent.test.tsx
src/layout/Group/__snapshots__/SummaryGroupComponent.test.tsx.snap
src/layout/RepeatingGroup/Summary/SummaryRepeatingGroup.test.tsx
src/layout/RepeatingGroup/Summary/__snapshots__/SummaryRepeatingGroup.test.tsx.snap
src/layout/SigningDocumentList/api.test.ts
src/queries/appPrefetcher.ts
src/queries/formPrefetcher.ts
src/utils/formLayout.test.ts
Expand Down
3 changes: 1 addition & 2 deletions src/App/frontend/src/app-components/Panel/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { PropsWithChildren } from 'react';

import { useIsMobile } from '@app/form-component';
import { ConditionalWrapper, useIsMobile } from '@app/form-component';
import { Heading } from '@digdir/designsystemet-react';
import {
CheckmarkCircleIcon,
Expand All @@ -12,7 +12,6 @@ import {
import cn from 'classnames';

import { useTranslation } from 'src/app-components/AppComponentsProvider';
import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { FullWidthWrapper } from 'src/app-components/FullWidthWrapper/FullWidthWrapper';
import { PANEL_VARIANT } from 'src/app-components/Panel/constants';
import classes from 'src/app-components/Panel/Panel.module.css';
Expand Down
12 changes: 0 additions & 12 deletions src/App/frontend/src/components/atoms/AltinnAttachments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,6 @@ jest.mock('src/utils/urls/urlHelper', () => ({
makeUrlRelativeIfSameDomain: jest.fn((url) => url),
}));

jest.mock('src/app-components/ConditionalWrapper/ConditionalWrapper', () => ({
ConditionalWrapper: jest.fn(({ condition, wrapper, otherwise, children }) => {
if (condition) {
return wrapper(children);
} else if (otherwise) {
return otherwise(children);
} else {
return children;
}
}),
}));

describe('AltinnAttachments', () => {
const mockUseCurrentLanguage = jest.mocked(useCurrentLanguage);

Expand Down
2 changes: 1 addition & 1 deletion src/App/frontend/src/components/form/RadioButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { forwardRef, useRef } from 'react';

import { ConditionalWrapper } from '@app/form-component';
import { Radio } from '@digdir/designsystemet-react';
import cn from 'classnames';
import type { RadioProps } from '@digdir/designsystemet-react';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { HelpText } from 'src/app-components/HelpText/HelpText';
import { translationKey } from 'src/AppComponentsBridge';
import classes from 'src/components/form/RadioButton.module.css';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import { ConditionalWrapper } from '@app/form-component';
import { Fieldset, useCheckboxGroup } from '@digdir/designsystemet-react';
import cn from 'classnames';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { AltinnSpinner } from 'src/components/AltinnSpinner';
import { LabelContent } from 'src/components/label/LabelContent';
import { Lang } from 'src/features/language/Lang';
Expand Down
2 changes: 1 addition & 1 deletion src/App/frontend/src/layout/Checkboxes/WrappedCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { forwardRef, useEffect, useState } from 'react';

import { ConditionalWrapper } from '@app/form-component';
import { Checkbox } from '@digdir/designsystemet-react';
import cn from 'classnames';
import type { CheckboxProps } from '@digdir/designsystemet-react';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { HelpText } from 'src/app-components/HelpText/HelpText';
import { translationKey } from 'src/AppComponentsBridge';
import { DeleteWarningPopover } from 'src/features/alertOnChange/DeleteWarningPopover';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';

import { Button } from '@app/form-component';
import { Button, ConditionalWrapper } from '@app/form-component';
import { PencilIcon, TrashIcon } from '@navikt/aksel-icons';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { DeleteWarningPopover } from 'src/features/alertOnChange/DeleteWarningPopover';
import { useAlertOnChange } from 'src/features/alertOnChange/useAlertOnChange';
import { isAttachmentUploaded } from 'src/features/attachments';
Expand Down
2 changes: 1 addition & 1 deletion src/App/frontend/src/layout/Grid/GridComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useEffect, useMemo } from 'react';
import type { PropsWithChildren } from 'react';

import { ConditionalWrapper } from '@app/form-component';
import { Table } from '@digdir/designsystemet-react';
import cn from 'classnames';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { FullWidthWrapper } from 'src/app-components/FullWidthWrapper/FullWidthWrapper';
import { Fieldset } from 'src/app-components/Label/Fieldset';
import { Caption } from 'src/components/form/caption/Caption';
Expand Down
2 changes: 1 addition & 1 deletion src/App/frontend/src/layout/Group/GroupComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import type { JSX } from 'react';

import { ConditionalWrapper } from '@app/form-component';
import { Heading } from '@digdir/designsystemet-react';
import cn from 'classnames';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { Fieldset } from 'src/app-components/Label/Fieldset';
import { Panel } from 'src/app-components/Panel/Panel';
import { FormStore } from 'src/features/form/FormContext';
Expand Down
3 changes: 1 addition & 2 deletions src/App/frontend/src/layout/Group/GroupSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';

import { Flex } from '@app/form-component';
import { ConditionalWrapper, Flex } from '@app/form-component';
import { Heading } from '@digdir/designsystemet-react';
import cn from 'classnames';
import type { HeadingProps } from '@digdir/designsystemet-react';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { Lang } from 'src/features/language/Lang';
import classes from 'src/layout/Group/GroupSummary.module.css';
import { ComponentSummary, SummaryFlexForContainer } from 'src/layout/Summary2/SummaryComponent2/ComponentSummary';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import { ConditionalWrapper } from '@app/form-component';
import { Fieldset, useRadioGroup } from '@digdir/designsystemet-react';
import cn from 'classnames';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { AltinnSpinner } from 'src/components/AltinnSpinner';
import { RadioButton } from 'src/components/form/RadioButton';
import { LabelContent } from 'src/components/label/LabelContent';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { forwardRef } from 'react';
import type { JSX } from 'react';

import { Button, Flex } from '@app/form-component';
import { Button, ConditionalWrapper, Flex } from '@app/form-component';
import { PlusIcon } from '@navikt/aksel-icons';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { FullWidthWrapper } from 'src/app-components/FullWidthWrapper/FullWidthWrapper';
import { Fieldset } from 'src/app-components/Label/Fieldset';
import { FormStore } from 'src/features/form/FormContext';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback, useMemo } from 'react';

import { ConditionalWrapper } from '@app/form-component';
import { Pagination, Table, usePagination } from '@digdir/designsystemet-react';
import type { UsePaginationProps } from '@digdir/designsystemet-react';

import { ConditionalWrapper } from 'src/app-components/ConditionalWrapper/ConditionalWrapper';
import { useResetScrollPosition } from 'src/core/ui/useResetScrollPosition';
import { FormStore } from 'src/features/form/FormContext';
import { useLanguage } from 'src/features/language/useLanguage';
Expand Down
Loading