Merge pull request #1564 from umbraco/feature/blueprint-create-action

Feature: Document Blueprint Create Action
This commit is contained in:
Lee Kelleher
2024-04-11 09:40:06 +01:00
committed by GitHub
10 changed files with 75 additions and 106 deletions

View File

@@ -1,5 +1,5 @@
import { UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE } from '../../entity.js';
import { UMB_DOCUMENT_BLUEPRINT_CREATE_OPTIONS_MODAL } from './modal/index.js';
import { UMB_DOCUMENT_BLUEPRINT_OPTIONS_CREATE_MODAL } from './modal/index.js';
import type { UmbEntityActionArgs } from '@umbraco-cms/backoffice/entity-action';
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -12,7 +12,7 @@ export class UmbCreateEntityAction extends UmbEntityActionBase<never> {
async execute() {
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
const modalContext = modalManager.open(this, UMB_DOCUMENT_BLUEPRINT_CREATE_OPTIONS_MODAL, {
const modalContext = modalManager.open(this, UMB_DOCUMENT_BLUEPRINT_OPTIONS_CREATE_MODAL, {
data: {
parent: {
unique: this.args.unique,
@@ -24,10 +24,11 @@ export class UmbCreateEntityAction extends UmbEntityActionBase<never> {
await modalContext.onSubmit().catch(() => undefined);
const documentTypeUnique = modalContext.getValue().documentTypeUnique;
if (!documentTypeUnique) return;
const url = `section/settings/workspace/${UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE}/create/parent/${this.args.entityType}/${
documentTypeUnique || 'null'
}`;
const url = `section/settings/workspace/${UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE}/create/parent/${this.args.unique ?? 'null'}/${documentTypeUnique}`;
history.pushState(null, '', url);
}
}
export default UmbCreateEntityAction;

View File

@@ -0,0 +1 @@
export * from './modal/index.js';

View File

@@ -1,12 +1,29 @@
import { UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE, UMB_DOCUMENT_BLUEPRINT_FOLDER_ENTITY_TYPE } from '../../entity.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
const entityActions: Array<ManifestTypes> = [
{
type: 'modal',
alias: 'Umb.Modal.DocumentBlueprintCreateOptions',
name: 'Document Blueprint Create Options Modal',
element: () => import('./modal/document-blueprint-create-options-modal.element.js'),
type: 'entityAction',
kind: 'default',
alias: 'Umb.EntityAction.DocumentBlueprint.Create',
name: 'Document Blueprint Options Create Entity Action',
weight: 1200,
api: () => import('./create.action.js'),
forEntityTypes: [UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE, UMB_DOCUMENT_BLUEPRINT_FOLDER_ENTITY_TYPE],
meta: {
icon: 'icon-add',
label: '#actions_createblueprint',
},
},
];
export const manifests = [...entityActions];
const manifestModals: Array<ManifestTypes> = [
{
type: 'modal',
alias: 'Umb.Modal.DocumentBlueprintOptionsCreate',
name: 'Document Blueprint Options Create Modal',
element: () => import('./modal/document-blueprint-options-create-modal.element.js'),
},
];
export const manifests = [...entityActions, ...manifestModals];

View File

@@ -1,43 +1,24 @@
import type {
UmbDocumentBlueprintCreateOptionsModalData,
UmbDocumentBlueprintCreateOptionsModalValue,
UmbDocumentBlueprintOptionsCreateModalData,
UmbDocumentBlueprintOptionsCreateModalValue,
} from './index.js';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { html, customElement, css, state } from '@umbraco-cms/backoffice/external/lit';
import { html, customElement, css } from '@umbraco-cms/backoffice/external/lit';
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';
import type { DocumentTypeResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
import { UmbDocumentTypeStructureRepository } from '@umbraco-cms/backoffice/document-type';
import { type UmbSelectedEvent, UmbSelectionChangeEvent } from '@umbraco-cms/backoffice/event';
import type { UmbTreeElement } from '@umbraco-cms/backoffice/tree';
@customElement('umb-document-blueprint-create-options-modal')
export class UmbDocumentBlueprintCreateOptionsModalElement extends UmbModalBaseElement<
UmbDocumentBlueprintCreateOptionsModalData,
UmbDocumentBlueprintCreateOptionsModalValue
@customElement('umb-document-blueprint-options-create-modal')
export class UmbDocumentBlueprintOptionsCreateModalElement extends UmbModalBaseElement<
UmbDocumentBlueprintOptionsCreateModalData,
UmbDocumentBlueprintOptionsCreateModalValue
> {
@state()
private _documentTypes?: Array<DocumentTypeResponseModel>;
#documentTypeRepository = new UmbDocumentTypeStructureRepository(this);
connectedCallback(): void {
super.connectedCallback();
}
async #fetchTypes() {
//const something = await this.#documentTypeRepository.
}
#onNavigate() {
this._submitModal();
}
#onSelected(event: UmbSelectedEvent) {
event.stopPropagation();
const element = event.target as UmbTreeElement;
this.value = { documentTypeUnique: element.getSelection()[0] };
this.modalContext?.dispatchEvent(new UmbSelectionChangeEvent());
this.#onNavigate();
this._submitModal();
}
render() {
@@ -71,10 +52,10 @@ export class UmbDocumentBlueprintCreateOptionsModalElement extends UmbModalBaseE
];
}
export default UmbDocumentBlueprintCreateOptionsModalElement;
export default UmbDocumentBlueprintOptionsCreateModalElement;
declare global {
interface HTMLElementTagNameMap {
'umb-document-blueprint-create-options-modal': UmbDocumentBlueprintCreateOptionsModalElement;
'umb-document-blueprint-create-options-modal': UmbDocumentBlueprintOptionsCreateModalElement;
}
}

View File

@@ -0,0 +1,22 @@
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
export interface UmbDocumentBlueprintOptionsCreateModalData {
parent: {
unique: string | null;
entityType: string;
};
}
export interface UmbDocumentBlueprintOptionsCreateModalValue {
documentTypeUnique: string;
}
export const UMB_DOCUMENT_BLUEPRINT_OPTIONS_CREATE_MODAL = new UmbModalToken<
UmbDocumentBlueprintOptionsCreateModalData,
UmbDocumentBlueprintOptionsCreateModalValue
>('Umb.Modal.DocumentBlueprintOptionsCreate', {
modal: {
type: 'sidebar',
size: 'small',
},
});

View File

@@ -1,22 +1,2 @@
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
export interface UmbDocumentBlueprintCreateOptionsModalData {
parent: {
unique: string | null;
entityType: string;
};
}
export interface UmbDocumentBlueprintCreateOptionsModalValue {
documentTypeUnique: string;
}
export const UMB_DOCUMENT_BLUEPRINT_CREATE_OPTIONS_MODAL = new UmbModalToken<
UmbDocumentBlueprintCreateOptionsModalData,
UmbDocumentBlueprintCreateOptionsModalValue
>('Umb.Modal.DocumentBlueprintCreateOptions', {
modal: {
type: 'sidebar',
size: 'small',
},
});
export * from './document-blueprint-options-create-modal.token.js';
export * from './document-blueprint-options-create-modal.element.js';

View File

@@ -1,25 +1,12 @@
import { UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE, UMB_DOCUMENT_BLUEPRINT_FOLDER_ENTITY_TYPE } from '../entity.js';
import { UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE } from '../entity.js';
import {
UMB_DOCUMENT_BLUEPRINT_DETAIL_REPOSITORY_ALIAS,
UMB_DOCUMENT_BLUEPRINT_ITEM_REPOSITORY_ALIAS,
} from '../index.js';
import { manifests as createManifests } from './create/manifests.js';
import { UmbCreateEntityAction } from './create/create.action.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
const entityActions: Array<ManifestTypes> = [
{
type: 'entityAction',
kind: 'default',
alias: 'Umb.EntityAction.DocumentBlueprint.Create',
name: 'Create Document Blueprint Entity Action',
api: UmbCreateEntityAction,
forEntityTypes: [UMB_DOCUMENT_BLUEPRINT_FOLDER_ENTITY_TYPE],
meta: {
icon: 'icon-add',
label: 'Create',
},
},
{
type: 'entityAction',
kind: 'delete',

View File

@@ -2,7 +2,7 @@ import { UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE } from '../../entity.js';
import type { UmbDocumentBlueprintItemModel } from './types.js';
import { DocumentBlueprintService } from '@umbraco-cms/backoffice/external/backend-api';
import { UmbItemServerDataSourceBase } from '@umbraco-cms/backoffice/repository';
import type { CancelablePromise, DocumentItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
import type { DocumentBlueprintItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
/**
@@ -12,7 +12,7 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
* @implements {DocumentTreeDataSource}
*/
export class UmbDocumentBlueprintItemServerDataSource extends UmbItemServerDataSourceBase<
DocumentItemResponseModel,
DocumentBlueprintItemResponseModel,
UmbDocumentBlueprintItemModel
> {
/**
@@ -29,29 +29,17 @@ export class UmbDocumentBlueprintItemServerDataSource extends UmbItemServerDataS
}
/* eslint-disable local-rules/no-direct-api-import */
const getItems = (uniques: Array<string>) =>
DocumentBlueprintService.getItemDocumentBlueprint({ id: uniques }) as unknown as CancelablePromise<
DocumentItemResponseModel[]
>;
const getItems = (uniques: Array<string>) => DocumentBlueprintService.getItemDocumentBlueprint({ id: uniques });
const mapper = (item: DocumentItemResponseModel): UmbDocumentBlueprintItemModel => {
const mapper = (item: DocumentBlueprintItemResponseModel): UmbDocumentBlueprintItemModel => {
return {
entityType: UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE,
unique: item.id,
isTrashed: item.isTrashed,
isProtected: item.isProtected,
name: item.name,
documentType: {
unique: item.documentType.id,
icon: item.documentType.icon,
collection: item.documentType.collection ? { unique: item.documentType.collection.id } : null,
},
variants: item.variants.map((variant) => {
return {
culture: variant.culture || null,
name: variant.name,
state: variant.state,
};
}),
name: item.variants[0]?.name, // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
};
};

View File

@@ -4,16 +4,13 @@ import type { UmbReferenceByUnique } from '@umbraco-cms/backoffice/models';
export interface UmbDocumentBlueprintItemModel {
entityType: UmbDocumentBlueprintEntityType;
name: string; // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
name: string;
unique: string;
isTrashed: boolean;
isProtected: boolean;
documentType: {
unique: string;
icon: string;
collection: UmbReferenceByUnique | null;
};
variants: Array<UmbDocumentBlueprintItemVariantModel>;
}
export interface UmbDocumentBlueprintItemVariantModel {

View File

@@ -1,17 +1,14 @@
import { UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE } from '../entity.js';
import type { UmbDocumentBlueprintTreeItemModel } from './types.js';
import { UmbTreeServerDataSourceBase } from '@umbraco-cms/backoffice/tree';
import { DocumentBlueprintService } from '@umbraco-cms/backoffice/external/backend-api';
import type { DocumentBlueprintTreeItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type {
UmbTreeAncestorsOfRequestArgs,
UmbTreeChildrenOfRequestArgs,
UmbTreeRootItemsRequestArgs,
} from '@umbraco-cms/backoffice/tree';
import { UmbTreeServerDataSourceBase } from '@umbraco-cms/backoffice/tree';
import type {
DocumentBlueprintTreeItemResponseModel,
DocumentTreeItemResponseModel,
} from '@umbraco-cms/backoffice/external/backend-api';
import { DocumentBlueprintService } from '@umbraco-cms/backoffice/external/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
/**
* A data source for a data type tree that fetches data from the server
@@ -61,12 +58,10 @@ const getAncestorsOf = (args: UmbTreeAncestorsOfRequestArgs) => {
};
const mapper = (item: DocumentBlueprintTreeItemResponseModel): UmbDocumentBlueprintTreeItemModel => {
//TODO remove temp hack when api endpoints are fixed
const hack = item as Partial<DocumentTreeItemResponseModel>;
return {
unique: item.id,
parentUnique: item.parent?.id || null,
name: hack?.variants?.[0].name ?? '',
name: (item as any).variants?.[0].name ?? item.name,
entityType: UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE,
isFolder: false,
hasChildren: item.hasChildren,