@datagrok/hit-triage 1.10.8 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/.grokignore +2 -0
  2. package/.turbo/turbo-build.log +24 -6
  3. package/.vscode/settings.json +16 -0
  4. package/CHANGELOG.md +80 -1
  5. package/CLAUDE.md +87 -10
  6. package/README_HD.md +14 -14
  7. package/README_HT.md +6 -6
  8. package/README_PH.md +110 -0
  9. package/bdd/bdd.config.json +3 -0
  10. package/bdd/bindings/campaign.ts +626 -0
  11. package/bdd/bindings/hit-design.ts +93 -0
  12. package/bdd/bindings/landing.ts +839 -0
  13. package/bdd/bindings/pepti-hit.ts +35 -0
  14. package/bdd/features/campaign/crumbs.feature +22 -0
  15. package/bdd/features/campaign/grid.feature +56 -0
  16. package/bdd/features/campaign/merge.feature +105 -0
  17. package/bdd/features/campaign/molecule-vid.feature +40 -0
  18. package/bdd/features/campaign/permissions.feature +46 -0
  19. package/bdd/features/campaign/progress-tracker.feature +89 -0
  20. package/bdd/features/campaign/refresh-hint.feature +33 -0
  21. package/bdd/features/campaign/ribbon.feature +49 -0
  22. package/bdd/features/campaign/stage-choices.feature +39 -0
  23. package/bdd/features/campaign/submit.feature +135 -0
  24. package/bdd/features/campaign/tracker-cards.feature +46 -0
  25. package/bdd/features/campaign/view-only.feature +37 -0
  26. package/bdd/features/hit-design/campaign-column-metadata.feature +61 -0
  27. package/bdd/features/landing/campaign-deep-links.feature +61 -0
  28. package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
  29. package/bdd/features/landing/hit-design-campaigns.feature +153 -0
  30. package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
  31. package/bdd/features/landing/new-campaign.feature +69 -0
  32. package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
  33. package/bdd/features/landing/pepti-hit-landing.feature +132 -0
  34. package/bdd/features/pepti-hit/helm-edit.feature +47 -0
  35. package/bdd/features/templates/template-editor.feature +130 -0
  36. package/bdd/features/templates/template-picker.feature +112 -0
  37. package/bdd/features/templates/triage-forms.feature +59 -0
  38. package/bdd/fixtures/bar-chart.layout +1 -0
  39. package/bdd/fixtures/merge-local.csv +2 -0
  40. package/bdd/generated/campaign/crumbs.test.ts +33 -0
  41. package/bdd/generated/campaign/grid.test.ts +79 -0
  42. package/bdd/generated/campaign/merge.test.ts +134 -0
  43. package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
  44. package/bdd/generated/campaign/permissions.test.ts +58 -0
  45. package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
  46. package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
  47. package/bdd/generated/campaign/ribbon.test.ts +65 -0
  48. package/bdd/generated/campaign/stage-choices.test.ts +55 -0
  49. package/bdd/generated/campaign/submit.test.ts +167 -0
  50. package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
  51. package/bdd/generated/campaign/view-only.test.ts +51 -0
  52. package/bdd/generated/hit-design/campaign-column-metadata.test.ts +76 -0
  53. package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
  54. package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
  55. package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
  56. package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
  57. package/bdd/generated/landing/new-campaign.test.ts +78 -0
  58. package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
  59. package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
  60. package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
  61. package/bdd/generated/templates/template-editor.test.ts +137 -0
  62. package/bdd/generated/templates/template-picker.test.ts +119 -0
  63. package/bdd/generated/templates/triage-forms.test.ts +68 -0
  64. package/bdd/package.json +1 -0
  65. package/bdd/tsconfig.json +13 -0
  66. package/css/hit-triage.css +27 -23
  67. package/dist/package-test.js +690 -4
  68. package/dist/package-test.js.map +1 -1
  69. package/dist/package.js +318 -73
  70. package/dist/package.js.map +1 -1
  71. package/package.json +15 -8
  72. package/queries/locks.sql +37 -0
  73. package/src/app/accordeons/layout-input.ts +52 -44
  74. package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
  75. package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
  76. package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
  77. package/src/app/accordeons/new-template-accordeon.ts +41 -24
  78. package/src/app/ai/view-functions.ts +22 -19
  79. package/src/app/base-view.ts +99 -8
  80. package/src/app/consts.ts +8 -5
  81. package/src/app/dialogs/functions-dialog.ts +14 -9
  82. package/src/app/dialogs/merge-table-dialog.ts +181 -325
  83. package/src/app/hit-app-base.ts +61 -90
  84. package/src/app/hit-design-app.ts +492 -882
  85. package/src/app/hit-design-views/info-view.ts +57 -407
  86. package/src/app/hit-design-views/submit-view.ts +216 -111
  87. package/src/app/hit-design-views/tiles-view.ts +168 -123
  88. package/src/app/hit-design-views/utils.css +0 -8
  89. package/src/app/hit-triage-app.ts +69 -38
  90. package/src/app/hit-triage-views/info-view.ts +70 -371
  91. package/src/app/pep-triage-app.ts +2 -2
  92. package/src/app/pep-triage-views/info-view.ts +42 -83
  93. package/src/app/pepti-hit-app.ts +32 -183
  94. package/src/app/pepti-hits-views/info-view.ts +15 -37
  95. package/src/app/shared/campaign-catalog.ts +408 -0
  96. package/src/app/shared/campaign-session.ts +557 -0
  97. package/src/app/shared/compute-editor.ts +274 -0
  98. package/src/app/shared/hit-home.ts +45 -0
  99. package/src/app/shared/new-campaign-form.ts +90 -0
  100. package/src/app/shared/permissions-editor.ts +93 -0
  101. package/src/app/shared/template-editor.ts +331 -0
  102. package/src/app/shared/template-picker.ts +154 -0
  103. package/src/app/types.ts +2 -0
  104. package/src/app/utils/merge-table.ts +183 -78
  105. package/src/app/utils.ts +34 -325
  106. package/src/package-api.ts +29 -8
  107. package/src/package-test.ts +17 -2
  108. package/src/package.g.ts +12 -8
  109. package/src/package.ts +19 -7
  110. package/src/tests/ai.ts +244 -0
  111. package/src/tests/campaign-layout.ts +82 -0
  112. package/src/tests/campaign-session.ts +168 -0
  113. package/src/tests/campaigns.ts +23 -0
  114. package/src/tests/catalog.ts +156 -0
  115. package/src/tests/compat.ts +482 -0
  116. package/src/tests/compute.ts +165 -0
  117. package/src/tests/fixtures.ts +359 -0
  118. package/src/tests/merge.ts +149 -0
  119. package/src/tests/owners.ts +11 -0
  120. package/src/tests/save-lock.ts +932 -0
  121. package/src/tests/storage.ts +106 -0
  122. package/src/tests/template-editor.ts +538 -0
  123. package/src/tests/templates.ts +143 -0
  124. package/src/tests/triage-start.ts +81 -0
  125. package/src/tests/u2-guards.ts +384 -0
  126. package/src/tests/vid.ts +77 -0
  127. package/tsconfig.json +3 -0
  128. package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
  129. package/src/app/dialogs/permissions-dialog.ts +0 -66
