update types

This commit is contained in:
Jesper Møller Jensen
2023-11-01 19:58:34 +13:00
parent f88eae8495
commit e642b927e1
2 changed files with 23 additions and 17 deletions

View File

@@ -18,7 +18,7 @@ export class UmbMediaTypeRepository implements UmbTreeRepository<EntityTreeItemR
#treeStore?: UmbMediaTypeTreeStore;
#detailSource: UmbMediaTypeDetailServerDataSource;
#store?: UmbMediaTypeStore;
#detailStore?: UmbMediaTypeStore;
#notificationContext?: UmbNotificationContext;
@@ -31,7 +31,7 @@ export class UmbMediaTypeRepository implements UmbTreeRepository<EntityTreeItemR
this.#init = Promise.all([
new UmbContextConsumerController(this.#host, UMB_MEDIA_TYPE_STORE_CONTEXT_TOKEN, (instance) => {
this.#store = instance;
this.#detailStore = instance;
}),
new UmbContextConsumerController(this.#host, UMB_MEDIA_TYPE_TREE_STORE_CONTEXT_TOKEN, (instance) => {
@@ -118,18 +118,18 @@ export class UmbMediaTypeRepository implements UmbTreeRepository<EntityTreeItemR
return this.#detailSource.createScaffold();
}
async requestDetails(id: string) {
async requestById(id: string) {
await this.#init;
// TODO: should we show a notification if the id is missing?
// Investigate what is best for Acceptance testing, cause in that perspective a thrown error might be the best choice?
if (!id) {
throw new Error('Id is missing');
}
debugger;
const { data, error } = await this.#detailSource.get(id);
if (data) {
this.#store?.append(data);
this.#detailStore?.append(data);
}
return { data, error };
}
@@ -158,7 +158,7 @@ export class UmbMediaTypeRepository implements UmbTreeRepository<EntityTreeItemR
// TODO: we currently don't use the detail store for anything.
// Consider to look up the data before fetching from the server
// Consider notify a workspace if a media type is updated in the store while someone is editing it.
this.#store?.append(mediaType);
this.#detailStore?.append(mediaType);
this.#treeStore?.updateItem(mediaType.id, { name: mediaType.name });
// TODO: would be nice to align the stores on methods/methodNames.

View File

@@ -1,18 +1,20 @@
import { UmbMediaTypeRepository } from '../repository/media-type.repository.js';
import type { MediaTypeDetails } from '../types.js';
import { UmbSaveableWorkspaceContextInterface, UmbWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { MediaTypeResponseModel } from '@umbraco-cms/backoffice/backend-api';
type EntityType = MediaTypeDetails;
export class UmbMediaTypeWorkspaceContext
extends UmbWorkspaceContext<UmbMediaTypeRepository, EntityType>
implements UmbSaveableWorkspaceContextInterface<EntityType | undefined>
extends UmbWorkspaceContext<UmbMediaTypeRepository, MediaTypeResponseModel>
implements UmbSaveableWorkspaceContextInterface<MediaTypeResponseModel | undefined>
{
#data = new UmbObjectState<MediaTypeDetails | undefined>(undefined);
#data = new UmbObjectState<MediaTypeResponseModel | undefined>(undefined);
data = this.#data.asObservable();
#getDataPromise?: Promise<any>;
name = this.#data.asObservablePart((data) => data?.name);
id = this.#data.asObservablePart((data) => data?.id);
constructor(host: UmbControllerHostElement) {
super(host, 'Umb.Workspace.MediaType', new UmbMediaTypeRepository(host));
@@ -38,10 +40,12 @@ export class UmbMediaTypeWorkspaceContext
// TODO => Implement setPropertyValue
}
async load(entityId: string) {
const { data } = await this.repository.requestDetails(entityId);
async load(id: string) {
this.#getDataPromise = this.repository.requestById(id);
const { data } = await this.#getDataPromise;
if (data) {
this.#data.next(data);
this.setIsNew(false);
this.#data.update(data);
}
}
@@ -63,8 +67,10 @@ export class UmbMediaTypeWorkspaceContext
}
}
export const UMB_MEDIA_TYPE_WORKSPACE_CONTEXT = new UmbContextToken<UmbSaveableWorkspaceContextInterface, UmbMediaTypeWorkspaceContext>(
export const UMB_MEDIA_TYPE_WORKSPACE_CONTEXT = new UmbContextToken<
UmbSaveableWorkspaceContextInterface,
UmbMediaTypeWorkspaceContext
>(
'UmbWorkspaceContext',
(context): context is UmbMediaTypeWorkspaceContext => context.getEntityType?.() === 'media-type'
(context): context is UmbMediaTypeWorkspaceContext => context.getEntityType?.() === 'media-type',
);