Merge pull request #747 from umbraco/feature/create-documents-at-root

create documents at root
This commit is contained in:
Jacob Overgaard
2023-06-01 11:35:14 +02:00
committed by GitHub
3 changed files with 45 additions and 17 deletions

View File

@@ -1,7 +1,8 @@
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
export interface UmbAllowedDocumentTypesModalData {
id: string | null;
parentId: string | null;
parentName?: string;
}
export interface UmbAllowedDocumentTypesModalResult {

View File

@@ -1,5 +1,5 @@
import { UmbDocumentTypeRepository } from '../../repository/document-type.repository.js';
import { html, nothing , customElement, state , ifDefined } from '@umbraco-cms/backoffice/external/lit';
import { html, nothing, customElement, state, ifDefined } from '@umbraco-cms/backoffice/external/lit';
import { UUITextStyles } from '@umbraco-cms/backoffice/external/uui';
import { UmbAllowedDocumentTypesModalData, UmbAllowedDocumentTypesModalResult } from '@umbraco-cms/backoffice/modal';
import { UmbModalBaseElement } from '@umbraco-cms/internal/modal';
@@ -15,12 +15,28 @@ export class UmbAllowedDocumentTypesModalElement extends UmbModalBaseElement<
@state()
private _allowedDocumentTypes: DocumentTypeTreeItemResponseModel[] = [];
async firstUpdated() {
// TODO: Support root aka. id of null? or maybe its an active prop, like 'atRoot'.
// TODO: show error
if (!this.data?.id) return;
@state()
private _headline?: string;
const { data } = await this.#documentTypeRepository.requestAllowedChildTypesOf(this.data.id);
public connectedCallback() {
super.connectedCallback();
const parentName = this.data?.parentName;
if (parentName) {
this._headline = `Create at '${parentName}'`;
} else {
this._headline = `Create`;
}
if (this.data?.parentId) {
// TODO: Support root aka. id of null? or maybe its an active prop, like 'atRoot'.
// TODO: show error
this._retrieveAllowedChildrenOf(this.data.parentId);
}
}
private async _retrieveAllowedChildrenOf(id: string) {
const { data } = await this.#documentTypeRepository.requestAllowedChildTypesOf(id);
if (data) {
this._allowedDocumentTypes = data;
@@ -41,7 +57,7 @@ export class UmbAllowedDocumentTypesModalElement extends UmbModalBaseElement<
render() {
return html`
<umb-body-layout headline="Headline">
<umb-body-layout headline=${this._headline}>
<uui-box>
${this._allowedDocumentTypes.length === 0 ? html`<p>No allowed types</p>` : nothing}
${this._allowedDocumentTypes.map(

View File

@@ -29,23 +29,34 @@ export class UmbCreateDocumentEntityAction extends UmbEntityActionBase<UmbDocume
private async _executeWithParent() {
// TODO: what to do if modal service is not available?
if (!this.#modalContext) return;
if (!this.repository) return;
const { data } = await this.repository.requestById(this.unique);
if (data && data.contentTypeId) {
const modalHandler = this.#modalContext?.open(UMB_ALLOWED_DOCUMENT_TYPES_MODAL, {
id: data.contentTypeId,
});
const { documentTypeKey } = await modalHandler.onSubmit();
// TODO: how do we want to generate these urls?
history.pushState(null, '', `section/content/workspace/document/create/${this.unique}/${documentTypeKey}`);
// TODO: We need to get the APP language context, use its VariantId to retrieve the right variant. The variant of which we get the name from.
this._openModal(data.contentTypeId, data.variants?.[0]?.name);
}
}
private async _executeAtRoot() {
alert('At root.');
this._openModal(null);
}
private async _openModal(parentId: string | null, parentName?: string) {
if (!this.#modalContext) return;
const modalHandler = this.#modalContext.open(UMB_ALLOWED_DOCUMENT_TYPES_MODAL, {
parentId: parentId,
parentName: parentName,
});
const { documentTypeKey } = await modalHandler.onSubmit();
// TODO: how do we want to generate these urls?
history.pushState(
null,
'',
`section/content/workspace/document/create/${this.unique ?? 'null'}/${documentTypeKey}`
);
}
}