Skip to content

Commit

Permalink
Remove texts from static component config
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Standeren authored and Andrea Standeren committed Feb 2, 2024
1 parent 0902154 commit 4b2ee7b
Show file tree
Hide file tree
Showing 25 changed files with 129 additions and 475 deletions.
4 changes: 2 additions & 2 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1636,8 +1636,8 @@
"ux_editor.modal_properties_textResourceBindings_shortName_add": "Legg til kortnavn",
"ux_editor.modal_properties_textResourceBindings_tableTitle": "Tittel i tabell",
"ux_editor.modal_properties_textResourceBindings_tableTitle_add": "Legg til tittel i tabell",
"ux_editor.modal_properties_textResourceBindings_tag": "Merkebeskrivelse:",
"ux_editor.modal_properties_textResourceBindings_tag_add": "Legg til merkebeskrivelse",
"ux_editor.modal_properties_textResourceBindings_tagTitle": "Merkebeskrivelse",
"ux_editor.modal_properties_textResourceBindings_tagTitle_add": "Legg til merkebeskrivelse",
"ux_editor.modal_properties_textResourceBindings_title": "Ledetekst",
"ux_editor.modal_properties_textResourceBindings_title_add": "Legg til ledetekst",
"ux_editor.modal_properties_trigger_validation_label": "Skal feltet trigge en validering?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ import { useLayoutSchemaQuery } from '../../hooks/queries/useLayoutSchemaQuery';

const user = userEvent.setup();

// Test data:
const textResourceEditTestId = 'text-resource-edit';

// Mocks:
jest.mock('../TextResourceEdit', () => ({
TextResourceEdit: () => <div data-testid={textResourceEditTestId} />,
}));

describe('ContentTab', () => {
afterEach(jest.clearAllMocks);

describe('when editing a text resource', () => {
it('should render the component', async () => {
await render({ props: {}, editId: 'test' });
expect(screen.getByTestId(textResourceEditTestId)).toBeInTheDocument();
});
});

describe('when editing a container', () => {
const props = {
formId: container1IdMock,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import React from 'react';
import { TextResourceEdit } from '../TextResourceEdit';
import { EditFormComponent } from '../config/EditFormComponent';
import { EditFormContainer } from '../config/EditFormContainer';
import { getCurrentEditId } from '../../selectors/textResourceSelectors';
import { useSelector } from 'react-redux';
import { useFormContext } from '../../containers/FormContext';
import { useTranslation } from 'react-i18next';
import { isContainer } from '../../utils/formItemUtils';

export const Content = () => {
const { formId, form, handleUpdate, debounceSave } = useFormContext();
const editId = useSelector(getCurrentEditId);
const { t } = useTranslation();

if (editId) return <TextResourceEdit />;
if (!formId || !form) return t('right_menu.content_empty');

return isContainer(form) ? (
<EditFormContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@ import { formContextProviderMock } from '../../testing/formContextMocks';
const user = userEvent.setup();

// Test data:
const textText = 'Tekst';
const contentText = 'Innhold';
const dynamicsText = 'Dynamikk';
const calculationsText = 'Beregninger';
const texts = {
'right_menu.text': textText,
'right_menu.content': contentText,
'right_menu.dynamics': dynamicsText,
'right_menu.calculations': calculationsText,
};

const textTestId = 'text';
const contentTestId = 'content';
const conditionalRenderingTestId = 'conditional-rendering';
const expressionsTestId = 'expressions';
const calculationsTestId = 'calculations';

// Mocks:
jest.mock('./Text', () => ({
Text: () => <div data-testid={textTestId} />,
}));
jest.mock('./Content', () => ({
Content: () => <div data-testid={contentTestId} />,
}));
Expand Down Expand Up @@ -115,11 +109,9 @@ describe('Properties', () => {
it('Renders accordion', () => {
const formIdMock = 'test-id';
render({ formId: formIdMock });
expect(screen.getByText(textText)).toBeInTheDocument();
expect(screen.getByText(contentText)).toBeInTheDocument();
expect(screen.getByText(dynamicsText)).toBeInTheDocument();
expect(screen.getByText(calculationsText)).toBeInTheDocument();
expect(screen.getByTestId(textTestId)).toBeInTheDocument();
expect(screen.getByTestId(contentTestId)).toBeInTheDocument();
expect(screen.getByTestId(expressionsTestId)).toBeInTheDocument();
expect(screen.getByTestId(calculationsTestId)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect } from 'react';
import { Calculations } from './Calculations';
import { Content } from './Content';
import { Text } from './Text';
import { useTranslation } from 'react-i18next';
import { Accordion } from '@digdir/design-system-react';
import { useFormContext } from '../../containers/FormContext';
Expand All @@ -18,7 +17,7 @@ export const Properties = () => {
useEffect(() => {
if (formIdRef.current !== formId) {
formIdRef.current = formId;
if (formId && openList.length === 0) setOpenList(['text']);
if (formId && openList.length === 0) setOpenList(['content']);
}
}, [formId, openList.length]);

Expand All @@ -33,27 +32,19 @@ export const Properties = () => {
return (
<div className={classes.root}>
<Accordion color='subtle'>
<Accordion.Item open={openList.includes('text')}>
<Accordion.Header onHeaderClick={() => toggleOpen('text')}>
{t('right_menu.text')}
</Accordion.Header>
<Accordion.Content>{formId ? <Text /> : t('right_menu.content_empty')}</Accordion.Content>
</Accordion.Item>
<Accordion.Item open={openList.includes('content')}>
<Accordion.Header onHeaderClick={() => toggleOpen('content')}>
{t('right_menu.content')}
</Accordion.Header>
<Accordion.Content>
{formId ? <Content /> : t('right_menu.content_empty')}
<Content />
</Accordion.Content>
</Accordion.Item>
<Accordion.Item open={openList.includes('dynamics')}>
<Accordion.Header onHeaderClick={() => toggleOpen('dynamics')}>
{t('right_menu.dynamics')}
</Accordion.Header>
<Accordion.Content>
{formId ? <Dynamics /> : t('right_menu.content_empty')}
</Accordion.Content>
<Accordion.Content>{formId && <Dynamics />}</Accordion.Content>
</Accordion.Item>
<Accordion.Item open={openList.includes('calculations')}>
<Accordion.Header onHeaderClick={(e) => toggleOpen('calculations')}>
Expand Down
188 changes: 0 additions & 188 deletions frontend/packages/ux-editor-v3/src/components/Properties/Text.test.tsx

This file was deleted.

48 changes: 0 additions & 48 deletions frontend/packages/ux-editor-v3/src/components/Properties/Text.tsx

This file was deleted.

Loading

0 comments on commit 4b2ee7b

Please sign in to comment.