@crombolo/backoffice-host 0.41.1 → 0.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/NOTICE +9 -0
  2. package/package.json +3 -3
  3. package/plugin/addresses-dashboard.js +3 -2
  4. package/plugin/app-preview/umbraco-package.json +1 -1
  5. package/plugin/approvals-active.js +40 -0
  6. package/plugin/audit-dashboard.js +3 -2
  7. package/plugin/branding/localization-en.js +9 -3
  8. package/plugin/branding/sign-in.js +0 -31
  9. package/plugin/branding/theme-dark.css +19 -5
  10. package/plugin/branding/theme.css +41 -19
  11. package/plugin/breadcrumb.js +29 -0
  12. package/plugin/changes-dashboard.js +3 -2
  13. package/plugin/edit-conflicts.js +11 -21
  14. package/plugin/jobs-dashboard.js +3 -2
  15. package/plugin/localizations/umbraco-package.json +1 -1
  16. package/plugin/notifications-dialog.js +8 -35
  17. package/plugin/overview-dashboard.js +412 -0
  18. package/plugin/overview-format.js +71 -0
  19. package/plugin/seo/umbraco-package.json +1 -1
  20. package/plugin/settings-cards.js +189 -0
  21. package/plugin/settings-section.js +436 -0
  22. package/plugin/side-panel/host.js +7 -63
  23. package/plugin/side-panel/layout.js +0 -15
  24. package/plugin/sign-in/umbraco-package.json +1 -1
  25. package/plugin/tsx-editors.js +56 -164
  26. package/plugin/umbraco-package.json +26 -55
  27. package/plugin/workflow-client.js +3 -0
  28. package/plugin/workflow-designer.js +17 -2
  29. package/src/branding.ts +4 -0
  30. package/plugin/branding/branding.js +0 -188
  31. package/plugin/branding/client-credentials.js +0 -49
  32. package/plugin/branding/log-viewer-menu.js +0 -70
  33. package/plugin/branding/query-builder.js +0 -28
  34. package/plugin/settings-dashboard.js +0 -123
  35. package/plugin/welcome-dashboard.js +0 -103
