fix type compliance
This commit is contained in:
@@ -3,7 +3,7 @@ import { UmbDataStoreBase } from '../../../core/stores/store';
|
||||
import { ApiError, DocumentTypeResource, DocumentTypeTreeItem, ProblemDetails } from '@umbraco-cms/backend-api';
|
||||
import type { DocumentTypeDetails } from '@umbraco-cms/models';
|
||||
|
||||
const isDocumentTypeDetails = (
|
||||
export const isDocumentTypeDetails = (
|
||||
documentType: DocumentTypeDetails | DocumentTypeTreeItem
|
||||
): documentType is DocumentTypeDetails => {
|
||||
return (documentType as DocumentTypeDetails).properties !== undefined;
|
||||
|
||||
@@ -23,4 +23,9 @@ export class UmbWorkspaceDocumentTypeContext extends UmbWorkspaceContentContext<
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
super(host, DefaultDocumentTypeData, 'umbDocumentTypeStore', 'documentType');
|
||||
}
|
||||
|
||||
|
||||
public setPropertyValue(alias: string, value: unknown) {
|
||||
throw new Error("setPropertyValue is not implemented for UmbWorkspaceDocumentTypeContext")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { UmbNodeStoreBase } from '../../../core/stores/store';
|
||||
import type { DocumentDetails } from '@umbraco-cms/models';
|
||||
import { ApiError, DocumentResource, DocumentTreeItem, FolderTreeItem, ProblemDetails } from '@umbraco-cms/backend-api';
|
||||
|
||||
const isDocumentDetails = (document: DocumentDetails | DocumentTreeItem): document is DocumentDetails => {
|
||||
export const isDocumentDetails = (document: DocumentDetails | DocumentTreeItem): document is DocumentDetails => {
|
||||
return (document as DocumentDetails).data !== undefined;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { UmbWorkspaceContentContext } from '../../../shared/components/workspace/workspace-content/workspace-content.context';
|
||||
import { STORE_ALIAS } from 'src/backoffice/documents/documents/document.store';
|
||||
import { isDocumentDetails, STORE_ALIAS } from 'src/backoffice/documents/documents/document.store';
|
||||
import type { UmbDocumentStore, UmbDocumentStoreItemType } from 'src/backoffice/documents/documents/document.store';
|
||||
import { UmbControllerHostInterface } from 'src/core/controller/controller-host.mixin';
|
||||
import type { DocumentDetails } from '@umbraco-cms/models';
|
||||
|
||||
const DefaultDocumentData = {
|
||||
key: '',
|
||||
@@ -37,8 +38,23 @@ export class UmbWorkspaceDocumentContext extends UmbWorkspaceContentContext<UmbD
|
||||
super(host, DefaultDocumentData, STORE_ALIAS, 'document');
|
||||
}
|
||||
|
||||
public setPropertyValue(alias: string, value: unknown) {
|
||||
const data = this.getData();
|
||||
// TODO: make sure to check that we have a details model:
|
||||
// TODO: make a Method to cast
|
||||
if(isDocumentDetails(data)) {
|
||||
const newDataSet = (data as DocumentDetails).data.map((entry) => {
|
||||
if (entry.alias === alias) {
|
||||
return {alias: alias, value: value};
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
|
||||
|
||||
this.update({data: newDataSet} as Partial<UmbDocumentStoreItemType>);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
concept notes:
|
||||
|
||||
@@ -51,4 +67,4 @@ export class UmbWorkspaceDocumentContext extends UmbWorkspaceContentContext<UmbD
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,8 @@ export class UmbWorkspaceMediaContext extends UmbWorkspaceContentContext<UmbMedi
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
super(host, DefaultMediaData, 'umbMediaStore', 'media');
|
||||
}
|
||||
|
||||
public setPropertyValue(alias: string, value: unknown) {
|
||||
throw new Error("setPropertyValue is not implemented for UmbWorkspaceMediaContext")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import { UmbControllerHostInterface } from 'src/core/controller/controller-host.
|
||||
import { UmbContextConsumerController } from 'src/core/context-api/consume/context-consumer.controller';
|
||||
import { UmbObserverController } from '@umbraco-cms/observable-api';
|
||||
import { UmbContextProviderController } from 'src/core/context-api/provide/context-provider.controller';
|
||||
import type { ContentDetails } from '@umbraco-cms/models';
|
||||
import { EntityTreeItem } from '@umbraco-cms/backend-api';
|
||||
|
||||
// TODO: Consider if its right to have this many class-inheritance of WorkspaceContext
|
||||
// TODO: Could we extract this code into a 'Manager' of its own, which will be instantiated by the concrete Workspace Context. This will be more transparent and 'reuseable'
|
||||
export class UmbWorkspaceContentContext<
|
||||
ContentTypeType extends ContentDetails = ContentDetails,
|
||||
export abstract class UmbWorkspaceContentContext<
|
||||
ContentTypeType extends EntityTreeItem = EntityTreeItem,
|
||||
StoreType extends UmbNodeStoreBase<ContentTypeType> = UmbNodeStoreBase<ContentTypeType>
|
||||
> {
|
||||
|
||||
@@ -108,22 +108,9 @@ export class UmbWorkspaceContentContext<
|
||||
return this._store;
|
||||
}
|
||||
|
||||
abstract setPropertyValue(alias: string, value: unknown):void;
|
||||
|
||||
|
||||
|
||||
|
||||
public setPropertyValue(alias: string, value: unknown) {
|
||||
const newDataSet = this.getData().data.map((entry) => {
|
||||
if (entry.alias === alias) {
|
||||
return {alias: alias, value: value};
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
|
||||
|
||||
this.update({data: newDataSet} as Partial<ContentTypeType>);
|
||||
}
|
||||
|
||||
public save(): Promise<void> {
|
||||
if(!this._store) {
|
||||
// TODO: more beautiful error:
|
||||
|
||||
@@ -21,4 +21,9 @@ export class UmbWorkspaceUserGroupContext extends UmbWorkspaceContentContext<
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
super(host, DefaultDataTypeData, 'umbUserStore', 'userGroup');
|
||||
}
|
||||
|
||||
|
||||
public setPropertyValue(alias: string, value: unknown) {
|
||||
throw new Error("setPropertyValue is not implemented for UmbWorkspaceUserGroupContext")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,8 @@ export class UmbWorkspaceUserContext extends UmbWorkspaceContentContext<UmbUserS
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
super(host, DefaultDataTypeData, 'umbUserStore', 'user');
|
||||
}
|
||||
|
||||
public setPropertyValue(alias: string, value: unknown) {
|
||||
throw new Error("setPropertyValue is not implemented for UmbWorkspaceUserContext")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,10 @@ export interface Entity {
|
||||
parentKey: string | null;
|
||||
}
|
||||
|
||||
export interface ContentDetails {
|
||||
key: string; // TODO: Remove this when the backend is fixed
|
||||
export interface ContentDetails extends ContentTreeItem {
|
||||
isTrashed: boolean; // TODO: remove only temp part of refactor
|
||||
properties: Array<ContentProperty>;
|
||||
data: Array<ContentPropertyData>;
|
||||
//data: Array<ContentPropertyData>;
|
||||
//layout?: any; // TODO: define layout type - make it non-optional
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ export interface ContentPropertyData {
|
||||
}
|
||||
|
||||
// Documents
|
||||
export interface DocumentDetails extends DocumentTreeItem, ContentDetails {
|
||||
export interface DocumentDetails extends DocumentTreeItem {
|
||||
key: string; // TODO: Remove this when the backend is fixed
|
||||
isTrashed: boolean; // TODO: remove only temp part of refactor
|
||||
properties: Array<ContentProperty>;
|
||||
|
||||
Reference in New Issue
Block a user