@@ -1,150 +1,195 @@
1
- import * as ui from 'datagrok-api/ui';
1
+ /* The progress tracker of a Hit Design / PeptiHit campaign: the platform Tile Viewer over the campaign's table, one
2
+ lane per stage (and one per other stage a row holds), in a modal dialog over the campaign view — pinned to it:
3
+ hidden while another view is current, closed with it. A card dragged to another lane moves its row to that stage at
4
+ once; closing the tracker, whichever way, keeps the moves and saves them. The card layout a user makes (Edit
5
+ Form...) is kept with the campaign. */
2
6
  import * as grok from 'datagrok-api/grok';
3
7
  import * as DG from 'datagrok-api/dg';
4
- import {HitDesignApp} from '../hit-design-app';
5
- import {_package} from '../../package';
8
+ import {Dialog, RecordsInput, TextInput, computed, div, signal, statusLine, subscribe} from '@datagrok-libraries/u2';
9
+ import type {ViewHost} from '@datagrok-libraries/u2/dg';
10
+ import type {HitDesignApp} from '../hit-design-app';
6
11
  import {TileCategoriesColName} from '../consts';
7
- // @ts-ignore
8
- import './utils.css';
9
- import {getTileCategoryEditor} from '../accordeons/new-hit-design-template-accordeon';
10
12
 
