Skip to content

Commit d7a32a3

Browse files
Reloads the template tree when creating a document type with a template (#19769)
* Reloads the template tree when creating a document type with a template. * Housekeeping: separating/sorting import types --------- Co-authored-by: leekelleher <[email protected]>
1 parent df9b387 commit d7a32a3

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type/document-type-workspace.context.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@ import {
33
UMB_CREATE_DOCUMENT_TYPE_WORKSPACE_PRESET_ELEMENT,
44
UMB_CREATE_DOCUMENT_TYPE_WORKSPACE_PRESET_TEMPLATE,
55
UMB_EDIT_DOCUMENT_TYPE_WORKSPACE_PATH_PATTERN,
6-
type UmbCreateDocumentTypeWorkspacePresetType,
76
} from '../../paths.js';
7+
import type { UmbCreateDocumentTypeWorkspacePresetType } from '../../paths.js';
88
import type { UmbDocumentTypeDetailModel } from '../../types.js';
99
import { UMB_DOCUMENT_TYPE_ENTITY_TYPE, UMB_DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS } from '../../constants.js';
10-
import { UmbDocumentTypeWorkspaceEditorElement } from './document-type-workspace-editor.element.js';
1110
import { UMB_DOCUMENT_TYPE_WORKSPACE_ALIAS } from './constants.js';
11+
import { UmbDocumentTypeWorkspaceEditorElement } from './document-type-workspace-editor.element.js';
12+
import { CompositionTypeModel } from '@umbraco-cms/backoffice/external/backend-api';
1213
import { UmbContentTypeWorkspaceContextBase } from '@umbraco-cms/backoffice/content-type';
14+
import { UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action';
1315
import {
1416
UmbWorkspaceIsNewRedirectController,
1517
UmbWorkspaceIsNewRedirectControllerAlias,
1618
} from '@umbraco-cms/backoffice/workspace';
19+
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
20+
import { UMB_TEMPLATE_ROOT_ENTITY_TYPE, UmbTemplateDetailRepository } from '@umbraco-cms/backoffice/template';
1721
import type { UmbContentTypeSortModel, UmbContentTypeWorkspaceContext } from '@umbraco-cms/backoffice/content-type';
1822
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
23+
import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity';
24+
import type { UmbPathPatternTypeAsEncodedParamsType } from '@umbraco-cms/backoffice/router';
1925
import type { UmbReferenceByUnique } from '@umbraco-cms/backoffice/models';
2026
import type { UmbRoutableWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
21-
import type { UmbPathPatternTypeAsEncodedParamsType } from '@umbraco-cms/backoffice/router';
22-
import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity';
23-
import { UmbTemplateDetailRepository } from '@umbraco-cms/backoffice/template';
24-
import { CompositionTypeModel } from '@umbraco-cms/backoffice/external/backend-api';
2527

2628
type DetailModelType = UmbDocumentTypeDetailModel;
2729
export class UmbDocumentTypeWorkspaceContext
@@ -189,6 +191,16 @@ export class UmbDocumentTypeWorkspaceContext
189191
const { data: template } = await this.#templateRepository.create(templateScaffold, null);
190192
if (!template) throw new Error('Could not create template');
191193

194+
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
195+
if (!eventContext) {
196+
throw new Error('Could not get the action event context');
197+
}
198+
const event = new UmbRequestReloadChildrenOfEntityEvent({
199+
entityType: UMB_TEMPLATE_ROOT_ENTITY_TYPE,
200+
unique: null,
201+
});
202+
eventContext.dispatchEvent(event);
203+
192204
const templateEntity = { id: template.unique };
193205
const allowedTemplates = this.getAllowedTemplateIds() ?? [];
194206
this.setAllowedTemplateIds([templateEntity, ...allowedTemplates]);

0 commit comments

Comments
 (0)