update all workspace actions

This commit is contained in:
Mads Rasmussen
2023-02-27 15:04:12 +01:00
committed by Jacob Overgaard
parent ed4ac9de17
commit a690566209
4 changed files with 16 additions and 21 deletions

View File

@@ -1,14 +1,10 @@
import { UmbWorkspaceAction } from '../../../../shared/components/workspace/workspace-action';
import { UmbDocumentWorkspaceContext } from '../document-workspace.context';
import { UmbDocumentRepository } from '../../repository/document.repository';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbDocumentSaveAndPublishWorkspaceAction extends UmbWorkspaceAction<
UmbDocumentRepository,
UmbDocumentWorkspaceContext
> {
constructor(host: UmbControllerHostInterface, repositoryAlias: string) {
super(host, repositoryAlias);
export class UmbDocumentSaveAndPublishWorkspaceAction extends UmbWorkspaceAction<UmbDocumentWorkspaceContext> {
constructor(host: UmbControllerHostInterface) {
super(host);
}
async execute() {
@@ -17,6 +13,6 @@ export class UmbDocumentSaveAndPublishWorkspaceAction extends UmbWorkspaceAction
const document = this.workspaceContext.getData();
// TODO: handle errors
if (!document) return;
this.repository?.saveAndPublish();
this.workspaceContext.repository.saveAndPublish();
}
}

View File

@@ -1,14 +1,10 @@
import { UmbWorkspaceAction } from '../../../../shared/components/workspace/workspace-action';
import { UmbDocumentRepository } from '../../repository/document.repository';
import { UmbDocumentWorkspaceContext } from '../document-workspace.context';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbSaveAndScheduleDocumentWorkspaceAction extends UmbWorkspaceAction<
UmbDocumentRepository,
UmbDocumentWorkspaceContext
> {
constructor(host: UmbControllerHostInterface, repositoryAlias: string) {
super(host, repositoryAlias);
export class UmbSaveAndScheduleDocumentWorkspaceAction extends UmbWorkspaceAction<UmbDocumentWorkspaceContext> {
constructor(host: UmbControllerHostInterface) {
super(host);
}
async execute() {
@@ -17,6 +13,6 @@ export class UmbSaveAndScheduleDocumentWorkspaceAction extends UmbWorkspaceActio
const document = this.workspaceContext.getData();
// TODO: handle errors
if (!document) return;
this.repository?.saveAndSchedule();
this.workspaceContext.repository.saveAndSchedule();
}
}

View File

@@ -1,6 +1,7 @@
import { Observable } from 'rxjs';
export interface UmbWorkspaceContextInterface<T = unknown> {
repository: any; // TODO: add type
isNew: Observable<boolean>;
getIsNew(): boolean;
setIsNew(value: boolean): void;

View File

@@ -3,9 +3,9 @@ import { UmbWorkspaceContextInterface } from '../components/workspace/workspace-
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
// TODO: add interface for repo/partial repo/save-repo
export class UmbSaveWorkspaceAction extends UmbWorkspaceAction<any, UmbWorkspaceContextInterface> {
constructor(host: UmbControllerHostInterface, repositoryAlias: string) {
super(host, repositoryAlias);
export class UmbSaveWorkspaceAction extends UmbWorkspaceAction<UmbWorkspaceContextInterface> {
constructor(host: UmbControllerHostInterface) {
super(host);
}
/* TODO: we need a solution for all actions to notify the system that is has been executed.
@@ -26,7 +26,8 @@ export class UmbSaveWorkspaceAction extends UmbWorkspaceAction<any, UmbWorkspace
if (!this.workspaceContext) return;
// TODO: preferably the actions dont talk directly with repository, but instead with its context.
const { error } = await this.repository.create(data);
// We just need to consider how third parties can extend the system.
const { error } = await this.workspaceContext.repository.create(data);
// TODO: this is temp solution to bubble validation errors to the UI
if (error) {
@@ -41,6 +42,7 @@ export class UmbSaveWorkspaceAction extends UmbWorkspaceAction<any, UmbWorkspace
}
#update(data: any) {
this.repository?.save(data);
if (!this.workspaceContext) return;
this.workspaceContext.repository?.save(data);
}
}