11
- export function getTilesViewDialog(app: HitDesignApp, getTableView: () => DG.TableView | null) {
12
- const tilesViewerSketchStateString = app.campaign?.tilesViewerFormSketch;
13
- let sketchState: any | null = null;
14
- if (tilesViewerSketchStateString && tilesViewerSketchStateString.length > 0) {
15
- try {
16
- sketchState = JSON.parse(tilesViewerSketchStateString);
17
- } catch (e) {
18
- console.error('Failed to parse sketch state string', e);
19
- }
20
- }
21
- if (sketchState) {
22
- // after saving, some columns might be removed in the meantime, so we need to update the
23
- //sketch state and remove them so that the viewer can be initialized correctly.
24
- if (sketchState.elementStates && (sketchState.elementStates.length ?? 0) > 0) {
25
- sketchState.elementStates = sketchState.elementStates.filter((elementState: any) =>
26
- elementState?.viewerSettings?.column && app.dataFrame!.col(elementState.viewerSettings.column),
27
- );
28
- // similarly, because the table name can be duplicated or changed,
29
- // we need to make sure that table name in all viewer settings corresponds to actual table name
30
- sketchState.elementStates.forEach((elState: any) => {
31
- if (elState?.viewerSettings?.table)
32
- elState.viewerSettings.table = app.dataFrame!.name;
33
- });
34
- }
35
- }
13
+ /** A lane as wide as its card, the lanes scrolling sideways when they do not fit: the platform's own card (no
14
+ * layout kept with the campaign) needs 368 px, so five lanes fit at 1920; a kept layout reaches its rightmost element,
15
+ * plus the card's frame. */
16
+ const LANE_WIDTH = 368;
17
+ const CARD_FRAME = 40;
36
18
 
37
- const tileOpts = {lanesColumnName: TileCategoriesColName,
38
- lanes: app.stages,
39
- ...((sketchState?.elementStates?.length ?? 0) > 0 ? {sketchState} : {})};
19
+ /** The progress tracker over the campaign of `host`'s view, shown pinned to the view; answers its dialog. */
20
+ export function showProgressTracker(app: HitDesignApp, host: ViewHost): Dialog {
21
+ const view = host.view as DG.TableView;
22
+ const df = view.dataFrame;
23
+ const dialog = new Dialog('Progress Tracker', {name: 'progress-tracker', closeOnly: true});
24
+ const lanes = div([], 'hit-design-tracker-lanes');
25
+ let viewer: DG.Viewer | null = null;
26
+ // the stages when the tracker opened, or since Modify Stages saved them: closing saves when they differ
27
+ let stagesBefore = stages();
28
+ const moved = signal(0);
29
+ const needed = signal(0);
30
+ const room = signal(0);
40
31
 
41
- const tv = getTableView();
32
+ dialog.build(() => {
33
+ dialog.add(lanes);
34
+ dialog.addButton('Modify Stages', () => modifyStages(), {start: true});
35
+ // a scrollbar the system may hide (macOS) is no sign that more lanes are there: the line says so
36
+ const fit = new ResizeObserver(() => room.value = lanes.clientWidth);
37
+ fit.observe(lanes);
38
+ dialog.own(() => fit.disconnect());
39
+ const more = computed(() => room.value > 0 && needed.value > room.value ? ' · scroll sideways for more stages' : '');
40
+ dialog.status(computed(() => (moved.value === 0 ? 'Drag a card to another lane to change its stage' :
41
+ `${moved.value} ${moved.value === 1 ? 'molecule' : 'molecules'} moved · saved when the tracker closes`) +
42
+ more.value));
43
+ dialog.onClose(() => closed());
44
+ subscribe(df.onValuesChanged, () => moved.value = countMoved());
45
+ });
46
+ mount();
47
+ return host.show(dialog,
48
+ {modal: true, x: 12, y: 12, width: window.innerWidth - 24, height: window.innerHeight - 24});
42
49
 
43
- if (!tv) {
44
- grok.shell.error('Failed to create tiles viewer. table view is not available.');
45
- return;
50
+ function stages(): (string | null)[] {
51
+ return df.col(TileCategoriesColName)?.toList() ?? [];
46
52
  }
47
- let v: DG.Viewer | null = null;
48
- const modal = ui.dialog('Progress Tracker');
49
- try {
50
- v = tv.addViewer(DG.VIEWER.TILE_VIEWER, tileOpts);
51
53
 
52
- const opts = v.getOptions();
53
- opts.look.sketchState = (sketchState?.elementStates?.length ?? 0) > 0 ? sketchState : null;
54
+ function countMoved(): number {
55
+ return stages().reduce((n, stage, i) => i < stagesBefore.length && stage !== stagesBefore[i] ? n + 1 : n, 0);
56
+ }
54
57
 
55
- v.setOptions(opts);
56
- v.copyViewersLook(v); // hacky way to apply sketch state
57
- } catch (e) {
58
- grok.shell.error('Failed to create tiles viewer with preset layout.\n Falling back to default layout.');
59
- console.error('Failed to create tiles viewer', e);
60
- if (v) {
61
- v.close();
62
- v.detach();
58
+ /** The campaign's card layout over this campaign's table, with what names a column the table no longer has dropped.
59
+ * The layout names the table it was made over ("Table"), which another open campaign may hold by now: the cards'
60
+ * fields would read that table's columns. */
61
+ function sketchState(): any | null {
62
+ const stored = app.campaign?.tilesViewerFormSketch;
63
+ if (!stored)
64
+ return null;
65
+ let state: any;
66
+ try {
67
+ state = JSON.parse(stored);
68
+ }
69
+ catch (e) {
70
+ console.error('Failed to parse sketch state string', e);
71
+ return null;
72
+ }
73
+ const table = view.dataFrame;
74
+ state.table = table.name;
75
+ state.elementStates = (state.elementStates ?? [])
76
+ .filter((s: any) => s?.viewerSettings?.column && table.col(s.viewerSettings.column));
77
+ for (const s of state.elementStates) {
78
+ if (s?.viewerSettings?.table)
79
+ s.viewerSettings.table = table.name;
63
80
  }
64
- v = tv.addViewer(DG.VIEWER.TILE_VIEWER,
65
- {lanesColumnName: TileCategoriesColName, lanes: app.stages});
81
+ return state.elementStates.length > 0 ? state : null;
66
82
  }
67
83
 
68
- if (!v) {
69
- grok.shell.error('Failed to create tiles viewer. check the console for more details.');
70
- return;
84
+ function laneWidth(sketch: any | null): number {
85
+ const right = Math.max(0, ...(sketch?.elementStates ?? [])
86
+ .map((s: any) => (Number(s?.left) || 0) + (Number(s?.width) || 0)));
87
+ return right > 0 ? right + CARD_FRAME : LANE_WIDTH;
71
88
  }
72
89
 
73
- let stageEditorDialog: DG.Dialog | null = null;
74
- const closeViewer = () => {// it can be already closed by the time we get here
90
+ /** The template's stages, then any other stage a row holds (a typo typed into the grid): no row is left out. */
91
+ function laneNames(): string[] {
92
+ const known = new Set(app.stages);
93
+ return [...app.stages, ...new Set(stages().filter((s): s is string => !!s && !known.has(s)))];
94
+ }
95
+
96
+ /** The Tile Viewer over the stages as they are now. */
97
+ function mount(): void {
98
+ unmount();
99
+ const names = laneNames();
100
+ const sketch = sketchState();
101
+ let tiles: DG.Viewer;
75
102
  try {
76
- v.detach();
77
- v.close();
103
+ tiles = view.addViewer(DG.VIEWER.TILE_VIEWER,
104
+ {lanesColumnName: TileCategoriesColName, lanes: names, ...sketch ? {sketchState: sketch} : {}});
105
+ const options = tiles.getOptions();
106
+ options.look.sketchState = sketch;
107
+ tiles.setOptions(options);
108
+ // the Tile Viewer applies a sketch state only through copying a look
109
+ tiles.copyViewersLook(tiles);
78
110
  } catch (e) {
111
+ grok.shell.error('Failed to create tiles viewer with preset layout.\n Falling back to default layout.');
112
+ console.error('Failed to create tiles viewer', e);
113
+ tiles = view.addViewer(DG.VIEWER.TILE_VIEWER, {lanesColumnName: TileCategoriesColName, lanes: names});
79
114
  }
80
- };
81
- modal.add(v.root);
82
- modal.addButton('Modify Stages', () => {
83
- stageEditorDialog?.close();
84
- const stageEditor = getTileCategoryEditor(app.stages);
85
- stageEditorDialog = ui.dialog('Modify Stages')
86
- .add(stageEditor.fieldsDiv)
87
- .onOK(async () => {
88
- closeViewer(); // so that its not included in the layout.
89
- ui.setUpdateIndicator(modal.root, true);
90
- try {
91
- await app.setStages(stageEditor.getFields());
92
- ui.setUpdateIndicator(modal.root, false);
93
- modal.close();
94
- await new Promise<void>((r) => setTimeout(() => {
95
- r();
96
- getTilesViewDialog(app, getTableView);
97
- }, 100));
98
- } catch (e) {
99
- grok.shell.error('Failed to update stages. check the console for more details.');
100
- console.error('Failed to update stages', e);
101
- } finally {
102
- if (modal?.root && document.contains(modal.root))
103
- modal.close();
104
- }
105
- })
106
- .show();
107
- stageEditorDialog.root.classList.add('hit-design-stage-editing-dialog');
108
- }, 0);
109
- // from this modal, only way to go to another view is through edit form.
110
- // when this happens, we should not destroy the viewer,
111
- //but just hide it so that when we come back, we can show it again.
112
- const hideModal = () => modal.root.style.setProperty('display', 'none', 'important');
113
- const showModal = () => modal.root.style.display = 'flex';
115
+ needed.value = names.length * laneWidth(sketch);
116
+ Object.assign(tiles.root.style, {minWidth: `${needed.value}px`, height: '100%'});
117
+ lanes.replaceChildren(tiles.root);
118
+ viewer = tiles;
119
+ }
114
120
 
115
- const viewChangeSub = grok.events.onCurrentViewChanged.subscribe(() => {
116
- if (grok.shell.v === tv)
117
- showModal();
118
- else
119
- hideModal();
120
- });
121
+ /** Off the view, so the campaign's saved layout never holds it. */
122
+ function unmount(): void {
123
+ const tiles = viewer;
124
+ viewer = null;
125
+ if (!tiles)
126
+ return;
127
+ try {
128
+ tiles.detach();
129
+ tiles.close();
130
+ }
131
+ catch {
132
+ // the view went first, and the viewer with it
133
+ }
134
+ }
121
135
 
122
- const colVersion = app.dataFrame?.col(TileCategoriesColName)?.version;
123
- const closeSub = modal.onClose.subscribe(() => {
124
- closeSub.unsubscribe();
125
- viewChangeSub.unsubscribe();
126
- stageEditorDialog?.close();
127
- // save the sketch state
136
+ /** Keeps the card layout with the campaign and saves the moved stages, however the tracker closed (its view too) —
137
+ * unless the app opened another campaign meanwhile: a save would write that one. */
138
+ function closed(): void {
128
139
  try {
129
- const sketchState = v.props.sketchState;
130
- if (sketchState && typeof sketchState == 'object') {
131
- const stringState = JSON.stringify(sketchState);
132
- if (app.campaign)
133
- app.campaign.tilesViewerFormSketch = stringState;
134
- }
140
+ const sketch = viewer?.props.sketchState;
141
+ if (sketch && typeof sketch === 'object' && app.campaign)
142
+ app.campaign.tilesViewerFormSketch = JSON.stringify(sketch);
135
143
  } catch (e) {
136
144
  grok.shell.error('Failed to save sketch state. check the console for more details.');
137
145
  console.error('Failed to save sketch state', e);
138
146
  }
139
- closeViewer();
140
- if (colVersion != undefined && app.dataFrame?.col(TileCategoriesColName)?.version !== colVersion)
141
- app.saveCampaign();
142
- });
143
-
144
- modal.showModal(true);
147
+ unmount();
148
+ if (app.dataFrame === df && countMoved() > 0)
149
+ void app.saveCampaign();
150
+ }
145
151
 
146
- modal.getButton('CANCEL')?.remove();
147
- modal.onOK(() => {});
148
- // remove the modal background
149
- document.querySelector('.d4-modal-background')?.remove();
152
+ /** The stages as rows, reordered, added and removed; OK saves them and the tracker shows their lanes. Rows in a
153
+ * removed stage move to the first one, which the dialog says before OK. */
154
+ function modifyStages(): void {
155
+ const modify = new Dialog('Modify Stages', {name: 'modify-stages'});
156
+ modify.build(() => {
157
+ const records = new RecordsInput<{name: string}>({
158
+ name: 'stages', orderable: true, addText: 'Add stage', newItem: () => ({name: ''}),
159
+ value: app.stages.map((name) => ({name})), rowName: (_, i) => `Stage ${i + 1}`,
160
+ columns: [{name: 'name', header: 'Name', input: (value) => new TextInput({value: value ?? '', inline: true})}],
161
+ });
162
+ const kept = computed(() => [...new Set((records.value ?? []).map((r) => r.name?.trim())
163
+ .filter((s): s is string => !!s))]);
164
+ const moves = computed(() => {
165
+ const names = new Set(kept.value);
166
+ const first = kept.value[0];
167
+ const counts = new Map<string, number>();
168
+ for (const stage of stages()) {
169
+ if (stage && !names.has(stage))
170
+ counts.set(stage, (counts.get(stage) ?? 0) + 1);
171
+ }
172
+ return first === undefined || counts.size === 0 ? null : [...counts]
173
+ .map(([stage, n]) => `${n} ${n === 1 ? 'molecule' : 'molecules'} in ${stage} move to ${first}`).join('; ');
174
+ });
175
+ modify.add(records);
176
+ modify.add(statusLine(moves));
177
+ modify.okDisabled(computed(() => kept.value.length === 0 ? 'A campaign needs at least one stage' : null),
178
+ {footer: true});
179
+ modify.onOK(async () => {
180
+ // off the view while the campaign saves its layout
181
+ unmount();
182
+ try {
183
+ // unsaved, the moves stay counted: closing the tracker saves them
184
+ if (await app.setStages(kept.peek())) {
185
+ stagesBefore = stages();
186
+ moved.value = 0;
187
+ }
188
+ } finally {
189
+ mount();
190
+ }
191
+ });
192
+ });
193
+ host.show(modify, {width: 420});
194
+ }
150
195
  }
@@ -1,11 +1,3 @@
1
1
  img[alt='hitDesignReadmeImg'] {
2
2
  max-width: 100%;
3
3
  }
4
-
5
- .hit-design-stage-editing-dialog {
6
- z-index: 10000 !important;
7
- }
8
-
9
- .hit-design-groupped-campaigns-table .d4-accordion-pane-content.expanded {
10
- margin: 0 !important;
11
- }
@@ -1,6 +1,7 @@
1
1
  import * as grok from 'datagrok-api/grok';
2
2
  import * as ui from 'datagrok-api/ui';
3
3
  import * as DG from 'datagrok-api/dg';
4
+ import {Platform, ViewHost, isView} from '@datagrok-libraries/u2/dg';
4
5
  import {AppName, HitTriageCampaign, IFunctionArgs,
5
6
  HitTriageTemplate, HitTriageTemplateIngest, IngestType, HitTriageCampaignStatus,
6
7
  HitDesignTemplate} from './types';
@@ -15,7 +16,7 @@ import {HitAppBase} from './hit-app-base';
15
16
  import {HitBaseView} from './base-view';
16
17
  import {saveCampaignDialog} from './dialogs/save-campaign-dialog';
17
18
  import {calculateColumns} from './utils/calculate-single-cell';
18
- import {defaultPermissions, PermissionsDialog} from './dialogs/permissions-dialog';
19
+ import {defaultPermissions, PermissionsEditor} from './shared/permissions-editor';
19
20
  import {attachHitInfoAi, attachHitCampaignAi} from './ai/view-functions';
20
21
  // @ts-ignore
21
22
  import '../../css/hit-triage.css';
@@ -31,6 +32,8 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
31
32
 
32
33
  private _filterViewName = 'Hit Triage | Pick';
33
34
  private _friendlyName?: string;
35
+ /** The pick view crumb's campaign label: a first save that had to take another code renames it. */
36
+ private _crumbLabel?: HTMLElement;
34
37
  protected _campaignFilters?: {[key: string]: any}[];
35
38
  protected _campaignId?: string;
36
39
  protected _dfName?: string;
@@ -40,7 +43,6 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
40
43
  private _campaign?: HitTriageCampaign;
41
44
  protected _filterDescriptions: string[] = [];
42
45
  public campaignProps: {[key: string]: any} = {};
43
- private currentPickViewId?: string;
44
46
  private _pickViewPromise?: Promise<void> | null = null;
45
47
 
46
48
  constructor(c: DG.FuncCall, appName: AppName = 'Hit Triage',
@@ -48,25 +50,13 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
48
50
  super(c, appName);
49
51
  this._infoView = infoViewConstructor(this);
50
52
  this.multiView = new DG.MultiView({viewFactories: {[this._infoView.name]: () => this._infoView}});
53
+ this.multiView.helpUrl = this._infoView.helpUrl;
51
54
  this.multiView.tabs.onTabChanged.subscribe((_) => {
52
55
  if (this.multiView.currentView instanceof HitBaseView)
53
56
  (this.multiView.currentView as HitBaseView<HitTriageTemplate, HitTriageApp>).onActivated();
54
57
  });
55
58
  this.multiView.parentCall = c;
56
59
  attachHitInfoAi(this.multiView, this);
57
- //grok.shell.addView(this.multiView);
58
-
59
- grok.events.onCurrentViewChanged.subscribe(() => {
60
- try {
61
- if (grok.shell.v?.name === this.currentPickViewId) {
62
- grok.shell.windows.showHelp = false;
63
- this.setBaseUrl();
64
- modifyUrl(CampaignIdKey, this._campaignId ?? this._campaign?.name ?? '');
65
- }
66
- } catch (e) {
67
- console.error(e);
68
- }
69
- });
70
60
  }
71
61
 
72
62
  public get submitParams() {
@@ -114,7 +104,7 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
114
104
  }
115
105
  await this.dataFrame.meta.detectSemanticTypes();
116
106
  await this.prepareDataFrame(template);
117
- this._molColName = this.dataFrame.columns.bySemType(DG.SEMTYPE.MOLECULE)?.name ?? undefined;
107
+ this._molColName = HitAppBase.moleculeColumn(this.dataFrame)?.name ?? undefined;
118
108
  this._dfName = this.dataFrame.name ?? ingestProps?.query;
119
109
  this.dataFrame.name = this._dfName ?? this.dataFrame.name ?? 'Molecules';
120
110
  this._campaignId = campaignId;
@@ -155,23 +145,29 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
155
145
 
156
146
  const curView = grok.shell.v;
157
147
  const pickV = grok.shell.addView(this.pickView);
158
- this.currentPickViewId = pickV.name;
148
+ // while the pick view is open, and no longer: its address each time it becomes current
149
+ ViewHost.of(pickV).subscribe(grok.events.onCurrentViewChanged, () => {
150
+ if (isView(grok.shell.v, pickV)) {
151
+ grok.shell.windows.showHelp = false;
152
+ this.setBaseUrl();
153
+ modifyUrl(CampaignIdKey, this._campaignId ?? this._campaign?.name ?? '');
154
+ }
155
+ });
159
156
  this._submitView = new SubmitView(this);
160
157
  this.setBaseUrl();
161
158
  modifyUrl(CampaignIdKey, this._campaignId ?? this._campaign?.name ?? '');
162
159
 
163
160
  const newView = pickV;
164
- const breadcrumbLabel = this._friendlyName ?? this._campaignId ?? 'Pick';
165
161
 
166
- setTimeout(() => {
167
- this._pickViewPromise && this._pickViewPromise.then(() => {
168
- const {sub} = addBreadCrumbsToRibbons(newView, this.appName, breadcrumbLabel, () => {
162
+ this._pickViewPromise?.then(() => {
163
+ const {breadcrumbs, sub} = addBreadCrumbsToRibbons(newView, this.appName,
164
+ this._friendlyName ?? this._campaignId ?? 'Pick', () => {
169
165
  grok.shell.v = curView;
170
166
  newView.close();
171
167
  sub.unsubscribe();
172
168
  });
173
- });
174
- }, 300);
169
+ this._crumbLabel = [...breadcrumbs.root.querySelectorAll<HTMLElement>('.ui-breadcrumbs-text-element')].pop();
170
+ });
175
171
  // this.multiView.addView(this._submitView.name, () => this._submitView!, false);
176
172
  grok.shell.windows.showHelp = false;
177
173
  }
@@ -186,7 +182,7 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
186
182
  return this._pickView = view;
187
183
  }
188
184
 
189
- get molColName() {return this._molColName ??= this.dataFrame?.columns.bySemType(DG.SEMTYPE.MOLECULE)?.name;}
185
+ get molColName() {return this._molColName ??= this.dataFrame && HitAppBase.moleculeColumn(this.dataFrame)?.name;}
190
186
 
191
187
  get fileInputType(): IngestType | undefined {return this._fileInputType;}
192
188
 
@@ -303,10 +299,11 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
303
299
  }
304
300
  });
305
301
  const permissionsButton = ui.iconFA('share', async () => {
306
- await (new PermissionsDialog(this.campaign?.permissions)).show((res) => {
307
- this.campaign!.permissions = res;
308
- this.saveCampaign(undefined, true);
309
- });
302
+ await PermissionsEditor.show(this.campaign?.permissions, {subject: this.campaignId!,
303
+ author: this.campaign?.authorUserFriendlyName, save: (res) => {
304
+ this.campaign!.permissions = res;
305
+ return this.saveCampaign(undefined, true);
306
+ }});
310
307
  }, 'Edit permissions');
311
308
  submitButton.classList.add('hit-design-submit-button');
312
309
  const hasSubmit = checkRibbonsHaveSubmit(ribbons);
@@ -331,7 +328,7 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
331
328
  view._onAdded();
332
329
  await new Promise((r) => setTimeout(r, 1000));
333
330
 
334
- const f = view.filters(this._campaignFilters ? {filters: this._campaignFilters} : undefined);
331
+ const f = view.filters(this._campaignFilters?.length ? {filters: this._campaignFilters} : undefined);
335
332
  const layoutViewState = this._campaign?.layout ?? this.template?.layoutViewState;
336
333
  if (layoutViewState) {
337
334
  try {
@@ -375,28 +372,62 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
375
372
  }
376
373
 
377
374
  async saveCampaign(status?: HitTriageCampaignStatus, notify = true): Promise<any> {
378
- const campaignId = this.campaignId!;
375
+ if (this.campaign)
376
+ return await this.writeCampaign(this.campaignId!, status, notify);
377
+ // a new campaign is written under its code's lock: no other session's first save takes the same code
378
+ let campaignId: string;
379
+ try {
380
+ campaignId = await this.lockNewCampaignCode(this.campaignId!, this.template!.key);
381
+ }
382
+ catch (e) {
383
+ _package.logger.error(e);
384
+ grok.shell.error('Failed to acquire campaign lock. Someone else might be editing the campaign. ' +
385
+ 'Please try again later.');
386
+ return undefined;
387
+ }
388
+ if (campaignId !== this._campaignId) {
389
+ this._campaignId = campaignId;
390
+ modifyUrl(CampaignIdKey, campaignId);
391
+ if (!this._friendlyName) {
392
+ if (this._pickView)
393
+ this._pickView.name = `${this.appName} | ${campaignId}`;
394
+ if (this._crumbLabel)
395
+ this._crumbLabel.textContent = campaignId;
396
+ }
397
+ }
398
+ try {
399
+ return await this.writeCampaign(campaignId, status, notify);
400
+ } finally {
401
+ await this.dropCampaignLock(campaignId);
402
+ }
403
+ }
404
+
405
+ private async writeCampaign(campaignId: string, status?: HitTriageCampaignStatus, notify = true): Promise<any> {
379
406
  const filters = this.filterSettings!;
380
407
  const templateName = this.template!.name;
381
408
  const enrichedDf = this.dataFrame!;
382
409
  const campaignPrefix = `System:AppData/HitTriage/${this.appName}/campaigns/${campaignId}/`;
383
410
  const campaignName = campaignId ?? await saveCampaignDialog(campaignId);
411
+ const saved = Platform.listedColumns(enrichedDf);
384
412
  const columnSemTypes: {[_: string]: string} = {};
385
- enrichedDf.columns.toList().forEach((col) => columnSemTypes[col.name] = col.semType);
386
-
387
413
  const colTypeMap: {[_: string]: string} = {};
388
- enrichedDf.columns.toList().forEach((col) => colTypeMap[col.name] = col.type);
414
+ for (const col of saved) {
415
+ columnSemTypes[col.name] = col.semType;
416
+ colTypeMap[col.name] = col.type;
417
+ }
389
418
 
390
419
  // if its first time save author as current user, else keep the same
391
420
  const authorUserId = this.campaign?.authorUserId ?? grok.shell.user.id;
392
421
  const permissions = this.campaign?.permissions ?? defaultPermissions;
393
422
  const authorName = authorUserId ? this.campaign?.authorUserFriendlyName ?? (await grok.dapi.users.find(authorUserId))?.friendlyName : undefined;
394
423
 
424
+ // the keys this app knows, and every key of the stored campaign it does not
395
425
  const campaign: HitTriageCampaign = {
426
+ ...this.campaign,
396
427
  name: campaignName,
397
428
  friendlyName: this._friendlyName ?? this.campaign?.friendlyName,
398
429
  templateName,
399
- filters: filters ?? {},
430
+ filters: filters ?? [],
400
431
  ingest: {
401
432
  type: 'File',
402
433
  query: `${campaignPrefix}${CampaignTableName}`,
@@ -416,14 +447,12 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
416
447
  permissions,
417
448
  };
418
449
 
419
- this.campaign = campaign;
420
450
  if (!this.hasEditPermission) {
451
+ this.campaign = campaign;
421
452
  grok.shell.error('You do not have permission to modify this campaign');
422
453
  return campaign;
423
454
  }
424
- const csvDf = DG.DataFrame.fromColumns(
425
- enrichedDf.columns.toList().filter((col) => !col.name.startsWith('~')),
426
- ).toCsv();
455
+ const csvDf = DG.DataFrame.fromColumns(saved).toCsv();
427
456
  await _package.files.writeAsText(`${this.appName}/campaigns/${campaignId}/${CampaignTableName}`, csvDf);
428
457
  const newLayout = this._pickView!.saveLayout();
429
458
  if (!newLayout)
@@ -431,6 +460,8 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
431
460
  else
432
461
  campaign.layout = newLayout.viewState;
433
462
  await _package.saveCampaignJson(this.appName, campaign);
463
+ // only a written campaign is an existing one: its next save no longer takes a code's lock
464
+ this.campaign = campaign;
434
465
  notify && grok.shell.info('Campaign saved successfully.');
435
466
  return campaign;
436
467
  }