diff --git a/apps/dataset-catalog/components/dataset-form/components/about-section.tsx b/apps/dataset-catalog/components/dataset-form/components/about-section.tsx index 760a511bb..964d46be3 100644 --- a/apps/dataset-catalog/components/dataset-form/components/about-section.tsx +++ b/apps/dataset-catalog/components/dataset-form/components/about-section.tsx @@ -1,10 +1,11 @@ import { Dataset } from '@catalog-frontend/types'; -import { FormikLanguageFieldset, TextareaWithPrefix, TitleWithTag } from '@catalog-frontend/ui'; +import { AddButton, FormikLanguageFieldset, TextareaWithPrefix, TitleWithTag } from '@catalog-frontend/ui'; import { localization } from '@catalog-frontend/utils'; import { Textfield, Fieldset } from '@digdir/designsystemet-react'; -import { Field, useFormikContext } from 'formik'; +import { Field, FieldArray, useFormikContext } from 'formik'; import { FieldsetDivider } from '@catalog-frontend/ui'; import { AccessRightsForm } from './access-rights.tsx/dataset-form-access-rights-section'; +import FieldsetWithDelete from '../../fieldset-with-delete'; export const AboutSection = () => { const errors = useFormikContext()?.errors; @@ -46,32 +47,11 @@ export const AboutSection = () => { - - {/* - {(arrayHelpers) => ( - <> - {arrayHelpers.form.values.landingPage && - arrayHelpers.form.values.landingPage.map((_: string, index: number) => ( -
- arrayHelpers.remove(index)}> - - -
- ))} - - arrayHelpers.push('')}>{localization.button.addUrl} - - )} -
*/} ); }; diff --git a/apps/dataset-catalog/components/dataset-form/components/access-rights.tsx/access-rights-uri-table.tsx b/apps/dataset-catalog/components/dataset-form/components/access-rights.tsx/access-rights-uri-table.tsx index d53863ebc..04dc774b7 100644 --- a/apps/dataset-catalog/components/dataset-form/components/access-rights.tsx/access-rights-uri-table.tsx +++ b/apps/dataset-catalog/components/dataset-form/components/access-rights.tsx/access-rights-uri-table.tsx @@ -137,7 +137,6 @@ const FieldModal = ({ template, formType, onSuccess, initialType = 'legalBasisFo validationSchema={uriWithLabelSchema} onSubmit={(formValues, { setSubmitting }) => { const trimmedValues = trimObjectWhitespace(formValues); - console.log('ny', { type: legalBasis, uriWithLabel: trimmedValues }); onSuccess({ type: legalBasis, uriWithLabel: trimmedValues }); setSubmitting(false); setSubmitted(true); diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-form-provenance-section.tsx b/apps/dataset-catalog/components/dataset-form/components/dataset-form-provenance-section.tsx deleted file mode 100644 index 0c37593ac..000000000 --- a/apps/dataset-catalog/components/dataset-form/components/dataset-form-provenance-section.tsx +++ /dev/null @@ -1,66 +0,0 @@ -'use client'; -import { Dataset, ReferenceDataCode } from '@catalog-frontend/types'; -import { FormContainer, FormikLanguageFieldset, TextareaWithPrefix } from '@catalog-frontend/ui'; -import { capitalizeFirstLetter, getTranslateText, localization } from '@catalog-frontend/utils'; -import { Heading, Combobox, Textfield, Textarea, Label } from '@digdir/designsystemet-react'; -import { Field, useFormikContext } from 'formik'; - -interface Props { - data: { provenanceStatements: ReferenceDataCode[]; frequencies: ReferenceDataCode[] }; -} - -export const ProvenanceSection = ({ data }: Props) => { - const { setFieldValue, values } = useFormikContext(); - const { provenanceStatements, frequencies } = data; - - return ( - <> - setFieldValue('provenance.uri', value.toString())} - label={localization.datasetForm.heading.provenance} - > - {`${localization.choose}...`} - {provenanceStatements.map((item) => ( - - {getTranslateText(item.label)} - - ))} - - - setFieldValue('accrualPeriodicity.uri', value.toString())} - label={localization.datasetForm.heading.frequency} - > - {`${localization.choose}...`} - {frequencies.map((item) => ( - - {capitalizeFirstLetter(getTranslateText(item.label).toString())} - - ))} - - - - - - ); -}; diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-form-qualified-attributions-section.tsx b/apps/dataset-catalog/components/dataset-form/components/dataset-form-qualified-attributions-section.tsx index 6cb82a52c..705772d94 100644 --- a/apps/dataset-catalog/components/dataset-form/components/dataset-form-qualified-attributions-section.tsx +++ b/apps/dataset-catalog/components/dataset-form/components/dataset-form-qualified-attributions-section.tsx @@ -45,31 +45,28 @@ export const QualifiedAttributionsSection = () => { ]; return ( - <> - {!isLoading && ( - setFieldValue('qualifiedAttributions', selectedValues)} - onChange={(input: any) => debouncedSearch(input.target.value)} - loading={searching} - multiple - value={values.qualifiedAttributions} - placeholder={`${localization.search.search}...`} - filter={() => true} // Deactivate filter, handled by backend - virtual - label={localization.datasetForm.heading.qualifiedAttributions} + setFieldValue('qualifiedAttributions', selectedValues)} + onChange={(input: any) => debouncedSearch(input.target.value)} + loading={searching} + multiple + value={values.qualifiedAttributions} + placeholder={`${localization.search.search}...`} + filter={() => true} // Deactivate filter, handled by backend + virtual + label={localization.datasetForm.heading.qualifiedAttributions} + > + {`${localization.search.noHits}...`} + {comboboxOptions.map((org) => ( + - {`${localization.search.noHits}...`} - {comboboxOptions.map((org) => ( - - {org.navn} - - ))} - - )} - + {org.navn} + + ))} + ); }; diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-form-relations-section.tsx b/apps/dataset-catalog/components/dataset-form/components/dataset-form-relations-section.tsx deleted file mode 100644 index fd5244e7a..000000000 --- a/apps/dataset-catalog/components/dataset-form/components/dataset-form-relations-section.tsx +++ /dev/null @@ -1,136 +0,0 @@ -import { useState } from 'react'; -import { Dataset, DatasetSeries } from '@catalog-frontend/types'; -import { AddButton, DeleteButton } from '@catalog-frontend/ui'; -import { getTranslateText, localization } from '@catalog-frontend/utils'; -import { Heading, Combobox, Label, Divider } from '@digdir/designsystemet-react'; -import { Field, FieldArray, useFormikContext } from 'formik'; -import relations from '../utils/relations.json'; -import { useSearchDatasetsByUri, useSearchDatasetSuggestions } from '../../../hooks/useSearchService'; -import { UriWithLabelFieldsetTable } from './uri-with-label-field-set-table'; - -type TitleSectionProps = { - searchEnv: string; - datasetSeries: DatasetSeries[]; -}; - -export const RelationsSection = ({ searchEnv, datasetSeries }: TitleSectionProps) => { - const { setFieldValue, values, errors } = useFormikContext(); - const [searchQuery, setSearchQuery] = useState(''); - - const getUriList = () => { - return values.references?.map((reference) => reference.source.uri).filter((uri) => uri) ?? []; - }; - - const { data: searchHits, isLoading: searching } = useSearchDatasetSuggestions(searchEnv, searchQuery); - const { data: selectedValues, isLoading } = useSearchDatasetsByUri(searchEnv, getUriList()); - - const comboboxOptions = [ - ...new Map( - [ - ...(searchHits ?? []), - ...(selectedValues ?? []), - ...(getUriList() ?? []).map((uri) => { - const foundItem = - searchHits?.find((item) => item.uri === uri) || selectedValues?.find((item) => item.uri === uri); - - return { - uri, - title: foundItem?.title ?? null, - }; - }), - ].map((option) => [option.uri, option]), - ).values(), - ]; - - return ( - <> - - {({ remove, push }) => ( -
- {values.references?.map((_, index) => ( -
- setFieldValue(`references[${index}].referenceType.code`, value.toString())} - value={ - values.references?.[index]?.referenceType?.code - ? [values.references?.[index]?.referenceType?.code] - : [] - } - placeholder={`${localization.datasetForm.fieldLabel.choseRelation}...`} - > - {localization.search.noHits} - {relations.map((relation) => ( - - {getTranslateText(relation?.label)} - - ))} - - - {!isLoading && ( - setSearchQuery(input.target.value)} - onValueChange={(value) => { - setFieldValue(`references.${[index]}.source.uri`, value.toString()); - }} - loading={searching} - value={values.references?.[index]?.source?.uri ? [values.references?.[index]?.source?.uri] : []} - placeholder={`${localization.search.search}...`} - > - {localization.search.noHits} - {comboboxOptions?.map((dataset) => ( - - {dataset?.title ? getTranslateText(dataset?.title) : dataset.uri} - - ))} - - )} - remove(index)}> -
- ))} - - push({ type: { code: '' }, source: { uri: '' } })}> -
- )} -
- - {datasetSeries && ( - setFieldValue('inSeries', value.toString())} - value={values.inSeries ? [values.inSeries] : []} - initialValue={values?.inSeries ? [values?.inSeries] : []} - placeholder={`${localization.search.search}...`} - > - {localization.search.noHits} - {datasetSeries.map((dataset) => ( - - {getTranslateText(dataset.title)} - - ))} - - )} -
- -
-
- - -
- - ); -}; diff --git a/apps/dataset-catalog/components/dataset-form/components/details-section/details-section.tsx b/apps/dataset-catalog/components/dataset-form/components/details-section/details-section.tsx new file mode 100644 index 000000000..851c65fce --- /dev/null +++ b/apps/dataset-catalog/components/dataset-form/components/details-section/details-section.tsx @@ -0,0 +1,32 @@ +'use client'; + +import { FieldsetDivider } from '@catalog-frontend/ui'; +import { useFormikContext } from 'formik'; +import { Dataset, ReferenceData } from '@catalog-frontend/types'; +import { RecommendedDetailFields } from './recommended-detail-fields'; +import { HiddenDetailFields } from './hidden-detail-fields'; + +type Props = { + referenceDataEnv: string; + referenceData: ReferenceData; +}; + +export const DetailsSection = ({ referenceDataEnv, referenceData }: Props) => { + const { datasetTypes, provenanceStatements, languages, frequencies } = referenceData; + return ( + <> + + +
+ +
+ + ); +}; diff --git a/apps/dataset-catalog/components/dataset-form/components/details-section/details.module.css b/apps/dataset-catalog/components/dataset-form/components/details-section/details.module.css new file mode 100644 index 000000000..b11177c65 --- /dev/null +++ b/apps/dataset-catalog/components/dataset-form/components/details-section/details.module.css @@ -0,0 +1,3 @@ +.padding { + padding-bottom: 0.5rem; +} diff --git a/apps/dataset-catalog/components/dataset-form/components/details-section/hidden-detail-fields.tsx b/apps/dataset-catalog/components/dataset-form/components/details-section/hidden-detail-fields.tsx new file mode 100644 index 000000000..9d908877c --- /dev/null +++ b/apps/dataset-catalog/components/dataset-form/components/details-section/hidden-detail-fields.tsx @@ -0,0 +1,220 @@ +'use client'; + +import { AddButton, FormikLanguageFieldset, TextareaWithPrefix } from '@catalog-frontend/ui'; +import { capitalizeFirstLetter, getTranslateText, localization } from '@catalog-frontend/utils'; +import { Combobox, Textfield } from '@digdir/designsystemet-react'; +import { Field, FieldArray, useFormikContext } from 'formik'; +import { Dataset, ReferenceDataCode } from '@catalog-frontend/types'; +import styles from './details.module.css'; +import { QualifiedAttributionsSection } from '../dataset-form-qualified-attributions-section'; +import FieldsetWithDelete from '../../../fieldset-with-delete'; +import { ToggleFieldButton } from '../toggle-field-button'; +import { UriWithLabelFieldsetTable } from '../uri-with-label-field-set-table'; + +type Props = { + datasetTypes: ReferenceDataCode[]; + provenanceStatements: ReferenceDataCode[]; + frequencies: ReferenceDataCode[]; +}; + +export const HiddenDetailFields = ({ datasetTypes, provenanceStatements, frequencies }: Props) => { + const { setFieldValue, errors, values } = useFormikContext(); + + return ( + <> +
+ + {(arrayHelpers) => ( + <> + {arrayHelpers.form.values.landingPage && + arrayHelpers.form.values.landingPage.map((_: string, index: number) => ( +
+ arrayHelpers.remove(index)}> + + +
+ ))} + + arrayHelpers.push('')}> + {`${localization.datasetForm.heading.landingPage}`} + + + )} +
+
+ + + setFieldValue('type', value.toString())} + > + {`${localization.choose}...`} + {datasetTypes.map((type) => ( + + {getTranslateText(type?.label)} + + ))} + + + + + setFieldValue('provenance.uri', value.toString())} + label={localization.datasetForm.heading.provenance} + size='sm' + > + {`${localization.choose}...`} + {provenanceStatements.map((item) => ( + + {getTranslateText(item.label)} + + ))} + + + + setFieldValue('accrualPeriodicity.uri', value.toString())} + label={localization.datasetForm.heading.frequency} + > + {`${localization.choose}...`} + {frequencies.map((item) => ( + + {capitalizeFirstLetter(getTranslateText(item.label).toString())} + + ))} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-form-geography-section.tsx b/apps/dataset-catalog/components/dataset-form/components/details-section/recommended-detail-fields.tsx similarity index 74% rename from apps/dataset-catalog/components/dataset-form/components/dataset-form-geography-section.tsx rename to apps/dataset-catalog/components/dataset-form/components/details-section/recommended-detail-fields.tsx index c145ad534..3e1be0d26 100644 --- a/apps/dataset-catalog/components/dataset-form/components/dataset-form-geography-section.tsx +++ b/apps/dataset-catalog/components/dataset-form/components/details-section/recommended-detail-fields.tsx @@ -3,24 +3,27 @@ import { AddButton, FormikSearchCombobox, TitleWithTag } from '@catalog-frontend import { getTranslateText, localization } from '@catalog-frontend/utils'; import { Checkbox, Label, Textfield } from '@digdir/designsystemet-react'; import { useCallback, useState } from 'react'; -import { useSearchAdministrativeUnits, useSearchAdministrativeUnitsByUri } from '../../../hooks/useReferenceDataSearch'; +import { + useSearchAdministrativeUnits, + useSearchAdministrativeUnitsByUri, +} from '../../../../hooks/useReferenceDataSearch'; import { Field, FieldArray, useFormikContext } from 'formik'; import { Dataset, ReferenceDataCode } from '@catalog-frontend/types'; import { debounce, sortBy } from 'lodash'; -import FieldsetWithDelete from '../../fieldset-with-delete'; +import FieldsetWithDelete from '../../../fieldset-with-delete'; interface Props { - envVariable: string; + referenceDataEnv: string; languages: ReferenceDataCode[]; } -export const GeographySection = ({ envVariable, languages }: Props) => { +export const RecommendedDetailFields = ({ referenceDataEnv, languages }: Props) => { const [searchTerm, setSearchTerm] = useState(''); const { values, setFieldValue } = useFormikContext(); const langNOR = languages.filter((lang) => lang.code === 'NOR')[0]; - const { data: searchHits, isLoading: isSearching } = useSearchAdministrativeUnits(searchTerm, envVariable); - const { data: selectedValues } = useSearchAdministrativeUnitsByUri(values?.spatialList, envVariable); + const { data: searchHits, isLoading: isSearching } = useSearchAdministrativeUnits(searchTerm, referenceDataEnv); + const { data: selectedValues } = useSearchAdministrativeUnitsByUri(values?.spatialList, referenceDataEnv); const debouncedSetSearchTerm = debounce((term: string) => { setSearchTerm(term); @@ -46,17 +49,55 @@ export const GeographySection = ({ envVariable, languages }: Props) => { return ( <> - setFieldValue('spatialList', selectedValues)} - value={values.spatialList || []} - virtual - loading={isSearching} - label={localization.datasetForm.heading.spatial} - /> + setFieldValue('languageList', values)} + value={values.languageList} + legend={ + + } + size='sm' + > + {values.languageList && values.languageList.includes('NOR') && ( + + {getTranslateText(langNOR.label)} + + )} + {sortedLanguages + .filter((lang) => lang.code !== 'NOR') + .map((lang) => ( + + {getTranslateText(lang.label)} + + ))} + +
+ + setFieldValue('spatialList', selectedValues)} + value={values.spatialList || []} + virtual + loading={isSearching} + /> +
( @@ -70,6 +111,7 @@ export const GeographySection = ({ envVariable, languages }: Props) => { > { /> { )} /> - - setFieldValue('languageList', values)} - value={values.languageList} - legend={localization.datasetForm.heading.language} - > - {values.languageList && values.languageList.includes('NOR') && ( - - {getTranslateText(langNOR.label)} - - )} - {sortedLanguages - .filter((lang) => lang.code !== 'NOR') - .map((lang) => ( - - {getTranslateText(lang.label)} - - ))} - ); }; diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/dataset-form-distribution-section.tsx b/apps/dataset-catalog/components/dataset-form/components/distribution-section/dataset-form-distribution-section.tsx similarity index 100% rename from apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/dataset-form-distribution-section.tsx rename to apps/dataset-catalog/components/dataset-form/components/distribution-section/dataset-form-distribution-section.tsx diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/distribution-details.tsx b/apps/dataset-catalog/components/dataset-form/components/distribution-section/distribution-details.tsx similarity index 100% rename from apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/distribution-details.tsx rename to apps/dataset-catalog/components/dataset-form/components/distribution-section/distribution-details.tsx diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/distribution-modal.tsx b/apps/dataset-catalog/components/dataset-form/components/distribution-section/distribution-modal.tsx similarity index 100% rename from apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/distribution-modal.tsx rename to apps/dataset-catalog/components/dataset-form/components/distribution-section/distribution-modal.tsx diff --git a/apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/distributions.module.css b/apps/dataset-catalog/components/dataset-form/components/distribution-section/distributions.module.css similarity index 100% rename from apps/dataset-catalog/components/dataset-form/components/dataset-from-distribution/distributions.module.css rename to apps/dataset-catalog/components/dataset-form/components/distribution-section/distributions.module.css diff --git a/apps/dataset-catalog/components/dataset-form/components/toggle-field-button.tsx b/apps/dataset-catalog/components/dataset-form/components/toggle-field-button.tsx new file mode 100644 index 000000000..25cc10900 --- /dev/null +++ b/apps/dataset-catalog/components/dataset-form/components/toggle-field-button.tsx @@ -0,0 +1,64 @@ +import { Dataset } from '@catalog-frontend/types'; +import { AddButton } from '@catalog-frontend/ui'; +import { localization } from '@catalog-frontend/utils'; +import { useFormikContext } from 'formik'; +import { PropsWithChildren, useMemo, useState } from 'react'; +import FieldsetWithDelete from '../../fieldset-with-delete'; +import _ from 'lodash'; + +type Props = { + fieldName: string; + fieldValues: any; + hasDeleteButton?: boolean; + onDeleteValue?: any; + addValue?: any; +} & PropsWithChildren; + +export const ToggleFieldButton = ({ + children, + fieldName, + hasDeleteButton, + onDeleteValue = undefined, + addValue = '', + fieldValues, +}: Props) => { + const { setFieldValue, values } = useFormikContext(); + + const shouldShowField = useMemo(() => { + if (fieldName === 'qualifiedAttributions' && _.isArray(fieldValues) && fieldValues.length === 0) { + return true; + } + + if (_.isArray(fieldValues)) return fieldValues.length > 0; + if (_.isObject(fieldValues)) return !_.isEmpty(fieldValues); + return !_.isNil(fieldValues); + }, [fieldValues, fieldName]); + + const handleDelete = () => { + setFieldValue(fieldName, onDeleteValue); + }; + + return ( + <> + {shouldShowField ? ( + hasDeleteButton ? ( + { + handleDelete(); + }} + > + {children} + + ) : ( + children + ) + ) : ( + { + setFieldValue(fieldName, addValue); + }} + >{`${localization.add} ${fieldName}`} + )} + + ); +}; diff --git a/apps/dataset-catalog/components/dataset-form/components/uri-with-label-field-set-table.tsx b/apps/dataset-catalog/components/dataset-form/components/uri-with-label-field-set-table.tsx index 4f65aa9ca..bf7e15414 100644 --- a/apps/dataset-catalog/components/dataset-form/components/uri-with-label-field-set-table.tsx +++ b/apps/dataset-catalog/components/dataset-form/components/uri-with-label-field-set-table.tsx @@ -11,6 +11,7 @@ import { uriWithLabelSchema } from '../utils/validation-schema'; interface Props { values: UriWithLabel[] | undefined; fieldName: string; + showLabel?: boolean; } interface ModalProps { @@ -25,12 +26,12 @@ const hasNoFieldValues = (values: UriWithLabel) => { return _.isEmpty(_.trim(values.uri)) && _.isEmpty(_.pickBy(values.prefLabel, _.identity)); }; -export const UriWithLabelFieldsetTable = ({ fieldName, values }: Props) => { +export const UriWithLabelFieldsetTable = ({ fieldName, values, showLabel = true }: Props) => { const { setFieldValue } = useFormikContext(); return ( <> - + {showLabel ?? } {values && values?.length > 0 && !hasNoFieldValues(values[0]) && ( @@ -87,7 +88,13 @@ const FieldModal = ({ fieldName, template, type, onSuccess }: ModalProps) => { return ( <> - {type === 'edit' ? : } + + {type === 'edit' ? ( + + ) : ( + {`${localization.add} ${localization.datasetForm.fieldLabel?.[fieldName]?.toLowerCase()}`} + )} + { +export const DatasetForm = ({ initialValues, referenceData, searchEnv, referenceDataEnv, datasetSeries }: Props) => { const { catalogId, datasetId } = useParams(); const [isDirty, setIsDirty] = useState(false); + const [isSubmitted, setIsSubmitted] = useState(false); + const [isCanceled, setIsCanceled] = useState(false); const { losThemes, dataThemes, provenanceStatements, datasetTypes, frequencies, languages, openLicenses } = referenceData; + const router = useRouter(); useWarnIfUnsavedChanges({ unsavedChanges: isDirty }); @@ -71,9 +62,8 @@ export const DatasetForm = ({ } }; - const router = useRouter(); - const handleCancel = () => { + setIsCanceled(true); router.push(datasetId ? `/catalogs/${catalogId}/datasets/${datasetId}` : `/catalogs/${catalogId}/datasets`); }; @@ -111,17 +101,18 @@ export const DatasetForm = ({ { + validateOnChange={isSubmitted} + validateOnBlur={isSubmitted} + onSubmit={async (values, { setSubmitting }) => { const trimmedValues = trimObjectWhitespace(values); - submitType === 'create' ? handleCreate(trimmedValues) : handleUpdate(trimmedValues as Dataset); + datasetId === null ? handleCreate(trimmedValues as Dataset) : await handleUpdate(trimmedValues as Dataset); setSubmitting(false); + setIsSubmitted(true); }} > - {({ errors, values, dirty, handleSubmit, isValid, setFieldValue }) => { + {({ setFieldValue, values, dirty, isValid, isSubmitting, isValidating, submitForm }) => { setTimeout(() => setIsDirty(dirty), 0); - const notifications = getNotifications({ isValid, hasUnsavedChanges: dirty }); + const notifications = getNotifications({ isValid, hasUnsavedChanges: false }); return ( <> @@ -132,16 +123,18 @@ export const DatasetForm = ({ e.preventDefault(); window.alert(localization.datasetForm.alert.formError); } else { - handleSubmit(e); + submitForm(); } }} > + > + + - + - + - - - - - + - - - - - - - - - - - + @@ -245,22 +210,27 @@ export const DatasetForm = ({ @@ -286,7 +256,7 @@ export const DatasetForm = ({ - + {notifications.length > 0 && } ); diff --git a/apps/dataset-catalog/components/dataset-form/utils/dataset-initial-values.tsx b/apps/dataset-catalog/components/dataset-form/utils/dataset-initial-values.tsx index ec9d054f5..c45efab0d 100644 --- a/apps/dataset-catalog/components/dataset-form/utils/dataset-initial-values.tsx +++ b/apps/dataset-catalog/components/dataset-form/utils/dataset-initial-values.tsx @@ -25,25 +25,25 @@ export const datasetTemplate = (dataset: Dataset): Dataset => { euThemeList: dataset.theme ? dataset.theme.filter((t) => t.uri && t.uri.includes('/data-theme/')).map((t) => t.uri) : [], - type: dataset.type ?? '', + type: dataset?.type, keywordList: dataset.keyword ? groupByKeys(dataset.keyword) : { nb: [] }, conceptList: dataset.concepts ? dataset.concepts.map((concept) => concept.uri) : [], - provenance: { uri: dataset?.provenance?.uri ?? '' }, - accrualPeriodicity: { uri: dataset?.accrualPeriodicity?.uri ?? '' }, - modified: dataset.modified ?? '', - hasCurrentnessAnnotation: { hasBody: { nb: dataset.hasCurrentnessAnnotation?.hasBody?.nb ?? '' } }, + provenance: dataset?.provenance?.uri ? { uri: dataset?.provenance?.uri } : undefined, + accrualPeriodicity: dataset?.accrualPeriodicity?.uri ? { uri: dataset?.accrualPeriodicity?.uri } : undefined, + modified: dataset?.modified, + hasCurrentnessAnnotation: { hasBody: dataset.hasCurrentnessAnnotation?.hasBody }, conformsTo: dataset?.conformsTo ?? [{ prefLabel: { nb: '' }, uri: '' }], - hasRelevanceAnnotation: { hasBody: { nb: dataset.hasRelevanceAnnotation?.hasBody?.nb ?? '' } }, - hasCompletenessAnnotation: { hasBody: { nb: dataset.hasCompletenessAnnotation?.hasBody?.nb ?? '' } }, - hasAccuracyAnnotation: { hasBody: { nb: dataset.hasAccuracyAnnotation?.hasBody?.nb ?? '' } }, - hasAvailabilityAnnotation: { hasBody: { nb: dataset.hasAvailabilityAnnotation?.hasBody?.nb ?? '' } }, + hasRelevanceAnnotation: { hasBody: dataset?.hasRelevanceAnnotation?.hasBody }, + hasCompletenessAnnotation: { hasBody: dataset.hasCompletenessAnnotation?.hasBody }, + hasAccuracyAnnotation: { hasBody: dataset?.hasAccuracyAnnotation?.hasBody }, + hasAvailabilityAnnotation: { hasBody: dataset.hasAvailabilityAnnotation?.hasBody }, 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) : [], informationModelsFromFDK: dataset.informationModelsFromFDK ?? [], informationModel: dataset.informationModel ?? [{ prefLabel: { nb: '' }, uri: '' }], - qualifiedAttributions: dataset.qualifiedAttributions ?? [], + qualifiedAttributions: dataset?.qualifiedAttributions, sample: dataset.sample ?? [ { description: { @@ -86,25 +86,25 @@ export const datasetToBeCreatedTemplate = (): DatasetToBeCreated => { legalBasisForRestriction: [], losThemeList: [], euThemeList: [], - type: '', + type: undefined, keywordList: { nb: [] }, conceptList: [], - provenance: { uri: '' }, - accrualPeriodicity: { uri: '' }, - modified: '', - hasCurrentnessAnnotation: { hasBody: { nb: '' } }, + provenance: undefined, + accrualPeriodicity: undefined, + modified: undefined, + hasCurrentnessAnnotation: undefined, conformsTo: [{ prefLabel: { nb: '' }, uri: '' }], - hasRelevanceAnnotation: { hasBody: { nb: '' } }, - hasCompletenessAnnotation: { hasBody: { nb: '' } }, - hasAccuracyAnnotation: { hasBody: { nb: '' } }, - hasAvailabilityAnnotation: { hasBody: { nb: '' } }, + hasRelevanceAnnotation: undefined, + hasCompletenessAnnotation: undefined, + hasAccuracyAnnotation: undefined, + hasAvailabilityAnnotation: undefined, spatialList: [], temporal: [{ startDate: '', endDate: '' }], issued: '', languageList: [], informationModelsFromFDK: [], informationModel: [{ prefLabel: { nb: '' }, uri: '' }], - qualifiedAttributions: [], + qualifiedAttributions: undefined, sample: [ { description: { @@ -120,7 +120,7 @@ export const datasetToBeCreatedTemplate = (): DatasetToBeCreated => { relations: [{ uri: '', prefLabel: { nb: '' } }], inSeries: '', distribution: [], - contactPoint: {}, + contactPoint: [], }; }; diff --git a/apps/dataset-catalog/components/dataset-form/utils/validation-schema.tsx b/apps/dataset-catalog/components/dataset-form/utils/validation-schema.tsx index 85f4e4a3a..26d720578 100644 --- a/apps/dataset-catalog/components/dataset-form/utils/validation-schema.tsx +++ b/apps/dataset-catalog/components/dataset-form/utils/validation-schema.tsx @@ -64,15 +64,13 @@ export const datasetValidationSchema = Yup.object().shape({ .url(localization.validation.invalidUrl), }), ), - contactPoint: Yup.array().of( - Yup.object().shape({ - hasURL: Yup.string() - .matches(httpsRegex, localization.validation.invalidProtocol) - .url(localization.validation.invalidUrl), - email: Yup.string().email(localization.validation.invalidEmail), - hasTelephone: Yup.string().matches(telephoneNumberRegex, localization.validation.invalidTlf), - }), - ), + // contactPoint: Yup.object().shape({ + // hasURL: Yup.string() + // .matches(httpsRegex, localization.validation.invalidProtocol) + // .url(localization.validation.invalidUrl), + // email: Yup.string().email(localization.validation.invalidEmail), + // hasTelephone: Yup.string().matches(telephoneNumberRegex, localization.validation.invalidTlf), + // }), }); export const distributionSectionSchema = Yup.object().shape({ diff --git a/libs/types/src/lib/dataset.ts b/libs/types/src/lib/dataset.ts index 5978fd8ef..51b2d9dab 100644 --- a/libs/types/src/lib/dataset.ts +++ b/libs/types/src/lib/dataset.ts @@ -25,11 +25,11 @@ export interface DatasetToBeCreated { provenance?: ReferenceDataCode; accrualPeriodicity?: ReferenceDataCode; modified?: string; - hasCurrentnessAnnotation?: { hasBody: LocalizedStrings }; - hasRelevanceAnnotation?: { hasBody: LocalizedStrings }; - hasCompletenessAnnotation?: { hasBody: LocalizedStrings }; - hasAvailabilityAnnotation?: { hasBody: LocalizedStrings }; - hasAccuracyAnnotation?: { hasBody: LocalizedStrings }; + hasCurrentnessAnnotation?: { hasBody?: LocalizedStrings }; + hasRelevanceAnnotation?: { hasBody?: LocalizedStrings }; + hasCompletenessAnnotation?: { hasBody?: LocalizedStrings }; + hasAvailabilityAnnotation?: { hasBody?: LocalizedStrings }; + hasAccuracyAnnotation?: { hasBody?: LocalizedStrings }; conformsTo?: UriWithLabel[]; spatial?: ReferenceDataCode[]; temporal?: DateRange[]; diff --git a/libs/ui/src/lib/formik-search-combobox/index.tsx b/libs/ui/src/lib/formik-search-combobox/index.tsx index f6b34f2bd..47aeb1c8b 100644 --- a/libs/ui/src/lib/formik-search-combobox/index.tsx +++ b/libs/ui/src/lib/formik-search-combobox/index.tsx @@ -54,6 +54,7 @@ export function FormikSearchCombobox({ placeholder={`${localization.search.search}...`} multiple filter={() => true} // disable filter + size='sm' > {`${localization.search.noHits}... `} {comboboxOptions.map((item) => ( diff --git a/libs/ui/src/lib/title-with-tag/index.tsx b/libs/ui/src/lib/title-with-tag/index.tsx index 775b9ada9..97d391a02 100644 --- a/libs/ui/src/lib/title-with-tag/index.tsx +++ b/libs/ui/src/lib/title-with-tag/index.tsx @@ -13,10 +13,10 @@ type TagColor = 'first' | 'second' | 'success' | 'danger' | 'third' | 'neutral' type TagSize = 'sm' | 'md' | 'lg' | 'small' | 'medium' | 'large'; -export function TitleWithTag({ title, tagTitle, tagColor = 'warning', tagSize = 'medium' }: Props) { +export function TitleWithTag({ title, tagTitle, tagColor = 'warning', tagSize = 'sm' }: Props) { return (
- {typeof title === 'string' ? : title} + {typeof title === 'string' ? : title}