From aff851cd5ac0648a968b74b3cc551cf1ab0157a7 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Thu, 26 Nov 2026 14:47:27 +0100 Subject: [PATCH 01/10] Add new primitives to easily wire Confirmation dialogs onto actions --- README.md | 4 + packages/oss-components/package.json | 4 + .../src/patterns/confirmation.ts | 239 ++++++++++++++ .../stories/patterns/Confirmation.mdx | 102 ++++++ .../integration/patterns/confirmation-test.ts | 308 ++++++++++++++++++ 5 files changed, 657 insertions(+) create mode 100644 packages/oss-components/src/patterns/confirmation.ts create mode 100644 packages/test-app/stories/patterns/Confirmation.mdx create mode 100644 packages/test-app/tests/integration/patterns/confirmation-test.ts diff --git a/README.md b/README.md index 8fa0f3e02..eef9c68d5 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,10 @@ FontAwesome is owned by the consuming app: install your licensed FontAwesome pac Follow [Consumer-owned asset maps](docs/asset-map.md). The consuming app explicitly calls `injectAssetMap` from `@upfluence/oss-components/build/classic-asset-map.cjs` (classic builds) or adds the `assetMap` plugin from `@upfluence/oss-components/build/vite-asset-map.mjs` (Vite builds); addon hooks do not activate either. Remove competing ember-cli-ifa registrations when adopting this adapter. +## Patterns + +Patterns attach a UX behavior to an existing action, such as asking for confirmation before running it. Import them from `@upfluence/oss-components/patterns/...` and see the [Patterns docs in Storybook](https://storybook.upfluence.co/?path=/docs/patterns-confirmation--docs) (source in [`packages/test-app/stories/patterns`](packages/test-app/stories/patterns)). + ## Development This is a pnpm workspace with the published addon in `packages/oss-components` and its demo, tests, and Storybook in `packages/test-app`. diff --git a/packages/oss-components/package.json b/packages/oss-components/package.json index b0c88ba75..be88b823a 100644 --- a/packages/oss-components/package.json +++ b/packages/oss-components/package.json @@ -176,6 +176,10 @@ "types": "./declarations/types.d.ts", "default": "./dist/types.js" }, + "./patterns/*": { + "types": "./declarations/patterns/*.d.ts", + "default": "./dist/patterns/*.js" + }, "./utils/*": { "types": "./declarations/utils/*.d.ts", "default": "./dist/utils/*.js" diff --git a/packages/oss-components/src/patterns/confirmation.ts b/packages/oss-components/src/patterns/confirmation.ts new file mode 100644 index 000000000..93fdbe83f --- /dev/null +++ b/packages/oss-components/src/patterns/confirmation.ts @@ -0,0 +1,239 @@ +import { setComponentTemplate } from '@ember/component'; +import templateOnly from '@ember/component/template-only'; +import { assert } from '@ember/debug'; +import { isDestroying, registerDestructor, unregisterDestructor } from '@ember/destroyable'; +import { hash } from '@ember/helper'; +import { getOwner } from '@ember/owner'; +import type Owner from '@ember/owner'; +import { renderComponent } from '@ember/renderer'; +import type RouterService from '@ember/routing/router-service'; +import { precompileTemplate } from '@ember/template-compilation'; +import { isTesting } from '@embroider/macros'; +import { tracked } from '@glimmer/tracking'; + +import type { IntlService } from 'ember-intl'; + +import OSSDialog, { type Skin as DialogSkin } from '../components/o-s-s/dialog'; + +type Content = ReturnType; +type Texts = { + title?: Content; + subtitle?: Content; + confirmLabel?: Content; + cancelLabel?: Content; +}; +type Text = Content | ((self: T, ...args: A) => Content); +type ConfirmOptions = Texts & { + baseTranslationKey?: string; + skin?: DialogSkin; + icon?: string; + onConfirm?: () => unknown; +}; + +export type ConfirmableOptions = { + baseTranslationKey?: string; + title?: Text; + subtitle?: Text; + confirmLabel?: Text; + cancelLabel?: Text; + skin?: DialogSkin; + icon?: string; + when?: (self: T, ...args: A) => boolean; +}; + +class ConfirmationState { + @tracked loading: boolean = false; + + constructor( + readonly texts: Texts, + readonly skin: DialogSkin | undefined, + readonly icon: string | undefined + ) {} +} + +const ConfirmationDialog = setComponentTemplate( + precompileTemplate( + `
+ +
`, + { strictMode: true, scope: () => ({ OSSDialog, hash }) } + ), + templateOnly() +); + +const HOST_ID = 'confirmable-dialog-host'; + +let activeDialog: { state: ConfirmationState; dismiss: () => void } | undefined; + +function hostElement(): HTMLElement { + let host = document.getElementById(HOST_ID); + + if (!host) { + host = document.createElement('div'); + host.id = HOST_ID; + ((isTesting() && document.getElementById('ember-testing')) || document.body).append(host); + } + + return host; +} + +function translate(owner: Owner, baseTranslationKey: string | undefined, suffix: string): Content | undefined { + if (!baseTranslationKey) return undefined; + + const intl = owner.lookup('service:intl') as IntlService; + const key = `${baseTranslationKey}.${suffix}`; + + assert(`[pattern][confirmation] Missing translation "${key}"`, intl.exists(key)); + + return intl.t(key); +} + +function isThenable(value: unknown): value is PromiseLike { + return typeof (value as PromiseLike | undefined)?.then === 'function'; +} + +export function confirm(context: object, options: ConfirmOptions): Promise { + const owner = getOwner(context); + + assert('[pattern][confirmation] The context must have an owner (component, controller, route or service)', owner); + + const texts: Texts = { + title: options.title ?? translate(owner, options.baseTranslationKey, 'title'), + subtitle: options.subtitle ?? translate(owner, options.baseTranslationKey, 'subtitle'), + confirmLabel: options.confirmLabel ?? translate(owner, options.baseTranslationKey, 'confirm'), + cancelLabel: options.cancelLabel ?? translate(owner, options.baseTranslationKey, 'cancel') + }; + assert( + '[pattern][confirmation] A title, a confirmLabel and a cancelLabel are mandatory, either directly or through a baseTranslationKey', + texts.title && texts.confirmLabel && texts.cancelLabel + ); + + if (activeDialog?.state.loading) return Promise.resolve(false); + activeDialog?.dismiss(); + + const router = owner.lookup('service:router') as RouterService; + const state = new ConfirmationState(texts, options.skin, options.icon); + + return new Promise((resolve, reject) => { + let closed = false; + + const close = (): void => { + closed = true; + router.off('routeWillChange', dismiss); + if (!isDestroying(context)) unregisterDestructor(context, dismiss); + if (activeDialog?.dismiss === dismiss) activeDialog = undefined; + rendered.destroy(); + }; + + const dismiss = (): void => { + if (closed) return; + close(); + resolve(false); + }; + + const onCancel = (event?: Event): void => { + event?.stopPropagation(); + if (!state.loading) dismiss(); + }; + + const onConfirm = (event?: Event): void => { + event?.stopPropagation(); + if (closed || state.loading) return; + + let outcome: unknown; + try { + outcome = options.onConfirm?.(); + } catch (error) { + close(); + reject(error); + return; + } + + if (!isThenable(outcome)) { + close(); + resolve(true); + return; + } + + state.loading = true; + outcome.then( + () => { + if (closed) return; + close(); + resolve(true); + }, + (error: unknown) => { + if (closed) return; + close(); + reject(error); + } + ); + }; + + const rendered = renderComponent(ConfirmationDialog, { + into: hostElement(), + owner, + args: { state, onConfirm, onCancel } + }); + + router.on('routeWillChange', dismiss); + registerDestructor(context, dismiss); + activeDialog = { state, dismiss }; + }); +} + +function resolveText(text: Text | undefined, self: T, args: A): Content | undefined { + return typeof text === 'function' ? text(self, ...args) : text; +} + +export function confirmable(options: ConfirmableOptions) { + return function unknown>( + _target: T, + key: string, + descriptor: TypedPropertyDescriptor + ): TypedPropertyDescriptor { + const original = descriptor.value; + + assert( + `[pattern][confirmation] \`${key}\` must be a method. If it is also an \`@action\`, put \`@action\` above \`@confirmable\`.`, + typeof original === 'function' + ); + + const openDialogs = new WeakMap>(); + + descriptor.value = function (this: T, ...args: A): unknown { + if (options.when && !options.when(this, ...args)) { + return original.apply(this, args); + } + + let dialog = openDialogs.get(this); + + if (!dialog) { + dialog = confirm(this, { + baseTranslationKey: options.baseTranslationKey, + title: resolveText(options.title, this, args), + subtitle: resolveText(options.subtitle, this, args), + confirmLabel: resolveText(options.confirmLabel, this, args), + cancelLabel: resolveText(options.cancelLabel, this, args), + skin: options.skin, + icon: options.icon, + onConfirm: () => original.apply(this, args) + }).finally(() => openDialogs.delete(this)); + + openDialogs.set(this, dialog); + } + + return dialog.then(() => undefined); + } as M; + + return descriptor; + }; +} diff --git a/packages/test-app/stories/patterns/Confirmation.mdx b/packages/test-app/stories/patterns/Confirmation.mdx new file mode 100644 index 000000000..5eeaa3820 --- /dev/null +++ b/packages/test-app/stories/patterns/Confirmation.mdx @@ -0,0 +1,102 @@ +import { Meta } from '@storybook/addon-docs/blocks'; + + + +# Confirmation + +Patterns attach a UX behavior to an existing action. Import them from `@upfluence/oss-components/patterns/...`. + +`@confirmable` asks for confirmation before running a method. It renders an `OSS::Dialog`, calls the method on confirm, and keeps the confirm button loading until the promise it returns settles. `confirm(context, options)` is the imperative form. + +## Usage + +```ts +import { action } from '@ember/object'; +import { confirmable } from '@upfluence/oss-components/patterns/confirmation'; + +export default class ListActions extends Component { + @action + @confirmable({ + baseTranslationKey: 'lists.delete_confirmation', + when: (self) => self.args.list.itemsCount > 0 + }) + deleteList(): Promise { + return this.args.list.destroyRecord(); + } +} +``` + +```yaml +lists: + delete_confirmation: + title: Delete this list? + subtitle: It can't be undone. + confirm: Delete + cancel: Cancel +``` + +## Options + +| Option | Description | +| -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `baseTranslationKey` | Reads the `title`, `subtitle`, `confirm` and `cancel` keys under it, as plain text. All four are required: a missing one fails an assertion when the dialog opens. | +| `title`, `subtitle`, `confirmLabel`, `cancelLabel` | A string, an `intl.t(key, { htmlSafe: true })` result, or a `(self, ...args) =>` function that returns one. Overrides its translation key. Without a `baseTranslationKey`, `title`, `confirmLabel` and `cancelLabel` are required. | +| `when` | `(self, ...args) => boolean`. When it returns `false`, the method runs right away, without a dialog. | +| `skin` | Passed to `OSS::Dialog`: `alert` (default), `primary` or `error`. | +| `icon` | Passed to `OSS::Dialog`. Defaults to `fa-warning`. | + +`self` is the decorated instance and `args` the method's arguments, both typed through the generics. A text that needs a value or markup comes from a function, here with an `htmlSafe` translation (OSS sanitizes those): + +```ts +@action +@confirmable({ + baseTranslationKey: 'lists.delete_confirmation', + title: (self, list) => self.intl.t('lists.delete_named', { htmlSafe: true, name: list.name }) +}) +deleteList(list: List): Promise { + return list.destroyRecord(); +} +``` + +## Rules + +- Put `@action` above `@confirmable`. The other way around fails an assertion. +- Return the method's promise so the dialog waits for it, showing the primary + action in loading state in the meantime. Cancel is ignored while it runs. An error closes the dialog and is rethrown to the caller. + +## Imperative form + +`confirm(context, options)` takes the same options as strings, plus `onConfirm`. It resolves to `true` once `onConfirm` has settled, and to `false` when cancelled. The context must have an owner: a component, controller, route or service. + +```ts +import { confirm } from '@upfluence/oss-components/patterns/confirmation'; + +async archiveSelection(): Promise { + const archived = await confirm(this, { + baseTranslationKey: 'lists.archive_confirmation', + onConfirm: () => this.lists.archive(this.selection) + }); + + if (archived) this.selection = []; +} +``` + +## Testing + +In tests, the dialog renders inside `#ember-testing`, so the usual test helpers find it: + +```ts +await click('[data-control-name="delete-list"]'); +assert.dom('[data-control-name="confirmable-dialog"]').exists(); + +await click('[data-control-name="dialog-primary-action-button"]'); +assert.true(this.destroyRecordStub.calledOnce); +``` + +Cancel is `[data-control-name="dialog-secondary-action-button"]`. diff --git a/packages/test-app/tests/integration/patterns/confirmation-test.ts b/packages/test-app/tests/integration/patterns/confirmation-test.ts new file mode 100644 index 000000000..5737ea02f --- /dev/null +++ b/packages/test-app/tests/integration/patterns/confirmation-test.ts @@ -0,0 +1,308 @@ +import { associateDestroyableChild, destroy } from '@ember/destroyable'; +import { action } from '@ember/object'; +import { setOwner } from '@ember/owner'; +import type Owner from '@ember/owner'; +import type RouterService from '@ember/routing/router-service'; +import { click, settled } from '@ember/test-helpers'; + +import type { IntlService } from 'ember-intl'; +import { setupIntl } from 'ember-intl/test-support'; +import { setupRenderingTest } from 'ember-qunit'; +import { module, test } from 'qunit'; +import sinon from 'sinon'; +import type { SinonStub } from 'sinon'; + +import { confirm, confirmable, type ConfirmableOptions } from '@upfluence/oss-components/patterns/confirmation'; + +const DIALOG = '[data-control-name="confirmable-dialog"]'; +const CONFIRM = '[data-control-name="dialog-primary-action-button"]'; +const CANCEL = '[data-control-name="dialog-secondary-action-button"]'; + +const TEXTS = { + title: 'Remove Batman?', + subtitle: 'They will lose access.', + confirmLabel: 'Remove', + cancelLabel: 'Cancel' +}; + +type Subject = { name: string; gated: boolean; removeStub: SinonStub; remove(list: string): Promise }; + +function buildSubject(owner: Owner, options: ConfirmableOptions): Subject { + class TestSubject { + name = 'Batman'; + gated = true; + removeStub = sinon.stub(); + + @confirmable(options) + remove(list: string): Promise { + return this.removeStub(list); + } + } + + const subject = new TestSubject(); + setOwner(subject, owner); + associateDestroyableChild(owner, subject); + + return subject; +} + +module('Integration | Pattern | confirmation', function (hooks) { + setupRenderingTest(hooks); + setupIntl(hooks, 'en-us', { + confirmation: { + remove: { title: 'Remove this member?', subtitle: 'They will lose access.', confirm: 'Remove', cancel: 'Keep' }, + partial: { title: 'Partial title', confirm: 'Yes', cancel: 'No' }, + html_title: 'Remove this member?' + } + }); + + module('Texts', () => { + test('It renders the given texts', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + + subject.remove('team'); + await settled(); + + assert.dom(`${DIALOG} .font-weight-semibold`).hasText('Remove Batman?'); + assert.dom(`${DIALOG} .font-size-sm`).hasText('They will lose access.'); + assert.dom(CONFIRM).hasText('Remove'); + assert.dom(CANCEL).hasText('Cancel'); + + await click(CANCEL); + }); + + test('Function texts receive the instance and the method arguments', async function (assert) { + const subject = buildSubject(this.owner, { + ...TEXTS, + title: (self, list) => `Remove ${self.name} from ${list}?` + }); + + subject.remove('team'); + await settled(); + + assert.dom(`${DIALOG} .font-weight-semibold`).hasText('Remove Batman from team?'); + + await click(CANCEL); + }); + + test('A text can be an htmlSafe translation', async function (assert) { + const intl = this.owner.lookup('service:intl') as IntlService; + const subject = buildSubject(this.owner, { + ...TEXTS, + title: () => intl.t('confirmation.html_title', { htmlSafe: true }) + }); + + subject.remove('team'); + await settled(); + + assert.dom(`${DIALOG} .font-weight-semibold strong`).hasText('this member'); + + await click(CANCEL); + }); + + test('A baseTranslationKey reads the title, subtitle, confirm and cancel keys', async function (assert) { + const subject = buildSubject(this.owner, { baseTranslationKey: 'confirmation.remove' }); + + subject.remove('team'); + await settled(); + + assert.dom(`${DIALOG} .font-weight-semibold`).hasText('Remove this member?'); + assert.dom(`${DIALOG} .font-size-sm`).hasText('They will lose access.'); + assert.dom(CONFIRM).hasText('Remove'); + assert.dom(CANCEL).hasText('Keep'); + + await click(CANCEL); + }); + + test('An explicit text overrides its translation key', async function (assert) { + const subject = buildSubject(this.owner, { + baseTranslationKey: 'confirmation.partial', + subtitle: 'Explicit subtitle' + }); + + subject.remove('team'); + await settled(); + + assert.dom(`${DIALOG} .font-weight-semibold`).hasText('Partial title'); + assert.dom(`${DIALOG} .font-size-sm`).hasText('Explicit subtitle'); + + await click(CANCEL); + }); + + test('A missing translation key fails', function (assert) { + const subject = buildSubject(this.owner, { baseTranslationKey: 'confirmation.partial' }); + + assert.throws(() => subject.remove('team'), /Missing translation "confirmation\.partial\.subtitle"/); + }); + + test('Without a baseTranslationKey, the title and both labels are mandatory', function (assert) { + const subject = buildSubject(this.owner, { title: 'Remove Batman?' }); + + assert.throws(() => subject.remove('team'), /A title, a confirmLabel and a cancelLabel are mandatory/); + }); + }); + + module('Flow', () => { + test('When `when` returns false, the method runs without a dialog', async function (assert) { + const subject = buildSubject(this.owner, { ...TEXTS, when: (self) => self.gated }); + subject.gated = false; + + await subject.remove('team'); + + assert.dom(DIALOG).doesNotExist(); + assert.true(subject.removeStub.calledOnceWithExactly('team')); + }); + + test('Cancel closes the dialog without calling the method', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + + const result = subject.remove('team'); + await settled(); + assert.dom(DIALOG).exists(); + + await click(CANCEL); + await result; + + assert.dom(DIALOG).doesNotExist(); + assert.true(subject.removeStub.notCalled); + }); + + test('Confirm calls the method with its arguments and closes the dialog', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + + const result = subject.remove('team'); + await settled(); + await click(CONFIRM); + await result; + + assert.dom(DIALOG).doesNotExist(); + assert.true(subject.removeStub.calledOnceWithExactly('team')); + }); + + test('A returned promise keeps the dialog open and loading until it settles', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + let resolveRemoval!: () => void; + subject.removeStub.returns(new Promise((resolve) => (resolveRemoval = resolve))); + + const result = subject.remove('team'); + await settled(); + await click(CONFIRM); + + assert.dom(`${CONFIRM} .fa-circle-notch`).exists(); + + await click(CANCEL); + assert.dom(DIALOG).exists(); + + resolveRemoval(); + await result; + await settled(); + + assert.dom(DIALOG).doesNotExist(); + }); + + test('A rejection closes the dialog and rejects the call', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + subject.removeStub.rejects(new Error('Removal failed')); + + const result = subject.remove('team'); + const rejection = assert.rejects(result, /Removal failed/); + await settled(); + await click(CONFIRM); + await rejection; + await settled(); + + assert.dom(DIALOG).doesNotExist(); + }); + + test('Clicks on the dialog buttons do not propagate', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + const listener = sinon.spy(); + document.addEventListener('click', listener); + + subject.remove('team'); + await settled(); + await click(CANCEL); + subject.remove('team'); + await settled(); + await click(CONFIRM); + + document.removeEventListener('click', listener); + assert.true(listener.notCalled); + }); + + test('Calling the method again while its dialog is open reuses it', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + + const first = subject.remove('team'); + const second = subject.remove('team'); + await settled(); + + assert.dom(DIALOG).exists({ count: 1 }); + + await click(CONFIRM); + await Promise.all([first, second]); + + assert.true(subject.removeStub.calledOnce); + }); + + test('A new confirmation while one is loading resolves false', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + let resolveRemoval!: () => void; + subject.removeStub.returns(new Promise((resolve) => (resolveRemoval = resolve))); + + const result = subject.remove('team'); + await settled(); + await click(CONFIRM); + + const other = {}; + setOwner(other, this.owner); + + assert.false(await confirm(other, TEXTS)); + assert.dom(DIALOG).exists({ count: 1 }); + assert.dom(`${CONFIRM} .fa-circle-notch`).exists(); + + resolveRemoval(); + await result; + }); + }); + + module('Dismissal', () => { + test('Destroying the context closes the dialog', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + + const result = subject.remove('team'); + await settled(); + destroy(subject); + await settled(); + await result; + + assert.dom(DIALOG).doesNotExist(); + assert.true(subject.removeStub.notCalled); + }); + + test('A route change closes the dialog', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + + const result = subject.remove('team'); + await settled(); + (this.owner.lookup('service:router') as RouterService).trigger('routeWillChange'); + await settled(); + await result; + + assert.dom(DIALOG).doesNotExist(); + assert.true(subject.removeStub.notCalled); + }); + }); + + test('It asserts when placed above @action', function (assert) { + assert.throws(() => { + class Broken { + @confirmable(TEXTS) + @action + remove(): void {} + } + + return Broken; + }, /put `@action` above `@confirmable`/); + }); +}); From c8b4cdee7d97155f9a89782f0ef0d82592eb9124 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Tue, 1 Dec 2026 16:58:08 +0100 Subject: [PATCH 02/10] Settle confirmations with the method's result and only decorate void methods Closing the dialog on a route change or the owner's destruction while the method runs no longer resolves the call early: it still settles with the method's result or error. @confirmable now only accepts methods returning void or Promise, since the result is dropped once a dialog shows. --- .../src/patterns/confirmation.ts | 23 +++---- .../stories/patterns/Confirmation.mdx | 10 +-- .../integration/patterns/confirmation-test.ts | 69 +++++++++++++++++++ 3 files changed, 85 insertions(+), 17 deletions(-) diff --git a/packages/oss-components/src/patterns/confirmation.ts b/packages/oss-components/src/patterns/confirmation.ts index 93fdbe83f..f04e6fb20 100644 --- a/packages/oss-components/src/patterns/confirmation.ts +++ b/packages/oss-components/src/patterns/confirmation.ts @@ -136,7 +136,12 @@ export function confirm(context: object, options: ConfirmOptions): Promise { if (closed) return; close(); - resolve(false); + if (!state.loading) resolve(false); + }; + + const settle = (finish: () => void): void => { + if (!closed) close(); + finish(); }; const onCancel = (event?: Event): void => { @@ -165,16 +170,8 @@ export function confirm(context: object, options: ConfirmOptions): Promise { - if (closed) return; - close(); - resolve(true); - }, - (error: unknown) => { - if (closed) return; - close(); - reject(error); - } + () => settle(() => resolve(true)), + (error: unknown) => settle(() => reject(error)) ); }; @@ -195,7 +192,7 @@ function resolveText(text: Text | undefined, self: } export function confirmable(options: ConfirmableOptions) { - return function unknown>( + return function void | Promise>( _target: T, key: string, descriptor: TypedPropertyDescriptor @@ -209,7 +206,7 @@ export function confirmable(o const openDialogs = new WeakMap>(); - descriptor.value = function (this: T, ...args: A): unknown { + descriptor.value = function (this: T, ...args: A): void | Promise { if (options.when && !options.when(this, ...args)) { return original.apply(this, args); } diff --git a/packages/test-app/stories/patterns/Confirmation.mdx b/packages/test-app/stories/patterns/Confirmation.mdx index 5eeaa3820..ee3c3a05a 100644 --- a/packages/test-app/stories/patterns/Confirmation.mdx +++ b/packages/test-app/stories/patterns/Confirmation.mdx @@ -26,8 +26,8 @@ export default class ListActions extends Component { baseTranslationKey: 'lists.delete_confirmation', when: (self) => self.args.list.itemsCount > 0 }) - deleteList(): Promise { - return this.args.list.destroyRecord(); + async deleteList(): Promise { + await this.args.list.destroyRecord(); } } ``` @@ -59,8 +59,8 @@ lists: baseTranslationKey: 'lists.delete_confirmation', title: (self, list) => self.intl.t('lists.delete_named', { htmlSafe: true, name: list.name }) }) -deleteList(list: List): Promise { - return list.destroyRecord(); +async deleteList(list: List): Promise { + await list.destroyRecord(); } ``` @@ -69,6 +69,8 @@ deleteList(list: List): Promise { - Put `@action` above `@confirmable`. The other way around fails an assertion. - Return the method's promise so the dialog waits for it, showing the primary action in loading state in the meantime. Cancel is ignored while it runs. An error closes the dialog and is rethrown to the caller. +- The method returns `void` or `Promise`. Its result is dropped once a dialog shows, so the types reject a method that returns a value. +- A route change or the destruction of the component or controller that opened the dialog closes it. Once the method has started, the call still waits for it and rethrows its error. ## Imperative form diff --git a/packages/test-app/tests/integration/patterns/confirmation-test.ts b/packages/test-app/tests/integration/patterns/confirmation-test.ts index 5737ea02f..9fce1ff33 100644 --- a/packages/test-app/tests/integration/patterns/confirmation-test.ts +++ b/packages/test-app/tests/integration/patterns/confirmation-test.ts @@ -292,6 +292,75 @@ module('Integration | Pattern | confirmation', function (hooks) { assert.dom(DIALOG).doesNotExist(); assert.true(subject.removeStub.notCalled); }); + + test('A route change while the method runs closes the dialog, and the call waits for the method', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + let resolveRemoval!: () => void; + subject.removeStub.returns(new Promise((resolve) => (resolveRemoval = resolve))); + let callSettled = false; + + const result = subject.remove('team').then(() => (callSettled = true)); + await settled(); + await click(CONFIRM); + (this.owner.lookup('service:router') as RouterService).trigger('routeWillChange'); + await settled(); + + assert.dom(DIALOG).doesNotExist(); + assert.false(callSettled); + + resolveRemoval(); + await result; + + assert.true(callSettled); + }); + + test('An error after a route change still rejects the call', async function (assert) { + const subject = buildSubject(this.owner, TEXTS); + let rejectRemoval!: (error: Error) => void; + subject.removeStub.returns(new Promise((_resolve, reject) => (rejectRemoval = reject))); + + const result = subject.remove('team'); + const rejection = assert.rejects(result, /Removal failed/); + await settled(); + await click(CONFIRM); + (this.owner.lookup('service:router') as RouterService).trigger('routeWillChange'); + await settled(); + + rejectRemoval(new Error('Removal failed')); + await rejection; + }); + + test('confirm() resolves true when its context is destroyed while onConfirm runs', async function (assert) { + const context = {}; + setOwner(context, this.owner); + let resolveAction!: () => void; + + const result = confirm(context, { + ...TEXTS, + onConfirm: () => new Promise((resolve) => (resolveAction = resolve)) + }); + await settled(); + await click(CONFIRM); + destroy(context); + await settled(); + + assert.dom(DIALOG).doesNotExist(); + + resolveAction(); + assert.true(await result); + }); + }); + + test('It only decorates methods that return void or a Promise', function (assert) { + class Typed { + // @ts-expect-error the result would be dropped once a dialog shows + @confirmable(TEXTS) + count(): Promise { + return Promise.resolve(1); + } + } + + assert.ok(Typed); }); test('It asserts when placed above @action', function (assert) { From 20e4ead295f61362a52bf8688b681d9abab98dd1 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Wed, 2 Dec 2026 09:56:09 +0100 Subject: [PATCH 03/10] Let confirmations keep the screen's data-control-name QA targets the data-control-name of the dialogs we migrate, so the pattern takes a dataControlName option and falls back on confirmable-dialog. --- .../src/patterns/confirmation.ts | 17 ++++++++++--- .../stories/patterns/Confirmation.mdx | 3 ++- .../integration/patterns/confirmation-test.ts | 25 +++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/oss-components/src/patterns/confirmation.ts b/packages/oss-components/src/patterns/confirmation.ts index f04e6fb20..e4c4259fa 100644 --- a/packages/oss-components/src/patterns/confirmation.ts +++ b/packages/oss-components/src/patterns/confirmation.ts @@ -27,6 +27,7 @@ type ConfirmOptions = Texts & { baseTranslationKey?: string; skin?: DialogSkin; icon?: string; + dataControlName?: string; onConfirm?: () => unknown; }; @@ -38,16 +39,20 @@ export type ConfirmableOptions = { cancelLabel?: Text; skin?: DialogSkin; icon?: string; + dataControlName?: string; when?: (self: T, ...args: A) => boolean; }; +const DEFAULT_DATA_CONTROL_NAME = 'confirmable-dialog'; + class ConfirmationState { @tracked loading: boolean = false; constructor( readonly texts: Texts, readonly skin: DialogSkin | undefined, - readonly icon: string | undefined + readonly icon: string | undefined, + readonly dataControlName: string ) {} } @@ -61,7 +66,7 @@ const ConfirmationDialog = setComponentTemplate( @icon={{@state.icon}} @mainAction={{hash label=@state.texts.confirmLabel action=@onConfirm loading=@state.loading}} @secondaryAction={{hash label=@state.texts.cancelLabel action=@onCancel}} - data-control-name="confirmable-dialog" + data-control-name={{@state.dataControlName}} /> `, { strictMode: true, scope: () => ({ OSSDialog, hash }) } @@ -120,7 +125,12 @@ export function confirm(context: object, options: ConfirmOptions): Promise((resolve, reject) => { let closed = false; @@ -222,6 +232,7 @@ export function confirmable(o cancelLabel: resolveText(options.cancelLabel, this, args), skin: options.skin, icon: options.icon, + dataControlName: options.dataControlName, onConfirm: () => original.apply(this, args) }).finally(() => openDialogs.delete(this)); diff --git a/packages/test-app/stories/patterns/Confirmation.mdx b/packages/test-app/stories/patterns/Confirmation.mdx index ee3c3a05a..3ee0dbf2f 100644 --- a/packages/test-app/stories/patterns/Confirmation.mdx +++ b/packages/test-app/stories/patterns/Confirmation.mdx @@ -50,6 +50,7 @@ lists: | `when` | `(self, ...args) => boolean`. When it returns `false`, the method runs right away, without a dialog. | | `skin` | Passed to `OSS::Dialog`: `alert` (default), `primary` or `error`. | | `icon` | Passed to `OSS::Dialog`. Defaults to `fa-warning`. | +| `dataControlName` | The `data-control-name` of the dialog. Defaults to `confirmable-dialog`. Pass the screen's existing name when migrating a hand-written dialog, so QA and test selectors keep working. | `self` is the decorated instance and `args` the method's arguments, both typed through the generics. A text that needs a value or markup comes from a function, here with an `htmlSafe` translation (OSS sanitizes those): @@ -91,7 +92,7 @@ async archiveSelection(): Promise { ## Testing -In tests, the dialog renders inside `#ember-testing`, so the usual test helpers find it: +In tests, the dialog renders inside `#ember-testing`, so the usual test helpers find it. Its `data-control-name` is `confirmable-dialog`, or the `dataControlName` you passed: ```ts await click('[data-control-name="delete-list"]'); diff --git a/packages/test-app/tests/integration/patterns/confirmation-test.ts b/packages/test-app/tests/integration/patterns/confirmation-test.ts index 9fce1ff33..4fb3c4d3b 100644 --- a/packages/test-app/tests/integration/patterns/confirmation-test.ts +++ b/packages/test-app/tests/integration/patterns/confirmation-test.ts @@ -140,6 +140,31 @@ module('Integration | Pattern | confirmation', function (hooks) { assert.throws(() => subject.remove('team'), /A title, a confirmLabel and a cancelLabel are mandatory/); }); + + test('A dataControlName replaces the default data-control-name', async function (assert) { + const subject = buildSubject(this.owner, { ...TEXTS, dataControlName: 'member-removal-dialog' }); + + subject.remove('team'); + await settled(); + + assert.dom('[data-control-name="member-removal-dialog"]').exists(); + assert.dom(DIALOG).doesNotExist(); + + await click(CANCEL); + }); + + test('confirm() accepts a dataControlName', async function (assert) { + const context = {}; + setOwner(context, this.owner); + + const result = confirm(context, { ...TEXTS, dataControlName: 'member-removal-dialog' }); + await settled(); + + assert.dom('[data-control-name="member-removal-dialog"]').exists(); + + await click(CANCEL); + assert.false(await result); + }); }); module('Flow', () => { From ffb25be36a8b6129965a1af91aee6c8c0a2a6bc8 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Wed, 2 Dec 2026 10:15:42 +0100 Subject: [PATCH 04/10] Develop against ember-intl 6.5.6 With @glimmer/component 2, ember-intl 6.4's private SafeString type no longer resolves, which turns intl.t's return type, and the confirmation texts typed from it, into any. 6.5 types it from @ember/template. --- packages/oss-components/package.json | 2 +- packages/test-app/package.json | 2 +- pnpm-lock.yaml | 255 +++++++-------------------- 3 files changed, 65 insertions(+), 194 deletions(-) diff --git a/packages/oss-components/package.json b/packages/oss-components/package.json index 3618aa559..97b9c2009 100644 --- a/packages/oss-components/package.json +++ b/packages/oss-components/package.json @@ -69,7 +69,7 @@ "ember-cli-babel": "^8.2.0", "ember-cli-code-coverage": "^3.1.0", "ember-cli-htmlbars": "^7.0.1", - "ember-intl": "^6.4.0", + "ember-intl": "^6.5.6", "ember-source": "~6.12.1", "ember-template-lint": "^3.15.0", "eslint": "^10.5.0", diff --git a/packages/test-app/package.json b/packages/test-app/package.json index 32aed0dd9..e217ebb19 100644 --- a/packages/test-app/package.json +++ b/packages/test-app/package.json @@ -54,7 +54,7 @@ "ember-cli-babel": "^8.2.0", "ember-cli-code-coverage": "^3.1.0", "ember-cli-htmlbars": "^7.0.1", - "ember-intl": "^6.4.0", + "ember-intl": "^6.5.6", "ember-load-initializers": "^3.0.1", "ember-modifier": "^3.2.7", "ember-qunit": "^9.0.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8b00d3abe..01c1999aa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -172,8 +172,8 @@ importers: specifier: ^7.0.1 version: 7.0.1(@babel/core@7.29.13)(ember-source@6.12.1(@glimmer/component@2.2.1)(rsvp@4.8.5)) ember-intl: - specifier: ^6.4.0 - version: 6.4.0(@babel/core@7.29.13)(@glint/template@1.5.2)(typescript@5.9.3)(webpack@5.112.2(postcss@8.5.32)) + specifier: ^6.5.6 + version: 6.5.6(@ember/test-helpers@5.8.0(@babel/core@7.29.13))(@glint/template@1.5.2)(typescript@5.9.3)(webpack@5.112.2(postcss@8.5.32)) ember-source: specifier: ~6.12.1 version: 6.12.1(@glimmer/component@2.2.1)(rsvp@4.8.5) @@ -337,8 +337,8 @@ importers: specifier: ^7.0.1 version: 7.0.1(@babel/core@7.29.13)(ember-source@6.12.1(@glimmer/component@2.2.1)(rsvp@4.8.5)) ember-intl: - specifier: ^6.4.0 - version: 6.4.0(@babel/core@7.29.13)(@glint/template@1.5.2)(typescript@5.9.3)(webpack@5.112.2(postcss@8.5.32)) + specifier: ^6.5.6 + version: 6.5.6(@ember/test-helpers@5.8.0(@babel/core@7.29.13))(@glint/template@1.5.2)(typescript@5.9.3)(webpack@5.112.2(postcss@8.5.32)) ember-load-initializers: specifier: ^3.0.1 version: 3.0.1(ember-source@6.12.1(@glimmer/component@2.2.1)(rsvp@4.8.5)) @@ -1968,10 +1968,6 @@ packages: resolution: {integrity: sha512-rgR9yxSaAJ+bcsi/XroT/S2AfPiIWloXAnrdfYSCms9ivVju0ishu/wW0J21Ho6+ZOR1r7RyeRbjiRuF87ix5Q==} engines: {node: '>=20'} - '@mrmlnc/readdir-enhanced@2.2.1': - resolution: {integrity: sha512-bPHp6Ji8b41szTOcaP63VlnbbO5Ny6dwAATtY6JTjh5N2OLrb5Qk/Th5cRkRQhkWCt+EJsYrNB0MiL+Gpn6e3g==} - engines: {node: '>=4'} - '@napi-rs/wasm-runtime@1.2.6': resolution: {integrity: sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==} engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} @@ -1990,10 +1986,6 @@ packages: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} - '@nodelib/fs.stat@1.1.3': - resolution: {integrity: sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==} - engines: {node: '>= 6'} - '@nodelib/fs.stat@2.0.5': resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} engines: {node: '>= 8'} @@ -3978,10 +3970,6 @@ packages: broccoli-kitchen-sink-helpers@0.3.1: resolution: {integrity: sha512-gqYnKSJxBSjj/uJqeuRAzYVbmjWhG0mOZ8jrp6+fnUIOgLN6MvI7XxBECDHkYMIFPJ8Smf4xaI066Q2FqQDnXg==} - broccoli-merge-files@0.8.0: - resolution: {integrity: sha512-S6dXHECbDkr7YMuCitAAQT8EZeW/kXom0Y8+QmQfiSkWspkKDGrr4vXgEZJjWqfa/FSx/Y18NEEOuMmbIW+XNQ==} - engines: {node: '>=8.0.0'} - broccoli-merge-trees@3.0.2: resolution: {integrity: sha512-ZyPAwrOdlCddduFbsMyyFzJUrvW6b04pMvDiAQZrCwghlvgowJDY+EfoXn+eR1RRA5nmGHJ+B68T63VnpRiT1A==} engines: {node: '>=6.0.0'} @@ -4137,9 +4125,6 @@ packages: resolution: {integrity: sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==} engines: {node: '>= 0.4'} - call-me-maybe@1.0.2: - resolution: {integrity: sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==} - callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} engines: {node: '>=6'} @@ -4850,10 +4835,6 @@ packages: resolution: {integrity: sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==} engines: {node: '>=10'} - define-data-property@1.1.2: - resolution: {integrity: sha512-SRtsSqsDbgpJBbW3pABMCOt6rQyeM8s8RiyeSN8jYG8sYmt/kGJejbydttUsnDs1tadr19tvhT4ShwMyoqAm4g==} - engines: {node: '>= 0.4'} - define-data-property@1.1.4: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} @@ -5153,12 +5134,15 @@ packages: peerDependencies: ember-source: ^3.25.0 || >=4.0.0 - ember-intl@6.4.0: - resolution: {integrity: sha512-BXxscjgoqzXQ6tUSV8aJsQcUAIcfqLJnNjegarFWdBBHLEOffQ8xARhvQC0hW40zGi/RHFEyTTx7vbiCPGtP1A==} + ember-intl@6.5.6: + resolution: {integrity: sha512-1CoQDiLu/aIOG8nHO0rSXpFaE+vgVcYOoOVrXJZAvUakhB+MNYuJ7+++iR1sfv5vIJiOt7XiNyK9CMhlxsvuwQ==} engines: {node: 16.* || >= 18} peerDependencies: + '@ember/test-helpers': ^2.9.4 || ^3.2.0 || ^4.0.0 typescript: ^4.8.0 || ^5.0.0 peerDependenciesMeta: + '@ember/test-helpers': + optional: true typescript: optional: true @@ -5620,10 +5604,6 @@ packages: fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} - fast-glob@2.2.7: - resolution: {integrity: sha512-g1KuQwHOZAmOZMuBtHdxDtju+T2RT8jgCC9aANsbpdiDDTSnjgfuVsIBNKbUeJI3oKMRExcfNDtJl4OhbffMsw==} - engines: {node: '>=4.0.0'} - fast-glob@3.3.3: resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==} engines: {node: '>=8.6.0'} @@ -6005,9 +5985,6 @@ packages: git-url-parse@13.1.0: resolution: {integrity: sha512-5FvPJP/70WkIprlUZ33bm4UAaFdjcLkJLpWft1BeZKqwR0uhhNGoKwlUaPtVb4LxCSQ++erHapRak9kWGj+FCA==} - glob-parent@3.1.0: - resolution: {integrity: sha512-E8Ak/2+dZY6fnzlR7+ueWvhsH1SjHr4jjss4YS/h4py44jY9MhK/VFdaZJAWDz6BbL21KeteKxFSFpq8OS5gVA==} - glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -6016,9 +5993,6 @@ packages: resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==} engines: {node: '>=10.13.0'} - glob-to-regexp@0.3.0: - resolution: {integrity: sha512-Iozmtbqv0noj0uDDqoL0zNq0VBEfK2YFoMAZoxJe4cwphvLR+JskfF30QhXHOR4m3KrE6NLRYw+U9MRXvifyig==} - glob@10.5.0: resolution: {integrity: sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==} deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me @@ -6148,9 +6122,6 @@ packages: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} - has-property-descriptors@1.0.1: - resolution: {integrity: sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==} - has-property-descriptors@1.0.2: resolution: {integrity: sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==} @@ -6544,10 +6515,6 @@ packages: resolution: {integrity: sha512-UCFta9F9rWFSavp9H3zHEHrARUfZbdJvmHKeEpds4BK3v7W2LdXoNypMtXXi5w5YBDEBCTYmbI+vsSwI8LYJaQ==} engines: {node: '>=0.8'} - is-glob@3.1.0: - resolution: {integrity: sha512-UFpDDrPgM6qpnFNI+rh/p3bUaq9hKLZN8bMUWzxmcnZVS3omf4IPK+BrewlnWjO1WmUsMYuSjKh4UJuV4+Lqmw==} - engines: {node: '>=0.10.0'} - is-glob@4.0.3: resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} engines: {node: '>=0.10.0'} @@ -7107,9 +7074,6 @@ packages: lodash.debounce@4.0.8: resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==} - lodash.defaults@4.2.0: - resolution: {integrity: sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==} - lodash.escaperegexp@4.1.2: resolution: {integrity: sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==} @@ -7936,10 +7900,6 @@ packages: resolution: {integrity: sha512-Mr5KC5efvAK5VUptYEIopP1bakB85k2IWXaRC0rsh1uwn1L6M0LVml8OIQ4Gudg4oyZakf7FmeRLkMMtZW1i5A==} engines: {node: '>=12'} - p-event@2.3.1: - resolution: {integrity: sha512-NQCqOFhbpVTMX4qMe8PF8lbGtzZ+LCiN7pcNrb/413Na7+TRoe1xkKUzuWa/YEJdGQ0FvKtj35EEbDoVPO2kbA==} - engines: {node: '>=6'} - p-finally@1.0.0: resolution: {integrity: sha512-LICb2p9CB7FS+0eR1oqWnHhp0FljGLZCWBE9aix0Uye9W8LTQPwMTYVGWQWIw9RdQiDg4+epXQODwIYJtSJaow==} engines: {node: '>=4'} @@ -7988,10 +7948,6 @@ packages: resolution: {integrity: sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==} engines: {node: '>=8'} - p-timeout@2.0.1: - resolution: {integrity: sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA==} - engines: {node: '>=4'} - p-timeout@3.2.0: resolution: {integrity: sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==} engines: {node: '>=8'} @@ -8083,10 +8039,6 @@ packages: resolution: {integrity: sha512-XHXfu/yOQRy9vYOtUDVMN60OEJjW013GoObG1o+xwQTpB9eYJX/BjXMsdW13ZDPruFhYYn0AG22w0xgQMwl3Nw==} engines: {node: '>=0.10.0'} - path-dirname@1.0.2: - resolution: {integrity: sha512-ALzNPpyNq9AqXMBjeymIjFDAkAFH06mHJH/cSBHAgU0s4vfpBn6b2nf8tiRLvagKD8RbTpq2FKTBg7cl9l3c7Q==} - deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. - path-exists@3.0.0: resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==} engines: {node: '>=4'} @@ -9062,10 +9014,6 @@ packages: resolution: {integrity: sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==} engines: {node: '>= 18'} - set-function-length@1.2.0: - resolution: {integrity: sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==} - engines: {node: '>= 0.4'} - set-function-length@1.2.2: resolution: {integrity: sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==} engines: {node: '>= 0.4'} @@ -11297,7 +11245,7 @@ snapshots: '@types/eslint': 7.29.0 fs-extra: 9.1.0 slash: 3.0.0 - tslib: 2.8.1 + tslib: 2.9.1 '@ember-tooling/blueprint-blueprint@0.2.1': {} @@ -11652,7 +11600,7 @@ snapshots: '@emnapi/core@2.0.0-beta.2': dependencies: '@emnapi/wasi-threads': 2.2.0 - tslib: 2.8.1 + tslib: 2.9.1 optional: true '@emnapi/runtime@1.10.0': @@ -11672,7 +11620,7 @@ snapshots: '@emnapi/runtime@2.0.0-beta.2': dependencies: - tslib: 2.8.1 + tslib: 2.9.1 optional: true '@emnapi/wasi-threads@1.2.1': @@ -11687,7 +11635,7 @@ snapshots: '@emnapi/wasi-threads@2.2.0': dependencies: - tslib: 2.8.1 + tslib: 2.9.1 optional: true '@esbuild/aix-ppc64@0.25.12': @@ -11828,34 +11776,34 @@ snapshots: '@formatjs/ecma402-abstract@1.18.2': dependencies: '@formatjs/intl-localematcher': 0.5.4 - tslib: 2.8.1 + tslib: 2.9.1 '@formatjs/fast-memoize@2.2.0': dependencies: - tslib: 2.8.1 + tslib: 2.9.1 '@formatjs/icu-messageformat-parser@2.7.6': dependencies: '@formatjs/ecma402-abstract': 1.18.2 '@formatjs/icu-skeleton-parser': 1.8.0 - tslib: 2.8.1 + tslib: 2.9.1 '@formatjs/icu-skeleton-parser@1.8.0': dependencies: '@formatjs/ecma402-abstract': 1.18.2 - tslib: 2.8.1 + tslib: 2.9.1 '@formatjs/intl-displaynames@6.6.6': dependencies: '@formatjs/ecma402-abstract': 1.18.2 '@formatjs/intl-localematcher': 0.5.4 - tslib: 2.8.1 + tslib: 2.9.1 '@formatjs/intl-listformat@7.5.5': dependencies: '@formatjs/ecma402-abstract': 1.18.2 '@formatjs/intl-localematcher': 0.5.4 - tslib: 2.8.1 + tslib: 2.9.1 '@formatjs/intl-localematcher@0.5.4': dependencies: @@ -11869,7 +11817,7 @@ snapshots: '@formatjs/intl-displaynames': 6.6.6 '@formatjs/intl-listformat': 7.5.5 intl-messageformat: 10.5.11 - tslib: 2.8.1 + tslib: 2.9.1 optionalDependencies: typescript: 5.9.3 @@ -12238,11 +12186,6 @@ snapshots: '@modelcontextprotocol/core': 2.4.0 zod: 4.6.7 - '@mrmlnc/readdir-enhanced@2.2.1': - dependencies: - call-me-maybe: 1.0.2 - glob-to-regexp: 0.3.0 - '@napi-rs/wasm-runtime@1.2.6(@emnapi/core@1.11.0)(@emnapi/runtime@1.11.0)': dependencies: '@emnapi/core': 1.11.0 @@ -12276,8 +12219,6 @@ snapshots: '@nodelib/fs.stat': 2.0.5 run-parallel: 1.2.0 - '@nodelib/fs.stat@1.1.3': {} - '@nodelib/fs.stat@2.0.5': {} '@nodelib/fs.walk@1.2.8': @@ -13042,8 +12983,8 @@ snapshots: '@types/ember__array': 4.0.10(@babel/core@7.29.13) '@types/ember__component': 4.0.22(@babel/core@7.29.13) '@types/ember__controller': 4.0.12(@babel/core@7.29.13) - '@types/ember__debug': 4.0.8(@babel/core@7.29.13) - '@types/ember__engine': 4.0.11(@babel/core@7.29.13) + '@types/ember__debug': 4.0.8 + '@types/ember__engine': 4.0.11 '@types/ember__error': 4.0.6 '@types/ember__object': 4.0.12(@babel/core@7.29.13) '@types/ember__polyfills': 4.0.6 @@ -13063,8 +13004,8 @@ snapshots: '@types/ember__array': 4.0.10(@babel/core@7.29.13) '@types/ember__component': 4.0.22(@babel/core@7.29.13) '@types/ember__controller': 4.0.12(@babel/core@7.29.13) - '@types/ember__debug': 4.0.8(@babel/core@7.29.13) - '@types/ember__engine': 4.0.11(@babel/core@7.29.13) + '@types/ember__debug': 4.0.8 + '@types/ember__engine': 4.0.11 '@types/ember__error': 4.0.6 '@types/ember__object': 4.0.12(@babel/core@7.29.13) '@types/ember__polyfills': 4.0.6 @@ -13085,7 +13026,7 @@ snapshots: dependencies: '@glimmer/component': 1.1.2(@babel/core@7.29.13) '@types/ember': 4.0.11 - '@types/ember__engine': 4.0.11(@babel/core@7.29.13) + '@types/ember__engine': 4.0.11 '@types/ember__object': 4.0.12(@babel/core@7.29.13) '@types/ember__owner': 4.0.9 '@types/ember__routing': 4.0.21(@babel/core@7.29.13) @@ -13120,22 +13061,16 @@ snapshots: - supports-color optional: true - '@types/ember__debug@4.0.8(@babel/core@7.29.13)': + '@types/ember__debug@4.0.8': dependencies: '@types/ember__object': 4.0.12(@babel/core@7.29.13) '@types/ember__owner': 4.0.9 - transitivePeerDependencies: - - '@babel/core' - - supports-color optional: true - '@types/ember__engine@4.0.11(@babel/core@7.29.13)': + '@types/ember__engine@4.0.11': dependencies: '@types/ember__object': 4.0.12(@babel/core@7.29.13) '@types/ember__owner': 4.0.9 - transitivePeerDependencies: - - '@babel/core' - - supports-color optional: true '@types/ember__error@4.0.6': @@ -13783,7 +13718,7 @@ snapshots: array-buffer-byte-length@1.0.1: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 is-array-buffer: 3.0.4 array-buffer-byte-length@1.0.2: @@ -13812,7 +13747,7 @@ snapshots: arraybuffer.prototype.slice@1.0.3: dependencies: array-buffer-byte-length: 1.0.1 - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 es-abstract: 1.22.3 es-errors: 1.3.0 @@ -14358,15 +14293,6 @@ snapshots: glob: 5.0.15 mkdirp: 0.5.6 - broccoli-merge-files@0.8.0: - dependencies: - broccoli-plugin: 1.3.1 - fast-glob: 2.2.7 - lodash.defaults: 4.2.0 - p-event: 2.3.1 - transitivePeerDependencies: - - supports-color - broccoli-merge-trees@3.0.2: dependencies: broccoli-plugin: 1.3.1 @@ -14666,7 +14592,7 @@ snapshots: es-errors: 1.3.0 function-bind: 1.1.2 get-intrinsic: 1.3.0 - set-function-length: 1.2.0 + set-function-length: 1.2.2 call-bind@1.0.9: dependencies: @@ -14680,8 +14606,6 @@ snapshots: call-bind-apply-helpers: 1.0.2 get-intrinsic: 1.3.0 - call-me-maybe@1.0.2: {} - callsites@3.1.0: {} camelcase@5.3.1: {} @@ -15240,13 +15164,6 @@ snapshots: defer-to-connect@2.0.1: {} - define-data-property@1.1.2: - dependencies: - es-errors: 1.3.0 - get-intrinsic: 1.3.0 - gopd: 1.2.0 - has-property-descriptors: 1.0.1 - define-data-property@1.1.4: dependencies: es-define-property: 1.0.1 @@ -15259,8 +15176,8 @@ snapshots: define-properties@1.2.1: dependencies: - define-data-property: 1.1.2 - has-property-descriptors: 1.0.1 + define-data-property: 1.1.4 + has-property-descriptors: 1.0.2 object-keys: 1.1.1 define-property@0.2.5: @@ -15831,13 +15748,13 @@ snapshots: transitivePeerDependencies: - supports-color - ember-intl@6.4.0(@babel/core@7.29.13)(@glint/template@1.5.2)(typescript@5.9.3)(webpack@5.112.2(postcss@8.5.32)): + ember-intl@6.5.6(@ember/test-helpers@5.8.0(@babel/core@7.29.13))(@glint/template@1.5.2)(typescript@5.9.3)(webpack@5.112.2(postcss@8.5.32)): dependencies: + '@babel/core': 7.29.13 '@formatjs/icu-messageformat-parser': 2.7.6 '@formatjs/intl': 2.10.0(typescript@5.9.3) broccoli-caching-writer: 3.0.3 broccoli-funnel: 3.0.8 - broccoli-merge-files: 0.8.0 broccoli-merge-trees: 4.2.0 broccoli-source: 3.0.1 broccoli-stew: 3.0.0 @@ -15854,9 +15771,9 @@ snapshots: json-stable-stringify: 1.1.1 silent-error: 1.1.1 optionalDependencies: + '@ember/test-helpers': 5.8.0(@babel/core@7.29.13) typescript: 5.9.3 transitivePeerDependencies: - - '@babel/core' - '@glint/template' - supports-color - webpack @@ -16127,7 +16044,7 @@ snapshots: array-buffer-byte-length: 1.0.1 arraybuffer.prototype.slice: 1.0.3 available-typed-arrays: 1.0.6 - call-bind: 1.0.6 + call-bind: 1.0.9 es-set-tostringtag: 2.0.2 es-to-primitive: 1.2.1 function.prototype.name: 1.1.6 @@ -16135,7 +16052,7 @@ snapshots: get-symbol-description: 1.0.1 globalthis: 1.0.3 gopd: 1.2.0 - has-property-descriptors: 1.0.1 + has-property-descriptors: 1.0.2 has-proto: 1.0.1 has-symbols: 1.1.0 hasown: 2.0.4 @@ -16229,7 +16146,7 @@ snapshots: es-get-iterator@1.1.3: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 get-intrinsic: 1.3.0 has-symbols: 1.1.0 is-arguments: 1.2.0 @@ -16684,17 +16601,6 @@ snapshots: fast-deep-equal@3.1.3: {} - fast-glob@2.2.7: - dependencies: - '@mrmlnc/readdir-enhanced': 2.2.1 - '@nodelib/fs.stat': 1.1.3 - glob-parent: 3.1.0 - is-glob: 4.0.3 - merge2: 1.4.1 - micromatch: 3.1.10 - transitivePeerDependencies: - - supports-color - fast-glob@3.3.3: dependencies: '@nodelib/fs.stat': 2.0.5 @@ -17059,7 +16965,7 @@ snapshots: function.prototype.name@1.1.6: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 es-abstract: 1.22.3 functions-have-names: 1.2.3 @@ -17129,7 +17035,7 @@ snapshots: get-symbol-description@1.0.1: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 es-errors: 1.3.0 get-symbol-description@1.1.0: @@ -17167,11 +17073,6 @@ snapshots: dependencies: git-up: 7.0.0 - glob-parent@3.1.0: - dependencies: - is-glob: 3.1.0 - path-dirname: 1.0.2 - glob-parent@5.1.2: dependencies: is-glob: 4.0.3 @@ -17180,8 +17081,6 @@ snapshots: dependencies: is-glob: 4.0.3 - glob-to-regexp@0.3.0: {} - glob@10.5.0: dependencies: foreground-child: 3.3.1 @@ -17357,10 +17256,6 @@ snapshots: has-flag@4.0.0: {} - has-property-descriptors@1.0.1: - dependencies: - get-intrinsic: 1.3.0 - has-property-descriptors@1.0.2: dependencies: es-define-property: 1.0.1 @@ -17650,7 +17545,7 @@ snapshots: '@formatjs/ecma402-abstract': 1.18.2 '@formatjs/fast-memoize': 2.2.0 '@formatjs/icu-messageformat-parser': 2.7.6 - tslib: 2.8.1 + tslib: 2.9.1 invert-kv@3.0.1: {} @@ -17671,7 +17566,7 @@ snapshots: is-array-buffer@3.0.4: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 get-intrinsic: 1.3.0 is-array-buffer@3.0.5: @@ -17700,7 +17595,7 @@ snapshots: is-boolean-object@1.1.2: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 has-tostringtag: 1.0.2 is-boolean-object@1.2.2: @@ -17783,10 +17678,6 @@ snapshots: is-git-url@1.0.0: {} - is-glob@3.1.0: - dependencies: - is-extglob: 2.1.1 - is-glob@4.0.3: dependencies: is-extglob: 2.1.1 @@ -17851,7 +17742,7 @@ snapshots: is-regex@1.1.4: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 has-tostringtag: 1.0.2 is-regex@1.2.1: @@ -17865,7 +17756,7 @@ snapshots: is-shared-array-buffer@1.0.2: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 is-shared-array-buffer@1.0.4: dependencies: @@ -17926,7 +17817,7 @@ snapshots: is-weakref@1.0.2: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 is-weakref@1.1.1: dependencies: @@ -18139,7 +18030,7 @@ snapshots: json-stable-stringify@1.1.1: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 isarray: 2.0.5 jsonify: 0.0.1 object-keys: 1.1.1 @@ -18335,8 +18226,6 @@ snapshots: lodash.debounce@4.0.8: {} - lodash.defaults@4.2.0: {} - lodash.escaperegexp@4.1.2: {} lodash.isplainobject@4.0.6: {} @@ -19127,7 +19016,7 @@ snapshots: object.assign@4.1.5: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 has-symbols: 1.1.0 object-keys: 1.1.1 @@ -19366,10 +19255,6 @@ snapshots: p-defer@4.0.1: {} - p-event@2.3.1: - dependencies: - p-timeout: 2.0.1 - p-finally@1.0.0: {} p-finally@2.0.1: @@ -19416,10 +19301,6 @@ snapshots: eventemitter3: 4.0.7 p-timeout: 3.2.0 - p-timeout@2.0.1: - dependencies: - p-finally: 1.0.0 - p-timeout@3.2.0: dependencies: p-finally: 1.0.0 @@ -19516,8 +19397,6 @@ snapshots: pascalcase@0.1.1: {} - path-dirname@1.0.2: {} - path-exists@3.0.0: {} path-exists@4.0.0: {} @@ -20057,7 +19936,7 @@ snapshots: regexp.prototype.flags@1.5.1: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 set-function-name: 2.0.1 @@ -20438,7 +20317,7 @@ snapshots: safe-array-concat@1.1.0: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 get-intrinsic: 1.3.0 has-symbols: 1.1.0 isarray: 2.0.5 @@ -20464,7 +20343,7 @@ snapshots: safe-regex-test@1.0.2: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 get-intrinsic: 1.3.0 is-regex: 1.1.4 @@ -20611,14 +20490,6 @@ snapshots: transitivePeerDependencies: - supports-color - set-function-length@1.2.0: - dependencies: - define-data-property: 1.1.2 - function-bind: 1.1.2 - get-intrinsic: 1.3.0 - gopd: 1.2.0 - has-property-descriptors: 1.0.1 - set-function-length@1.2.2: dependencies: define-data-property: 1.1.4 @@ -20630,9 +20501,9 @@ snapshots: set-function-name@2.0.1: dependencies: - define-data-property: 1.1.2 + define-data-property: 1.1.4 functions-have-names: 1.2.3 - has-property-descriptors: 1.0.1 + has-property-descriptors: 1.0.2 set-function-name@2.0.2: dependencies: @@ -20976,7 +20847,7 @@ snapshots: string.prototype.matchall@4.0.10: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 es-abstract: 1.22.3 get-intrinsic: 1.3.0 @@ -21005,7 +20876,7 @@ snapshots: string.prototype.trim@1.2.8: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 es-abstract: 1.22.3 @@ -21018,13 +20889,13 @@ snapshots: string.prototype.trimend@1.0.7: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 es-abstract: 1.22.3 string.prototype.trimstart@1.0.7: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 define-properties: 1.2.1 es-abstract: 1.22.3 @@ -21419,7 +21290,7 @@ snapshots: typed-array-buffer@1.0.0: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 get-intrinsic: 1.3.0 is-typed-array: 1.1.13 @@ -21431,7 +21302,7 @@ snapshots: typed-array-byte-length@1.0.0: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 for-each: 0.3.3 has-proto: 1.0.1 is-typed-array: 1.1.13 @@ -21447,7 +21318,7 @@ snapshots: typed-array-byte-offset@1.0.0: dependencies: available-typed-arrays: 1.0.6 - call-bind: 1.0.6 + call-bind: 1.0.9 for-each: 0.3.3 has-proto: 1.0.1 is-typed-array: 1.1.13 @@ -21463,7 +21334,7 @@ snapshots: typed-array-length@1.0.4: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 for-each: 0.3.3 is-typed-array: 1.1.13 @@ -21520,7 +21391,7 @@ snapshots: unbox-primitive@1.0.2: dependencies: - call-bind: 1.0.6 + call-bind: 1.0.9 has-bigints: 1.0.2 has-symbols: 1.1.0 which-boxed-primitive: 1.0.2 @@ -21918,7 +21789,7 @@ snapshots: which-typed-array@1.1.14: dependencies: available-typed-arrays: 1.0.6 - call-bind: 1.0.6 + call-bind: 1.0.9 for-each: 0.3.3 gopd: 1.2.0 has-tostringtag: 1.0.2 From c02d1506767623e465bfa7a6c0c708a2006648eb Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Wed, 2 Dec 2026 10:39:31 +0100 Subject: [PATCH 05/10] Use promise chains in the confirmation docs --- .../test-app/stories/patterns/Confirmation.mdx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/test-app/stories/patterns/Confirmation.mdx b/packages/test-app/stories/patterns/Confirmation.mdx index 3ee0dbf2f..b9779c3dd 100644 --- a/packages/test-app/stories/patterns/Confirmation.mdx +++ b/packages/test-app/stories/patterns/Confirmation.mdx @@ -26,8 +26,8 @@ export default class ListActions extends Component { baseTranslationKey: 'lists.delete_confirmation', when: (self) => self.args.list.itemsCount > 0 }) - async deleteList(): Promise { - await this.args.list.destroyRecord(); + deleteList(): Promise { + return this.args.list.destroyRecord().then(() => {}); } } ``` @@ -60,8 +60,8 @@ lists: baseTranslationKey: 'lists.delete_confirmation', title: (self, list) => self.intl.t('lists.delete_named', { htmlSafe: true, name: list.name }) }) -async deleteList(list: List): Promise { - await list.destroyRecord(); +deleteList(list: List): Promise { + return list.destroyRecord().then(() => {}); } ``` @@ -70,7 +70,7 @@ async deleteList(list: List): Promise { - Put `@action` above `@confirmable`. The other way around fails an assertion. - Return the method's promise so the dialog waits for it, showing the primary action in loading state in the meantime. Cancel is ignored while it runs. An error closes the dialog and is rethrown to the caller. -- The method returns `void` or `Promise`. Its result is dropped once a dialog shows, so the types reject a method that returns a value. +- The method returns `void` or `Promise`. Its result is dropped once a dialog shows, so the types reject a method that returns a value: end a model promise with `.then(() => {})`. - A route change or the destruction of the component or controller that opened the dialog closes it. Once the method has started, the call still waits for it and rethrows its error. ## Imperative form @@ -80,13 +80,13 @@ async deleteList(list: List): Promise { ```ts import { confirm } from '@upfluence/oss-components/patterns/confirmation'; -async archiveSelection(): Promise { - const archived = await confirm(this, { +archiveSelection(): Promise { + return confirm(this, { baseTranslationKey: 'lists.archive_confirmation', onConfirm: () => this.lists.archive(this.selection) + }).then((archived) => { + if (archived) this.selection = []; }); - - if (archived) this.selection = []; } ``` From 873b20f8acf276007d6143843bb649dc6ee16600 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Wed, 2 Dec 2026 10:45:14 +0100 Subject: [PATCH 06/10] Let decorated methods return anything The primitive drops what the method resolves with, so it shouldn't constrain it. The docs say the confirmed call resolves without the result. --- .../oss-components/src/patterns/confirmation.ts | 4 ++-- .../test-app/stories/patterns/Confirmation.mdx | 10 +++++----- .../integration/patterns/confirmation-test.ts | 16 +++++++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/oss-components/src/patterns/confirmation.ts b/packages/oss-components/src/patterns/confirmation.ts index e4c4259fa..d900826cc 100644 --- a/packages/oss-components/src/patterns/confirmation.ts +++ b/packages/oss-components/src/patterns/confirmation.ts @@ -202,7 +202,7 @@ function resolveText(text: Text | undefined, self: } export function confirmable(options: ConfirmableOptions) { - return function void | Promise>( + return function unknown>( _target: T, key: string, descriptor: TypedPropertyDescriptor @@ -216,7 +216,7 @@ export function confirmable(o const openDialogs = new WeakMap>(); - descriptor.value = function (this: T, ...args: A): void | Promise { + descriptor.value = function (this: T, ...args: A): unknown { if (options.when && !options.when(this, ...args)) { return original.apply(this, args); } diff --git a/packages/test-app/stories/patterns/Confirmation.mdx b/packages/test-app/stories/patterns/Confirmation.mdx index b9779c3dd..8aa980d6d 100644 --- a/packages/test-app/stories/patterns/Confirmation.mdx +++ b/packages/test-app/stories/patterns/Confirmation.mdx @@ -26,8 +26,8 @@ export default class ListActions extends Component { baseTranslationKey: 'lists.delete_confirmation', when: (self) => self.args.list.itemsCount > 0 }) - deleteList(): Promise { - return this.args.list.destroyRecord().then(() => {}); + deleteList(): Promise { + return this.args.list.destroyRecord(); } } ``` @@ -60,8 +60,8 @@ lists: baseTranslationKey: 'lists.delete_confirmation', title: (self, list) => self.intl.t('lists.delete_named', { htmlSafe: true, name: list.name }) }) -deleteList(list: List): Promise { - return list.destroyRecord().then(() => {}); +deleteList(list: List): Promise { + return list.destroyRecord(); } ``` @@ -70,7 +70,7 @@ deleteList(list: List): Promise { - Put `@action` above `@confirmable`. The other way around fails an assertion. - Return the method's promise so the dialog waits for it, showing the primary action in loading state in the meantime. Cancel is ignored while it runs. An error closes the dialog and is rethrown to the caller. -- The method returns `void` or `Promise`. Its result is dropped once a dialog shows, so the types reject a method that returns a value: end a model promise with `.then(() => {})`. +- The method can return anything. Once a dialog shows, the call resolves when the dialog closes, without the method's result, so don't read it. - A route change or the destruction of the component or controller that opened the dialog closes it. Once the method has started, the call still waits for it and rethrows its error. ## Imperative form diff --git a/packages/test-app/tests/integration/patterns/confirmation-test.ts b/packages/test-app/tests/integration/patterns/confirmation-test.ts index 4fb3c4d3b..20fbf102e 100644 --- a/packages/test-app/tests/integration/patterns/confirmation-test.ts +++ b/packages/test-app/tests/integration/patterns/confirmation-test.ts @@ -376,16 +376,22 @@ module('Integration | Pattern | confirmation', function (hooks) { }); }); - test('It only decorates methods that return void or a Promise', function (assert) { - class Typed { - // @ts-expect-error the result would be dropped once a dialog shows - @confirmable(TEXTS) + test('A confirmed call resolves without the method result', async function (assert) { + class Counter { + @confirmable(TEXTS) count(): Promise { return Promise.resolve(1); } } - assert.ok(Typed); + const counter = new Counter(); + setOwner(counter, this.owner); + + const result = counter.count(); + await settled(); + await click(CONFIRM); + + assert.strictEqual(await result, undefined); }); test('It asserts when placed above @action', function (assert) { From 6cf40aa8049d37d3fece435fb1c141d6528f2323 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Wed, 2 Dec 2026 10:45:29 +0100 Subject: [PATCH 07/10] Release 5.2.0-beta.0 --- packages/oss-components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/oss-components/package.json b/packages/oss-components/package.json index 97b9c2009..e1cb4bad3 100644 --- a/packages/oss-components/package.json +++ b/packages/oss-components/package.json @@ -1,6 +1,6 @@ { "name": "@upfluence/oss-components", - "version": "5.1.3", + "version": "5.2.0-beta.0", "repository": "https://github.com/upfluence/oss-components", "publishConfig": { "registry": "https://npm.pkg.github.com", From 536d18dcd18c795e1f5c1ffc47d9118808c739de Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Thu, 3 Dec 2026 19:50:19 +0100 Subject: [PATCH 08/10] Move the confirmation handlers to a private utils file --- packages/oss-components/package.json | 3 +- packages/oss-components/rollup.config.mjs | 3 +- .../src/patterns/confirmation.ts | 93 ++++-------------- .../patterns/private/confirmation-utils.ts | 96 +++++++++++++++++++ 4 files changed, 120 insertions(+), 75 deletions(-) create mode 100644 packages/oss-components/src/patterns/private/confirmation-utils.ts diff --git a/packages/oss-components/package.json b/packages/oss-components/package.json index e1cb4bad3..77bd24da6 100644 --- a/packages/oss-components/package.json +++ b/packages/oss-components/package.json @@ -201,7 +201,8 @@ "default": "./dist/utils/index.js" }, "./components/o-s-s/private/base-modal": null, - "./modifiers/install-scroll-reached-modifier": null + "./modifiers/install-scroll-reached-modifier": null, + "./patterns/private/*": null }, "typesVersions": { "*": { diff --git a/packages/oss-components/rollup.config.mjs b/packages/oss-components/rollup.config.mjs index 8d8654230..6b29e3c6b 100644 --- a/packages/oss-components/rollup.config.mjs +++ b/packages/oss-components/rollup.config.mjs @@ -15,7 +15,8 @@ export default { exclude: [ '**/*.stories.*', 'components/o-s-s/private/base-modal.*', - 'modifiers/install-scroll-reached-modifier.*' + 'modifiers/install-scroll-reached-modifier.*', + 'patterns/private/**' ] }), addon.appReexports( diff --git a/packages/oss-components/src/patterns/confirmation.ts b/packages/oss-components/src/patterns/confirmation.ts index d900826cc..931ecde0a 100644 --- a/packages/oss-components/src/patterns/confirmation.ts +++ b/packages/oss-components/src/patterns/confirmation.ts @@ -1,8 +1,7 @@ import { setComponentTemplate } from '@ember/component'; import templateOnly from '@ember/component/template-only'; import { assert } from '@ember/debug'; -import { isDestroying, registerDestructor, unregisterDestructor } from '@ember/destroyable'; -import { hash } from '@ember/helper'; +import { fn, hash } from '@ember/helper'; import { getOwner } from '@ember/owner'; import type Owner from '@ember/owner'; import { renderComponent } from '@ember/renderer'; @@ -14,6 +13,14 @@ import { tracked } from '@glimmer/tracking'; import type { IntlService } from 'ember-intl'; import OSSDialog, { type Skin as DialogSkin } from '../components/o-s-s/dialog'; +import { + cancelDialog, + confirmDialog, + createDialog, + dismissActiveDialog, + hasLoadingDialog, + openDialog +} from './private/confirmation-utils'; type Content = ReturnType; type Texts = { @@ -64,20 +71,22 @@ const ConfirmationDialog = setComponentTemplate( @subtitle={{@state.texts.subtitle}} @skin={{@state.skin}} @icon={{@state.icon}} - @mainAction={{hash label=@state.texts.confirmLabel action=@onConfirm loading=@state.loading}} - @secondaryAction={{hash label=@state.texts.cancelLabel action=@onCancel}} + @mainAction={{hash + label=@state.texts.confirmLabel + action=(fn confirmDialog @dialog) + loading=@state.loading + }} + @secondaryAction={{hash label=@state.texts.cancelLabel action=(fn cancelDialog @dialog)}} data-control-name={{@state.dataControlName}} /> `, - { strictMode: true, scope: () => ({ OSSDialog, hash }) } + { strictMode: true, scope: () => ({ OSSDialog, hash, fn, confirmDialog, cancelDialog }) } ), templateOnly() ); const HOST_ID = 'confirmable-dialog-host'; -let activeDialog: { state: ConfirmationState; dismiss: () => void } | undefined; - function hostElement(): HTMLElement { let host = document.getElementById(HOST_ID); @@ -101,10 +110,6 @@ function translate(owner: Owner, baseTranslationKey: string | undefined, suffix: return intl.t(key); } -function isThenable(value: unknown): value is PromiseLike { - return typeof (value as PromiseLike | undefined)?.then === 'function'; -} - export function confirm(context: object, options: ConfirmOptions): Promise { const owner = getOwner(context); @@ -121,8 +126,8 @@ export function confirm(context: object, options: ConfirmOptions): Promise((resolve, reject) => { - let closed = false; - - const close = (): void => { - closed = true; - router.off('routeWillChange', dismiss); - if (!isDestroying(context)) unregisterDestructor(context, dismiss); - if (activeDialog?.dismiss === dismiss) activeDialog = undefined; - rendered.destroy(); - }; - - const dismiss = (): void => { - if (closed) return; - close(); - if (!state.loading) resolve(false); - }; - - const settle = (finish: () => void): void => { - if (!closed) close(); - finish(); - }; - - const onCancel = (event?: Event): void => { - event?.stopPropagation(); - if (!state.loading) dismiss(); - }; - - const onConfirm = (event?: Event): void => { - event?.stopPropagation(); - if (closed || state.loading) return; - - let outcome: unknown; - try { - outcome = options.onConfirm?.(); - } catch (error) { - close(); - reject(error); - return; - } - - if (!isThenable(outcome)) { - close(); - resolve(true); - return; - } + const dialog = createDialog({ context, router, state, action: options.onConfirm, resolve, reject }); - state.loading = true; - outcome.then( - () => settle(() => resolve(true)), - (error: unknown) => settle(() => reject(error)) - ); - }; - - const rendered = renderComponent(ConfirmationDialog, { - into: hostElement(), - owner, - args: { state, onConfirm, onCancel } - }); - - router.on('routeWillChange', dismiss); - registerDestructor(context, dismiss); - activeDialog = { state, dismiss }; + openDialog(dialog, renderComponent(ConfirmationDialog, { into: hostElement(), owner, args: { state, dialog } })); }); } diff --git a/packages/oss-components/src/patterns/private/confirmation-utils.ts b/packages/oss-components/src/patterns/private/confirmation-utils.ts new file mode 100644 index 000000000..3ba073c8b --- /dev/null +++ b/packages/oss-components/src/patterns/private/confirmation-utils.ts @@ -0,0 +1,96 @@ +import { isDestroying, registerDestructor, unregisterDestructor } from '@ember/destroyable'; +import type RouterService from '@ember/routing/router-service'; + +export type Dialog = { + readonly context: object; + readonly router: RouterService; + readonly state: { loading: boolean }; + readonly action: (() => unknown) | undefined; + readonly resolve: (confirmed: boolean) => void; + readonly reject: (error: unknown) => void; + readonly dismiss: () => void; + rendered?: { destroy(): void }; + closed: boolean; +}; + +let activeDialog: Dialog | undefined; + +export function createDialog(fields: Omit): Dialog { + const dialog: Dialog = { + ...fields, + closed: false, + // Bound once: router.off and unregisterDestructor need the reference that was registered. + dismiss: () => dismissDialog(dialog) + }; + + return dialog; +} + +export function openDialog(dialog: Dialog, rendered: { destroy(): void }): void { + dialog.rendered = rendered; + dialog.router.on('routeWillChange', dialog.dismiss); + registerDestructor(dialog.context, dialog.dismiss); + activeDialog = dialog; +} + +export function hasLoadingDialog(): boolean { + return activeDialog?.state.loading ?? false; +} + +export function dismissActiveDialog(): void { + if (activeDialog) dismissDialog(activeDialog); +} + +export function dismissDialog(dialog: Dialog): void { + if (dialog.closed) return; + closeDialog(dialog); + if (!dialog.state.loading) dialog.resolve(false); +} + +export function cancelDialog(dialog: Dialog, event?: Event): void { + event?.stopPropagation(); + if (!dialog.state.loading) dismissDialog(dialog); +} + +export function confirmDialog(dialog: Dialog, event?: Event): void { + event?.stopPropagation(); + if (dialog.closed || dialog.state.loading) return; + + let outcome: unknown; + try { + outcome = dialog.action?.(); + } catch (error) { + closeDialog(dialog); + dialog.reject(error); + return; + } + + if (!isThenable(outcome)) { + closeDialog(dialog); + dialog.resolve(true); + return; + } + + dialog.state.loading = true; + outcome.then( + () => settleDialog(dialog, () => dialog.resolve(true)), + (error: unknown) => settleDialog(dialog, () => dialog.reject(error)) + ); +} + +function closeDialog(dialog: Dialog): void { + dialog.closed = true; + dialog.router.off('routeWillChange', dialog.dismiss); + if (!isDestroying(dialog.context)) unregisterDestructor(dialog.context, dialog.dismiss); + if (activeDialog === dialog) activeDialog = undefined; + dialog.rendered?.destroy(); +} + +function settleDialog(dialog: Dialog, finish: () => void): void { + if (!dialog.closed) closeDialog(dialog); + finish(); +} + +function isThenable(value: unknown): value is PromiseLike { + return typeof (value as PromiseLike | undefined)?.then === 'function'; +} From 95d04b097947802d549749be1ac3cad64fa29404 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Fri, 4 Dec 2026 08:35:49 +0100 Subject: [PATCH 09/10] Close confirmation dialogs when their owner is destroyed A dialog opened on a context its owner never destroys (a plain object, a handler) stayed in activeDialog after the owner's teardown: its promise never settled and, if it was loading, every later confirm() resolved false. Tests cover it, along with a second confirmation from another context replacing the open one. --- .../src/patterns/confirmation.ts | 2 +- .../patterns/private/confirmation-utils.ts | 5 ++ .../integration/patterns/confirmation-test.ts | 71 ++++++++++++++++++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/packages/oss-components/src/patterns/confirmation.ts b/packages/oss-components/src/patterns/confirmation.ts index 931ecde0a..80d23a8a5 100644 --- a/packages/oss-components/src/patterns/confirmation.ts +++ b/packages/oss-components/src/patterns/confirmation.ts @@ -138,7 +138,7 @@ export function confirm(context: object, options: ConfirmOptions): Promise((resolve, reject) => { - const dialog = createDialog({ context, router, state, action: options.onConfirm, resolve, reject }); + const dialog = createDialog({ context, owner, router, state, action: options.onConfirm, resolve, reject }); openDialog(dialog, renderComponent(ConfirmationDialog, { into: hostElement(), owner, args: { state, dialog } })); }); diff --git a/packages/oss-components/src/patterns/private/confirmation-utils.ts b/packages/oss-components/src/patterns/private/confirmation-utils.ts index 3ba073c8b..b49a6deb1 100644 --- a/packages/oss-components/src/patterns/private/confirmation-utils.ts +++ b/packages/oss-components/src/patterns/private/confirmation-utils.ts @@ -1,8 +1,10 @@ import { isDestroying, registerDestructor, unregisterDestructor } from '@ember/destroyable'; +import type Owner from '@ember/owner'; import type RouterService from '@ember/routing/router-service'; export type Dialog = { readonly context: object; + readonly owner: Owner; readonly router: RouterService; readonly state: { loading: boolean }; readonly action: (() => unknown) | undefined; @@ -30,6 +32,8 @@ export function openDialog(dialog: Dialog, rendered: { destroy(): void }): void dialog.rendered = rendered; dialog.router.on('routeWillChange', dialog.dismiss); registerDestructor(dialog.context, dialog.dismiss); + // A context that its owner never destroys (a plain object, a handler) must not keep the dialog past the owner. + registerDestructor(dialog.owner, dialog.dismiss); activeDialog = dialog; } @@ -82,6 +86,7 @@ function closeDialog(dialog: Dialog): void { dialog.closed = true; dialog.router.off('routeWillChange', dialog.dismiss); if (!isDestroying(dialog.context)) unregisterDestructor(dialog.context, dialog.dismiss); + if (!isDestroying(dialog.owner)) unregisterDestructor(dialog.owner, dialog.dismiss); if (activeDialog === dialog) activeDialog = undefined; dialog.rendered?.destroy(); } diff --git a/packages/test-app/tests/integration/patterns/confirmation-test.ts b/packages/test-app/tests/integration/patterns/confirmation-test.ts index 20fbf102e..97eeef1c7 100644 --- a/packages/test-app/tests/integration/patterns/confirmation-test.ts +++ b/packages/test-app/tests/integration/patterns/confirmation-test.ts @@ -1,9 +1,10 @@ +import type Application from '@ember/application'; import { associateDestroyableChild, destroy } from '@ember/destroyable'; import { action } from '@ember/object'; import { setOwner } from '@ember/owner'; import type Owner from '@ember/owner'; import type RouterService from '@ember/routing/router-service'; -import { click, settled } from '@ember/test-helpers'; +import { click, getApplication, settled } from '@ember/test-helpers'; import type { IntlService } from 'ember-intl'; import { setupIntl } from 'ember-intl/test-support'; @@ -46,6 +47,18 @@ function buildSubject(owner: Owner, options: ConfirmableOptions { + return (getApplication() as Application).buildInstance().boot({ isInteractive: false }); +} + +function contextOf(owner: Owner): object { + const context = {}; + setOwner(context, owner); + + return context; +} + module('Integration | Pattern | confirmation', function (hooks) { setupRenderingTest(hooks); setupIntl(hooks, 'en-us', { @@ -289,6 +302,62 @@ module('Integration | Pattern | confirmation', function (hooks) { resolveRemoval(); await result; }); + + test('A confirmation from another context closes the open one and resolves it false', async function (assert) { + const firstAction = sinon.spy(); + const secondAction = sinon.spy(); + + const first = confirm(contextOf(this.owner), { ...TEXTS, onConfirm: firstAction }); + await settled(); + const second = confirm(contextOf(this.owner), { ...TEXTS, title: 'Remove Robin?', onConfirm: secondAction }); + await settled(); + + assert.false(await first); + assert.dom(DIALOG).exists({ count: 1 }); + assert.dom(`${DIALOG} .font-weight-semibold`).hasText('Remove Robin?'); + + await click(CONFIRM); + + assert.true(await second); + assert.true(firstAction.notCalled); + assert.true(secondAction.calledOnce); + }); + }); + + // Each test runs on its own app instance, destroyed at teardown. The contexts below are plain objects, which that + // teardown never destroys: only the owner's destruction can clean their dialog up. + module('Between tests', () => { + test('A dialog left open closes with its app instance and resolves false', async function (assert) { + const previousOwner = await bootOtherInstance(); + const leaked = confirm(contextOf(previousOwner), TEXTS); + await settled(); + + destroy(previousOwner); + await settled(); + + assert.dom(DIALOG).doesNotExist(); + assert.false(await leaked); + }); + + test('A dialog left loading does not block the next app instance', async function (assert) { + const previousOwner = await bootOtherInstance(); + confirm(contextOf(previousOwner), { ...TEXTS, onConfirm: () => new Promise(() => {}) }); + await settled(); + await click(CONFIRM); + assert.dom(`${CONFIRM} .fa-circle-notch`).exists(); + + destroy(previousOwner); + await settled(); + assert.dom(DIALOG).doesNotExist(); + + const result = confirm(contextOf(this.owner), TEXTS); + await settled(); + + assert.dom(DIALOG).exists({ count: 1 }); + + await click(CANCEL); + assert.false(await result); + }); }); module('Dismissal', () => { From 52d62c4bba7e10f25ad1e64939ddc6546e6eb380 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Fri, 4 Dec 2026 09:20:17 +0100 Subject: [PATCH 10/10] Remove unnecessary comments in the confirmation pattern --- .../oss-components/src/patterns/private/confirmation-utils.ts | 2 -- .../test-app/tests/integration/patterns/confirmation-test.ts | 3 --- 2 files changed, 5 deletions(-) diff --git a/packages/oss-components/src/patterns/private/confirmation-utils.ts b/packages/oss-components/src/patterns/private/confirmation-utils.ts index b49a6deb1..fb3b31b52 100644 --- a/packages/oss-components/src/patterns/private/confirmation-utils.ts +++ b/packages/oss-components/src/patterns/private/confirmation-utils.ts @@ -21,7 +21,6 @@ export function createDialog(fields: Omit dismissDialog(dialog) }; @@ -32,7 +31,6 @@ export function openDialog(dialog: Dialog, rendered: { destroy(): void }): void dialog.rendered = rendered; dialog.router.on('routeWillChange', dialog.dismiss); registerDestructor(dialog.context, dialog.dismiss); - // A context that its owner never destroys (a plain object, a handler) must not keep the dialog past the owner. registerDestructor(dialog.owner, dialog.dismiss); activeDialog = dialog; } diff --git a/packages/test-app/tests/integration/patterns/confirmation-test.ts b/packages/test-app/tests/integration/patterns/confirmation-test.ts index 97eeef1c7..6c2481d09 100644 --- a/packages/test-app/tests/integration/patterns/confirmation-test.ts +++ b/packages/test-app/tests/integration/patterns/confirmation-test.ts @@ -47,7 +47,6 @@ function buildSubject(owner: Owner, options: ConfirmableOptions { return (getApplication() as Application).buildInstance().boot({ isInteractive: false }); } @@ -324,8 +323,6 @@ module('Integration | Pattern | confirmation', function (hooks) { }); }); - // Each test runs on its own app instance, destroyed at teardown. The contexts below are plain objects, which that - // teardown never destroys: only the owner's destruction can clean their dialog up. module('Between tests', () => { test('A dialog left open closes with its app instance and resolves false', async function (assert) { const previousOwner = await bootOtherInstance();