Skip to content

Commit

Permalink
feat: add data service endpointDescriptions to endpoint section
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsOveTen committed Jan 16, 2025
1 parent 60f6f33 commit f831239
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 30 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { DataService } from '@catalog-frontend/types';
import { AddButton, LabelWithHelpTextAndTag } from '@catalog-frontend/ui';
import { localization } from '@catalog-frontend/utils';
import { Textfield } from '@digdir/designsystemet-react';
import { FastField, FieldArray, useFormikContext } from 'formik';
import FieldsetWithDelete from '../../fieldset-with-delete';
import styles from './endpoint.module.css';

export const EndpointSection = () => {
const errors = useFormikContext<DataService>()?.errors;
return (
<>
<FastField
name='endpointUrl'
as={Textfield}
size='sm'
label={
<LabelWithHelpTextAndTag
tagTitle={localization.tag.required}
helpText={localization.dataServiceForm.helptext.endpoint}
helpAriaLabel={localization.dataServiceForm.fieldLabel.endpoint}
>
{localization.dataServiceForm.fieldLabel.endpoint}
</LabelWithHelpTextAndTag>
}
error={errors?.endpointUrl}
/>

<div>
<FieldArray name='endpointDescriptions'>
{(arrayHelpers) => (
<>
{arrayHelpers.form.values.endpointDescriptions &&
arrayHelpers.form.values.endpointDescriptions.map((_, index: number) => (
<div
key={`endpointDescriptions-${index}`}
className={styles.padding}
>
<FieldsetWithDelete onDelete={() => arrayHelpers.remove(index)}>
<FastField
name={`endpointDescriptions[${index}]`}
label={
index < 1 ? (
<LabelWithHelpTextAndTag
helpAriaLabel={localization.dataServiceForm.fieldLabel.endpointDescriptions}
helpText={localization.dataServiceForm.helptext.endpointDescriptions}
>
{localization.dataServiceForm.fieldLabel.endpointDescriptions}
</LabelWithHelpTextAndTag>
) : (
''
)
}
as={Textfield}
size='sm'
error={errors?.endpointDescriptions?.[index]}
/>
</FieldsetWithDelete>
</div>
))}

<AddButton onClick={() => arrayHelpers.push('')}>
{`${localization.dataServiceForm.fieldLabel.endpointDescriptions}`}
</AddButton>
</>
)}
</FieldArray>
</div>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.padding {
padding-bottom: 0.5rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { DataService, DataServiceToBeCreated } from '@catalog-frontend/types';
import { FormLayout, StickyFooterBar, useWarnIfUnsavedChanges } from '@catalog-frontend/ui';
import { Formik, Form } from 'formik';
import { useState } from 'react';
import { TitleSection } from './components/data-service-form-title-section';
import { TitleSection } from './components/title-section';
import { useParams, useRouter } from 'next/navigation';
import { createDataService, updateDataService } from '../../app/actions/actions';
import { Button } from '@digdir/designsystemet-react';
import styles from './data-service-form.module.css';
import { EndpointSection } from './components/data-service-form-endpoint-section';
import { EndpointSection } from './components/endpoint-section';

type Props = {
initialValues: DataService | DataServiceToBeCreated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export const dataServiceToBeCreatedTemplate = (): DataServiceToBeCreated => {
modified: '',
status: '',
endpointUrl: '',
endpointDescriptions: [],
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.content {
display: flex;
align-items: flex-end;
}

.singleChild {
width: 100%;
}

.twoChildren {
display: grid;
grid-template-columns: 49% 49%;
gap: 2%;
width: 100%;
}

.deleteButton {
height: fit-content;
width: fit-content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { PropsWithChildren } from 'react';
import { DeleteButton } from '@catalog-frontend/ui';
import styles from './fieldset-with-delete.module.scss';

type Props = {
onDelete: () => void;
} & PropsWithChildren;

export const FieldsetWithDelete = ({ children, onDelete }: Props) => {
const childArray = React.Children.toArray(children).filter(Boolean);

return (
<div className={styles.content}>
<div className={childArray.length === 1 ? styles.singleChild : styles.twoChildren}>{children}</div>
<DeleteButton
className={styles.deleteButton}
onClick={onDelete}
/>
</div>
);
};

export default FieldsetWithDelete;
1 change: 1 addition & 0 deletions libs/types/src/lib/data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface DataServiceToBeCreated {
modified: string;
status: string;
endpointUrl: string;
endpointDescriptions: string[];
}
3 changes: 3 additions & 0 deletions libs/utils/src/lib/language/data.service.form.nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export const dataServiceFormNb = {
title: 'Tittelen skal være kortfattet, kunne stå alene og gi mening. Forkortelser skal skrives helt ut.',
description: 'Beskrivelsen skal være kortfattet. Det bør fremgå hva som er formålet til APIet.',
endpoint: 'Rotplassering eller primært endepunkt for APIet.',
endpointDescriptions:
'Legg til lenke til spesifikasjon av APIet. F.eks OAS, Swagger, GraphQL eller lignende.',
},
heading: {
titleAndDescription: 'Tittel og beskrivelse',
Expand All @@ -12,6 +14,7 @@ export const dataServiceFormNb = {
description: 'Beskrivelse av APIet',
title: 'Tittel',
endpoint: 'EndepunktURL',
endpointDescriptions: 'Endepunktsbeskrivelse',
},
alert: {
confirmDelete: 'Er du sikker på at du vil slette API-beskrivelsen?',
Expand Down

0 comments on commit f831239

Please sign in to comment.