@bakers-build/addon-bakers-ui 0.10.0 → 0.10.1-next.10

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.
@@ -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
- }