@bakers-build/addon-bakers-ui 0.10.1-next.4 → 0.10.1-next.6

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.
@@ -7,23 +7,10 @@ export declare const CANCELLED_RUN_STATE = "cancelled";
7
7
  * with the YAML transition whenever its source states change.
8
8
  */
9
9
  export declare const CANCELLABLE_RUN_STATES: ReadonlySet<string>;
10
- export declare const CANCEL_RUN_ACTION_ID = "cancelRun";
11
- export type RunEditFieldId = typeof CANCEL_RUN_ACTION_ID;
12
10
  export interface CancelRunPayload {
13
11
  attributes: {
14
12
  state: typeof CANCELLED_RUN_STATE;
15
13
  };
16
14
  }
17
15
  export declare const cancelRunPayload: () => CancelRunPayload;
18
- declare const EDIT_FORM: {
19
- fields: import("../../../Form/field.js").FieldDecl[];
20
- activeField: (s: import("../../../Form/form.js").FormState<Record<string, never>>) => import("../../../Form/field.js").FieldDecl;
21
- move: (s: import("../../../Form/form.js").FormState<Record<string, never>>, d: number) => import("../../../Form/form.js").FormState<Record<string, never>>;
22
- initial(options: Record<string, never>, prefill?: Partial<Record<string, never>>): import("../../../Form/form.js").FormState<Record<string, never>>;
23
- apply(s: import("../../../Form/form.js").FormState<Record<string, never>>, options: Record<string, never>, intent: import("../../../Form/form.js").Intent): import("../../../Form/form.js").FormState<Record<string, never>>;
24
- toObject: (s: import("../../../Form/form.js").FormState<Record<string, never>>, options: Record<string, never>) => CancelRunPayload;
25
- };
26
- export type EditRunFormDeclaration = typeof EDIT_FORM;
27
16
  export declare const isRunCancellable: (state: string) => boolean;
28
- export declare const editRunFormFor: (runState: string) => EditRunFormDeclaration | undefined;
29
- export {};
@@ -1,4 +1,3 @@
1
- import { declareForm } from '../../../Form/index.js';
2
1
  export const CANCELLED_RUN_STATE = 'cancelled';
3
2
  /**
4
3
  * The run states `cancel` leaves, mirroring `bb_run.transitions.cancel.from`
@@ -11,13 +10,7 @@ export const CANCELLABLE_RUN_STATES = new Set([
11
10
  'claimed',
12
11
  'running',
13
12
  ]);
14
- export const CANCEL_RUN_ACTION_ID = 'cancelRun';
15
13
  export const cancelRunPayload = () => ({
16
14
  attributes: { state: CANCELLED_RUN_STATE },
17
15
  });
18
- const EDIT_FORM = declareForm({
19
- fields: (f) => [f.action('Cancel run', CANCEL_RUN_ACTION_ID)],
20
- toObject: () => cancelRunPayload(),
21
- });
22
16
  export const isRunCancellable = (state) => CANCELLABLE_RUN_STATES.has(state);
23
- export const editRunFormFor = (runState) => isRunCancellable(runState) ? EDIT_FORM : undefined;
@@ -0,0 +1,18 @@
1
+ import type { ConfirmRequest } from '../../../Screen/confirm-dialog.js';
2
+ import type { ScreenContext } from '../../../Screen/screen.js';
3
+ import type { TicketDetailDocument } from '../../../types.js';
4
+ /** What a run cancellation hands back to the screen that asked for it. */
5
+ export interface RunCancelledResult {
6
+ readonly type: 'run-cancelled';
7
+ readonly runId: string;
8
+ readonly document: TicketDetailDocument;
9
+ }
10
+ /** `#<number>` of a run in `document`, or `''` when it is not included. */
11
+ export declare const runNumber: (document: TicketDetailDocument, runId: string) => string;
12
+ /**
13
+ * PATCH the run to cancelled and return `document` with that run's state
14
+ * patched, so the caller repaints without a refetch.
15
+ */
16
+ export declare const cancelRun: (context: ScreenContext, document: TicketDetailDocument, runId: string) => Promise<RunCancelledResult>;
17
+ /** Cancel run, for the confirmation dialog. */
18
+ export declare const cancelRunRequest: (document: TicketDetailDocument, runId: string) => ConfirmRequest;
@@ -0,0 +1,48 @@
1
+ import { runResource } from '../Component/run-detail/index.js';
2
+ import { CANCELLED_RUN_STATE, cancelRunPayload } from '../Form/edit.js';
3
+ /** `#<number>` of a run in `document`, or `''` when it is not included. */
4
+ export const runNumber = (document, runId) => {
5
+ const run = runResource(document, runId);
6
+ return run
7
+ ? ` #${String(run.attributes?.drupal_internal__id ?? run.id)}`
8
+ : '';
9
+ };
10
+ /**
11
+ * PATCH the run to cancelled and return `document` with that run's state
12
+ * patched, so the caller repaints without a refetch.
13
+ */
14
+ export const cancelRun = async (context, document, runId) => {
15
+ const client = context.services?.writeClient ?? context.services?.client;
16
+ if (!client)
17
+ throw new Error('No connection to cancel the run.');
18
+ await client.update('bb_run--bb_run', runId, cancelRunPayload());
19
+ return {
20
+ type: 'run-cancelled',
21
+ runId,
22
+ document: {
23
+ ...document,
24
+ ...(document.included
25
+ ? {
26
+ included: document.included.map((resource) => resource.id === runId
27
+ ? {
28
+ ...resource,
29
+ attributes: {
30
+ ...resource.attributes,
31
+ state: CANCELLED_RUN_STATE,
32
+ },
33
+ }
34
+ : resource),
35
+ }
36
+ : {}),
37
+ },
38
+ };
39
+ };
40
+ /** Cancel run, for the confirmation dialog. */
41
+ export const cancelRunRequest = (document, runId) => ({
42
+ title: '✕ Cancel run',
43
+ prepare: () => Promise.resolve({
44
+ message: `Cancel run${runNumber(document, runId)}?`,
45
+ detail: 'This marks the run as cancelled.',
46
+ confirm: (context) => cancelRun(context, document, runId),
47
+ }),
48
+ });
@@ -24,7 +24,7 @@ export declare class RunDetailScreen extends AsyncScreen<TicketDetailDocument> {
24
24
  context: (_params: Readonly<Record<string, string>>, state: unknown, base: import("../../../Routing/context.js").ContextBag) => import("../../../Routing/context.js").ContextBag;
25
25
  };
26
26
  readonly id: string;
