@crombolo/backoffice-host 0.45.0 → 0.46.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/backoffice-host",
3
- "version": "0.45.0",
3
+ "version": "0.46.1",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Serves the Umbraco backoffice SPA: shell HTML, import map and package manifests.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -32,7 +32,7 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@crombolo/core": "0.45.0",
36
- "@crombolo/backoffice-dist": "0.45.0"
35
+ "@crombolo/core": "0.46.1",
36
+ "@crombolo/backoffice-dist": "0.46.1"
37
37
  }
38
38
  }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo App Preview",
4
4
  "id": "Crombolo.AppPreview",
5
- "version": "0.45.0",
5
+ "version": "0.46.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -126,7 +126,10 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
126
126
  /** The signature, and the install it leads to unless this site would refuse it. */
127
127
  #review(item) {
128
128
  const checked = this._signatures.get(item.name)
129
- const refused = Boolean(checked?.refused) || checked?.provenance?.state === 'invalid'
129
+ const refused =
130
+ Boolean(checked?.refused) ||
131
+ checked?.provenance?.state === 'invalid' ||
132
+ checked?.provenance?.state === 'unchecked'
130
133
  return html`
131
134
  ${this.#signature(item)}
132
135
  <div class="actions">
@@ -28,6 +28,11 @@ export function signatureWords(provenance, refused, policy) {
28
28
  } else if (provenance?.state === 'local') {
29
29
  label = 'From this site'
30
30
  detail = "Linked from this site's own code, not from a package registry."
31
+ } else if (provenance?.state === 'unchecked') {
32
+ tone = 'warning'
33
+ label = "Couldn't be checked right now"
34
+ detail =
35
+ "Its signature couldn't be checked just now, so it will not be installed. Try again in a few minutes."
31
36
  } else if (provenance?.state === 'invalid') {
32
37
  tone = 'danger'
33
38
  label = "Signature doesn't match"
@@ -36,7 +41,7 @@ export function signatureWords(provenance, refused, policy) {
36
41
  : "Its signature can't be checked, so it will not be installed."
37
42
  }
38
43
  let refusal = ''
39
- if (refused && provenance?.state !== 'invalid') {
44
+ if (refused && provenance?.state !== 'invalid' && provenance?.state !== 'unchecked') {
40
45
  tone = 'danger'
41
46
  refusal =
42
47
  provenance?.state === 'signed' && policy?.sources?.length
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Localizations",
4
4
  "id": "Crombolo.Localizations",
5
- "version": "0.45.0",
5
+ "version": "0.46.1",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,21 @@
1
+ /** What the header says about a large media change running in the background (story 246). Pure. */
2
+
3
+ const count = (n) => n.toLocaleString('en')
4
+
5
+ /**
6
+ * @param {{ state: string, progress?: { done: number, total?: number } | null }} job
7
+ * @returns {{ tone: string, label: string }}
8
+ */
9
+ export function mediaJobWords(job) {
10
+ if (job.state === 'failed') return { tone: 'danger', label: "A media change didn't finish" }
11
+ if (job.state === 'succeeded') return { tone: 'positive', label: 'Media updated' }
12
+ const progress = job.progress
13
+ if (progress?.total)
14
+ return {
15
+ tone: 'default',
16
+ label: `Updating media: ${count(progress.done)} of ${count(progress.total)}`,
17
+ }
18
+ if (progress?.done)
19
+ return { tone: 'default', label: `Updating media: ${count(progress.done)} done` }
20
+ return { tone: 'default', label: 'Updating media…' }
21
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * A header app that follows a large media change queued in the background (story
3
+ * 246): told the job's id when it is queued, it reads its progress until it
4
+ * finishes, then reloads the Media tree and the recycle bin.
5
+ */
6
+ import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'
7
+ import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'
8
+ import { UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action'
9
+ import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
10
+ import { UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT } from '@umbraco-cms/backoffice/management-api'
11
+ import { mediaJobWords } from './media-jobs-words.js'
12
+
13
+ const POLL_MS = 2000
14
+ const SHOWN_AFTER_MS = 5000
15
+
16
+ const statusUrl = (id) =>
17
+ `${(document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')}/crombolo/api/media-jobs/${encodeURIComponent(id)}`
18
+
19
+ export default class CromboloMediaJobsElement extends UmbElementMixin(LitElement) {
20
+ static properties = { _jobs: { state: true } }
21
+
22
+ #actions
23
+ #timer
24
+
25
+ constructor() {
26
+ super()
27
+ /** @type {Map<string, { state: string, progress?: object | null }>} */
28
+ this._jobs = new Map()
29
+ this.consumeContext(UMB_ACTION_EVENT_CONTEXT, (context) => {
30
+ this.#actions = context
31
+ })
32
+ this.consumeContext(UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT, (context) => {
33
+ if (!context) return
34
+ this.observe(
35
+ context.byEventSourcesAndEventTypes(['Crombolo:MediaJob'], ['Queued']),
36
+ (event) => {
37
+ if (!event?.key || this._jobs.has(event.key)) return
38
+ this._jobs = new Map(this._jobs).set(event.key, { state: 'queued' })
39
+ this.#poll()
40
+ },
41
+ )
42
+ })
43
+ }
44
+
45
+ disconnectedCallback() {
46
+ super.disconnectedCallback()
47
+ clearTimeout(this.#timer)
48
+ }
49
+
50
+ async #poll() {
51
+ clearTimeout(this.#timer)
52
+ const running = [...this._jobs].filter(
53
+ ([, job]) => job.state === 'queued' || job.state === 'running',
54
+ )
55
+ if (running.length === 0) return
56
+ const next = new Map(this._jobs)
57
+ for (const [id] of running) {
58
+ const response = await fetch(statusUrl(id), { credentials: 'include' }).catch(() => undefined)
59
+ // Someone without the Media section is not told about it.
60
+ if (response?.status === 403 || response?.status === 404) next.delete(id)
61
+ if (!response?.ok) continue
62
+ const job = await response.json()
63
+ next.set(id, job)
64
+ if (job.state === 'succeeded' || job.state === 'failed') this.#finished(id)
65
+ }
66
+ this._jobs = next
67
+ this.#timer = setTimeout(() => this.#poll(), POLL_MS)
68
+ }
69
+
70
+ #finished(id) {
71
+ for (const entityType of ['media-root', 'media-recycle-bin-root'])
72
+ this.#actions?.dispatchEvent(
73
+ new UmbRequestReloadChildrenOfEntityEvent({ entityType, unique: null }),
74
+ )
75
+ setTimeout(() => {
76
+ const next = new Map(this._jobs)
77
+ next.delete(id)
78
+ this._jobs = next
79
+ }, SHOWN_AFTER_MS)
80
+ }
81
+
82
+ render() {
83
+ if (this._jobs.size === 0) return nothing
84
+ return html`${[...this._jobs.values()].map((job) => {
85
+ const words = mediaJobWords(job)
86
+ return html`<uui-tag look="primary" color=${words.tone}>${words.label}</uui-tag>`
87
+ })}`
88
+ }
89
+
90
+ static styles = css`
91
+ :host { display: flex; align-items: center; gap: var(--uui-size-space-2); padding: 0 var(--uui-size-space-3); }
92
+ `
93
+ }
94
+
95
+ customElements.define('crombolo-media-jobs', CromboloMediaJobsElement)
@@ -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.45.0",
5
+ "version": "0.46.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Sign-in Dialog",
4
4
  "id": "Crombolo.SignInDialog",
5
- "version": "0.45.0",
5
+ "version": "0.46.1",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo",
4
4
  "id": "Crombolo.Core",
5
- "version": "0.45.0",
5
+ "version": "0.46.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -468,6 +468,13 @@
468
468
  "element": "/crombolo-plugin/bundles-changed.js",
469
469
  "weight": 999
470
470
  },
471
+ {
472
+ "type": "headerApp",
473
+ "alias": "Crombolo.HeaderApp.MediaJobs",
474
+ "name": "Crombolo Media Changes In Progress",
475
+ "element": "/crombolo-plugin/media-jobs.js",
476
+ "weight": 998
477
+ },
471
478
  {
472
479
  "type": "headerApp",
473
480
  "kind": "button",