fix create action
This commit is contained in:
@@ -1,27 +1,22 @@
|
||||
import type { UmbDocumentDetailRepository } from '../../repository/index.js';
|
||||
import { UmbDocumentItemRepository } from '../../repository/index.js';
|
||||
import { UMB_DOCUMENT_CREATE_OPTIONS_MODAL } from './document-create-options-modal.token.js';
|
||||
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
export class UmbCreateDocumentEntityAction extends UmbEntityActionBase<UmbDocumentDetailRepository> {
|
||||
#itemRepository;
|
||||
|
||||
constructor(host: UmbControllerHost, repositoryAlias: string, unique: string, entityType: string) {
|
||||
super(host, repositoryAlias, unique, entityType);
|
||||
this.#itemRepository = new UmbDocumentItemRepository(host);
|
||||
export class UmbCreateDocumentEntityAction extends UmbEntityActionBase<never> {
|
||||
constructor(host: UmbControllerHost, args: UmbEntityActionArgs<never>) {
|
||||
super(host, args);
|
||||
}
|
||||
|
||||
async execute() {
|
||||
if (!this.repository) return;
|
||||
|
||||
// default to root
|
||||
let documentItem = null;
|
||||
|
||||
if (this.unique) {
|
||||
if (this.args.unique) {
|
||||
// get document item to get the doc type id
|
||||
const { data, error } = await this.#itemRepository.requestItems([this.unique]);
|
||||
const itemRepository = new UmbDocumentItemRepository(this._host);
|
||||
const { data, error } = await itemRepository.requestItems([this.args.unique]);
|
||||
if (error || !data) throw new Error(`Failed to load document item`);
|
||||
documentItem = data[0];
|
||||
}
|
||||
@@ -29,11 +24,13 @@ export class UmbCreateDocumentEntityAction extends UmbEntityActionBase<UmbDocume
|
||||
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
|
||||
const modalContext = modalManager.open(this, UMB_DOCUMENT_CREATE_OPTIONS_MODAL, {
|
||||
data: {
|
||||
parent: { unique: this.unique, entityType: this.entityType },
|
||||
parent: { unique: this.args.unique, entityType: this.args.entityType },
|
||||
documentType: documentItem ? { unique: documentItem.documentType.unique } : null,
|
||||
},
|
||||
});
|
||||
|
||||
await modalContext.onSubmit();
|
||||
}
|
||||
|
||||
destroy(): void {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user