27
- private editable;
27
+ private cancellable;
28
28
  /**
29
29
  * A `run-cancelled` result received here (BB-536) is re-armed as this
30
30
  * screen's own `back` result, so the ticket's Runs tab — the *next* screen
@@ -45,15 +45,7 @@ export declare class RunDetailScreen extends AsyncScreen<TicketDetailDocument> {
45
45
  receiveResult(result: unknown, context: ScreenContext): void;
46
46
  handleInput(input: string, context: ScreenContext): boolean;
47
47
  takeAction(): ScreenAction | undefined;
48
- actionForInput(input: string, context: ScreenContext): {
49
- type: "navigate";
50
- routeId: string;
51
- params: {
52
- ticketId: string;
53
- runId: string;
54
- };
55
- result: TicketDetailDocument | undefined;
56
- } | undefined;
48
+ actionForInput(input: string, context: ScreenContext): ScreenAction | undefined;
57
49
  /**
58
50
  * F5 — the pipe's own output, and it is `string[]`.
59
51
  *
@@ -2,8 +2,10 @@ import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
2
  import { actionItem } from '../../../Component/footer-actions/index.js';
3
3
  import { defineContext } from '../../../Routing/context.js';
4
4
  import { AsyncScreen } from '../../../Screen/async-screen.js';
5
+ import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
5
6
  import { runDetailRows, runDetailTitle, runDetailTree, runResource, } from '../Component/run-detail/index.js';
6
7
  import { isRunCancellable } from '../Form/edit.js';
8
+ import { cancelRunRequest } from './run-actions.js';
7
9
  export const runDetailInputContext = defineContext('run-detail-input', 'input');
8
10
  /**
9
11
  * Run detail — normal {@link AsyncScreen}. The document arrives via navigation
@@ -24,7 +26,7 @@ export class RunDetailScreen extends AsyncScreen {
24
26
  : base,
25
27
  };
26
28
  id = RunDetailScreen.route.id;
27
- editable = false;
29
+ cancellable = false;
28
30
  /**
29
31
  * A `run-cancelled` result received here (BB-536) is re-armed as this
30
32
  * screen's own `back` result, so the ticket's Runs tab — the *next* screen
@@ -62,14 +64,16 @@ export class RunDetailScreen extends AsyncScreen {
62
64
  }
63
65
  didLoad(document, context) {
64
66
  const run = runResource(document, context.params?.runId);
65
- this.editable =
67
+ this.cancellable =
66
68
  !!run && isRunCancellable(String(run.attributes?.state ?? ''));
67
69
  }
68
70
  actions() {
69
- return this.editable ? [actionItem('run-edit', 'e', 'edit')] : [];
71
+ return this.cancellable
72
+ ? [actionItem('run-cancel', 'x', 'cancel run')]
73
+ : [];
70
74
  }
71
75
  commandForInput(input) {
72
- return input === 'e' && this.editable ? 'edit-run' : undefined;
76
+ return input === 'x' && this.cancellable ? 'cancel-run' : undefined;
73
77
  }
74
78
  receiveResult(result, context) {
75
79
  if (result &&
@@ -78,7 +82,7 @@ export class RunDetailScreen extends AsyncScreen {
78
82
  const document = result.document;
79
83
  if (document)
80
84
  this.replaceReady(document);
81
- this.editable = false;
85
+ this.cancellable = false;
82
86
  this.forwardResult = { type: 'back', result };
83
87
  context.requestDraw();
84
88
  }
@@ -94,17 +98,12 @@ export class RunDetailScreen extends AsyncScreen {
94
98
  return action;
95
99
  }
96
100
  actionForInput(input, context) {
97
- if (this.commandForInput(input) !== 'edit-run' || !context.navigate)
101
+ const runId = context.params?.runId;
102
+ if (this.commandForInput(input) !== 'cancel-run' ||
103
+ !runId ||
104
+ !this.readyValue)
98
105
  return undefined;
99
- return {
100
- type: 'navigate',
101
- routeId: 'run.edit',
102
- params: {
103
- ticketId: context.params?.ticketId ?? '',
104
- runId: context.params?.runId ?? '',
105
- },
106
- result: this.readyValue,
107
- };
106
+ return confirmNavigation(cancelRunRequest(this.readyValue, runId));
108
107
  }
109
108
  /**
110
109
  * F5 — the pipe's own output, and it is `string[]`.
@@ -21,8 +21,8 @@
21
21
  // things that really are this popup's own — around one call.
22
22
  //
23
23
  // BB-313 (D4) finally makes the claim above literally true: the field list is
24
- // HANDED IN rather than imported. There are two declarations now — with and
25
- // without Cancel ticket — so importing either here would make this file a
24
+ // HANDED IN rather than imported. There are two declarations now — writable
25
+ // and a closed ticket's read-only one — so importing either here would make this file a
26
26
  // second decider that can drift from the screen's. It names no field; it renders
27
27
  // the list it is given.
28
28
  //
@@ -58,7 +58,7 @@ const WARNING_INDENT = 2;
58
58
  const LEGEND = 'Assignee = human ownership · Reviewers = named reviewers · Conductor = who works it next · ' +
59
59
  'Estimate/Spent = accounted time, not the run footprint (1d 2h 30m, 90m, or a bare number as minutes) · ' +
60
60
  'Parent = optional parent ticket · Labels = multi-select from label · ' +
61
- 'Cancel ticket abandons a non-terminal ticket (Esc closes and writes nothing)';
61
+ 'Esc closes and writes nothing';
62
62
  /**
63
63
  * A block of chrome prose, wrapped so the frame never has to clip it.
64
64
  *
@@ -4,9 +4,9 @@ import type { TicketDetailDocument } from '../../../types.js';
4
4
  export type FieldDef<Id extends string = string> = Omit<FieldDecl, 'id'> & {
5
5
  id: Id;
6
6
  };
7
- export type EditFieldId = 'assignee' | 'reviewers' | 'conductor' | 'estimate' | 'spent' | 'parent' | 'ticketType' | 'recipe' | 'labels' | 'submit' | 'cancelTicket';
7
+ export type EditFieldId = 'assignee' | 'reviewers' | 'conductor' | 'estimate' | 'spent' | 'parent' | 'ticketType' | 'recipe' | 'labels' | 'submit';
8
8
  /**
9
- * BB-313 / BB-360 — the ONE lifecycle move this popup offers, as a named
9
+ * BB-313 / BB-360 — the ONE lifecycle move the ticket detail offers, as a named
10
10
  * constant.
11
11
  *
12
12
  * Not derived, and deliberately so: `state_flow` is a `bb_dashboard` computed
@@ -20,13 +20,6 @@ export type EditFieldId = 'assignee' | 'reviewers' | 'conductor' | 'estimate' |
20
20
  * predicate, and no workflow id is needed to tell them apart.
21
21
  */
22
22
  export declare const CANCELLED_STATE = "cancelled";
