Skip to content

Commit

Permalink
feat: add main languages field to dataset form
Browse files Browse the repository at this point in the history
  • Loading branch information
hegeaal committed Oct 25, 2024
1 parent f7c983c commit 2f6be74
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/dataset-catalog/app/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function createDataset(values: DatasetToBeCreated, catalogId: strin
keyword: values?.keywordList ? transformToLocalizedStrings(values?.keywordList) : '',
concepts: values?.conceptList ? convertListToObjectStructure(values.conceptList, 'uri') : [],
spatial: values?.spatialList ? convertListToObjectStructure(values.spatialList, 'uri') : [],
language: values.languageList ? convertListToObjectStructure(values.languageList, 'uri') : [],
};
const datasetNoEmptyValues = removeEmptyValues(newDataset);

Expand Down Expand Up @@ -105,6 +106,7 @@ export async function updateDataset(catalogId: string, initialDataset: Dataset,
keyword: values?.keywordList ? transformToLocalizedStrings(values?.keywordList) : '',
concepts: values?.conceptList ? convertListToObjectStructure(values.conceptList, 'uri') : [],
spatial: values?.spatialList ? convertListToObjectStructure(values.spatialList, 'uri') : [],
language: values.languageList ? convertListToObjectStructure(values.languageList, 'uri') : [],
});

const diff = compare(initialDataset, updatedDataset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getDatasetTypes,
getDataThemes,
getFrequencies,
getLanguages,
getLosThemes,
getOrganization,
getProvenanceStatements,
Expand All @@ -26,12 +27,14 @@ export default async function NewDatasetPage({ params }: Params) {
datasetTypesResponse,
provenanceStatementsResponse,
frequenciesResponse,
languageResponse
] = 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())
]);

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

const breadcrumbList = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useMemo, useState } from 'react';
import { useSearchAdministrativeUnits, useSearchAdministrativeUnitsByUri } from '../../hooks/useReferenceDataSearch';
import { Field, FieldArray, useFormikContext } from 'formik';
import { Dataset, ReferenceDataCode } from '@catalog-frontend/types';
import { debounce } from 'lodash';
import { debounce, sortBy } from 'lodash';
import styles from './dataset-form.module.css';

interface Props {
Expand All @@ -17,6 +17,7 @@ interface Props {
export const GeographySection = ({ envVariable, languages }: Props) => {
const [searchTerm, setSearchTerm] = useState<string>('');
const { values, setFieldValue } = useFormikContext<Dataset>();
const langNOR = languages.filter(lang => lang.code === 'NOR')[0]

const { data: searchHits, isLoading: isSearching } = useSearchAdministrativeUnits(searchTerm, envVariable);
const { data: selectedValues, isLoading: isLoadingselectedValues } = useSearchAdministrativeUnitsByUri(
Expand All @@ -36,6 +37,16 @@ export const GeographySection = ({ envVariable, languages }: Props) => {
if (uri.includes('nasjon')) return localization.spatial.country;
return '';
};
const customLanguageOrder = [
"http://publications.europa.eu/resource/authority/language/NOB",
"http://publications.europa.eu/resource/authority/language/NNO",
"http://publications.europa.eu/resource/authority/language/ENG",
"http://publications.europa.eu/resource/authority/language/SMI"
];

const sortedLanguages = sortBy(languages, (item) => {
return customLanguageOrder.indexOf(item.uri);
});

const comboboxOptions = [
// Combines selectedValues and searchHits, and add uri's for values not found in selectedValues
Expand Down Expand Up @@ -157,11 +168,19 @@ export const GeographySection = ({ envVariable, languages }: Props) => {
subtitle={localization.datasetForm.helptext.language}
/>
<Checkbox.Group
error=''
legend='Velg...'
size='md'
legend={`${localization.choose}...`}
onChange={(values) => setFieldValue('languageList', values)}
value={values.languageList}
>
{languages.map((lang) => (
{values.languageList && values.languageList.includes('http://publications.europa.eu/resource/authority/language/NOR') &&
<Checkbox
key={langNOR.uri}
value={langNOR.uri}
>
{getTranslateText(langNOR.label)}
</Checkbox>
}
{sortedLanguages.filter(lang => lang.code !== 'NOR').map((lang) => (
<Checkbox
key={lang.uri}
value={lang.uri}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AccessRights, Dataset, DatasetToBeCreated, PublicationStatus } from '@c
import { groupByKeys } from '@catalog-frontend/utils';

export const datasetTemplate = (dataset: Dataset): Dataset => {
console.log(dataset.theme);
return {
id: dataset?.id ?? '',
catalogId: dataset?.catalogId ?? '',
Expand Down Expand Up @@ -45,6 +44,7 @@ export const datasetTemplate = (dataset: Dataset): Dataset => {
spatialList: dataset.spatial ? dataset.spatial.map((spatial) => spatial.uri) : [],
temporal: dataset.temporal ?? [{ startDate: '', endDate: '' }],
issued: dataset.issued ?? '',
languageList: dataset.language ? dataset.language.map((lang) => lang.uri) : [],
};
};

Expand Down Expand Up @@ -82,6 +82,7 @@ export const datasetToBeCreatedTemplate = (): DatasetToBeCreated => {
hasAvailabilityAnnotation: { hasBody: { nb: '' } },
spatialList: [],
temporal: [{ startDate: '', endDate: '' }],
issued: '',
issued: '',
languageList: []
};
};
2 changes: 2 additions & 0 deletions libs/types/src/lib/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ export interface DatasetToBeCreated {
spatial?: ReferenceDataCode[];
temporal?: DateRange[];
issued?: string;
language?: ReferenceDataCode[]
// Arrays of uris used as helper values for Formik. These properties is not part of the db object.
losThemeList?: string[];
euThemeList?: string[];
conceptList?: string[];
spatialList?: string[];
languageList?: string[]
}

export interface UriWithLabel {
Expand Down

0 comments on commit 2f6be74

Please sign in to comment.