Skip to content

Commit

Permalink
feat: add distribution to dataset form
Browse files Browse the repository at this point in the history
  • Loading branch information
hegeaal committed Dec 5, 2024
1 parent c6e0e29 commit 2622b50
Show file tree
Hide file tree
Showing 20 changed files with 872 additions and 70 deletions.
8 changes: 8 additions & 0 deletions apps/dataset-catalog/app/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export async function createDataset(values: DatasetToBeCreated, catalogId: strin
concepts: values?.conceptList ? convertListToListOfObjects(values.conceptList, 'uri') : [],
spatial: values?.spatialList ? convertListToListOfObjects(values.spatialList, 'uri') : [],
language: values.languageList ? convertListToListOfObjects(values.languageList, 'uri') : [],
distribution: values.distribution?.map((dist) => ({
...dist,
accessService: dist.accessServiceList ? convertListToListOfObjects(dist.accessServiceList, 'uri') : [],
})),
};
const datasetNoEmptyValues = removeEmptyValues(newDataset);

Expand Down Expand Up @@ -107,6 +111,10 @@ export async function updateDataset(catalogId: string, initialDataset: Dataset,
concepts: values?.conceptList ? convertListToListOfObjects(values.conceptList, 'uri') : [],
spatial: values?.spatialList ? convertListToListOfObjects(values.spatialList, 'uri') : [],
language: values.languageList ? convertListToListOfObjects(values.languageList, 'uri') : [],
distribution: values.distribution?.map((dist) => ({
...dist,
accessService: dist.accessServiceList ? convertListToListOfObjects(dist.accessServiceList, 'uri') : [],
})),
});

const diff = compare(initialDataset, updatedDataset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getFrequencies,
getLanguages,
getLosThemes,
getOpenLicenses,
getOrganization,
getProvenanceStatements,
} from '@catalog-frontend/data-access';
Expand All @@ -32,14 +33,16 @@ export default async function EditDatasetPage({ params }: Params) {
datasetTypesResponse,
provenanceStatementsResponse,
frequenciesResponse,
languagesResponse,
languageResponse,
licenceResponse,
] = await Promise.all([
getLosThemes().then((res) => res.json()),
getDataThemes().then((res) => res.json()),
getDatasetTypes().then((res) => res.json()),
getProvenanceStatements().then((res) => res.json()),
getFrequencies().then((res) => res.json()),
getLanguages().then((res) => res.json()),
getOpenLicenses().then((res) => res.json()),
]);

const referenceData = {
Expand All @@ -48,7 +51,8 @@ export default async function EditDatasetPage({ params }: Params) {
datasetTypes: datasetTypesResponse.datasetTypes,
provenanceStatements: provenanceStatementsResponse.provenanceStatements,
frequencies: frequenciesResponse.frequencies,
languages: languagesResponse.linguisticSystems,
languages: languageResponse.linguisticSystems,
openLicenses: licenceResponse.openLicenses,
};

const breadcrumbList = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getFrequencies,
getLanguages,
getLosThemes,
getOpenLicenses,
getOrganization,
getProvenanceStatements,
} from '@catalog-frontend/data-access';
Expand All @@ -32,13 +33,15 @@ export default async function NewDatasetPage({ params }: Params) {
provenanceStatementsResponse,
frequenciesResponse,
languageResponse,
licenceResponse,
] = await Promise.all([
getLosThemes().then((res) => res.json()),
getDataThemes().then((res) => res.json()),
getDatasetTypes().then((res) => res.json()),
getProvenanceStatements().then((res) => res.json()),
getFrequencies().then((res) => res.json()),
getLanguages().then((res) => res.json()),
getOpenLicenses().then((res) => res.json()),
]);

const referenceData = {
Expand All @@ -48,6 +51,7 @@ export default async function NewDatasetPage({ params }: Params) {
provenanceStatements: provenanceStatementsResponse.provenanceStatements,
frequencies: frequenciesResponse.frequencies,
languages: languageResponse.linguisticSystems,
openLicenses: licenceResponse.openLicenses,
};

const breadcrumbList = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AccessRights, Dataset } from '@catalog-frontend/types';
import { FormContainer, TitleWithTag } from '@catalog-frontend/ui';
import { AddButton, FormContainer, FormikLanguageFieldset, TitleWithTag } from '@catalog-frontend/ui';
import { localization } from '@catalog-frontend/utils';
import { Button, Heading, NativeSelect, Textfield } from '@digdir/designsystemet-react';
import { MinusCircleIcon, PlusCircleIcon } from '@navikt/aksel-icons';
import { Field, FieldArray, FormikErrors, FormikHelpers } from 'formik';
import FieldsetWithDelete from '../../fieldset-with-delete';

