Fix: remember validation state when creating (#18432)

* only reset state and load if its a new unique

* related clean up

* return response promise
This commit is contained in:
Niels Lyngsø
2025-02-24 22:09:43 +01:00
committed by GitHub
parent 347e898190
commit a4f385ba01
7 changed files with 21 additions and 5 deletions

View File

@@ -92,4 +92,9 @@ export class UmbStateManager<StateType extends UmbState = UmbState> extends UmbC
clear() {
this._states.setValue([]);
}
override destroy() {
super.destroy();
this._states.destroy();
}
}

View File

@@ -34,7 +34,7 @@ export class UmbWorkspaceIsNewRedirectController extends UmbControllerBase {
id: unique,
});
this.destroy();
window.history.replaceState({}, '', newPath);
window.history.replaceState(null, '', newPath);
}
}
}

View File

@@ -167,6 +167,9 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
}
async load(unique: string) {
if (unique === this.getUnique() && this._getDataPromise) {
return (await this._getDataPromise) as GetDataType;
}
this.resetState();
this.#entityContext.setUnique(unique);
this.loading.addState({ unique: LOADING_STATE_UNIQUE, message: `Loading ${this.getEntityType()} Details` });
@@ -389,8 +392,10 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
override resetState() {
super.resetState();
this.loading.clear();
this._data.clear();
this.#allowNavigateAway = false;
this._getDataPromise = undefined;
}
#checkIfInitialized() {
@@ -447,6 +452,7 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
);
this._detailRepository?.destroy();
this.#entityContext.destroy();
this._getDataPromise = undefined;
super.destroy();
}
}

View File

@@ -57,7 +57,6 @@ export abstract class UmbSubmittableWorkspaceContextBase<WorkspaceDataModelType>
}
protected resetState() {
//this.validation.reset();
this.#validationContexts.forEach((context) => context.reset());
this.#isNew.setValue(undefined);
}

View File

@@ -177,10 +177,15 @@ export class UmbDocumentWorkspaceContext
]);
}
override resetState(): void {
super.resetState();
this.#isTrashedContext.setIsTrashed(false);
}
override async load(unique: string) {
const response = await super.load(unique);
if (response.data) {
if (response?.data) {
this.#isTrashedContext.setIsTrashed(response.data.isTrashed);
}

View File

@@ -89,13 +89,14 @@ export class UmbMediaWorkspaceContext
public override resetState() {
super.resetState();
this.#isTrashedContext.setIsTrashed(false);
this.removeUmbControllerByAlias(UmbWorkspaceIsNewRedirectControllerAlias);
}
public override async load(unique: string) {
const response = await super.load(unique);
if (response.data) {
if (response?.data) {
this.#isTrashedContext.setIsTrashed(response.data.isTrashed);
}

View File

@@ -78,7 +78,7 @@ export class UmbMemberWorkspaceContext
preset: {
memberType: {
unique: memberTypeUnique,
icon: "icon-user"
icon: 'icon-user',
},
},
});