@datagrok/hit-triage 1.10.9 → 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 (123) hide show
  1. package/.grokignore +2 -0
  2. package/.turbo/turbo-build.log +25 -3
  3. package/CHANGELOG.md +78 -0
  4. package/CLAUDE.md +87 -10
  5. package/README_HD.md +14 -14
  6. package/README_HT.md +6 -6
  7. package/README_PH.md +110 -0
  8. package/bdd/bdd.config.json +3 -1
  9. package/bdd/bindings/campaign.ts +626 -0
  10. package/bdd/bindings/hit-design.ts +36 -42
  11. package/bdd/bindings/landing.ts +839 -0
  12. package/bdd/bindings/pepti-hit.ts +35 -0
  13. package/bdd/features/campaign/crumbs.feature +22 -0
  14. package/bdd/features/campaign/grid.feature +56 -0
  15. package/bdd/features/campaign/merge.feature +105 -0
  16. package/bdd/features/campaign/molecule-vid.feature +40 -0
  17. package/bdd/features/campaign/permissions.feature +46 -0
  18. package/bdd/features/campaign/progress-tracker.feature +89 -0
  19. package/bdd/features/campaign/refresh-hint.feature +33 -0
  20. package/bdd/features/campaign/ribbon.feature +49 -0
  21. package/bdd/features/campaign/stage-choices.feature +39 -0
  22. package/bdd/features/campaign/submit.feature +135 -0
  23. package/bdd/features/campaign/tracker-cards.feature +46 -0
  24. package/bdd/features/campaign/view-only.feature +37 -0
  25. package/bdd/features/landing/campaign-deep-links.feature +61 -0
  26. package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
  27. package/bdd/features/landing/hit-design-campaigns.feature +153 -0
  28. package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
  29. package/bdd/features/landing/new-campaign.feature +69 -0
  30. package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
  31. package/bdd/features/landing/pepti-hit-landing.feature +132 -0
  32. package/bdd/features/pepti-hit/helm-edit.feature +47 -0
  33. package/bdd/features/templates/template-editor.feature +130 -0
  34. package/bdd/features/templates/template-picker.feature +112 -0
  35. package/bdd/features/templates/triage-forms.feature +59 -0
  36. package/bdd/fixtures/bar-chart.layout +1 -0
  37. package/bdd/fixtures/merge-local.csv +2 -0
  38. package/bdd/generated/campaign/crumbs.test.ts +33 -0
  39. package/bdd/generated/campaign/grid.test.ts +79 -0
  40. package/bdd/generated/campaign/merge.test.ts +134 -0
  41. package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
  42. package/bdd/generated/campaign/permissions.test.ts +58 -0
  43. package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
  44. package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
  45. package/bdd/generated/campaign/ribbon.test.ts +65 -0
  46. package/bdd/generated/campaign/stage-choices.test.ts +55 -0
  47. package/bdd/generated/campaign/submit.test.ts +167 -0
  48. package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
  49. package/bdd/generated/campaign/view-only.test.ts +51 -0
  50. package/bdd/generated/hit-design/campaign-column-metadata.test.ts +1 -0
  51. package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
  52. package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
  53. package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
  54. package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
  55. package/bdd/generated/landing/new-campaign.test.ts +78 -0
  56. package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
  57. package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
  58. package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
  59. package/bdd/generated/templates/template-editor.test.ts +137 -0
  60. package/bdd/generated/templates/template-picker.test.ts +119 -0
  61. package/bdd/generated/templates/triage-forms.test.ts +68 -0
  62. package/css/hit-triage.css +27 -23
  63. package/dist/package-test.js +690 -4
  64. package/dist/package-test.js.map +1 -1
  65. package/dist/package.js +318 -73
  66. package/dist/package.js.map +1 -1
  67. package/package.json +11 -7
  68. package/queries/locks.sql +37 -0
  69. package/src/app/accordeons/layout-input.ts +52 -44
  70. package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
  71. package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
  72. package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
  73. package/src/app/accordeons/new-template-accordeon.ts +41 -24
  74. package/src/app/ai/view-functions.ts +22 -19
  75. package/src/app/base-view.ts +99 -8
  76. package/src/app/consts.ts +8 -5
  77. package/src/app/dialogs/functions-dialog.ts +14 -9
  78. package/src/app/dialogs/merge-table-dialog.ts +181 -325
  79. package/src/app/hit-app-base.ts +61 -90
  80. package/src/app/hit-design-app.ts +481 -886
  81. package/src/app/hit-design-views/info-view.ts +57 -407
  82. package/src/app/hit-design-views/submit-view.ts +216 -111
  83. package/src/app/hit-design-views/tiles-view.ts +168 -123
  84. package/src/app/hit-design-views/utils.css +0 -8
  85. package/src/app/hit-triage-app.ts +69 -38
  86. package/src/app/hit-triage-views/info-view.ts +70 -371
  87. package/src/app/pep-triage-app.ts +2 -2
  88. package/src/app/pep-triage-views/info-view.ts +42 -83
  89. package/src/app/pepti-hit-app.ts +32 -183
  90. package/src/app/pepti-hits-views/info-view.ts +15 -37
  91. package/src/app/shared/campaign-catalog.ts +408 -0
  92. package/src/app/shared/campaign-session.ts +557 -0
  93. package/src/app/shared/compute-editor.ts +274 -0
  94. package/src/app/shared/hit-home.ts +45 -0
  95. package/src/app/shared/new-campaign-form.ts +90 -0
  96. package/src/app/shared/permissions-editor.ts +93 -0
  97. package/src/app/shared/template-editor.ts +331 -0
  98. package/src/app/shared/template-picker.ts +154 -0
  99. package/src/app/utils/merge-table.ts +183 -78
  100. package/src/app/utils.ts +34 -325
  101. package/src/package-api.ts +29 -8
  102. package/src/package-test.ts +17 -2
  103. package/src/package.g.ts +12 -8
  104. package/src/package.ts +19 -7
  105. package/src/tests/ai.ts +244 -0
  106. package/src/tests/campaign-layout.ts +82 -0
  107. package/src/tests/campaign-session.ts +168 -0
  108. package/src/tests/campaigns.ts +23 -0
  109. package/src/tests/catalog.ts +156 -0
  110. package/src/tests/compat.ts +482 -0
  111. package/src/tests/compute.ts +165 -0
  112. package/src/tests/fixtures.ts +359 -0
  113. package/src/tests/merge.ts +149 -0
  114. package/src/tests/owners.ts +11 -0
  115. package/src/tests/save-lock.ts +932 -0
  116. package/src/tests/storage.ts +106 -0
  117. package/src/tests/template-editor.ts +538 -0
  118. package/src/tests/templates.ts +143 -0
  119. package/src/tests/triage-start.ts +81 -0
  120. package/src/tests/u2-guards.ts +384 -0
  121. package/src/tests/vid.ts +77 -0
  122. package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
  123. package/src/app/dialogs/permissions-dialog.ts +0 -66