type AccessRightsSectionProps = {
errors: FormikErrors<Dataset>;
Expand All @@ -12,11 +13,7 @@ type AccessRightsSectionProps = {

export const AccessRightsSection = ({ errors, values }: AccessRightsSectionProps) => {
return (
<div>
{/* <FormContainer.Header
title={localization.datasetForm.heading.accessRights}
subtitle={localization.datasetForm.helptext.accessRights}
/> */}
<>
<Field name='accessRights.uri'>
{({ field, form }: { field: any; form: FormikHelpers<Dataset> }) => (
<NativeSelect
Expand Down Expand Up @@ -49,39 +46,22 @@ export const AccessRightsSection = ({ errors, values }: AccessRightsSectionProps
<>
{values.legalBasisForRestriction?.map((_, index) => (
<div key={index}>
<Field
name={`legalBasisForRestriction[${index}].prefLabel.nb`}
<FormikLanguageFieldset
name={`legalBasisForRestriction[${index}].prefLabel`}
as={Textfield}
label={localization.title}
/>
<Field
name={`legalBasisForRestriction[${index}].uri`}
as={Textfield}
label={localization.link}
// @ts-expect-error uri exsists in object legalBasisForRestriction
error={errors?.legalBasisForRestriction?.[index]?.uri}
/>
<Button
type='button'
onClick={() => remove(index)}
variant='tertiary'
color='danger'
>
<MinusCircleIcon />
{localization.remove}
</Button>
<FieldsetWithDelete onDelete={() => remove(index)}>
<Field
name={`legalBasisForRestriction[${index}].uri`}
as={Textfield}
label={localization.link}
// @ts-expect-error uri exsists in object legalBasisForRestriction
error={errors?.legalBasisForRestriction?.[index]?.uri}
/>
</FieldsetWithDelete>
</div>
))}
<div>
<Button
type='button'
onClick={() => push({ prefLabel: { nb: '' }, uri: '' })}
variant='tertiary'
>
<PlusCircleIcon />
{localization.add}
</Button>
</div>
<AddButton onClick={() => push({ prefLabel: { nb: '' }, uri: '' })} />
</>
)}
</FieldArray>
Expand Down Expand Up @@ -181,6 +161,6 @@ export const AccessRightsSection = ({ errors, values }: AccessRightsSectionProps
</FieldArray>
</>
)}
</div>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const ConceptSection = ({ searchEnv }: Props) => {
<Textfield
label={
<TitleWithTag
// title={localization.datasetForm.fieldLabel.keyword.nb}
title={localization.datasetForm.fieldLabel.keyword}
tagTitle={localization.tag.recommended}
tagColor='info'
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import { Dataset } from '@catalog-frontend/types';
import { AddButton, FormContainer } from '@catalog-frontend/ui';
import { AddButton, FormContainer, FormikLanguageFieldset, TextareaWithPrefix } from '@catalog-frontend/ui';
import { localization } from '@catalog-frontend/utils';
import { Heading, Textfield, Textarea, Button, Label, HelpText, Fieldset } from '@digdir/designsystemet-react';
import { MinusCircleIcon, PlusCircleIcon } from '@navikt/aksel-icons';
Expand Down Expand Up @@ -47,28 +47,32 @@ export const ContentSection = () => {
)}
</FieldArray>

<Field
as={Textarea}
<FormikLanguageFieldset
as={TextareaWithPrefix}
name='hasRelevanceAnnotation.hasBody.nb'
label={localization.datasetForm.heading.relevance}
legend={localization.datasetForm.heading.relevance}
requiredLanguages={['nb']}
/>

<Field
as={Textarea}
name='hasCompletenessAnnotation.hasBody.nb'
label={localization.datasetForm.heading.completeness}
<FormikLanguageFieldset
as={TextareaWithPrefix}
name='hasCompletenessAnnotation.hasBody'
legend={localization.datasetForm.heading.completeness}
requiredLanguages={['nb']}
/>

<Field
as={Textarea}
name='hasCompletenessAnnotation.hasBody.nb'
label={localization.datasetForm.heading.accuracy}
<FormikLanguageFieldset
as={TextareaWithPrefix}
name='hasCompletenessAnnotation.hasBody.'
legend={localization.datasetForm.heading.accuracy}
requiredLanguages={['nb']}
/>

<Field
as={Textarea}
name='hasAvailabilityAnnotation.hasBody.nb'
label={localization.datasetForm.heading.availability}
<FormikLanguageFieldset
as={TextareaWithPrefix}
name='hasAvailabilityAnnotation.hasBody'
legend={localization.datasetForm.heading.availability}
requiredLanguages={['nb']}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';
import { Dataset, ReferenceDataCode } from '@catalog-frontend/types';
import { FormContainer } from '@catalog-frontend/ui';
import { FormContainer, FormikLanguageFieldset, TextareaWithPrefix } from '@catalog-frontend/ui';
import { capitalizeFirstLetter, getTranslateText, localization } from '@catalog-frontend/utils';
import { Heading, Combobox, Textfield, Textarea } from '@digdir/designsystemet-react';
import { Heading, Combobox, Textfield, Textarea, Label } from '@digdir/designsystemet-react';
import { Field, useFormikContext } from 'formik';

interface Props {
Expand All @@ -14,7 +14,7 @@ export const ProvenanceSection = ({ data }: Props) => {
const { provenanceStatements, frequencies } = data;

return (
<div>
<>
<Combobox
value={values?.provenance?.uri ? [values?.provenance?.uri] : []}
placeholder={`${localization.search.search}...`}
Expand Down Expand Up @@ -56,12 +56,11 @@ export const ProvenanceSection = ({ data }: Props) => {
type='date'
label={localization.datasetForm.heading.lastUpdated}
/>

<Field
as={Textarea}
name='hasCurrentnessAnnotation.hasBody.nb'
label={localization.datasetForm.heading.actuality}
></Field>
</div>
<FormikLanguageFieldset
as={TextareaWithPrefix}
name='hasCurrentnessAnnotation.hasBody'
legend={localization.datasetForm.heading.actuality}
/>
</>
);
};
Loading

0 comments on commit 2622b50

Please sign in to comment.