diff --git a/i18n/es.po b/i18n/es.po index ed5b7180..a6144c53 100644 --- a/i18n/es.po +++ b/i18n/es.po @@ -197,9 +197,8 @@ msgstr "" msgid "DataSet name" msgstr "" -#, fuzzy msgid "DataSet description" -msgstr "Sección" +msgstr "" msgid "Expiry Days" msgstr "" @@ -240,9 +239,8 @@ msgstr "" msgid "and {{number}} more." msgstr "" -#, fuzzy msgid "Description" -msgstr "Sección" +msgstr "" msgid "Linked Project" msgstr "" diff --git a/src/CompositionRoot.ts b/src/CompositionRoot.ts index 78816d1c..bc2d7e9a 100644 --- a/src/CompositionRoot.ts +++ b/src/CompositionRoot.ts @@ -25,7 +25,7 @@ import { SaveDataSetUseCase } from "$/domain/usecases/SaveDataSetUseCase"; import { SaveOrgUnitDataSetUseCase } from "$/domain/usecases/SaveOrgUnitDataSetUseCase"; import { SaveSharingDataSetsUseCase } from "$/domain/usecases/SaveSharingDataSetsUseCase"; import { SearchSharingUseCase } from "$/domain/usecases/SearchSharingUseCase"; -import { ValidateNameUseCase } from "$/domain/usecases/ValidateNameUseCase"; +import { ValidateDataSetNameUseCase } from "$/domain/usecases/ValidateDataSetNameUseCase"; import { UserD2Repository } from "./data/repositories/UserD2Repository"; import { UserTestRepository } from "./data/repositories/UserTestRepository"; import { UserRepository } from "./domain/repositories/UserRepository"; @@ -55,7 +55,7 @@ function getCompositionRoot(repositories: Repositories) { repositories.dataSetsRepository, repositories.projectRepository ), - validateName: new ValidateNameUseCase(repositories.dataSetsRepository), + validateName: new ValidateDataSetNameUseCase(repositories.dataSetsRepository), save: new SaveDataSetUseCase(repositories.dataSetsRepository), }, logs: { diff --git a/src/data/repositories/D2ApiCategoryOption.ts b/src/data/repositories/D2ApiCategoryOption.ts index 8f267c64..5f55e011 100644 --- a/src/data/repositories/D2ApiCategoryOption.ts +++ b/src/data/repositories/D2ApiCategoryOption.ts @@ -4,6 +4,7 @@ import { D2Api } from "$/types/d2-api"; import _ from "$/domain/entities/generic/Collection"; import { chunkRequest } from "$/data/utils"; import { FutureData } from "$/domain/entities/generic/Future"; +import { Maybe } from "$/utils/ts-utils"; export class D2ApiCategoryOption { constructor(private api: D2Api) {} @@ -22,3 +23,9 @@ export class D2ApiCategoryOption { } export type D2CategoryOptionType = { id: string; displayName: string; lastUpdated: ISODateString }; +export type D2CategoryOptionDates = { + startDate: Maybe; + endDate: Maybe; +}; + +export type D2CategoryOptionWithDates = D2CategoryOptionType & D2CategoryOptionDates; diff --git a/src/data/repositories/DataSetD2Api.ts b/src/data/repositories/DataSetD2Api.ts index 9753895f..9b478b8e 100644 --- a/src/data/repositories/DataSetD2Api.ts +++ b/src/data/repositories/DataSetD2Api.ts @@ -221,7 +221,6 @@ export class DataSetD2Api { data: this.buildPermission(d2DataSet.sharing.public, "data"), metadata: this.buildPermission(d2DataSet.sharing.public, "metadata"), }, - shortName: d2DataSet.displayShortName, access: this.buildAccessByType(d2DataSet.userAccesses, "users").concat( this.buildAccessByType(d2DataSet.userGroupAccesses, "groups") ), diff --git a/src/data/repositories/DataSetD2Repository.ts b/src/data/repositories/DataSetD2Repository.ts index 4f6aed54..8c28ac82 100644 --- a/src/data/repositories/DataSetD2Repository.ts +++ b/src/data/repositories/DataSetD2Repository.ts @@ -2,7 +2,7 @@ import { D2AttributeValue } from "@eyeseetea/d2-api/2.36"; import { D2Api } from "$/types/d2-api"; import { apiToFuture } from "$/data/api-futures"; -import { DataSet, DataSetList, DataSetToSave } from "$/domain/entities/DataSet"; +import { DataSet, DataSetList } from "$/domain/entities/DataSet"; import { Paginated } from "$/domain/entities/Paginated"; import { DataSetName, @@ -16,6 +16,7 @@ import { DataSetD2Api, dataSetFieldsWithOrgUnits } from "$/data/repositories/Dat import { Maybe } from "$/utils/ts-utils"; import { chunkRequest } from "$/data/utils"; import { D2Config } from "$/data/repositories/D2ApiConfig"; +import { DataSetToSave } from "$/domain/entities/DataSetToSave"; export class DataSetD2Repository implements DataSetRepository { private d2DataSetApi: DataSetD2Api; @@ -166,10 +167,10 @@ export class DataSetD2Repository implements DataSetRepository { ) { return { id: dataSet.id || getUid(dataSet.name), + shortName: dataSet.shortName, name: dataSet.name, periodType: "Monthly", description: dataSet.description, - shortName: dataSet.shortName, publicAccess: this.d2DataSetApi.generateFullPermission(dataSet.permissions), userAccesses: dataSet.access .filter(access => access.type === "users") @@ -203,25 +204,21 @@ export class DataSetD2Repository implements DataSetRepository { dataSet: DataSetToSave, attributes: D2Config["attributes"] ) { - // if (!dataSet.project) return existingAttributes || []; - // const projectAttributeId = attributes.project.id; - // const projectAttribute = existingAttributes?.find( - // attribute => attribute.attribute.id === projectAttributeId - // ); - - const pa = { attribute: { id: attributes.project.id }, value: dataSet.project?.id }; + const projectAttribute = { + attribute: { id: attributes.project.id }, + value: dataSet.project?.id, + }; const createdByAttribute = { attribute: { id: attributes.createdByApp.id }, value: "true" }; - const attributesToSave = _([pa, createdByAttribute]) - .compactMap(attribute => (attribute.value ? attribute : undefined)) - .value(); + const attributesToSave = [projectAttribute, createdByAttribute].filter( + attribute => attribute.value + ); const filteredExisting = existingAttributes?.filter( attr => !attributesToSave.some(save => save.attribute.id === attr.attribute.id) ) || []; - // Combinar `filteredExisting` con `toSave` return [...filteredExisting, ...attributesToSave]; } } diff --git a/src/data/repositories/OrgUnitD2Repository.ts b/src/data/repositories/OrgUnitD2Repository.ts index 89e4397f..f94f6794 100644 --- a/src/data/repositories/OrgUnitD2Repository.ts +++ b/src/data/repositories/OrgUnitD2Repository.ts @@ -2,7 +2,7 @@ import { D2Api } from "$/types/d2-api"; import { apiToFuture } from "$/data/api-futures"; import { OrgUnit } from "$/domain/entities/DataSet"; import { Id } from "$/domain/entities/Ref"; -import { Future, FutureData } from "$/domain/entities/generic/Future"; +import { FutureData } from "$/domain/entities/generic/Future"; import { OrgUnitRepository } from "$/domain/repositories/OrgUnitRepository"; import { chunkRequest } from "$/data/utils"; @@ -10,9 +10,7 @@ export class OrgUnitD2Repository implements OrgUnitRepository { constructor(private api: D2Api) {} getByIds(ids: Id[]): FutureData { - if (ids.length === 0) return Future.success([]); - - const $requests = chunkRequest(ids, idsToFetch => { + const d2OrgsUnits$ = chunkRequest(ids, idsToFetch => { return apiToFuture( this.api.models.organisationUnits.get({ fields: { id: true, displayName: true, path: true }, @@ -22,9 +20,8 @@ export class OrgUnitD2Repository implements OrgUnitRepository { ).map(response => response.objects); }); - return $requests.map(response => { - // const allRecords = response.flatMap(r => r); - return response.map(d2OrgUnit => { + return d2OrgsUnits$.map(d2OrgUnits => { + return d2OrgUnits.map(d2OrgUnit => { return { id: d2OrgUnit.id, name: d2OrgUnit.displayName, diff --git a/src/data/repositories/ProjectD2Repository.ts b/src/data/repositories/ProjectD2Repository.ts index c018ec93..0b92d3d2 100644 --- a/src/data/repositories/ProjectD2Repository.ts +++ b/src/data/repositories/ProjectD2Repository.ts @@ -8,9 +8,13 @@ import _ from "$/domain/entities/generic/Collection"; import { DataSetD2Api } from "$/data/repositories/DataSetD2Api"; import { ISODateString, Id } from "$/domain/entities/Ref"; import { DataSet } from "$/domain/entities/DataSet"; -import { D2CategoryOptionType } from "$/data/repositories/D2ApiCategoryOption"; +import { + D2CategoryOptionType, + D2CategoryOptionWithDates, +} from "$/data/repositories/D2ApiCategoryOption"; import { Future, FutureData } from "$/domain/entities/generic/Future"; import { D2ApiConfig, D2Config } from "$/data/repositories/D2ApiConfig"; +import { Maybe } from "$/utils/ts-utils"; export class ProjectD2Repository implements ProjectRepository { private d2DataSetApi: DataSetD2Api; @@ -23,32 +27,8 @@ export class ProjectD2Repository implements ProjectRepository { getList(): FutureData { return this.getCategories().flatMap(categories => { - return apiToFuture( - this.api.models.categoryOptions.get({ - fields: { - id: true, - displayName: true, - startDate: true, - endDate: true, - lastUpdated: true, - }, - filter: { "categories.code": { eq: categories.project.code } }, - order: "displayName:asc", - paging: false, - }) - ).map(d2Response => { - return d2Response.objects.map((d2CategoryOption): Project => { - return Project.build({ - dataSets: [], - id: d2CategoryOption.id, - name: d2CategoryOption.displayName, - lastUpdated: d2CategoryOption.lastUpdated, - isOpen: this.isProjectOpen( - d2CategoryOption.startDate, - d2CategoryOption.endDate - ), - }); - }); + return this.getCategoryOptionsByCode(categories.project.code).map(d2Response => { + return this.getProjectsWithDates(d2Response.objects); }); }); } @@ -57,7 +37,36 @@ export class ProjectD2Repository implements ProjectRepository { return this.getAllProjects(1, []); } - private isProjectOpen(date1: ISODateString, date2: ISODateString): boolean { + private getCategoryOptionsByCode(code: string) { + return apiToFuture( + this.api.models.categoryOptions.get({ + fields: { + id: true, + displayName: true, + startDate: true, + endDate: true, + lastUpdated: true, + }, + filter: { "categories.code": { eq: code } }, + order: "displayName:asc", + paging: false, + }) + ); + } + + private getProjectsWithDates(categoryOptions: D2CategoryOptionWithDates[]): Project[] { + return categoryOptions.map(d2CategoryOption => { + return Project.build({ + dataSets: [], + id: d2CategoryOption.id, + name: d2CategoryOption.displayName, + lastUpdated: d2CategoryOption.lastUpdated, + isOpen: this.isProjectOpen(d2CategoryOption.startDate, d2CategoryOption.endDate), + }); + }); + } + + private isProjectOpen(date1: Maybe, date2: Maybe): boolean { if (!date1 || !date2) return false; const today = new Date(); diff --git a/src/domain/entities/DataSet.ts b/src/domain/entities/DataSet.ts index 00afc59e..414e50a6 100644 --- a/src/domain/entities/DataSet.ts +++ b/src/domain/entities/DataSet.ts @@ -8,6 +8,7 @@ import _ from "$/domain/entities/generic/Collection"; import { Either } from "$/domain/entities/generic/Either"; import { ValidationError } from "$/domain/entities/generic/Error"; import { validateOrgUnits, validateRequired } from "$/domain/entities/generic/Validation"; +import { DataSetToSave } from "$/domain/entities/DataSetToSave"; export type DataSetAttrs = { created: ISODateString; @@ -17,7 +18,6 @@ export type DataSetAttrs = { lastUpdated: ISODateString; permissions: Permissions; project: Maybe; - shortName: string; coreCompetencies: CoreCompetency[]; access: AccessData[]; orgUnits: OrgUnit[]; @@ -26,9 +26,9 @@ export type DataSetAttrs = { notifyUser: boolean; }; -export type DataSetToSave = Omit & { - orgUnits: Ref[]; -}; +// export type DataSetToSave = Omit & { +// orgUnits: Ref[]; +// }; export type OrgUnit = { id: Id; name: string; path: Id[] }; export type Permissions = { data: Permission; metadata: Permission }; @@ -39,6 +39,15 @@ export type CoreCompetency = { id: Id; name: string; code: string }; export type DataSetList = Pick; export class DataSet extends Struct() { + get shortName(): string { + return this.truncateValue(this.name); + } + + private truncateValue(input: string): string { + const targetLength = 50; + return input.length > targetLength ? input.slice(0, targetLength) : input; + } + validateSetup(): Either[], DataSet> { const errors: ValidationError[] = [ { @@ -61,7 +70,7 @@ export class DataSet extends Struct() { return this._update({ project, name }); } - update(fieldName: keyof DataSet, value: string | number | boolean): DataSet { + update(fieldName: K, value: DataSet[K]): DataSet { return this._update({ [fieldName]: value }); } @@ -73,15 +82,6 @@ export class DataSet extends Struct() { return DataSet.create({ ...this, orgUnits }); } - static buildOrgUnitsFromPaths(paths: string[]): OrgUnit[] { - const orgUnits = paths.map(path => ({ - id: _(path.split("/")).last() || "", - name: path, - path: path.split("/").slice(1), - })); - return orgUnits; - } - static buildAccess(permissions: Permissions): string { const dataDescription = DataSet.buildAccessDescription(permissions.data); const metadataDescription = DataSet.buildAccessDescription(permissions.metadata); @@ -103,4 +103,25 @@ export class DataSet extends Struct() { return ""; } } + + static initial(id: Id): DataSet { + return DataSet.create({ + access: [], + coreCompetencies: [], + created: "", + description: "", + id, + lastUpdated: "", + name: "", + orgUnits: [], + permissions: { + data: Permission.create({ read: false, write: false }), + metadata: Permission.create({ read: false, write: false }), + }, + project: undefined, + expiryDays: 0, + openFuturePeriods: 0, + notifyUser: false, + }); + } } diff --git a/src/domain/entities/DataSetToSave.ts b/src/domain/entities/DataSetToSave.ts new file mode 100644 index 00000000..1dd67123 --- /dev/null +++ b/src/domain/entities/DataSetToSave.ts @@ -0,0 +1,8 @@ +import { DataSet, DataSetAttrs } from "$/domain/entities/DataSet"; +import { Ref } from "$/domain/entities/Ref"; + +export type DataSetToSaveAttrs = Omit & { + orgUnits: Ref[]; +}; + +export class DataSetToSave extends DataSet {} diff --git a/src/domain/entities/generic/Error.ts b/src/domain/entities/generic/Error.ts index a74df4f8..1f717154 100644 --- a/src/domain/entities/generic/Error.ts +++ b/src/domain/entities/generic/Error.ts @@ -20,7 +20,7 @@ export function getErrorMessageFromErrors(errors: ValidationError[]): stri return errors .map(error => { return error.errors.map(err => - validationErrorMessages[err](error.property as string, error.value) + validationErrorMessages[err](error.property, error.value) ); }) .flat() @@ -28,17 +28,13 @@ export function getErrorMessageFromErrors(errors: ValidationError[]): stri } export function getErrors(errors: ValidationError[]): string[] { - return errors - .map(error => { - return error.errors.map(err => - validationErrorMessages[err](error.property as string, error.value) - ); - }) - .flat(); + return errors.flatMap(error => { + return error.errors.map(err => validationErrorMessages[err](error.property, error.value)); + }); } export type ValidationError = { - property: keyof T; + property: keyof T & string; value: unknown; errors: ValidationErrorKey[]; }; diff --git a/src/domain/repositories/DataSetRepository.ts b/src/domain/repositories/DataSetRepository.ts index c3be2054..b940faa2 100644 --- a/src/domain/repositories/DataSetRepository.ts +++ b/src/domain/repositories/DataSetRepository.ts @@ -1,7 +1,8 @@ import { FutureData } from "$/domain/entities/generic/Future"; -import { DataSet, DataSetList, DataSetToSave } from "$/domain/entities/DataSet"; +import { DataSet, DataSetList } from "$/domain/entities/DataSet"; import { Paginated } from "$/domain/entities/Paginated"; import { Id } from "$/domain/entities/Ref"; +import { DataSetToSave } from "$/domain/entities/DataSetToSave"; export interface DataSetRepository { getByIds(ids: Id[]): FutureData; diff --git a/src/domain/usecases/SaveDataSetUseCase.ts b/src/domain/usecases/SaveDataSetUseCase.ts index 8a1a8bf2..0e3af537 100644 --- a/src/domain/usecases/SaveDataSetUseCase.ts +++ b/src/domain/usecases/SaveDataSetUseCase.ts @@ -2,38 +2,18 @@ import _ from "$/domain/entities/generic/Collection"; import { DataSet } from "$/domain/entities/DataSet"; import { Future, FutureData } from "$/domain/entities/generic/Future"; import { DataSetRepository } from "$/domain/repositories/DataSetRepository"; -import { Maybe } from "$/utils/ts-utils"; import { getErrors } from "$/domain/entities/generic/Error"; export class SaveDataSetUseCase { constructor(private dataSetRepository: DataSetRepository) {} execute(dataSet: DataSet): FutureData { - return this.getDataSetById(dataSet.id).flatMap(existingDataSet => { - const dataSetToSave = DataSet.create({ - ...(existingDataSet || {}), - ...dataSet, - shortName: this.truncateValue(dataSet.name), - }); + const result = dataSet.validateSetup(); + if (result.isError()) { + const errors = getErrors(result.value.error); + return Future.error(new Error(errors.join("\n"))); + } - const result = dataSetToSave.validateSetup(); - if (result.isError()) { - const errors = getErrors(result.value.error); - return Future.error(new Error(errors.join("\n"))); - } - - return this.dataSetRepository.save([dataSetToSave]); - }); - } - - private getDataSetById(id: string): FutureData> { - return this.dataSetRepository.getByIds([id]).map(dataSets => { - return _(dataSets).first(); - }); - } - - private truncateValue(input: string): string { - const targetLength = 50; - return input.length > targetLength ? input.slice(0, targetLength) : input; + return this.dataSetRepository.save([dataSet]); } } diff --git a/src/domain/usecases/SaveOrgUnitDataSetUseCase.ts b/src/domain/usecases/SaveOrgUnitDataSetUseCase.ts index fdf1a2e5..22fe97be 100644 --- a/src/domain/usecases/SaveOrgUnitDataSetUseCase.ts +++ b/src/domain/usecases/SaveOrgUnitDataSetUseCase.ts @@ -1,8 +1,9 @@ import { FutureData } from "$/domain/entities/generic/Future"; -import { DataSet, DataSetToSave } from "$/domain/entities/DataSet"; +import { DataSet } from "$/domain/entities/DataSet"; import { Id, Ref } from "$/domain/entities/Ref"; import { DataSetRepository } from "$/domain/repositories/DataSetRepository"; import _ from "$/domain/entities/generic/Collection"; +import { DataSetToSave } from "$/domain/entities/DataSetToSave"; export class SaveOrgUnitDataSetUseCase { constructor(private dataSetRepository: DataSetRepository) {} diff --git a/src/domain/usecases/ValidateNameUseCase.ts b/src/domain/usecases/ValidateDataSetNameUseCase.ts similarity index 74% rename from src/domain/usecases/ValidateNameUseCase.ts rename to src/domain/usecases/ValidateDataSetNameUseCase.ts index d335a29b..d83d6161 100644 --- a/src/domain/usecases/ValidateNameUseCase.ts +++ b/src/domain/usecases/ValidateDataSetNameUseCase.ts @@ -2,10 +2,10 @@ import { Id } from "$/domain/entities/Ref"; import { FutureData } from "$/domain/entities/generic/Future"; import { DataSetRepository } from "$/domain/repositories/DataSetRepository"; -export class ValidateNameUseCase { +export class ValidateDataSetNameUseCase { constructor(private dataSetRepository: DataSetRepository) {} - execute(options: ValidateNameOptions): FutureData { + execute(options: ValidateDataSetNameOptions): FutureData { return this.dataSetRepository.getByName(options.name).map(dataSets => { return dataSets.some( dataSet => @@ -15,4 +15,4 @@ export class ValidateNameUseCase { }); } } -export type ValidateNameOptions = { name: string; dataSetId: Id }; +export type ValidateDataSetNameOptions = { name: string; dataSetId: Id }; diff --git a/src/webapp/components/dataset-wizard/DataSetWizard.tsx b/src/webapp/components/dataset-wizard/DataSetWizard.tsx index 6fa86f7d..ee5770c1 100644 --- a/src/webapp/components/dataset-wizard/DataSetWizard.tsx +++ b/src/webapp/components/dataset-wizard/DataSetWizard.tsx @@ -38,6 +38,8 @@ export const DataSetWizard = React.memo((props: DataSetWizardProps) => { const navigateTo = useNavigateTo(); const [validationStatus, setValidationStatus] = React.useState("idle"); + const { validateSteps } = useValidateDataSetWizard({ validationStatus, dataSet }); + const goBackToHome = React.useCallback(() => { navigateTo("dataSets"); }, [navigateTo]); @@ -75,24 +77,6 @@ export const DataSetWizard = React.memo((props: DataSetWizardProps) => { }); }, [dataSet, projects, steps, validateDataSetName, validationStatus, updateDataSet]); - const validationInProgressOrError = - !validationStatus || validationStatus === "error" || validationStatus === "loading"; - - const validateSteps = React.useCallback( - (currentStep: WizardStep) => { - if (validationInProgressOrError) - return Promise.resolve(["Validation name in progress"]); - if (currentStep.key === "setup") { - const result = dataSet.validateSetup(); - if (result.isError()) { - return Promise.resolve(getErrors(result.value.error)); - } - } - return Promise.resolve([]); - }, - [dataSet, validationInProgressOrError] - ); - return ( @@ -117,4 +101,32 @@ export const DataSetWizard = React.memo((props: DataSetWizardProps) => { ); }); +export function useValidateDataSetWizard(props: { + validationStatus: ValidationStatusType; + dataSet: DataSet; +}) { + const { validationStatus, dataSet } = props; + + const validationInProgressOrError = + !validationStatus || validationStatus === "error" || validationStatus === "loading"; + + const validateSteps = React.useCallback( + (currentStep: WizardStep) => { + if (validationInProgressOrError) { + return Promise.resolve(["Validation name in progress"]); + } else if (currentStep.key === "setup") { + const result = dataSet.validateSetup(); + return result.isError() + ? Promise.resolve(getErrors(result.value.error)) + : Promise.resolve([]); + } else { + return Promise.resolve([]); + } + }, + [dataSet, validationInProgressOrError] + ); + + return { validateSteps }; +} + DataSetWizard.displayName = "DataSetWizard"; diff --git a/src/webapp/components/dataset-wizard/SetupDataSet.tsx b/src/webapp/components/dataset-wizard/SetupDataSet.tsx index 27825026..d5d27cfb 100644 --- a/src/webapp/components/dataset-wizard/SetupDataSet.tsx +++ b/src/webapp/components/dataset-wizard/SetupDataSet.tsx @@ -18,6 +18,7 @@ import { Project } from "$/domain/entities/Project"; import { ProjectsSelectorModal } from "$/webapp/components/dataset-wizard/ProjectsSelectorModal"; import { Maybe } from "$/utils/ts-utils"; import { component } from "$/utils/react"; +import _ from "$/domain/entities/generic/Collection"; export type SetupDataSetProps = { dataSet: DataSet; @@ -28,7 +29,7 @@ export type SetupDataSetProps = { }; const SetupDataSet_ = React.memo((props: SetupDataSetProps) => { - const { api } = useAppContext(); + const { api, compositionRoot } = useAppContext(); const { dataSet, onChange, onValidate, projects, validationStatus } = props; const [projectModalOpen, setProjectModalOpen] = React.useState(false); @@ -64,11 +65,13 @@ const SetupDataSet_ = React.memo((props: SetupDataSetProps) => { const updateOrgUnits = React.useCallback( (paths: string[]) => { - const orgUnits = DataSet.buildOrgUnitsFromPaths(paths); - const updateData = DataSet.create({ ...dataSet, orgUnits }); - onChange(updateData); + const idsFromPaths = paths.map(path => _(path.split("/")).last() || ""); + compositionRoot.orgUnits.getByIds.execute(idsFromPaths).run(orgUnitsDetails => { + const updateData = DataSet.create({ ...dataSet, orgUnits: orgUnitsDetails }); + onChange(updateData); + }, console.error); }, - [onChange, dataSet] + [compositionRoot.orgUnits.getByIds, onChange, dataSet] ); const updateProject = React.useCallback( diff --git a/src/webapp/pages/register-dataset/RegisterDataSetPage.tsx b/src/webapp/pages/register-dataset/RegisterDataSetPage.tsx index caa1936f..540b9a64 100644 --- a/src/webapp/pages/register-dataset/RegisterDataSetPage.tsx +++ b/src/webapp/pages/register-dataset/RegisterDataSetPage.tsx @@ -2,7 +2,6 @@ import React from "react"; import { useParams } from "react-router"; import { DataSet } from "$/domain/entities/DataSet"; -import { Permission } from "$/domain/entities/Permission"; import { Id, Ref } from "$/domain/entities/Ref"; import { DataSetWizard } from "$/webapp/components/dataset-wizard/DataSetWizard"; import { useAppContext } from "$/webapp/contexts/app-context"; @@ -56,27 +55,9 @@ function useGetDataSetById(props: { id: Maybe }) { const { id } = props; const { compositionRoot } = useAppContext(); const snackbar = useSnackbar(); - const [status, setStatus] = React.useState("idle"); + const [status, setStatus] = React.useState("idle"); const [dataSet, updateDataSet] = React.useState(() => { - return DataSet.create({ - access: [], - coreCompetencies: [], - created: "", - description: "", - id: getUid(new Date().getTime().toString()), - lastUpdated: "", - name: "", - orgUnits: [], - permissions: { - data: Permission.create({ read: false, write: false }), - metadata: Permission.create({ read: false, write: false }), - }, - project: undefined, - shortName: "", - expiryDays: 0, - openFuturePeriods: 0, - notifyUser: false, - }); + return DataSet.initial(getUid(new Date().getTime().toString())); }); React.useEffect(() => { @@ -98,6 +79,6 @@ function useGetDataSetById(props: { id: Maybe }) { return { dataSet, status, updateDataSet }; } -export type HttpStatus = "idle" | "loading" | "finished" | "error"; +export type LoadingStatus = "idle" | "loading" | "finished" | "error"; export const RegisterDataSetPage = component(RegisterDataSetPage_);