@@ -0,0 +1,412 @@
1
+ /**
2
+ * The Content section's Overview (story 236), in place of Umbraco's news: the
3
+ * pages changed lately, how many are drafts or published, what people did, and
4
+ * a way to start a new page. Everything comes from `crombolo/api/overview`,
5
+ * already narrowed to what the signed-in user may see.
6
+ */
7
+ import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'
8
+ import { UMB_DOCUMENT_CREATE_OPTIONS_MODAL } from '@umbraco-cms/backoffice/document'
9
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
10
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
11
+ import { umbOpenModal } from '@umbraco-cms/backoffice/modal'
12
+ import { activityLine, ago, avatarHue, firstName, initials, STATES } from './overview-format.js'
13
+
14
+ const base = () =>
15
+ (document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')
16
+
17
+ const LISTS = { recent: 'Recent content', drafts: 'Drafts', published: 'Published' }
18
+ const SHORT = 5
19
+ const LONG = 25
20
+
21
+ export default class CromboloOverviewDashboardElement extends UmbLitElement {
22
+ static properties = {
23
+ _name: { state: true },
24
+ _data: { state: true },
25
+ _list: { state: true },
26
+ _take: { state: true },
27
+ _skip: { state: true },
28
+ _error: { state: true },
29
+ }
30
+
31
+ constructor() {
32
+ super()
33
+ this._list = 'recent'
34
+ this._take = SHORT
35
+ this._skip = 0
36
+ this.consumeContext(UMB_CURRENT_USER_CONTEXT, (user) => {
37
+ this.observe(user?.currentUser, (current) => {
38
+ this._name = current?.name
39
+ })
40
+ })
41
+ }
42
+
43
+ connectedCallback() {
44
+ super.connectedCallback()
45
+ this.#load()
46
+ }
47
+
48
+ async #load() {
49
+ const query = new URLSearchParams({
50
+ list: this._list,
51
+ skip: String(this._skip),
52
+ take: String(this._take),
53
+ })
54
+ try {
55
+ const response = await fetch(`${base()}/crombolo/api/overview?${query}`, {
56
+ credentials: 'include',
57
+ headers: { accept: 'application/json' },
58
+ })
59
+ if (!response.ok) throw new Error(`overview responded ${response.status}`)
60
+ this._data = await response.json()
61
+ this._error = undefined
62
+ } catch {
63
+ this._error = 'The overview could not be loaded. Try again in a moment.'
64
+ }
65
+ }
66
+
67
+ #show(list, take = SHORT) {
68
+ this._list = list
69
+ this._take = take
70
+ this._skip = 0
71
+ this.#load()
72
+ }
73
+
74
+ #page(by) {
75
+ this._skip = Math.max(0, this._skip + by * this._take)
76
+ this.#load()
77
+ }
78
+
79
+ async #newPage() {
80
+ const under = this._data?.newPageUnder ?? null
81
+ await umbOpenModal(this, UMB_DOCUMENT_CREATE_OPTIONS_MODAL, {
82
+ data: {
83
+ parent: under
84
+ ? { unique: under, entityType: 'document' }
85
+ : { unique: null, entityType: 'document-root' },
86
+ documentType: null,
87
+ },
88
+ }).catch(() => undefined)
89
+ }
90
+
91
+ render() {
92
+ const name = firstName(this._name)
93
+ return html`
94
+ <header>
95
+ <h1>Overview</h1>
96
+ <p>${name ? `Welcome back, ${name}. ` : ''}Here’s what’s happening with your content.</p>
97
+ </header>
98
+ ${this._error ? html`<uui-box><p class="error">${this._error}</p></uui-box>` : nothing}
99
+ <div class="grid">
100
+ <div class="main">
101
+ ${this.#renderPages()}
102
+ <button class="new" type="button" @click=${() => this.#newPage()}>
103
+ <span>
104
+ <strong>New content</strong>
105
+ <small>Start a page from any of the site’s page types</small>
106
+ </span>
107
+ <uui-icon name="icon-add"></uui-icon>
108
+ </button>
109
+ </div>
110
+ <div class="side">${this.#renderStats()} ${this.#renderActivity()}</div>
111
+ </div>
112
+ `
113
+ }
114
+
115
+ #renderPages() {
116
+ const pages = this._data?.pages
117
+ const expanded = this._take === LONG
118
+ return html`<uui-box>
119
+ <div class="box-head" slot="header">
120
+ <span class="headline">${LISTS[this._list]}</span>
121
+ ${
122
+ this._list !== 'recent' || expanded
123
+ ? html`<button class="link" type="button" @click=${() => this.#show('recent')}>
124
+ Back to recent
125
+ </button>`
126
+ : html`<button class="link" type="button" @click=${() => this.#show('recent', LONG)}>
127
+ View all ›
128
+ </button>`
129
+ }
130
+ </div>
131
+ ${
132
+ !pages
133
+ ? html`<uui-loader></uui-loader>`
134
+ : pages.items.length === 0
135
+ ? html`<p class="empty">${this.#emptyText()}</p>`
136
+ : html`<table>
137
+ <thead>
138
+ <tr><th>Title</th><th>Type</th><th>Status</th><th>Updated</th><th>Author</th></tr>
139
+ </thead>
140
+ <tbody>
141
+ ${pages.items.map(
142
+ (p) => html`<tr>
143
+ <td>
144
+ <span class="title">
145
+ <uui-icon name="icon-document"></uui-icon>
146
+ <a href=${`${base()}/section/content/workspace/document/edit/${p.key}`}>${p.name}</a>
147
+ </span>
148
+ </td>
149
+ <td><span class="pill">${p.type}</span></td>
150
+ <td><span class="state ${p.state}">${STATES[p.state] ?? p.state}</span></td>
151
+ <td class="muted">${ago(p.updated)}</td>
152
+ <td>
153
+ ${
154
+ p.author
155
+ ? html`<span class="avatar hue-${avatarHue(p.author)}" title=${p.author}>${initials(p.author)}</span>`
156
+ : nothing
157
+ }
158
+ </td>
159
+ </tr>`,
160
+ )}
161
+ </tbody>
162
+ </table>`
163
+ }
164
+ ${
165
+ pages && this._take === LONG && pages.total > LONG
166
+ ? html`<div class="pager">
167
+ <uui-button label="Newer" ?disabled=${this._skip === 0} @click=${() => this.#page(-1)}></uui-button>
168
+ <span class="muted">${this._skip + 1}–${Math.min(this._skip + LONG, pages.total)} of ${pages.total}</span>
169
+ <uui-button label="Older" ?disabled=${this._skip + LONG >= pages.total} @click=${() => this.#page(1)}></uui-button>
170
+ </div>`
171
+ : nothing
172
+ }
173
+ </uui-box>`
174
+ }
175
+
176
+ #emptyText() {
177
+ if (this._list === 'drafts') return 'No drafts: every page you can see is published.'
178
+ if (this._list === 'published') return 'Nothing is published yet.'
179
+ return 'No pages yet. Start one with New content.'
180
+ }
181
+
182
+ #renderStats() {
183
+ const counts = this._data?.counts
184
+ const stat = (list, icon, label, count) => html`<div class="stat">
185
+ <span class="stat-icon ${list}"><uui-icon name=${icon}></uui-icon></span>
186
+ <strong>${count ?? '–'}</strong>
187
+ <span>${label}</span>
188
+ <button class="link" type="button" @click=${() => this.#show(list, LONG)}>
189
+ View ${label.toLowerCase()} ›
190
+ </button>
191
+ </div>`
192
+ return html`<uui-box headline="Quick stats">
193
+ <div class="stats">
194
+ ${stat('drafts', 'icon-edit', 'Drafts', counts?.drafts)}
195
+ ${stat('published', 'icon-check', 'Published', counts?.published)}
196
+ </div>
197
+ </uui-box>`
198
+ }
199
+
200
+ #renderActivity() {
201
+ const activity = this._data?.activity
202
+ return html`<uui-box>
203
+ <div class="box-head" slot="header">
204
+ <span class="headline">Activity</span>
205
+ ${
206
+ this._data?.mayReadAudit
207
+ ? html`<a class="link" href=${`${base()}/section/settings/dashboard/audit-log`}>View all ›</a>`
208
+ : nothing
209
+ }
210
+ </div>
211
+ ${
212
+ !activity
213
+ ? html`<uui-loader></uui-loader>`
214
+ : activity.length === 0
215
+ ? html`<p class="empty">Nothing has happened to your pages yet.</p>`
216
+ : html`<ul class="feed">
217
+ ${activity.map(
218
+ (a) => html`<li>
219
+ <span class="feed-icon ${a.action.includes('ublish') ? 'publish' : ''}">
220
+ <uui-icon name="icon-document"></uui-icon>
221
+ </span>
222
+ <a href=${`${base()}/section/content/workspace/document/edit/${a.key}`}>${activityLine(a)}</a>
223
+ <span class="muted when">${ago(a.when)}</span>
224
+ </li>`,
225
+ )}
226
+ </ul>`
227
+ }
228
+ </uui-box>`
229
+ }
230
+
231
+ static styles = css`
232
+ :host {
233
+ display: block;
234
+ padding: var(--uui-size-layout-1);
235
+ max-width: 1400px;
236
+ }
237
+ header h1 {
238
+ margin: 0 0 var(--uui-size-space-3);
239
+ font-size: 2rem;
240
+ line-height: 1.15;
241
+ font-weight: 800;
242
+ letter-spacing: -0.02em;
243
+ }
244
+ header p {
245
+ margin: 0 0 var(--uui-size-layout-1);
246
+ color: var(--uui-color-text-alt);
247
+ }
248
+ uui-box {
249
+ box-shadow: var(--crombolo-card-shadow, none);
250
+ --uui-box-border-radius: 12px;
251
+ }
252
+ .grid {
253
+ display: grid;
254
+ grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
255
+ gap: var(--uui-size-layout-1);
256
+ align-items: start;
257
+ }
258
+ @media (max-width: 1000px) {
259
+ .grid { grid-template-columns: minmax(0, 1fr); }
260
+ }
261
+ .main, .side {
262
+ display: flex;
263
+ flex-direction: column;
264
+ gap: var(--uui-size-layout-1);
265
+ }
266
+ .box-head {
267
+ display: flex;
268
+ justify-content: space-between;
269
+ align-items: center;
270
+ width: 100%;
271
+ }
272
+ .headline { font-weight: 700; font-size: var(--uui-type-h5-size, 1rem); }
273
+ .link {
274
+ background: none;
275
+ border: 0;
276
+ padding: 0;
277
+ font: inherit;
278
+ color: var(--uui-color-interactive-emphasis);
279
+ cursor: pointer;
280
+ text-decoration: none;
281
+ }
282
+ .link:hover { text-decoration: underline; }
283
+ table { width: 100%; border-collapse: collapse; }
284
+ th {
285
+ text-align: left;
286
+ font-weight: 400;
287
+ color: var(--uui-color-text-alt);
288
+ padding: var(--uui-size-space-3) var(--uui-size-space-3);
289
+ border-bottom: 1px solid var(--uui-color-border);
290
+ }
291
+ td {
292
+ padding: var(--uui-size-space-4) var(--uui-size-space-3);
293
+ border-bottom: 1px solid var(--uui-color-border);
294
+ vertical-align: middle;
295
+ }
296
+ tr:last-child td { border-bottom: 0; }
297
+ .title { display: flex; gap: var(--uui-size-space-3); align-items: center; }
298
+ .title a { color: inherit; text-decoration: none; }
299
+ .title a:hover { text-decoration: underline; }
300
+ .pill {
301
+ background: var(--crombolo-terracotta-tint, var(--uui-color-surface-alt));
302
+ border-radius: var(--uui-border-radius);
303
+ padding: var(--uui-size-space-1) var(--uui-size-space-3);
304
+ white-space: nowrap;
305
+ }
306
+ .state { white-space: nowrap; }
307
+ .state::before {
308
+ content: '';
309
+ display: inline-block;
310
+ width: 0.6em;
311
+ height: 0.6em;
312
+ border-radius: 50%;
313
+ margin-right: var(--uui-size-space-2);
314
+ background: var(--uui-color-positive);
315
+ }
316
+ .state.draft::before { background: var(--uui-color-warning); }
317
+ .state.changed::before { background: var(--uui-color-warning-emphasis, var(--uui-color-warning)); }
318
+ .muted { color: var(--uui-color-text-alt); white-space: nowrap; }
319
+ .avatar {
320
+ display: inline-grid;
321
+ place-items: center;
322
+ width: 2.2em;
323
+ height: 2.2em;
324
+ border-radius: 50%;
325
+ background: var(--uui-color-surface-alt);
326
+ color: #54321f;
327
+ font-size: 0.85em;
328
+ font-weight: 700;
329
+ }
330
+ /* Soft colours, dark ink on each: the same in light and dark. */
331
+ .avatar.hue-0 { background: #f6dccf; }
332
+ .avatar.hue-1 { background: #dcebdc; }
333
+ .avatar.hue-2 { background: #ece0f3; }
334
+ .avatar.hue-3 { background: #f7e8c6; }
335
+ .avatar.hue-4 { background: #d9e8f2; }
336
+ .avatar.hue-5 { background: #f3dbe2; }
337
+ .pager {
338
+ display: flex;
339
+ justify-content: space-between;
340
+ align-items: center;
341
+ padding-top: var(--uui-size-space-4);
342
+ }
343
+ .empty { color: var(--uui-color-text-alt); margin: 0; }
344
+ .error { color: var(--uui-color-danger); margin: 0; }
345
+ .new {
346
+ display: flex;
347
+ justify-content: space-between;
348
+ align-items: center;
349
+ width: 100%;
350
+ padding: var(--uui-size-layout-1);
351
+ border: 0;
352
+ border-radius: var(--uui-border-radius);
353
+ background: var(--uui-color-selected);
354
+ color: var(--uui-color-selected-contrast);
355
+ font: inherit;
356
+ text-align: left;
357
+ cursor: pointer;
358
+ }
359
+ .new:hover { filter: brightness(1.05); }
360
+ .new strong { display: block; font-size: 1.3em; }
361
+ .new uui-icon {
362
+ font-size: 1.4em;
363
+ background: var(--uui-color-surface);
364
+ color: var(--uui-color-selected);
365
+ border-radius: 50%;
366
+ padding: var(--uui-size-space-3);
367
+ }
368
+ .stats {
369
+ display: grid;
370
+ grid-template-columns: 1fr 1fr;
371
+ gap: var(--uui-size-space-4);
372
+ }
373
+ .stat {
374
+ display: flex;
375
+ flex-direction: column;
376
+ gap: var(--uui-size-space-2);
377
+ border: 1px solid var(--uui-color-border);
378
+ border-radius: var(--uui-border-radius);
379
+ padding: var(--uui-size-space-5);
380
+ }
381
+ .stat strong { font-size: 2em; line-height: 1; }
382
+ .stat .link { text-align: left; margin-top: var(--uui-size-space-3); }
383
+ .stat-icon, .feed-icon {
384
+ display: inline-grid;
385
+ place-items: center;
386
+ width: 2.4em;
387
+ height: 2.4em;
388
+ border-radius: 50%;
389
+ background: color-mix(in srgb, var(--uui-color-interactive-emphasis) 14%, transparent);
390
+ color: var(--uui-color-interactive-emphasis);
391
+ }
392
+ .stat-icon.published, .feed-icon.publish {
393
+ background: color-mix(in srgb, var(--uui-color-positive) 14%, transparent);
394
+ color: var(--uui-color-positive);
395
+ }
396
+ .feed { list-style: none; margin: 0; padding: 0; }
397
+ .feed li {
398
+ display: grid;
399
+ grid-template-columns: auto 1fr auto;
400
+ gap: var(--uui-size-space-4);
401
+ align-items: center;
402
+ padding: var(--uui-size-space-4) 0;
403
+ border-bottom: 1px solid var(--uui-color-border);
404
+ }
405
+ .feed li:last-child { border-bottom: 0; }
406
+ .feed a { color: inherit; text-decoration: none; }
407
+ .feed a:hover { text-decoration: underline; }
408
+ .feed-icon { border-radius: var(--uui-border-radius); }
409
+ `
410
+ }
411
+
412
+ customElements.define('crombolo-overview-dashboard', CromboloOverviewDashboardElement)
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The Overview's words (story 236): a page's state, how long ago, initials for
3
+ * an avatar, and a line for each activity. Pure, so the unit tests read it.
4
+ */
5
+
6
+ export const STATES = {
7
+ published: 'Published',
8
+ changed: 'Changes not published',
9
+ draft: 'Draft',
10
+ }
11
+
12
+ const VERBS = {
13
+ Create: 'created %',
14
+ Save: 'saved %',
15
+ CreateAndPublish: 'created and published %',
16
+ SaveAndPublish: 'published %',
17
+ Publish: 'published %',
18
+ PublishWithDescendants: 'published % and the pages below it',
19
+ Unpublish: 'unpublished %',
20
+ Trash: 'moved % to the recycle bin',
21
+ Restore: 'restored %',
22
+ Move: 'moved %',
23
+ Copy: 'copied %',
24
+ Revert: 'rolled back %',
25
+ }
26
+
27
+ /** The first word of a name, for the greeting. */
28
+ export const firstName = (name) =>
29
+ String(name ?? '')
30
+ .trim()
31
+ .split(/\s+/)[0] ?? ''
32
+
33
+ /** Up to two initials. */
34
+ export function initials(name) {
35
+ const words = String(name ?? '')
36
+ .trim()
37
+ .split(/\s+/)
38
+ .filter(Boolean)
39
+ if (words.length === 0) return '?'
40
+ const first = words[0]?.[0] ?? ''
41
+ const last = words.length > 1 ? (words[words.length - 1]?.[0] ?? '') : ''
42
+ return `${first}${last}`.toUpperCase()
43
+ }
44
+
45
+ /** "just now", "5m ago", "2h ago", "3d ago", then the date. */
46
+ export function ago(when, now = new Date()) {
47
+ const then = new Date(when)
48
+ const seconds = Math.max(0, (now.getTime() - then.getTime()) / 1000)
49
+ if (seconds < 60) return 'just now'
50
+ if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`
51
+ if (seconds < 86_400) return `${Math.floor(seconds / 3600)}h ago`
52
+ if (seconds < 7 * 86_400) return `${Math.floor(seconds / 86_400)}d ago`
53
+ return then.toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' })
54
+ }
55
+
56
+ /** "You published "Home"" or "Jordan Wu saved "About"". */
57
+ export function activityLine(entry) {
58
+ const who = entry.mine ? 'You' : entry.who || 'Someone'
59
+ const verb = VERBS[entry.action] ?? `${entry.action.toLowerCase()} %`
60
+ return `${who} ${verb.replace('%', `“${entry.name}”`)}`
61
+ }
62
+
63
+ /** How many soft colours an avatar can take; `avatarHue` picks one per name. */
64
+ export const AVATAR_HUES = 6
65
+
66
+ /** The same name always gets the same colour, so a person is recognisable down a list. */
67
+ export function avatarHue(name) {
68
+ let hash = 0
69
+ for (const char of String(name ?? '')) hash = (hash * 31 + char.codePointAt(0)) >>> 0
70
+ return hash % AVATAR_HUES
71
+ }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Search & sharing",
4
4
  "id": "Crombolo.Seo",
5
- "version": "0.41.1",
5
+ "version": "0.43.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,189 @@
1
+ /**
2
+ * The Settings landing page's cards and which tree an editor sits beside
3
+ * (story 234). Pure, so the unit tests read it outside a browser.
4
+ */
5
+
6
+ export const STRUCTURE_MENU = 'Umb.Menu.StructureSettings'
7
+ export const CODE_MENU = 'Umb.Menu.Templating'
8
+ export const ADVANCED_MENU = 'Umb.Menu.AdvancedSettings'
9
+
10
+ /** The sidebar app that draws each tree. */
11
+ export const SIDEBAR_APPS = {
12
+ structure: 'Umb.SectionSidebarMenu.Settings',
13
+ code: 'Umb.SectionSidebarMenu.Templating',
14
+ }
15
+
16
+ export const GROUPS = ['Build', 'Site', 'Health', 'History', 'Other']
17
+
18
+ /** Our words for each tool, by the alias of its dashboard or menu item. */
19
+ export const CARDS = {
20
+ structure: {
21
+ group: 'Build',
22
+ title: 'Structure',
23
+ description: 'Content, media and member types, data types and languages.',
24
+ },
25
+ code: {
26
+ group: 'Build',
27
+ title: 'Code',
28
+ description: 'Components, stylesheets and scripts.',
29
+ },
30
+ 'Umb.Dashboard.ModelsBuilder': {
31
+ group: 'Build',
32
+ title: 'Types for code',
33
+ description: 'The TypeScript types written from the schema, and whether they are out of date.',
34
+ },
35
+ 'Crombolo.Dashboard.Workflows': {
36
+ group: 'Build',
37
+ title: 'Workflows',
38
+ description:
39
+ 'The approval steps a page goes through before it is published, and who decides each.',
40
+ },
41
+ 'Crombolo.Dashboard.Seo': {
42
+ group: 'Site',
43
+ title: 'Search & sharing',
44
+ description:
45
+ 'What every page falls back to in search results and when shared, the robots file and the missing-page page.',
46
+ },
47
+ 'Crombolo.Dashboard.Addresses': {
48
+ group: 'Site',
49
+ title: 'Page addresses',
50
+ description: "Whether the top-level page's name is part of every address below it.",
51
+ },
52
+ 'Umb.Dashboard.RedirectManagement': {
53
+ group: 'Site',
54
+ title: 'Redirects',
55
+ description: "Old addresses that send visitors on to a page's new one.",
56
+ },
57
+ 'Umb.MenuItem.Webhook': {
58
+ group: 'Site',
59
+ title: 'Webhooks',
60
+ description: 'Tell other systems when content changes.',
61
+ },
62
+ 'Umb.MenuItem.LogViewer': {
63
+ group: 'Site',
64
+ title: 'Logs',
65
+ description: 'Search and read what the server has logged.',
66
+ },
67
+ 'Umb.Dashboard.ExamineManagement': {
68
+ group: 'Site',
69
+ title: 'Search indexes',
70
+ description: "The back office's search indexes: their health, and rebuilding them.",
71
+ },
72
+ 'Crombolo.Dashboard.BackgroundJobs': {
73
+ group: 'Site',
74
+ title: 'Background jobs',
75
+ description: 'Scheduled and queued work, how far each got, and running a failed one again.',
76
+ },
77
+ 'Umb.MenuItem.Extensions': {
78
+ group: 'Site',
79
+ title: 'Extensions',
80
+ description: 'What the back office has loaded, and from which package.',
81
+ },
82
+ 'Umb.Dashboard.HealthCheck': {
83
+ group: 'Health',
84
+ title: 'Health check',
85
+ description: "Checks on the site's setup and data, with a fix where there is one.",
86
+ },
87
+ 'Umb.Dashboard.PublishedStatus': {
88
+ group: 'Health',
89
+ title: 'Published status',
90
+ description: 'The published cache visitors are served from, and rebuilding it.',
91
+ },
92
+ 'Umb.MenuItem.Relations': {
93
+ group: 'Health',
94
+ title: 'Relations',
95
+ description: 'How items point at each other, such as a copy and its original.',
96
+ },
97
+ 'Crombolo.Dashboard.Changes': {
98
+ group: 'History',
99
+ title: 'Changes',
100
+ description: 'What an upgrade or an arriving bundle needs from you, and what is resolved.',
101
+ },
102
+ 'Crombolo.Dashboard.AuditLog': {
103
+ group: 'History',
104
+ title: 'Audit log',
105
+ description: 'Who did what, when and from where.',
106
+ },
107
+ }
108
+
109
+ /**
110
+ * The landing page's groups, in order, each with its cards in the order above.
111
+ * `dashboards` are `{ alias, label, path }`; `advanced` are `{ alias, label,
112
+ * entityType }`; `structure` and `code` say whether the user may open an item
113
+ * of that tree. Paths are relative to the section.
114
+ *
115
+ * @param {{
116
+ * dashboards?: { alias: string, label?: string, path: string }[],
117
+ * advanced?: { alias: string, label?: string, entityType: string }[],
118
+ * structure?: boolean,
119
+ * code?: boolean,
120
+ * }} from
121
+ */
122
+ export function settingsCards({ dashboards = [], advanced = [], structure = false, code = false }) {
123
+ const found = []
124
+ if (structure) found.push({ alias: 'structure', path: 'structure' })
125
+ if (code) found.push({ alias: 'code', path: 'code' })
126
+ for (const d of dashboards) found.push({ alias: d.alias, label: d.label, path: d.path })
127
+ for (const item of advanced)
128
+ found.push({ alias: item.alias, label: item.label, path: `workspace/${item.entityType}` })
129
+
130
+ const order = Object.keys(CARDS)
131
+ const cards = found
132
+ .map((card) => {
133
+ const words = CARDS[card.alias]
134
+ return words
135
+ ? { alias: card.alias, path: card.path, ...words }
136
+ : { alias: card.alias, path: card.path, group: 'Other', title: card.label ?? card.alias }
137
+ })
138
+ .sort((a, b) => rank(order, a.alias) - rank(order, b.alias))
139
+
140
+ return GROUPS.map((group) => ({ group, cards: cards.filter((c) => c.group === group) })).filter(
141
+ (g) => g.cards.length > 0,
142
+ )
143
+ }
144
+
145
+ const rank = (order, alias) => {
146
+ const at = order.indexOf(alias)
147
+ return at === -1 ? order.length : at
148
+ }
149
+
150
+ const STRUCTURE_TYPES = ['document-type', 'media-type', 'member-type', 'data-type', 'language']
151
+ const CODE_TYPES = ['partial-view', 'template', 'stylesheet', 'script']
152
+
153
+ /** The tree an editor for `entityType` sits beside, or undefined for none. */
154
+ export function treeFor(entityType) {
155
+ if (typeof entityType !== 'string') return undefined
156
+ if (STRUCTURE_TYPES.some((type) => entityType.startsWith(type))) return 'structure'
157
+ if (CODE_TYPES.some((type) => entityType.startsWith(type))) return 'code'
158
+ return undefined
159
+ }
160
+
161
+ /**
162
+ * The trail above a Settings page: Settings, then the tree or tool it is in.
163
+ * Paths are relative to the section; the last crumb is the page itself.
164
+ *
165
+ * @param {{ tree?: 'structure' | 'code', title?: string }} at
166
+ */
167
+ export function crumbsFor({ tree, title } = {}) {
168
+ const settings = { label: 'Settings', path: '' }
169
+ if (tree) return [settings, { label: CARDS[tree]?.title ?? tree }]
170
+ if (title) return [settings, { label: title }]
171
+ return []
172
+ }
173
+
174
+ /**
175
+ * The card title of the Advanced tool an editor belongs to, by the entity type
176
+ * the editor opened, e.g. `webhook` for a webhook under `webhook-root`.
177
+ *
178
+ * @param {{ alias: string, label?: string, entityType?: string }[]} advanced
179
+ * @param {string | undefined} entityType
180
+ */
181
+ export function advancedToolTitle(advanced, entityType) {
182
+ if (typeof entityType !== 'string') return undefined
183
+ const item = advanced.find(
184
+ (m) =>
185
+ typeof m.entityType === 'string' &&
186
+ (entityType === m.entityType || entityType.startsWith(m.entityType.replace(/-root$/, ''))),
187
+ )
188
+ return item ? (CARDS[item.alias]?.title ?? item.label) : undefined
189
+ }