Skip to content

Commit 7b438e6

Browse files
committed
render picked apps
1 parent 6cb70db commit 7b438e6

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/dashboard/default/dashboard.element.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { ManifestDashboardApp } from '../dashboard-app.extension.js';
22
import { UMB_DASHBOARD_APP_PICKER_MODAL } from '../app/picker/picker-modal.token.js';
3-
import type { UmbDashboardAppDetailModel } from '../app/types.js';
43
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
54
import { css, html, customElement, nothing, ifDefined, state, repeat } from '@umbraco-cms/backoffice/external/lit';
65
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
7-
import type { UmbExtensionElementInitializer } from '@umbraco-cms/backoffice/extension-api';
6+
import {
7+
UmbExtensionsElementInitializer,
8+
type UmbExtensionElementInitializer,
9+
} from '@umbraco-cms/backoffice/extension-api';
810
import { umbOpenModal } from '@umbraco-cms/backoffice/modal';
11+
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
912

1013
@customElement('umb-dashboard')
1114
export class UmbDashboardElement extends UmbLitElement {
@@ -17,17 +20,49 @@ export class UmbDashboardElement extends UmbLitElement {
1720
['large', 'large'],
1821
]);
1922

23+
#extensionsController?: UmbExtensionsElementInitializer<UmbExtensionManifest, 'dashboardApp', ManifestDashboardApp>;
24+
2025
@state()
21-
_apps: Array<UmbDashboardAppDetailModel> = [];
26+
_appElements: Array<any> = [];
2227

23-
// TODO: this is just a temp value. We need to look up the item data.
2428
@state()
2529
_appUniques: Array<string> = [];
2630

2731
constructor() {
2832
super();
2933
}
3034

35+
#observeDashboardApps(): void {
36+
this.#extensionsController?.destroy();
37+
this.#extensionsController = new UmbExtensionsElementInitializer<
38+
UmbExtensionManifest,
39+
'dashboardApp',
40+
ManifestDashboardApp
41+
>(
42+
this,
43+
umbExtensionsRegistry,
44+
'dashboardApp',
45+
(manifest) => this._appUniques.includes(manifest.alias),
46+
(extensionControllers) => {
47+
this._appElements = extensionControllers.map((controller) => {
48+
if (controller.component && controller.manifest) {
49+
const size = this.#sizeMap.get(controller.manifest.meta?.size) ?? this.#defaultSize;
50+
const headline = controller.manifest?.meta?.headline
51+
? this.localize.string(controller.manifest?.meta?.headline)
52+
: undefined;
53+
54+
return html`<uui-box part="umb-dashboard-app-${size}" headline=${ifDefined(headline)}
55+
>${controller.component}</uui-box
56+
>`;
57+
} else {
58+
return html`<uui-box part="umb-dashboard-app-${this.#defaultSize}">Not Found</uui-box>`;
59+
}
60+
});
61+
},
62+
undefined, // We can leave the alias to undefined, as we destroy this our selfs.
63+
);
64+
}
65+
3166
async #openAppPicker() {
3267
const value = await umbOpenModal(this, UMB_DASHBOARD_APP_PICKER_MODAL, {
3368
data: {
@@ -39,22 +74,22 @@ export class UmbDashboardElement extends UmbLitElement {
3974
}).catch(() => undefined);
4075

4176
if (value) {
42-
//this._apps = value.selection;
4377
this._appUniques = value.selection.filter((item) => item !== null) as Array<string>;
78+
this.#observeDashboardApps();
4479
}
4580
}
4681

4782
override render() {
4883
return html`
4984
<section id="content">
5085
<uui-button look="placeholder" @click=${this.#openAppPicker}>Add</uui-button>
51-
${repeat(
52-
this._appUniques,
53-
(unique) => unique,
54-
(unique) => {
55-
return html`${unique}`;
56-
},
57-
)}
86+
<div class="grid-container">
87+
${repeat(
88+
this._appElements,
89+
(element) => element,
90+
(element) => element,
91+
)}
92+
</div>
5893
<umb-extension-slot
5994
type="dashboardApp"
6095
.renderMethod=${this.#extensionSlotRenderMethod}
@@ -83,7 +118,6 @@ export class UmbDashboardElement extends UmbLitElement {
83118
.grid-container {
84119
display: grid;
85120
grid-template-columns: repeat(4, 1fr);
86-
grid-template-rows: repeat(100, 225px);
87121
margin: calc(var(--uui-size-space-3) * -1);
88122
}
89123

0 commit comments

Comments
 (0)