23
- /**
24
- * The Cancel ticket action's field id (BB-360 D4).
25
- *
26
- * Never `'cancel'` — `intent.kind === 'cancel'` already means "close the
27
- * popup", and two meanings for one word is a defect waiting.
28
- */
29
- export declare const CANCEL_TICKET_ACTION_ID = "cancelTicket";
30
23
  /**
31
24
  * The states no transition leaves, in every ticket workflow.
32
25
  *
@@ -127,7 +120,7 @@ export interface CancelEditPayload {
127
120
  state: typeof CANCELLED_STATE;
128
121
  };
129
122
  }
130
- /** The ordinary popup: a non-terminal ticket can be cancelled from it. */
123
+ /** The ordinary popup: assignment, times, structure and Save. */
131
124
  export declare const EDIT_FORM: {
132
125
  fields: FieldDecl[];
133
126
  activeField: (s: FormState<EditValues>) => FieldDecl;
@@ -136,18 +129,9 @@ export declare const EDIT_FORM: {
136
129
  apply(s: FormState<EditValues>, options: EditFormOptions, intent: import("../../../Form/form.js").Intent): FormState<EditValues>;
137
130
  toObject: (s: FormState<EditValues>, options: EditFormOptions) => EditFormPayload;
138
131
  };
139
- /** A terminal ticket's popup: assignment, times, structure — no Cancel ticket. */
140
- export declare const EDIT_FORM_TERMINAL: {
141
- fields: FieldDecl[];
142
- activeField: (s: FormState<EditValues>) => FieldDecl;
143
- move: (s: FormState<EditValues>, d: number) => FormState<EditValues>;
144
- initial(options: EditFormOptions, prefill?: Partial<EditValues>): FormState<EditValues>;
145
- apply(s: FormState<EditValues>, options: EditFormOptions, intent: import("../../../Form/form.js").Intent): FormState<EditValues>;
146
- toObject: (s: FormState<EditValues>, options: EditFormOptions) => EditFormPayload;
147
- };
148
132
  /**
149
- * A closed ticket's popup: read-only, no Save and no Cancel ticket. The server
150
- * freezes a ticket on its stored `closed` flag and answers any PATCH with 403.
133
+ * A closed ticket's popup: read-only, no Save. The server freezes a ticket on
134
+ * its stored `closed` flag and answers any PATCH with 403.
151
135
  */
152
136
  export declare const EDIT_FORM_CLOSED: {
153
137
  fields: FieldDecl[];
@@ -160,27 +144,26 @@ export declare const EDIT_FORM_CLOSED: {
160
144
  export type EditFormDeclaration = typeof EDIT_FORM;
161
145
  /** The ticket's state as the popup sees it; `''` when the read carried none. */
162
146
  export declare const ticketState: (document: TicketDetailDocument) => string;
147
+ /** Which declaration a ticket gets: a closed ticket's popup is read-only. */
148
+ export declare const editFormFor: (document: TicketDetailDocument) => EditFormDeclaration;
163
149
  /**
164
- * Which declaration a ticket gets (AC-4 / D13).
150
+ * Whether the ticket detail offers Cancel ticket: not closed, not terminal.
165
151
  *
166
152
  * An unknown state fails OPEN (D13): `loadTicketDetail` requests no fieldset, so
167
153
  * a missing `state` means genuinely unknown rather than not-requested. Hiding
168
154
  * Cancel ticket on a thin read would cost a legitimate affordance; offering it
169
- * costs at worst the server's 422, which the popup already renders in full.
155
+ * costs at worst the server's 422, which the dialog shows in full.
170
156
  */
171
- export declare const editFormFor: (document: TicketDetailDocument) => EditFormDeclaration;
157
+ export declare const isTicketCancellable: (document: TicketDetailDocument) => boolean;
172
158
  /** Field order in the popup, per declaration. */
173
159
  export declare const EDIT_FIELDS: FieldDef<EditFieldId>[];
174
- export declare const EDIT_FIELDS_TERMINAL: FieldDef<EditFieldId>[];
175
160
  export declare const EDIT_FIELDS_CLOSED: FieldDef<EditFieldId>[];
176
161
  export type EditFormState = FormState<EditValues>;
177
162
  /**
178
163
  * No lists to OFFER — bags start empty until the adapter / option loader fills
179
164
  * them. Prefill names every value, and `clear`/`toObject` read no option list
180
165
  * for the required fields, so adapters that have no options hand over this bag.
181
- * Exported so the screen's options-failure path can reuse it (D11): a failed
182
- * user/conductor/label read must not silently remove Cancel ticket (D8 keeps
183
- * the action on the declaration, not in the bag).
166
+ * Exported so the screen's options-failure path can reuse it (D11).
184
167
  */
185
168
  export declare const EMPTY_EDIT_FORM_OPTIONS: EditFormOptions;
186
169
  /** Prefill from the ticket's CURRENT values (AC-1) — never from `opts[0]`. The
@@ -188,10 +171,8 @@ export declare const EMPTY_EDIT_FORM_OPTIONS: EditFormOptions;
188
171
  * explicit `null` STICKS instead of falling back to the first option. */
189
172
  export declare function initialEditForm(document: TicketDetailDocument): EditFormState;
190
173
  /**
191
- * The Cancel ticket PATCH body (BB-360 D1): lifecycle only.
192
- *
193
- * Local field edits are discarded; after a successful write the detail reloads
194
- * from the server (same as Save's reload path). No relationships.
174
+ * The Cancel ticket PATCH body (BB-360 D1): lifecycle only, no relationships.
175
+ * After a successful write the detail reloads from the server.
195
176
  */
196
177
  export declare const cancelEditPayload: () => CancelEditPayload;
197
178
  export declare const activeEditField: (s: EditFormState) => FieldDef<EditFieldId>;
@@ -1,19 +1,14 @@
1
1
  // The "Edit ticket" popup (BB-233, widened by BB-308 / BB-313 / BB-360)
2
2
  // as a DECLARATION over the form kernel (BB-236): two `clearable` selects, two
3
3
  // text fields for accounted durations, a clearable Parent autocomplete, a Labels
4
- // multi-select, and dual actions (Save + Cancel ticket on non-terminal). One
5
- // `toObject` yields the ordinary Save PATCH; Cancel ticket uses a separate pure
6
- // payload helper. No I/O here.
7
- //
8
- // BB-360 removes the State select entirely (D8). Cancelling is a second
9
- // `f.action` whose id is never `cancel` — that intent closes the popup (Esc).
10
- // Two declarations from one body: a terminal ticket's popup simply omits the
11
- // Cancel ticket action (D3), and `editFormFor` picks between them.
4
+ // multi-select, and Save. One `toObject` yields the ordinary Save PATCH. No I/O
5
+ // here. Cancelling a ticket is not part of this popup: it is its own action on
6
+ // the ticket detail, confirmed in the shared dialog (`cancelEditPayload` below).
12
7
  import { declareForm, } from '../../../Form/index.js';
13
8
  import { formatDuration, parseDuration } from '../../../lib/format.js';
14
9
  import { PARENT_PAGE_SIZE } from '../Data/parents.js';
15
10
  /**
16
- * BB-313 / BB-360 — the ONE lifecycle move this popup offers, as a named
11
+ * BB-313 / BB-360 — the ONE lifecycle move the ticket detail offers, as a named
17
12
  * constant.
18
13
  *
19
14
  * Not derived, and deliberately so: `state_flow` is a `bb_dashboard` computed
@@ -27,13 +22,6 @@ import { PARENT_PAGE_SIZE } from '../Data/parents.js';
27
22
  * predicate, and no workflow id is needed to tell them apart.
28
23
  */
29
24
  export const CANCELLED_STATE = 'cancelled';
30
- /**
31
- * The Cancel ticket action's field id (BB-360 D4).
32
- *
33
- * Never `'cancel'` — `intent.kind === 'cancel'` already means "close the
34
- * popup", and two meanings for one word is a defect waiting.
35
- */
36
- export const CANCEL_TICKET_ACTION_ID = 'cancelTicket';
37
25
  /**
38
26
  * The states no transition leaves, in every ticket workflow.
39
27
  *
@@ -84,7 +72,7 @@ const timeAttributes = (v) => {
84
72
  return out;
85
73
  };
86
74
  /**
87
- * One body, two declarations (D3 / D8).
75
+ * One body, two declarations: writable, and a closed ticket's read-only one.
88
76
  *
89
77
  * BOTH assignment selects are `clearable`: AC-4 requires REMOVING an assignment,
90
78
  * not only changing it, so `null` is a real position in each cycle. Parent is
@@ -94,7 +82,7 @@ const timeAttributes = (v) => {
94
82
  *
95
83
  * Ordinary Save NEVER includes `attributes.state` — a self-transition is not a
96
84
  * declared edge, so echoing the current state would turn every ordinary edit
97
- * into a 422. Cancel ticket is a separate action that uses `cancelEditPayload`.
85
+ * into a 422.
98
86
  *
99
87
  * The kernel builds its field list once, at module load, and every consumer —
100
88
  * the renderer's `▸` marker, `keyToIntent`, `apply` — indexes that array by
@@ -102,7 +90,7 @@ const timeAttributes = (v) => {
102
90
  * every index below it; absence has to be a property of WHICH DECLARATION is in
103
91
  * force.
104
92
  */
105
- const declareEditForm = (savable, cancellable) => declareForm({
93
+ const declareEditForm = (savable) => declareForm({
106
94
  fields: (f) => [
107
95
  f.select('assignee', 'Assignee', { from: 'users', clearable: true }),
108
96
  f.multi('reviewers', 'Reviewers', { from: 'reviewers' }),
@@ -123,9 +111,6 @@ const declareEditForm = (savable, cancellable) => declareForm({
123
111
  f.select('recipe', 'Recipe', { from: 'recipes', clearable: true }),
124
112
  f.multi('labels', 'Labels', { from: 'labels' }),
125
113
  ...(savable ? [f.action('Save', 'submit')] : []),
126
- ...(cancellable
127
- ? [f.action('Cancel ticket', CANCEL_TICKET_ACTION_ID)]
128
- : []),
129
114
  ],
130
115
  toObject: (v) => ({
131
116
  // Ordinary Save never writes lifecycle state (D6/D7).
@@ -150,46 +135,38 @@ const declareEditForm = (savable, cancellable) => declareForm({
150
135
  },
151
136
  }),
152
137
  });
153
- /** The ordinary popup: a non-terminal ticket can be cancelled from it. */
154
- export const EDIT_FORM = declareEditForm(true, true);
155
- /** A terminal ticket's popup: assignment, times, structure — no Cancel ticket. */
156
- export const EDIT_FORM_TERMINAL = declareEditForm(true, false);
138
+ /** The ordinary popup: assignment, times, structure and Save. */
139
+ export const EDIT_FORM = declareEditForm(true);
157
140
  /**
158
- * A closed ticket's popup: read-only, no Save and no Cancel ticket. The server
159
- * freezes a ticket on its stored `closed` flag and answers any PATCH with 403.
141
+ * A closed ticket's popup: read-only, no Save. The server freezes a ticket on
142
+ * its stored `closed` flag and answers any PATCH with 403.
160
143
  */
161
- export const EDIT_FORM_CLOSED = declareEditForm(false, false);
144
+ export const EDIT_FORM_CLOSED = declareEditForm(false);
162
145
  /** The ticket's state as the popup sees it; `''` when the read carried none. */
163
146
  export const ticketState = (document) => {
164
147
  const value = document.data?.attributes?.state;
165
148
  return typeof value === 'string' ? value : '';
166
149
  };
150
+ /** Which declaration a ticket gets: a closed ticket's popup is read-only. */
151
+ export const editFormFor = (document) => document.data?.attributes?.closed === true ? EDIT_FORM_CLOSED : EDIT_FORM;
167
152
  /**
168
- * Which declaration a ticket gets (AC-4 / D13).
153
+ * Whether the ticket detail offers Cancel ticket: not closed, not terminal.
169
154
  *
170
155
  * An unknown state fails OPEN (D13): `loadTicketDetail` requests no fieldset, so
171
156
  * a missing `state` means genuinely unknown rather than not-requested. Hiding
172
157
  * Cancel ticket on a thin read would cost a legitimate affordance; offering it
173
- * costs at worst the server's 422, which the popup already renders in full.
158
+ * costs at worst the server's 422, which the dialog shows in full.
174
159
  */
175
- export const editFormFor = (document) => {
176
- if (document.data?.attributes?.closed === true)
177
- return EDIT_FORM_CLOSED;
178
- return TERMINAL_TICKET_STATES.has(ticketState(document))
179
- ? EDIT_FORM_TERMINAL
180
- : EDIT_FORM;
181
- };
160
+ export const isTicketCancellable = (document) => document.data?.attributes?.closed !== true &&
161
+ !TERMINAL_TICKET_STATES.has(ticketState(document));
182
162
  /** Field order in the popup, per declaration. */
183
163
  export const EDIT_FIELDS = EDIT_FORM.fields;
184
- export const EDIT_FIELDS_TERMINAL = EDIT_FORM_TERMINAL.fields;
185
164
  export const EDIT_FIELDS_CLOSED = EDIT_FORM_CLOSED.fields;
186
165
  /**
187
166
  * No lists to OFFER — bags start empty until the adapter / option loader fills
188
167
  * them. Prefill names every value, and `clear`/`toObject` read no option list
189
168
  * for the required fields, so adapters that have no options hand over this bag.
190
- * Exported so the screen's options-failure path can reuse it (D11): a failed
191
- * user/conductor/label read must not silently remove Cancel ticket (D8 keeps
192
- * the action on the declaration, not in the bag).
169
+ * Exported so the screen's options-failure path can reuse it (D11).
193
170
  */
194
171
  export const EMPTY_EDIT_FORM_OPTIONS = {
195
172
  users: [],
@@ -278,10 +255,8 @@ export function initialEditForm(document) {
278
255
  });
279
256
  }
280
257
  /**
281
- * The Cancel ticket PATCH body (BB-360 D1): lifecycle only.
282
- *
283
- * Local field edits are discarded; after a successful write the detail reloads
284
- * from the server (same as Save's reload path). No relationships.
258
+ * The Cancel ticket PATCH body (BB-360 D1): lifecycle only, no relationships.
259
+ * After a successful write the detail reloads from the server.
285
260
  */
286
261
  export const cancelEditPayload = () => ({
287
262
  attributes: { state: CANCELLED_STATE },
@@ -9,7 +9,7 @@ import { activeRunInfo } from '../../run/Data/active-run.js';
9
9
  import { resolveWhoCandidate } from '../../user/Data/users.js';
10
10
  import { EDIT_FORM_REGION, editFormTree, } from '../Component/edit-form/index.js';
11
11
  import { loadTicketDetail } from '../Data/detail.js';
12
- import { CANCEL_TICKET_ACTION_ID, cancelEditPayload, EDIT_FORM_CLOSED, EMPTY_EDIT_FORM_OPTIONS, editFormFor, initialEditForm, serializeEdit, } from '../Form/edit.js';
12
+ import { EDIT_FORM_CLOSED, EMPTY_EDIT_FORM_OPTIONS, editFormFor, initialEditForm, serializeEdit, } from '../Form/edit.js';
13
13
  import { loadEditFormOptions } from '../Form/edit-data.js';
14
14
  import { editParentOptionSource } from '../Form/edit-parent-source.js';
15
15
  import { keyToIntent } from '../Form/keys.js';
@@ -187,22 +187,14 @@ export class EditAssignmentFormScreen extends AsyncModalScreen {
187
187
  this.action = undefined;
188
188
  return action;
189
189
  }
190
- submit(context, data,
191
- /** When true, Cancel ticket path (lifecycle-only). */
192
- cancelTicket) {
190
+ submit(context, data) {
193
191
  if (this.submitting || !this.form || !context.services)
194
192
  return;
195
193
  this.submitting = true;
196
194
  this.message = '';
197
195
  const ticketId = data.document.data?.id ?? context.params?.ticketId ?? '';
198
- const payload = cancelTicket
199
- ? cancelEditPayload()
200
- : serializeEdit(this.form);
201
- const assigneeId = cancelTicket
202
- ? (relationshipId(data.document, 'assignee_user_id') ?? '')
203
- : 'relationships' in payload
204
- ? (payload.relationships.assignee_user_id.data?.id ?? '')
205
- : '';
196
+ const payload = serializeEdit(this.form);
197
+ const assigneeId = payload.relationships.assignee_user_id.data?.id ?? '';
206
198
  void (context.services.writeClient ?? context.services.client)
207
199
  .update('bb_ticket--bb_ticket', ticketId, payload)
208
200
  .then(async () => {
@@ -257,10 +249,7 @@ export class EditAssignmentFormScreen extends AsyncModalScreen {
257
249
  this.message = 'This ticket is closed and read-only.';
258
250
  }
259
251
  else if (intent.kind === 'submit') {
260
- // D10: Ctrl+S ALWAYS Save, even when the cursor is on Cancel ticket.
261
- // Only Enter/submit while standing on the cancelTicket action cancels.
262
- const cancelTicket = input !== 'ctrl+s' && field.id === CANCEL_TICKET_ACTION_ID;
263
- this.submit(context, data, cancelTicket);
252
+ this.submit(context, data);
264
253
  }
265
254
  else if (!this.savable && intent.kind !== 'move') {
266
255
  // A closed ticket's values stay as they are; only ↑↓ moves.
@@ -320,7 +309,7 @@ export class EditAssignmentFormScreen extends AsyncModalScreen {
320
309
  return this.declaration.fields.some((f) => f.id === 'submit');
321
310
  }
322
311
  actions() {
323
- // BB-360 D12 — Esc:close (not cancel); Cancel ticket is lifecycle.
312
+ // BB-360 D12 — Esc:close (not cancel).
324
313
  return [
325
314
  actionItem('edit-field', '↑↓', 'field'),
326
315
  ...(this.savable
@@ -0,0 +1,13 @@
1
+ import type { ConfirmRequest } from '../../../Screen/confirm-dialog.js';
2
+ import type { TicketDetailDocument } from '../../../types.js';
3
+ /** Cancel ticket, for the confirmation dialog. */
4
+ export declare const cancelTicketRequest: (document: TicketDetailDocument) => ConfirmRequest;
5
+ /**
6
+ * Restart run, for the confirmation dialog: cancel the ticket's active run and
7
+ * nothing else; the conductor claims the ticket again as usual.
8
+ *
9
+ * The Overview document carries no runs (transcripts are big), so the dialog
10
+ * reads them when it opens, with only the fields it needs. A run that ended
11
+ * since leaves nothing to confirm.
12
+ */
13
+ export declare const restartRunRequest: (ticketId: string, identifier: string) => ConfirmRequest;
@@ -0,0 +1,61 @@
1
+ import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
+ import { CANCELLABLE_RUN_STATES } from '../../run/Form/edit.js';
3
+ import { cancelRun, runNumber } from '../../run/Screen/run-actions.js';
4
+ import { loadTicketDetail } from '../Data/detail.js';
5
+ import { cancelEditPayload } from '../Form/edit.js';
6
+ const identifierOf = (document) => String(document.data?.attributes?.identifier ?? document.data?.id ?? '');
7
+ /** Cancel ticket, for the confirmation dialog. */
8
+ export const cancelTicketRequest = (document) => ({
9
+ title: '✕ Cancel ticket',
10
+ prepare: () => Promise.resolve({
11
+ message: `Cancel ${identifierOf(document)}?`,
12
+ detail: 'The ticket moves to cancelled.',
13
+ confirm: async (context) => {
14
+ const services = context.services;
15
+ const ticketId = document.data?.id;
16
+ if (!services || !ticketId)
17
+ throw new Error('No connection to cancel the ticket.');
18
+ await (services.writeClient ?? services.client).update('bb_ticket--bb_ticket', ticketId, cancelEditPayload());
19
+ return {
20
+ type: 'ticket-cancelled',
21
+ document: await loadTicketDetail(services.client, ticketId),
22
+ };
23
+ },
24
+ }),
25
+ });
26
+ /**
27
+ * Restart run, for the confirmation dialog: cancel the ticket's active run and
28
+ * nothing else; the conductor claims the ticket again as usual.
29
+ *
30
+ * The Overview document carries no runs (transcripts are big), so the dialog
31
+ * reads them when it opens, with only the fields it needs. A run that ended
32
+ * since leaves nothing to confirm.
33
+ */
34
+ export const restartRunRequest = (ticketId, identifier) => ({
35
+ title: '↻ Restart run',
36
+ prepare: async (context) => {
37
+ const client = context.services?.client;
38
+ if (!client)
39
+ throw new Error('No connection to read the runs.');
40
+ const readRuns = () => client.get(`bb_ticket/bb_ticket/${ticketId}`, new DrupalJsonApiParams()
41
+ .addInclude(['runs'])
42
+ .addFields('bb_run--bb_run', ['state', 'drupal_internal__id']));
43
+ const document = await readRuns();
44
+ const active = document.included?.find((resource) => resource.type === 'bb_run--bb_run' &&
45
+ CANCELLABLE_RUN_STATES.has(String(resource.attributes?.state ?? '')));
46
+ const runId = active?.id;
47
+ if (!runId)
48
+ return { message: 'No active run any more.' };
49
+ return {
50
+ message: `Restart run${runNumber(document, runId)} of ${identifier}?`,
51
+ detail: 'The active run is cancelled; the conductor starts a new one.',
52
+ // Read again after the write: the ticket's derived_status changes with it.
53
+ confirm: async (confirmContext) => {
54
+ const cancelled = await cancelRun(confirmContext, document, runId);
55
+ // The write landed; a failed re-read must not report it as failed.
56
+ const fresh = await readRuns().catch(() => cancelled.document);
57
+ return { ...cancelled, document: fresh };
58
+ },
59
+ };
60
+ },
61
+ });
@@ -69,6 +69,8 @@ export declare abstract class TicketContentScreen extends AsyncScreen<TicketDeta
69
69
  */
70
70
  private toggleFrozen;
71
71
  handleInput(input: string, context: ScreenContext): boolean;
72
+ private cancellable;
73
+ private restartable;
72
74
  commandForInput(input: string): string | undefined;
73
75
  actionForInput(input: string, context: ScreenContext): ScreenAction | undefined;
74
76
  receiveResult(result: unknown, context: ScreenContext): void;
@@ -3,7 +3,9 @@ import { copyThrough } from '../../../lib/clipboard.js';
3
3
  import { serverMessage } from '../../../lib/jsonapi-error.js';
4
4
  import { BORDER, textNode } from '../../../lib/vnode.js';
5
5
  import { AsyncScreen, } from '../../../Screen/async-screen.js';
6
+ import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
6
7
  import { runRowAction } from '../../../Screen/row-action.js';
8
+ import { activeRunInfo } from '../../run/Data/active-run.js';
7
9
  import { ADDONS_KEY, hasAddonsMessages, TicketContent, } from '../Component/ticket-content/index.js';
8
10
  import { initialExpandedKeys, resolveSelectedKey, retainExpandedKeys, ticketContentModel, ticketContentRowId, } from '../Component/ticket-content/model.js';
9
11
  import { handleTicketCopy, ticketCopyActions, ticketEditAction, ticketHeaderTree, ticketTitleOf, } from '../Component/ticket-detail/index.js';
@@ -11,8 +13,10 @@ import { ticketTeaserLines, ticketTeaserTree, } from '../Component/ticket-teaser
11
13
  import { readTicketAddons } from '../Data/addons.js';
12
14
  import { loadTicketDetail } from '../Data/detail.js';
13
15
  import { ticketDetailInputContext } from '../Data/input.js';
14
- import { loadTicketView, readTicket, refreshTicket, saveTicket, ticketLoaded, watchTicket, } from '../Data/store.js';
16
+ import { loadTicketView, mergeTicketDocuments, readTicket, refreshTicket, saveTicket, ticketLoaded, watchTicket, } from '../Data/store.js';
15
17
  import { updateTicketFrozen } from '../Data/write.js';
18
+ import { isTicketCancellable } from '../Form/edit.js';
19
+ import { cancelTicketRequest, restartRunRequest } from './ticket-actions.js';
16
20
  /** Overview width when the context carries none — a pipe has no terminal. */
17
21
  const DEFAULT_COLUMNS = 80;
18
22
  /**
@@ -318,20 +322,46 @@ export class TicketContentScreen extends AsyncScreen {
318
322
  return this.select(keys.length - 1, context);
319
323
  return false;
320
324
  }
325
+ cancellable() {
326
+ return !!this.document && isTicketCancellable(this.document);
327
+ }
328
+ restartable() {
329
+ return !!this.document && activeRunInfo(this.document) !== null;
330
+ }
321
331
  commandForInput(input) {
322
- return this.state === 'ready' && this.viewMode === 'full' && input === 'e'
323
- ? 'edit-assignment'
324
- : undefined;
332
+ if (this.state !== 'ready' || this.viewMode !== 'full')
333
+ return undefined;
334
+ if (input === 'e')
335
+ return 'edit-assignment';
336
+ if (input === 'x' && this.cancellable())
337
+ return 'cancel-ticket';
338
+ if (input === 'r' && this.restartable())
339
+ return 'restart-run';
340
+ return undefined;
325
341
  }
326
342
  actionForInput(input, context) {
327
- return this.commandForInput(input) === 'edit-assignment'
328
- ? ticketEditAction(context, this.document)
329
- : undefined;
343
+ const command = this.commandForInput(input);
344
+ if (command === 'edit-assignment')
345
+ return ticketEditAction(context, this.document);
346
+ if (command === 'cancel-ticket' && this.document)
347
+ return confirmNavigation(cancelTicketRequest(this.document));
348
+ if (command === 'restart-run' && this.document)
349
+ return confirmNavigation(restartRunRequest(this.document.data?.id ?? context.params?.ticketId ?? '', ticketTitleOf(this.document).identifier));
350
+ return undefined;
330
351
  }
331
352
  receiveResult(result, context) {
332
- if (result &&
333
- typeof result === 'object' &&
334
- result.type === 'ticket-assignment-updated') {
353
+ const type = result && typeof result === 'object'
354
+ ? result.type
355
+ : undefined;
356
+ if (type === 'ticket-cancelled' || type === 'run-cancelled') {
357
+ const document = result.document;
358
+ // Restart run returns a sparse read: merged, so this view's includes stay.
359
+ if (document)
360
+ this.replaceReady(saveTicket(context, mergeTicketDocuments(this.document, document)));
361
+ context.requestDraw();
362
+ return;
363
+ }
364
+ if (type === 'ticket-assignment-updated') {
335
365
  const returned = result;
336
366
  if (returned.document)
337
367
  this.replaceReady(saveTicket(context, returned.document));
@@ -384,6 +414,12 @@ export class TicketContentScreen extends AsyncScreen {
384
414
  return [
385
415
  actionItem('detail-tab', 'Tab', 'section'),
386
416
  actionItem('detail-edit', 'e', 'edit'),
417
+ ...(this.cancellable()
418
+ ? [actionItem('ticket-cancel', 'x', 'cancel ticket')]
419
+ : []),
420
+ ...(this.restartable()
421
+ ? [actionItem('detail-restart', 'r', 'restart run')]
422
+ : []),
387
423
  // Freeze and paging before copy: at 80 columns the footer clips the
388
424
  // tail, and `Y:Copy link` is the hint that yields.
389
425
  actionItem('detail-freeze', 'f', this.isFrozen() ? 'unfreeze' : 'freeze'),
@@ -42,10 +42,10 @@ export declare class TicketRunsScreen extends AsyncScreen<TicketDetailDocument>
42
42
  select(index: number, context: ScreenContext): boolean;
43
43
  activate(index: number, context: ScreenContext): boolean;
44
44
  handleInput(input: string, context: ScreenContext): boolean;
45
- /** The selected run, when it can still be edited (claimed or running). */
46
- private editableRun;
45
+ /** The selected run, when it can still be cancelled (claimed or running). */
46
+ private cancellableRun;
47
47
  commandForInput(input: string): string | undefined;
48
- actionForInput(input: string, context: ScreenContext): ScreenAction | undefined;
48
+ actionForInput(input: string): ScreenAction | undefined;
49
49
  receiveResult(result: unknown, context: ScreenContext): void;
50
50
  protected renderReady(document: TicketDetailDocument, context: ScreenContext): VNode;
51
51
  protected chrome(context: ScreenContext): FullScreenChrome;
@@ -3,9 +3,11 @@ import { flattenSections } from '../../../Component/section-list/index.js';
3
3
  import { ListCursor } from '../../../lib/cursor.js';
4
4
  import { columnNode } from '../../../lib/vnode.js';
5
5
  import { AsyncScreen } from '../../../Screen/async-screen.js';
6
+ import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
6
7
  import { listRowIds, listTableRows, listTableTree } from '../../collection.js';
7
8
  import { TICKET_RUN_TABLE, ticketRunRows } from '../../run/Data/runs.js';
8
9
  import { isRunCancellable } from '../../run/Form/edit.js';
10
+ import { cancelRunRequest } from '../../run/Screen/run-actions.js';
9
11
  import { handleTicketCopy, ticketCopyActions, ticketHeaderTree, ticketTitleOf, } from '../Component/ticket-detail/index.js';
10
12
  import { ticketDetailInputContext, ticketInputContext } from '../Data/input.js';
11
13
  import { loadTicketView, readTicket, refreshTicket, saveTicket, ticketLoaded, watchTicket, } from '../Data/store.js';
@@ -132,31 +134,23 @@ export class TicketRunsScreen extends AsyncScreen {
132
134
  return this.select(view.selectable - 1, context);
133
135
  return false;
134
136
  }
135
- /** The selected run, when it can still be edited (claimed or running). */
136
- editableRun() {
137
+ /** The selected run, when it can still be cancelled (claimed or running). */
138
+ cancellableRun() {
137
139
  if (!this.document)
138
140
  return undefined;
139
141
  const run = ticketRunRows(this.document)[this.cursor.index];
140
142
  return run?.id && isRunCancellable(run.state) ? { id: run.id } : undefined;
141
143
  }
142
144
  commandForInput(input) {
143
- return this.state === 'ready' && input === 'e' && this.editableRun()
144
- ? 'edit-run'
145
+ return this.state === 'ready' && input === 'x' && this.cancellableRun()
146
+ ? 'cancel-run'
145
147
  : undefined;
146
148
  }
147
- actionForInput(input, context) {
148
- const run = this.editableRun();
149
- if (this.commandForInput(input) !== 'edit-run' || !run)
149
+ actionForInput(input) {
150
+ const run = this.cancellableRun();
151
+ if (this.commandForInput(input) !== 'cancel-run' || !run || !this.document)
150
152
  return undefined;
151
- return {
152
- type: 'navigate',
153
- routeId: 'run.edit',
154
- params: {
155
- ticketId: this.document?.data?.id ?? context.params?.ticketId ?? '',
156
- runId: run.id,
157
- },
158
- result: this.document,
159
- };
153
+ return confirmNavigation(cancelRunRequest(this.document, run.id));
160
154
  }
161
155
  receiveResult(result, context) {
162
156
  if (result &&
@@ -194,8 +188,8 @@ export class TicketRunsScreen extends AsyncScreen {
194
188
  const view = this.currentView(context);
195
189
  return [
196
190
  actionItem('detail-tab', 'Tab', 'section'),
197
- ...(this.editableRun()
198
- ? [actionItem('detail-edit', 'e', 'edit run')]
191
+ ...(this.cancellableRun()
192
+ ? [actionItem('run-cancel', 'x', 'cancel run')]
199
193
  : []),
200
194
  ...ticketCopyActions(),
201
195
  actionItem('detail-arrows', '↑↓', view.selectable > 1 ? 'select' : 'scroll'),
@@ -6,7 +6,6 @@ import { ProjectConductorsScreen } from '../Entity/conductor/Screen/project-cond
6
6
  import { ProjectOverviewScreen } from '../Entity/project/Screen/project-overview.js';
7
7
  import { ProjectPickerScreen } from '../Entity/project/Screen/project-picker.js';
8
8
  import { ProjectsScreen } from '../Entity/project/Screen/projects-screen.js';
9
- import { EditRunFormScreen } from '../Entity/run/Screen/edit-run-form.js';
10
9
  import { RunDetailScreen } from '../Entity/run/Screen/run-detail.js';
11
10
  import { RunsScreen } from '../Entity/run/Screen/runs.js';
12
11
  import { WorkspaceMemberRunsScreen } from '../Entity/run/Screen/user-runs.js';
@@ -27,6 +26,7 @@ import { WhoFilterScreen } from '../Entity/ticket/Screen/who-filter-form.js';
27
26
  import { WorkspaceMemberOverviewScreen } from '../Entity/user/Screen/member-overview.js';
28
27
  import { UsersScreen } from '../Entity/user/Screen/users.js';
29
28
  import { WorkspacePickerScreen } from '../Entity/workspace/Screen/workspace-picker.js';
29
+ import { ConfirmDialogScreen } from '../Screen/confirm-dialog.js';
30
30
  import { defineRoutes } from './registry.js';
31
31
  export const bootLocationFor = (route) => {
32
32
  if (!route)
@@ -84,7 +84,7 @@ const BUILT_IN = [
84
84
  TicketAddonsScreen,
85
85
  AddonActionFormScreen,
86
86
  RunDetailScreen,
87
- EditRunFormScreen,
87
+ ConfirmDialogScreen,
88
88
  ];
89
89
  export function buildRoutes(contributed = [], isWorkspaceAdmin = false) {
90
90
  const builtIn = isWorkspaceAdmin
@@ -0,0 +1,49 @@
1
+ import type { VNode } from '@opentui/core';
2
+ import { AsyncModalScreen } from './async-modal-screen.js';
3
+ import type { ModalChrome } from './modal-screen.js';
4
+ import type { ScreenAction, ScreenContext } from './screen.js';
5
+ /** What the dialog shows once its request is prepared. */
6
+ export interface ConfirmPrompt {
7
+ readonly message: string;
8
+ readonly detail?: string;
9
+ /** Absent: there is nothing to confirm, and Enter writes nothing. */
10
+ readonly confirm?: (context: ScreenContext) => Promise<unknown>;
11
+ }
12
+ /**
13
+ * One confirmable action. The dialog knows no entity: each slice builds its
14
+ * own request, so a shared screen never imports a slice.
15
+ */
16
+ export interface ConfirmRequest {
17
+ readonly title: string;
18
+ readonly prepare: (context: ScreenContext) => Promise<ConfirmPrompt>;
19
+ }
20
+ export declare const confirmRequestContext: import("../Routing/context.js").ContextKey<ConfirmRequest>;
21
+ /** The action that opens the dialog for `request`. */
22
+ export declare const confirmNavigation: (request: ConfirmRequest) => ScreenAction;
23
+ /** The confirmation dialog: Enter confirms, Esc closes and writes nothing. */
24
+ export declare class ConfirmDialogScreen extends AsyncModalScreen<ConfirmPrompt> {
25
+ static readonly route: {
26
+ id: string;
27
+ path: string;
28
+ presentation: "modal";
29
+ context: (_params: Readonly<Record<string, string>>, state: unknown, base: import("../Routing/context.js").ContextBag) => import("../Routing/context.js").ContextBag;
30
+ };
31
+ readonly id: string;
32
+ private request;
33
+ private action;
34
+ private message;
35
+ private submitting;
36
+ /** Index of the focused button; Confirm, the first, when there is one. */
37
+ private focus;
38
+ private buttons;
39
+ protected load(context: ScreenContext): Promise<ConfirmPrompt>;
40
+ protected renderLoading(): string[];
41
+ protected renderReady(prompt: ConfirmPrompt): VNode;
42
+ protected modalChrome(): ModalChrome;
43
+ protected actions(): import("../Component/footer-actions/index.js").ActionItem[];
44
+ takeAction(): ScreenAction | undefined;
45
+ handleInput(input: string, context: ScreenContext): boolean;
46
+ /** Closing drops the prompt: the next open carries a different request. */
47
+ leave(): void;
48
+ reset(): void;
49
+ }
@@ -0,0 +1,148 @@
1
+ import { actionItem } from '../Component/footer-actions/index.js';
2
+ import { serverMessage } from '../lib/jsonapi-error.js';
3
+ import { columnNode, rowNode, textNode } from '../lib/vnode.js';
4
+ import { wrapToWidth } from '../lib/width.js';
5
+ import { defineContext } from '../Routing/context.js';
6
+ import { AsyncModalScreen } from './async-modal-screen.js';
7
+ export const confirmRequestContext = defineContext('confirm-request', 'input');
8
+ /** The action that opens the dialog for `request`. */
9
+ export const confirmNavigation = (request) => ({
10
+ type: 'navigate',
11
+ routeId: ConfirmDialogScreen.route.id,
12
+ params: {},
13
+ result: request,
14
+ });
15
+ /** Text width inside the popup, as the edit popup measures it. */
16
+ const WIDTH = 58;
17
+ /** One node per physical row: a server message is longer than the popup. */
18
+ const rowsOf = (id, text) => text
19
+ .split('\n')
20
+ .flatMap((line) => wrapToWidth(line, WIDTH))
21
+ .map((content, index) => textNode({ id: `${id}-${index}`, content }));
22
+ const BUTTON_LABELS = {
23
+ confirm: 'Confirm',
24
+ close: 'Close',
25
+ };
26
+ /** The confirmation dialog: Enter confirms, Esc closes and writes nothing. */
27
+ export class ConfirmDialogScreen extends AsyncModalScreen {
28
+ static route = {
29
+ id: 'confirm',
30
+ path: '/confirm',
31
+ presentation: 'modal',
32
+ context: (_params, state, base) => state ? base.set(confirmRequestContext, state) : base,
33
+ };
34
+ id = ConfirmDialogScreen.route.id;
35
+ request;
36
+ action;
37
+ message = '';
38
+ submitting = false;
39
+ /** Index of the focused button; Confirm, the first, when there is one. */
40
+ focus = 0;
41
+ buttons() {
42
+ return this.readyValue?.confirm ? ['confirm', 'close'] : ['close'];
43
+ }
44
+ load(context) {
45
+ this.request = context.contexts?.has(confirmRequestContext)
46
+ ? context.contexts.get(confirmRequestContext)
47
+ : undefined;
48
+ return this.request?.prepare(context) ?? Promise.resolve({ message: '' });
49
+ }
50
+ renderLoading() {
51
+ return ['Loading…'];
52
+ }
53
+ renderReady(prompt) {
54
+ return columnNode('confirm-dialog', ...rowsOf('confirm-dialog-message', prompt.message), ...rowsOf('confirm-dialog-detail', this.message || prompt.detail || ''), textNode({ id: 'confirm-dialog-gap', content: '' }), rowNode('confirm-dialog-buttons', ...this.buttons().flatMap((button, index) => [
55
+ ...(index > 0
56
+ ? [textNode({ id: `confirm-dialog-gap-${index}`, content: ' ' })]
57
+ : []),
58
+ textNode({
59
+ id: `confirm-dialog-button-${button}`,
60
+ content: `${index === this.focus ? '▸' : ' '}[ ${BUTTON_LABELS[button]} ]`,
61
+ selected: index === this.focus,
62
+ }),
63
+ ])));
64
+ }
65
+ modalChrome() {
66
+ return { title: this.request?.title ?? '' };
67
+ }
68
+ actions() {
69
+ return [
70
+ actionItem('confirm-move', '←→', 'button'),
71
+ actionItem('confirm-press', 'Enter', 'press'),
72
+ actionItem('confirm-esc', 'Esc', 'close'),
73
+ ];
74
+ }
75
+ takeAction() {
76
+ const action = this.action;
77
+ this.action = undefined;
78
+ return action;
79
+ }
80
+ handleInput(input, context) {
81
+ if (super.handleInput(input, context))
82
+ return true;
83
+ if (!this.readyValue)
84
+ return false;
85
+ const buttons = this.buttons();
86
+ const step = input === 'right' || input === 'tab'
87
+ ? 1
88
+ : input === 'left' || input === 'shift+tab'
89
+ ? -1
90
+ : 0;
91
+ if (step !== 0) {
92
+ if (!this.submitting)
93
+ this.focus = (this.focus + step + buttons.length) % buttons.length;
94
+ context.requestDraw();
95
+ return true;
96
+ }
97
+ const pressed = input === 'escape'
98
+ ? 'close'
99
+ : input === 'enter' || input === ' '
100
+ ? buttons[this.focus]
101
+ : undefined;
102
+ if (!pressed)
103
+ return false;
104
+ // A pending write still lands; leaving now would let its result pop the
105
+ // screen below as well, and a second confirm would write twice.
106
+ if (this.submitting)
107
+ return true;
108
+ const confirm = this.readyValue.confirm;
109
+ if (pressed === 'close' || !confirm) {
110
+ this.action = { type: 'back' };
111
+ context.requestDraw();
112
+ return true;
113
+ }
114
+ this.submitting = true;
115
+ this.message = '';
116
+ void confirm(context)
117
+ .then((result) => {
118
+ if (!context.isActive())
119
+ return;
120
+ if (context.back)
121
+ context.back(result);
122
+ else
123
+ this.action = { type: 'back', result };
124
+ })
125
+ .catch((caught) => {
126
+ this.message = serverMessage(caught);
127
+ })
128
+ .finally(() => {
129
+ this.submitting = false;
130
+ if (context.isActive())
131
+ context.requestDraw();
132
+ });
133
+ return true;
134
+ }
135
+ /** Closing drops the prompt: the next open carries a different request. */
136
+ leave() {
137
+ this.reset();
138
+ super.leave();
139
+ }
140
+ reset() {
141
+ this.request = undefined;
142
+ this.action = undefined;
143
+ this.message = '';
144
+ this.submitting = false;
145
+ this.focus = 0;
146
+ super.reset();
147
+ }
148
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-bakers-ui",
3
- "version": "0.10.1-next.4",
3
+ "version": "0.10.1-next.6",
4
4
  "description": "bakers.build TUI: interactive terminal UI (dashboard, projects, tickets) as a dropsh `tui` renderer plugin.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,11 +32,11 @@
32
32
  "zustand": "^5.0.15"
33
33
  },
34
34
  "peerDependencies": {
35
- "@bakers-build/core": "^0.10.1-next.4",
36
- "@bakers-build/message": "^0.10.1-next.4"
35
+ "@bakers-build/core": "^0.10.1-next.6",
36
+ "@bakers-build/message": "^0.10.1-next.6"
37
37
  },
38
38
  "bakersBuild": {
39
- "commit": "f4aaa8754ca44aad3904a3dc98eccb590f1e1a62",
39
+ "commit": "93f045b91e4490c2e2569bd02bd641f4d1c6491f",
40
40
  "channel": "next"
41
41
  }
42
42
  }
@@ -1,26 +0,0 @@
1
- import type { VNode } from '@opentui/core';
2
- import { AsyncModalScreen } from '../../../Screen/async-modal-screen.js';
3
- import type { ModalChrome } from '../../../Screen/modal-screen.js';
4
- import type { ScreenAction, ScreenContext } from '../../../Screen/screen.js';
5
- import type { TicketDetailDocument } from '../../../types.js';
6
- export declare class EditRunFormScreen extends AsyncModalScreen<TicketDetailDocument> {
7
- readonly modal = true;
8
- static readonly route: {
9
- id: string;
10
- path: string;
11
- parent: string;
12
- presentation: "modal";
13
- context: (_params: Readonly<Record<string, string>>, state: unknown, base: import("../../../Routing/context.js").ContextBag) => import("../../../Routing/context.js").ContextBag;
14
- };
15
- readonly id: string;
16
- private action;
17
- private message;
18
- private submitting;
19
- protected load(context: ScreenContext): Promise<TicketDetailDocument>;
20
- protected renderLoading(): string[];
21
- protected renderReady(document: TicketDetailDocument, context: ScreenContext): VNode;
22
- protected modalChrome(_context: ScreenContext): ModalChrome;
23
- protected actions(): import("../../../Component/footer-actions/index.js").ActionItem[];
24
- takeAction(): ScreenAction | undefined;
25
- handleInput(input: string, context: ScreenContext): boolean;
26
- }
@@ -1,117 +0,0 @@
1
- import { actionItem } from '../../../Component/footer-actions/index.js';
2
- import { columnNode, textNode } from '../../../lib/vnode.js';
3
- import { AsyncModalScreen } from '../../../Screen/async-modal-screen.js';
4
- import { runResource } from '../Component/run-detail/index.js';
5
- import { cancelRunPayload, isRunCancellable } from '../Form/edit.js';
6
- import { runDetailInputContext } from './run-detail.js';
7
- export class EditRunFormScreen extends AsyncModalScreen {
8
- modal = true;
9
- static route = {
10
- id: 'run.edit',
11
- path: '/tickets/:ticketId/runs/:runId/edit',
12
- parent: 'run.detail',
13
- presentation: 'modal',
14
- context: (_params, state, base) => state
15
- ? base.set(runDetailInputContext, {
16
- document: state,
17
- })
18
- : base,
19
- };
20
- id = EditRunFormScreen.route.id;
21
- action;
22
- message = '';
23
- submitting = false;
24
- load(context) {
25
- if (context.contexts?.has(runDetailInputContext))
26
- return Promise.resolve(context.contexts.get(runDetailInputContext).document);
27
- return Promise.resolve({});
28
- }
29
- renderLoading() {
30
- return ['Loading run edit…'];
31
- }
32
- renderReady(document, context) {
33
- const run = runResource(document, context.params?.runId);
34
- return columnNode('run-edit-form', textNode({
35
- id: 'run-edit-form-label',
36
- content: `Cancel run${run ? ` #${String(run.attributes?.drupal_internal__id ?? run.id)}` : ''}?`,
37
- }), textNode({
38
- id: 'run-edit-form-message',
39
- content: this.message || 'This marks the run as cancelled.',
40
- }));
41
- }
42
- modalChrome(_context) {
43
- return { title: '✕ Cancel run' };
44
- }
45
- actions() {
46
- return [
47
- actionItem('run-cancel-submit', 'Enter', 'cancel'),
48
- actionItem('run-cancel-esc', 'Esc', 'close'),
49
- ];
50
- }
51
- takeAction() {
52
- const action = this.action;
53
- this.action = undefined;
54
- return action;
55
- }
56
- handleInput(input, context) {
57
- if (super.handleInput(input, context))
58
- return true;
59
- if (input === 'escape') {
60
- this.action = { type: 'back' };
61
- context.requestDraw();
62
- return true;
63
- }
64
- if (input !== 'enter' || this.submitting)
65
- return false;
66
- const document = this.readyValue;
67
- const runId = context.params?.runId;
68
- if (!document || !runId)
69
- return false;
70
- const run = runResource(document, runId);
71
- if (!run || !isRunCancellable(String(run.attributes?.state ?? '')))
72
- return false;
73
- const client = context.services?.writeClient ?? context.services?.client;
74
- if (!client)
75
- return false;
76
- this.submitting = true;
77
- void client
78
- .update('bb_run--bb_run', runId, cancelRunPayload())
79
- .then(() => {
80
- const updatedDocument = {
81
- ...document,
82
- ...(document.included
83
- ? {
84
- included: document.included.map((resource) => resource.id === runId
85
- ? {
86
- ...resource,
87
- attributes: {
88
- ...resource.attributes,
89
- state: 'cancelled',
90
- },
91
- }
92
- : resource),
93
- }
94
- : {}),
95
- };
96
- const result = {
97
- type: 'run-cancelled',
98
- runId,
99
- document: updatedDocument,
100
- };
101
- if (context.back)
102
- context.back(result);
103
- else
104
- this.action = { type: 'back', result };
105
- })
106
- .catch((caught) => {
107
- this.message =
108
- caught instanceof Error ? caught.message : String(caught);
109
- })
110
- .finally(() => {
111
- this.submitting = false;
112
- if (context.isActive())
113
- context.requestDraw();
114
- });
115
- return true;
116
- }
117
- }