@@ -0,0 +1,274 @@
1
+ /* ComputeEditor: what a template calculates for every molecule, the descriptors and the compute functions, as one
2
+ master-detail box: a row per function on the left (its checkbox, its name, how many descriptors are picked), the
3
+ current row's settings on the right: the descriptors as a searchable tree whose groups say how many of theirs are
4
+ picked, or a function's own form and "Re-run when campaign opens". "Reorder…" orders and hides the functions, kept
5
+ where the compute dialog keeps them. The value is the compute config the compute dialog writes. Nothing here is
6
+ HitTriage's but the box's size (`.hit-triage-compute-box` in css/hit-triage.css, which moves with it). For Chem MPO,
7
+ which asks for one function and no descriptors, it still lacks the dialog's single choice (`singleSelect`). */
8
+ import * as DG from 'datagrok-api/dg';
9
+ import {BoolInput, ChecklistInput, Control, Dialog, MasterDetail, TextInput, VirtualTree, component, computed, div,
10
+ divH, divV, link, signal, statusLine, untracked} from '@datagrok-libraries/u2';
11
+ import type {Signal, TreeNode} from '@datagrok-libraries/u2';
12
+ import {funcForm} from '@datagrok-libraries/u2/dg';
13
+ import type {ComputeFunctions, IComputeDialogResult, IDescriptorTree, IFunctionArgs, TemplateCompute}
14
+ from '@datagrok-libraries/statistics/src/compute-functions/types';
15
+ import {HTQueryPrefix, HTScriptPrefix} from '@datagrok-libraries/statistics/src/compute-functions/consts';
16
+ import {getFuncPackageNameSafe, getSavedFunctionOrdering, setSavedFunctionOrdering}
17
+ from '@datagrok-libraries/statistics/src/compute-functions/utils';
18
+ import '../../../css/hit-triage.css';
19
+
20
+ export interface ComputeEditorOptions {
21
+ /** The functions a template may calculate (`discoverComputeFunctions`). */
22
+ functions: ComputeFunctions;
23
+ value: TemplateCompute;
24
+ /** The descriptors to pick from; without it there is no Descriptors row and the value's descriptors stay as given. */
25
+ descriptors?: () => Promise<IDescriptorTree>;
26
+ /** Where the order of the functions and the hidden ones are kept, as {order, hidden} of their names. */
27
+ orderKey: string;
28
+ /** A checkbox per function that flags it to be calculated again whenever a campaign opens. */
29
+ rerunOnOpen?: {label: string, tooltip: string};
30
+ }
31
+
32
+ const DESCRIPTORS = 'Descriptors';
33
+
34
+ interface Entry {
35
+ /** `Descriptors`, `<package>:<name>`, `HTScript:<name>:<id>` or `HTQuery:<name>:<id>`: the compute dialog's keys. */
36
+ key: string;
37
+ /** The friendly name: what the row shows and what the order is kept by. */
38
+ name: string;
39
+ checked: Signal<boolean>;
40
+ rerun: Signal<boolean>;
41
+ /** The call holding the function's arguments; none for the descriptors. */
42
+ call?: DG.FuncCall;
43
+ /** The inputs a template does not keep: a function's table and column, a query's molecules. */
44
+ skip: number;
45
+ }
46
+
47
+ type Kept = {args?: IFunctionArgs, rerunOnOpen?: boolean} | undefined;
48
+
49
+ export interface ComputeEditor {
50
+ /** The descriptors are listed (or could not be): until then the ones picked read as given. */
51
+ readonly ready: Promise<void>;
52
+ /** A pick in the descriptor tree changed what the editor holds (the inputs tell their own edits). */
53
+ readonly edited: Signal<boolean>;
54
+ /** The compute config the editor holds, in the compute dialog's shape. */
55
+ read(): TemplateCompute;
56
+ }
57
+
58
+ export function computeEditor(options: ComputeEditorOptions): Control & ComputeEditor {
59
+ return component((self) => {
60
+ const edited = signal(false);
61
+ const tree = signal<IDescriptorTree | null>(null);
62
+ const treeError = signal<string | null>(null);
63
+ const given = options.value.descriptors;
64
+ const picked = signal(new Set(given?.args ?? []));
65
+ const descriptorEntry: Entry | undefined = options.descriptors === undefined ? undefined : {key: DESCRIPTORS,
66
+ name: DESCRIPTORS, skip: 0, rerun: signal(false),
67
+ checked: signal(!!given?.enabled && (given?.args?.length ?? 0) > 0)};
68
+ const entries = [...descriptorEntry ? [descriptorEntry] : [], ...computeEntries(options.functions, options.value)];
69
+ const order = signal(getSavedFunctionOrdering(options.orderKey));
70
+ const ready = options.descriptors === undefined ? Promise.resolve() : options.descriptors().then((t) => {
71
+ tree.value = t;
72
+ }, (e) => {
73
+ treeError.value = e instanceof Error ? e.message : String(e);
74
+ });
75
+
76
+ // built now, not when first shown: a function's form writes its computed defaults into the call read() keeps
77
+ const details = new Map<string, Control | HTMLElement>();
78
+ for (const e of entries)
79
+ details.set(e.key, e.call === undefined ? descriptorsDetail() : functionDetail(e));
80
+ const box = new MasterDetail<Entry>({items: computed(() => shown()), keyOf: (e) => e.key, label: 'Functions',
81
+ row: (e) => ({label: e.name, check: e.checked, checkTooltip: 'Toggle calculation of this function',
82
+ hint: e.call !== undefined ? undefined : computed(() => {
83
+ const n = descriptorArgs().length;
84
+ return e.checked.value && n > 0 ? `${n} selected` : '';
85
+ })}),
86
+ detail: (e) => details.get(e.key)!,
87
+ disabled: (e) => e.call === undefined ? null :
88
+ computed(() => e.checked.value ? null : `Check ${e.name} to change its settings`)});
89
+ box.root.classList.add('hit-triage-compute-box');
90
+ const root = divV([divH([link('Reorder…', () => reorder())]), box], {gap: 's'});
91
+ return {root, ready, edited, read};
92
+
93
+ function read(): TemplateCompute {
94
+ const hidden = new Set(order.peek().hidden);
95
+ const result: IComputeDialogResult = {descriptors: descriptorEntry || !given?.enabled ? [] : given.args ?? [],
96
+ externals: {}, scripts: {}, queries: {}, ...options.rerunOnOpen ? {rerunOnOpen: {}} : {}};
97
+ for (const e of entries) {
98
+ if (!e.checked.peek() || hidden.has(e.name))
99
+ continue;
100
+ if (e.call === undefined) {
101
+ result.descriptors = untracked(() => descriptorArgs());
102
+ continue;
103
+ }
104
+ const args: IFunctionArgs = {};
105
+ for (const [name, value] of Object.entries(e.call.inputs).slice(e.skip))
106
+ args[name] = value;
107
+ const target = e.key.startsWith(`${HTScriptPrefix}:`) ? result.scripts! :
108
+ e.key.startsWith(`${HTQueryPrefix}:`) ? result.queries! : result.externals;
109
+ target[e.key] = args;
110
+ if (result.rerunOnOpen && e.rerun.peek())
111
+ result.rerunOnOpen[e.key] = true;
112
+ }
113
+ return templateCompute(result);
114
+ }
115
+
116
+ /** The entries in the saved order of their names, the ones it does not name after them, the hidden ones out. */
117
+ function shown(): Entry[] {
118
+ const {order: names, hidden} = order.value;
119
+ const rank = (e: Entry) => names.includes(e.name) ? names.indexOf(e.name) : names.length;
120
+ return entries.map((e, at) => ({e, at})).filter(({e}) => !hidden.includes(e.name))
121
+ .sort((a, b) => rank(a.e) - rank(b.e) || a.at - b.at).map(({e}) => e);
122
+ }
123
+
124
+ function descriptorsDetail(): HTMLElement {
125
+ const search = new TextInput({inline: true, search: true, name: 'descriptor-search',
126
+ placeholder: 'Search descriptors'});
127
+ const view = new VirtualTree<string>({itemHeight: 24, onCheck: (node, checked) => check(node, checked)});
128
+ const status = div([statusLine(computed(() => treeError.value === null ? null :
129
+ `Could not list the descriptors: ${treeError.value}`), 'Listing the descriptors…')]);
130
+ self.effect(() => {
131
+ const query = search.value.trim().toLowerCase();
132
+ const roots = nodes(query);
133
+ view.setRoots(roots);
134
+ if (query !== '')
135
+ view.expanded.value = new Set(roots.map((r) => r.id));
136
+ });
137
+ self.effect(() => {
138
+ const listed = tree.value !== null;
139
+ view.root.hidden = !listed;
140
+ status.hidden = listed;
141
+ });
142
+ return divV([search.root, status, view.root], {gap: 's', cls: 'hit-triage-compute-descriptors'});
143
+ }
144
+
145
+ /** The function's own form, its table and column hidden, and the re-run flag last on the same label column. */
146
+ function functionDetail(e: Entry): Control {
147
+ const hide = Object.fromEntries(e.call!.func.inputs.slice(0, e.skip).map((p) => [p.name, {visible: false}]));
148
+ const form = funcForm(e.call!,
149
+ {showTableSelectors: false, skipTableAutoFill: true, editors: 'auto', overrides: hide});
150
+ const rerun = options.rerunOnOpen;
151
+ if (rerun) {
152
+ form.add(new BoolInput({label: rerun.label, name: `rerun-${e.key}`, bind: e.rerun,
153
+ tooltipText: rerun.tooltip}));
154
+ }
155
+ return form;
156
+ }
157
+
158
+ /** The descriptor groups, each with the descriptors that match `query` and how many of all its own are picked. */
159
+ function nodes(query: string): TreeNode<string>[] {
160
+ const groups = tree.value;
161
+ const names = picked.value;
162
+ if (groups === null)
163
+ return [];
164
+ const roots: TreeNode<string>[] = [];
165
+ for (const [group, {descriptors}] of Object.entries(groups)) {
166
+ const matching = query === '' ? descriptors : descriptors.filter((d) => d.name.toLowerCase().includes(query));
167
+ if (matching.length === 0)
168
+ continue;
169
+ const on = descriptors.filter((d) => names.has(d.name)).length;
170
+ roots.push({id: `group:${group}`, label: `${group} · ${on} of ${descriptors.length}`, checked: on > 0,
171
+ children: matching.map((d) => ({id: `${group}/${d.name}`, label: d.name, tooltip: d.description,
172
+ data: d.name, checked: names.has(d.name)}))});
173
+ }
174
+ return roots;
175
+ }
176
+
177
+ /** A descriptor, or a group's descriptors the search shows, picked or dropped; picking turns the descriptors on. */
178
+ function check(node: TreeNode<string>, checked: boolean): void {
179
+ const names = node.data !== undefined ? [node.data] : (node.children as TreeNode<string>[]).map((c) => c.data!);
180
+ const next = new Set(picked.peek());
181
+ for (const name of names) {
182
+ if (checked)
183
+ next.add(name);
184
+ else
185
+ next.delete(name);
186
+ }
187
+ picked.value = next;
188
+ edited.value = true;
189
+ if (checked)
190
+ descriptorEntry!.checked.value = true;
191
+ }
192
+
193
+ /** The picked descriptors in the tree's order; as given while the tree is not listed. */
194
+ function descriptorArgs(): string[] {
195
+ const groups = tree.value;
196
+ const names = picked.value;
197
+ if (groups === null)
198
+ return [...names];
199
+ return Object.values(groups).flatMap((g) => g.descriptors.map((d) => d.name)).filter((n) => names.has(n));
200
+ }
201
+
202
+ function reorder(): void {
203
+ self.build(() => {
204
+ const names = ordered(entries.map((e) => e.name), order.peek().order);
205
+ const hidden = order.peek().hidden;
206
+ const functions = new ChecklistInput({name: 'functions', orderable: true, items: names,
207
+ value: names.filter((n) => !hidden.includes(n))});
208
+ new Dialog('Order and hide functions')
209
+ .add(functions)
210
+ .onOK(() => {
211
+ const kept = functions.peek();
212
+ order.value = {order: kept, hidden: names.filter((n) => !kept.includes(n))};
213
+ setSavedFunctionOrdering(order.peek(), options.orderKey);
214
+ })
215
+ .show();
216
+ });
217
+ }
218
+ }, {name: 'compute-editor'});
219
+ }
220
+
221
+ /** The functions, scripts and queries a template may calculate, each with what `value` keeps of it; one that cannot
222
+ * be prepared is left out, as the compute dialog leaves it. */
223
+ function computeEntries(functions: ComputeFunctions, value: TemplateCompute): Entry[] {
224
+ const entries: Entry[] = [];
225
+ const add = (f: DG.Func, key: () => string, kept: () => Kept, skip: number) => {
226
+ try {
227
+ const k = kept();
228
+ entries.push({key: key(), name: f.friendlyName ?? f.name, skip, checked: signal(k !== undefined),
229
+ rerun: signal(!!k?.rerunOnOpen), call: f.prepare(k?.args ?? {})});
230
+ }
231
+ catch (e) {
232
+ console.error(e);
233
+ }
234
+ };
235
+ const onColumn = (f: DG.Func) => f.inputs.length >= 2 && f.inputs[0].propertyType === 'dataframe' &&
236
+ f.inputs[1].propertyType === 'column';
237
+ for (const f of functions.functions.filter(onColumn)) {
238
+ add(f, () => `${f.package.name}:${f.name}`, () => value.functions?.find((t) => t.name === f.name &&
239
+ t.package === getFuncPackageNameSafe(f)), 2);
240
+ }
241
+ for (const s of functions.scripts.filter(onColumn))
242
+ add(s, () => `${HTScriptPrefix}:${s.name ?? ''}:${s.id}`, () => value.scripts?.find((t) => t.id === s.id), 2);
243
+ for (const q of functions.queries.filter((q) => q.inputs.length > 0 && q.inputs[0].propertyType === 'list'))
244
+ add(q, () => `${HTQueryPrefix}:${q.name ?? ''}:${q.id}`, () => value.queries?.find((t) => t.id === q.id), 1);
245
+ return entries;
246
+ }
247
+
248
+ /** `names`, each once, in the saved order, the ones it does not name after them. */
249
+ function ordered(names: string[], order: string[]): string[] {
250
+ const unique = [...new Set(names)];
251
+ const known = order.filter((n) => unique.includes(n));
252
+ return [...known, ...unique.filter((n) => !known.includes(n))];
253
+ }
254
+
255
+ /** The compute config a template keeps, from the compute dialog's answer; `rerunOnOpen` is written only where the
256
+ * dialog offered it. */
257
+ export function templateCompute(result: IComputeDialogResult): TemplateCompute {
258
+ const rerun = (key: string) => result.rerunOnOpen ? {rerunOnOpen: !!result.rerunOnOpen[key]} : {};
259
+ const byId = (entries: {[key: string]: IFunctionArgs} | undefined, prefix: string) =>
260
+ Object.entries(entries ?? {}).filter(([key]) => key.startsWith(prefix) && key.split(':').length === 3)
261
+ .map(([key, args]) => {
262
+ const [, name, id] = key.split(':');
263
+ return {name, id, args, ...rerun(key)};
264
+ });
265
+ return {
266
+ descriptors: {enabled: result.descriptors.length > 0, args: result.descriptors},
267
+ functions: Object.entries(result.externals).map(([key, args]) => {
268
+ const [pkg, name] = key.split(':');
269
+ return {name, package: pkg, args, ...rerun(key)};
270
+ }),
271
+ scripts: byId(result.scripts, HTScriptPrefix),
272
+ queries: byId(result.queries, HTQueryPrefix),
273
+ };
274
+ }
@@ -0,0 +1,45 @@
1
+ /* The landing of the HitTriage apps, top to bottom in one scrolling column: the app header, "Continue Campaign" with
2
+ the campaigns table and its icons, "New Campaign" with the template picker and its form. */
3
+ import {AppHeader, Control, Page, component, div, signal} from '@datagrok-libraries/u2';
4
+ import type {AppHeaderOptions} from '@datagrok-libraries/u2';
5
+ import {i18n} from '../consts';
6
+ import {CampaignCatalog, CampaignCatalogOptions, campaignCatalog} from './campaign-catalog';
7
+ import {CampaignTemplate, PICKER_PX, TemplatePicker, TemplatePickerOptions, templatePicker} from './template-picker';
8
+
9
+ export interface HitHomeOptions<T extends CampaignTemplate> {
10
+ header: AppHeaderOptions;
11
+ catalog: CampaignCatalogOptions;
12
+ picker: TemplatePickerOptions<T>;
13
+ }
14
+
15
+ /** Under this width of the campaigns table, campaign names are cut shorter. */
16
+ const NARROW_PX = 820;
17
+
18
+ export interface HitHome {
19
+ readonly catalog: CampaignCatalog;
20
+ readonly picker: Control & TemplatePicker;
21
+ }
22
+
23
+ export function hitHome<T extends CampaignTemplate>(options: HitHomeOptions<T>): Control & HitHome {
24
+ return component((self) => {
25
+ const narrow = signal(false);
26
+ const catalog = campaignCatalog({...options.catalog, narrow});
27
+ const table = catalog.table.root;
28
+ // a hidden landing (another view current) measures 0: it keeps the width it had
29
+ const observer = new ResizeObserver(() => {
30
+ if (table.clientWidth > 0)
31
+ narrow.value = table.clientWidth < NARROW_PX;
32
+ });
33
+ observer.observe(table);
34
+ self.own(() => observer.disconnect());
35
+ const picker = templatePicker<T>(options.picker);
36
+ const page = new Page({labelColumn: false, sections: [
37
+ {title: i18n.continueCampaigns, actions: catalog.chrome(), content: catalog.table},
38
+ {title: i18n.createNewCampaignHeader, content: picker, maxWidth: PICKER_PX},
39
+ ]});
40
+ // in a plain block the page is as tall as its content: the view scrolls the header away with the rest, as before
41
+ const root = div([div([new AppHeader({name: 'app-header', ...options.header})], 'hit-triage-home-header'),
42
+ div([page])], 'hit-triage-home');
43
+ return {root, catalog, picker};
44
+ }, {name: 'hit-home'});
45
+ }
@@ -0,0 +1,90 @@
1
+ /* The New Campaign form of Hit Design and PeptiHit: Campaign Name and an input per field of the template, on the
2
+ picker's label column, then START — disabled while a required field is empty, with the reason as its tooltip and
3
+ in the line beside it, which otherwise says what START will make. */
4
+ import {AsyncValue, BoolInput, Control, DateInput, Form, Input, NumberInput, TextInput, button, component, computed,
5
+ div, signal, statusLine} from '@datagrok-libraries/u2';
6
+ import type {LabelColumn} from '@datagrok-libraries/u2';
7
+ import {moleculeInput} from '@datagrok-libraries/u2/dg';
8
+ import {HitDesignTemplate, HitTriageCampaignField} from '../types';
9
+ import {i18n} from '../consts';
10
+ import {PICKER_PX} from './template-picker';
11
+
12
+ export interface NewCampaignRequest {
13
+ /** The field values as campaign.json keeps them: an empty field is left out, a date as {_value, isUtc, date}. */
14
+ fields: {[name: string]: unknown};
15
+ name?: string;
16
+ }
17
+
18
+ export interface NewCampaignFormOptions {
19
+ template: HitDesignTemplate;
20
+ column: LabelColumn;
21
+ /** The code the campaign is likely to get ("KHL-13"); the save takes the one that is free then. */
22
+ nextCode: () => Promise<string>;
23
+ start: (request: NewCampaignRequest) => Promise<unknown>;
24
+ }
25
+
26
+ type FieldInput = readonly [HitTriageCampaignField, Input<any>];
27
+
28
+ export interface NewCampaignForm {
29
+ readonly form: Form;
30
+ }
31
+
32
+ export function newCampaignForm(options: NewCampaignFormOptions): Control & NewCampaignForm {
33
+ return component(() => {
34
+ const form = new Form({labelColumn: options.column, maxWidth: PICKER_PX});
35
+ const name = new TextInput({label: 'Campaign Name', name: 'campaign-name', placeholder: 'Optional',
36
+ tooltipText: 'New campaign name. If empty, campaign code will be used.'});
37
+ form.add(name);
38
+ const fields: FieldInput[] = options.template.campaignFields.map((f) => [f, fieldInput(f)] as const);
39
+ for (const [, input] of fields)
40
+ form.add(input);
41
+ const code = new AsyncValue(() => options.nextCode(), {debounceMs: 0});
42
+ const busy = signal(false);
43
+ const missing = computed(() => fields.filter(([f, input]) => f.required && input.validity.value !== null)
44
+ .map(([f]) => f.name));
45
+ const start = button(i18n.StartCampaign, async () => {
46
+ busy.value = true;
47
+ try {
48
+ await options.start({fields: fieldValues(fields), name: name.peek()?.trim() || undefined});
49
+ } finally {
50
+ busy.value = false;
51
+ }
52
+ }, {primary: true, disabled: computed(() => busy.value ? 'Starting…' : form.problem.value)});
53
+ const quiet = computed(() => missing.value.length > 0 ? `Fill in ${missing.value.join(', ')} to start` :
54
+ code.value === undefined ? '' : `Creates ${code.value} from ${options.template.name}`);
55
+ // in red once a field shows its error, named by its caption ("Owner: Value can't be empty")
56
+ form.addButtons((row) => row.append(start, statusLine(form.shownProblem, quiet)), {align: 'editors'});
57
+ return {root: div([form.root]), form};
58
+ }, {name: 'new-campaign'});
59
+ }
60
+
61
+ /** The editor of a template field: text, number, date, checkbox, or the sketcher for a molecule. */
62
+ function fieldInput(field: HitTriageCampaignField): Input<any> {
63
+ const options = {label: field.name, name: field.name, required: field.required === true};
64
+ if (field.type === 'Molecule' || field.semtype === 'Molecule')
65
+ return moleculeInput(field.name, {name: field.name, required: field.required === true});
66
+ switch (field.type) {
67
+ case 'Number':
68
+ return new NumberInput(options);
69
+ case 'Date':
70
+ return new DateInput(options);
71
+ case 'Boolean':
72
+ return new BoolInput({label: field.name, name: field.name});
73
+ default:
74
+ return new TextInput(options);
75
+ }
76
+ }
77
+
78
+ /** What the inputs hold, as campaign.json keeps it: a Date as {_value, isUtc, date}, the fields left empty (a
79
+ * Boolean left unchecked) out, as the platform form left them. */
80
+ function fieldValues(fields: readonly FieldInput[]): {[name: string]: unknown} {
81
+ const values: {[name: string]: unknown} = {};
82
+ for (const [field, input] of fields) {
83
+ const value = input.peek();
84
+ if (Input.isEmpty(value) || value === false)
85
+ continue;
86
+ values[field.name] = value instanceof Date ?
87
+ {_value: value.getTime(), isUtc: false, date: value.toISOString()} : value;
88
+ }
89
+ return values;
90
+ }
@@ -0,0 +1,93 @@
1
+ /* Edit Permissions: who may view a campaign and who may edit it, one row per user or group (u2 AccessGrid). The
2
+ campaign keeps {view, edit} lists of group ids: edit implies view, and nobody listed means all users may view. */
3
+ import * as grok from 'datagrok-api/grok';
4
+ import * as DG from 'datagrok-api/dg';
5
+ import {AccessGrid, Dialog, computed, divV, signal, statusLine} from '@datagrok-libraries/u2';
6
+ import type {AccessRow} from '@datagrok-libraries/u2';
7
+ import {groupIcon, groupInput} from '@datagrok-libraries/u2/dg';
8
+ import type {ViewHost} from '@datagrok-libraries/u2/dg';
9
+ import {TriagePermissions} from '../types';
10
+
11
+ export const defaultPermissions: TriagePermissions = {
12
+ view: [DG.Group.defaultGroupsIds['All users']],
13
+ edit: [DG.Group.defaultGroupsIds['All users']],
14
+ };
15
+
16
+ export interface PermissionsEditorOptions {
17
+ /** The campaign as the footer names it: "KHL-3 (BTK covalent follow-up)". */
18
+ subject: string;
19
+ /** Who edits it whatever the grid says: its author. */
20
+ author?: string;
21
+ /** Runs on OK, the dialog busy until it is done; a failure stays in the dialog. */
22
+ save: (permissions: TriagePermissions) => unknown;
23
+ /** The campaign view the dialog belongs to: pinned to it, closed when it goes. */
24
+ host?: ViewHost;
25
+ }
26
+
27
+ export class PermissionsEditor {
28
+ static async show(permissions: TriagePermissions | undefined, options: PermissionsEditorOptions): Promise<void> {
29
+ const current = permissions ?? defaultPermissions;
30
+ const ids = [...new Set([...current.view, ...current.edit])];
31
+ const groups = (await Promise.all(ids.map((id) => grok.dapi.groups.find(id))))
32
+ .filter((g): g is DG.Group => g != null);
33
+ if (options.host?.scope.isDisposed)
34
+ return;
35
+ let shown: AccessRow[] = groups.map((g) =>
36
+ ({principal: g.id, can: {view: true, edit: current.edit.includes(g.id)}}));
37
+ const known = new Map(groups.map((g) => [g.id, g]));
38
+ const dialog = new Dialog('Edit Permissions', {name: 'edit-permissions'});
39
+ dialog.build(() => {
40
+ const grid: AccessGrid = new AccessGrid({
41
+ name: 'access',
42
+ fill: true,
43
+ capabilities: [{name: 'view', label: 'Can View'}, {name: 'edit', label: 'Can Edit'}],
44
+ principalLabel: 'User or group',
45
+ principals: groups.map((g) => ({value: g.id, label: g.friendlyName})),
46
+ icon: (id) => known.has(id) ? groupIcon(known.get(id)!) : null,
47
+ value: shown,
48
+ picker: (add) => groupInput({placeholder: '+ Add user or group…', onPick: (group, label) => {
49
+ known.set(group.id, group);
50
+ add({value: group.id, label});
51
+ }}).root,
52
+ onInput: (rows) => {
53
+ const implied = PermissionsEditor.implied(shown, rows);
54
+ shown = implied;
55
+ if (implied !== rows)
56
+ grid.value = implied;
57
+ },
58
+ });
59
+ const rows = computed(() => grid.value ?? []);
60
+ const editors = computed(() => rows.value.some((r) => r.can.edit));
61
+ // what `stored` does with a list nobody can view: said only while the grid shows that
62
+ const nobody = computed(() => !rows.value.some((r) => r.can.view || r.can.edit));
63
+ dialog.add(divV([grid.root,
64
+ statusLine(signal(null), computed(() => nobody.value ? 'With no one listed, all users can view.' :
65
+ 'Can Edit includes Can View.')),
66
+ statusLine(signal(null), computed(() => editors.value ? `OK saves who can access ${options.subject}` :
67
+ `Only ${options.author ?? 'the author'} will be able to edit ${options.subject}`)),
68
+ ]));
69
+ dialog.onOK(() => options.save(PermissionsEditor.stored(grid.peek() ?? [])));
70
+ });
71
+ options.host ? options.host.show(dialog, {width: 440}) : dialog.show({width: 440});
72
+ }
73
+
74
+ /** Checking Can Edit checks Can View; unchecking Can View unchecks Can Edit. Answers `next` when it holds. */
75
+ static implied(previous: readonly AccessRow[], next: AccessRow[]): AccessRow[] {
76
+ let changed = false;
77
+ const rows = next.map((r) => {
78
+ if (!r.can.edit || r.can.view)
79
+ return r;
80
+ changed = true;
81
+ const viewWasOn = previous.find((p) => p.principal === r.principal)?.can.view === true;
82
+ return {...r, can: viewWasOn ? {...r.can, edit: false} : {...r.can, view: true}};
83
+ });
84
+ return changed ? rows : next;
85
+ }
86
+
87
+ /** The grid as the campaign keeps it: editors can view too, and an empty view list is all users. */
88
+ static stored(rows: readonly AccessRow[]): TriagePermissions {
89
+ const edit = rows.filter((r) => r.can.edit).map((r) => r.principal);
90
+ const view = rows.filter((r) => r.can.view || r.can.edit).map((r) => r.principal);
91
+ return {edit, view: view.length > 0 ? view : [...defaultPermissions.view]};
92
+ }
93
+ }