@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
@@ -12,6 +12,7 @@ import {ItemType, ItemsGrid} from '@datagrok-libraries/utils/src/items-grid';
12
12
  import {HitAppBase} from '../hit-app-base';
13
13
  import {getLayoutInput} from './layout-input';
14
14
  import {getFuncPackageNameSafe, loadTemplate} from '../utils';
15
+ import {freeKey, freeName} from '../shared/template-editor';
15
16
 
16
17
 
17
18
  export async function createTemplateAccordeon(app: HitAppBase<any>,
@@ -39,34 +40,37 @@ export async function createTemplateAccordeon(app: HitAppBase<any>,
39
40
  submitFunctionInput.nullable = true;
40
41
  submitFunctionInput.fireChanged();
41
42
  submitFunctionInput.setTooltip('Select function to be called upon submitting');
42
- const layoutInput = getLayoutInput();
43
+ const layoutInput = getLayoutInput(preset);
43
44
  const errorDiv = ui.divText('Template name is empty or already exists', {classes: 'hit-triage-error-div'});
44
45
 
45
46
  const keyErrorDiv = ui.divText('Template key is empty or already exists', {classes: 'hit-triage-error-div'});
46
47
 
47
- const templateNameInput = ui.input.string('Name', {value: preset ? `${preset.name} (copy)` : '', onValueChanged: (value) => {
48
- if (value === '' || availableTemplates.includes(value)) {
49
- templateNameInput.root.style.borderBottom = '1px solid red';
50
- errorDiv.style.opacity = '100%';
51
- } else {
52
- templateNameInput.root.style.borderBottom = 'none';
53
- errorDiv.style.opacity = '0%';
48
+ const nameProblem = () => !templateNameInput.value?.trim() || availableTemplates.includes(templateNameInput.value) ?
49
+ 'Template name is empty or already exists' : null;
50
+ const keyProblem = () => !templateKeyInput.value?.trim() || availableTemplateKeys.includes(templateKeyInput.value) ?
51
+ 'Template key is empty or already exists' : null;
52
+ let createTemplateButton: HTMLButtonElement | null = null;
53
+ let createProblem: string | null = null;
54
+ let createDisabled = false;
55
+ function updateCreate() {
56
+ createProblem = nameProblem() ?? keyProblem();
57
+ if (createTemplateButton && (createProblem !== null) !== createDisabled) {
58
+ createDisabled = createProblem !== null;
59
+ ui.setDisabled(createTemplateButton, createDisabled, () => createProblem);
54
60
  }
61
+ }
62
+
63
+ const templateNameInput = ui.input.string('Name', {value: preset ? freeName(preset.name, new Set(availableTemplates.map((n) => n.toLowerCase()))) : '', onValueChanged: () => {
64
+ showTemplateInputError(templateNameInput, errorDiv, nameProblem() !== null);
65
+ updateCreate();
55
66
  }});
56
- const templateKeyInput = ui.input.string('Key', {value: preset ? `${preset.key}-copy` : '', onValueChanged: (value) => {
57
- if (value === '' || availableTemplateKeys.includes(value)) {
58
- templateKeyInput.root.style.borderBottom = '1px solid red';
59
- keyErrorDiv.style.opacity = '100%';
60
- } else {
61
- templateKeyInput.root.style.borderBottom = 'none';
62
- keyErrorDiv.style.opacity = '0%';
63
- }
67
+ const templateKeyInput = ui.input.string('Key', {value: preset ? freeKey(preset.key, new Set(availableTemplateKeys.map((k) => k.toLowerCase()))) : '', onValueChanged: () => {
68
+ showTemplateInputError(templateKeyInput, keyErrorDiv, keyProblem() !== null);
69
+ updateCreate();
64
70
  }});
65
71
 
66
72
  templateKeyInput.setTooltip('Template key used for campaign prefix');
67
73
  templateNameInput.setTooltip('Template name');
68
- templateNameInput.root.style.borderBottom = 'none';
69
- templateKeyInput.root.style.borderBottom = 'none';
70
74
  errorDiv.style.opacity = '0%';
71
75
  keyErrorDiv.style.opacity = '0%';
72
76
 
@@ -128,8 +132,9 @@ export async function createTemplateAccordeon(app: HitAppBase<any>,
128
132
  const promise = new Promise<HitTriageTemplate>((resolve) => {
129
133
  async function onOkProxy() {
130
134
  funcInput.okProxy();
131
- if (errorDiv.style.opacity === '100%') {
132
- grok.shell.error('Template name is empty or already exists');
135
+ const problem = nameProblem() ?? keyProblem();
136
+ if (problem) {
137
+ grok.shell.error(problem);
133
138
  return;
134
139
  }
135
140
  const submitFunction = submitFunctionInput.value ? submitFunctionsMap[submitFunctionInput.value] : undefined;
@@ -176,17 +181,29 @@ export async function createTemplateAccordeon(app: HitAppBase<any>,
176
181
  ...(submitFunction ? {submit: {fName: submitFunction.name, package: getFuncPackageNameSafe(submitFunction)}} : {}),
177
182
  queryFunctionName: (ingestTypeInput.value === 'Query') ? dataSourceFunctionInput.value ?? undefined : undefined,
178
183
  };
179
- saveTemplate(out);
184
+ try {
185
+ await saveTemplate(out);
186
+ }
187
+ catch (e) {
188
+ grok.shell.error(`Could not save template ${out.name}: ${e instanceof Error ? e.message : e}`);
189
+ return;
190
+ }
180
191
  grok.shell.info('Template created successfully');
181
192
  resolve(out);
182
193
  }
183
- const createTemplateButton = ui.bigButton(C.i18n.createTemplate, () => onOkProxy());
194
+ createTemplateButton = ui.bigButton(C.i18n.createTemplate, () => onOkProxy());
184
195
  buttonsContainerDiv.appendChild(createTemplateButton);
196
+ updateCreate();
185
197
  });
186
198
 
187
199
  return {root: form, template: promise, cancelPromise};
188
200
  }
189
201
 
202
+ export function showTemplateInputError(input: DG.InputBase, errorDiv: HTMLElement, shown: boolean) {
203
+ input.root.classList.toggle('hit-triage-input-error', shown);
204
+ errorDiv.style.opacity = shown ? '100%' : '0%';
205
+ }
206
+
190
207
  export function getCampaignFieldEditors(preset?: HitTriageCampaignField[]) {
191
208
  const props = [DG.Property.fromOptions({name: 'Name', type: DG.TYPE.STRING}),
192
209
  DG.Property.fromOptions({name: 'Type', type: DG.TYPE.STRING, choices: Object.keys(CampaignFieldTypes)}),
@@ -232,6 +249,6 @@ export function getCampaignFieldEditors(preset?: HitTriageCampaignField[]) {
232
249
  };
233
250
  }
234
251
 
235
- export function saveTemplate(template: HitTriageTemplate) {
236
- _package.files.writeAsText(`Hit Triage/templates/${template.name}.json`, JSON.stringify(template));
252
+ export function saveTemplate(template: HitTriageTemplate): Promise<void> {
253
+ return _package.files.writeAsText(`Hit Triage/templates/${template.name}.json`, JSON.stringify(template));
237
254
  }
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import * as grok from 'datagrok-api/grok';
14
14
  import * as DG from 'datagrok-api/dg';
15
+ import {Platform} from '@datagrok-libraries/u2/dg';
15
16
  import {HitAppBase} from '../hit-app-base';
16
17
  import {HitDesignApp} from '../hit-design-app';
17
18
  import {_package} from '../../package';
@@ -19,7 +20,6 @@ import {AppName, HitDesignCampaign, HitDesignTemplate, HitTriageCampaign, HitTri
19
20
  import {TileCategoriesColName, ViDColName} from '../consts';
20
21
  import {checkEditPermissions, loadTemplate} from '../utils';
21
22
  import {registerMol} from '../utils/molreg';
22
- import {createNewHitDesignDataFrame} from '../accordeons/new-hit-design-campaign-accordeon';
23
23
 
24
24
  type AnyCampaign = HitTriageCampaign | HitDesignCampaign;
25
25
  type AnyTemplate = HitTriageTemplate | HitDesignTemplate;
@@ -31,7 +31,8 @@ interface IHitApp {
31
31
  campaignId?: string;
32
32
  molColName?: string;
33
33
  infoView: IHitInfoView;
34
- saveCampaign(...args: unknown[]): Promise<AnyCampaign>;
34
+ /** Answers nothing when the campaign was not saved (a balloon says why). */
35
+ saveCampaign(...args: unknown[]): Promise<AnyCampaign | undefined>;
35
36
  submitParams?: {fName: string, package: string};
36
37
  submitView?: {submit(): Promise<boolean>, submitWithStatus?(status?: string): Promise<boolean>};
37
38
  }
@@ -45,6 +46,7 @@ type HitApp = HitAppBase<AnyTemplate> & IHitApp;
45
46
 
46
47
  const AI_NAMESPACE = 'HitTriageAI';
47
48
  const DEFAULT_SEARCH_LIMIT = 10;
49
+ const NOT_SAVED = 'The campaign was not saved; the balloon says why';
48
50
 
49
51
  const _funcs = new Map<string, DG.Func>();
50
52
 
@@ -94,7 +96,7 @@ function campaignTableView(view: any): DG.TableView {
94
96
  if (v instanceof DG.TableView)
95
97
  return v;
96
98
  const app = appOf(view) as any;
97
- const tv = app._designView ?? app._pickView;
99
+ const tv = app.designView ?? app._pickView;
98
100
  if (tv instanceof DG.TableView)
99
101
  return tv;
100
102
  throw new Error('No campaign table view is open');
@@ -145,7 +147,7 @@ function serializeResult(value: any): any {
145
147
  if (value == null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
146
148
  return value;
147
149
  if (value instanceof DG.DataFrame)
148
- return {type: 'dataframe', name: value.name, rowCount: value.rowCount, columns: value.columns.names()};
150
+ return {type: 'dataframe', name: value.name, rowCount: value.rowCount, columns: Platform.listedColumns(value).map((c) => c.name)};
149
151
  if (value instanceof DG.Column)
150
152
  return {type: 'column', name: value.name, length: value.length};
151
153
  if (value instanceof DG.ViewBase)
@@ -254,14 +256,7 @@ export function hitInfoViewFunctions(): DG.Func[] {
254
256
  .map((f) => f.name);
255
257
  if (missing.length)
256
258
  return {success: false, error: `Missing required campaign fields: ${missing.join(', ')} — pass them in campaignFields`};
257
- app.clearCampaign();
258
- app.dataFrame = createNewHitDesignDataFrame(template, app.appName === 'PeptiHit');
259
- await app.setTemplate(template as any);
260
- app.campaignProps = {...(campaignFields ?? {})};
261
- const friendly = campaignName?.trim() ? campaignName.trim() : undefined;
262
- await app.saveCampaign(false, true, {friendlyName: friendly});
263
- if (template.layoutViewState && app.campaign)
264
- app.campaign.layout = template.layoutViewState;
259
+ await app.startNewCampaign(template, {...(campaignFields ?? {})}, campaignName?.trim() || undefined);
265
260
  return {success: true, campaign: app.campaignId, note: 'The campaign is created and its design view is open'};
266
261
  }),
267
262
 
@@ -299,7 +294,7 @@ function campaignSharedFunctions(): DG.Func[] {
299
294
  ...(stages.length ? {stages} : {}),
300
295
  rows: df?.rowCount ?? 0,
301
296
  filteredRows: df?.filter.trueCount ?? 0,
302
- columns: df ? df.columns.toList().filter((c) => !c.name.startsWith('~'))
297
+ columns: df ? Platform.listedColumns(df)
303
298
  .map((c) => ({name: c.name, type: c.type, ...(c.semType ? {semType: c.semType} : {})})) : [],
304
299
  canEdit: app.canEdit,
305
300
  submitFunction: app.submitParams ? `${app.submitParams.package}:${app.submitParams.fName}` : null,
@@ -313,7 +308,8 @@ function campaignSharedFunctions(): DG.Func[] {
313
308
  const app = appOf(view);
314
309
  if (!app.canEdit)
315
310
  return {success: false, error: 'You do not have permission to modify this campaign'};
316
- await app.saveCampaign();
311
+ if (await app.saveCampaign() === undefined)
312
+ return {success: false, error: NOT_SAVED};
317
313
  return {success: true, campaign: app.campaignId ?? app.campaign?.name};
318
314
  }),
319
315
 
@@ -327,9 +323,14 @@ function campaignSharedFunctions(): DG.Func[] {
327
323
  return {success: false, error: 'No campaign is open'};
328
324
  if (!app.canEdit)
329
325
  return {success: false, error: 'You do not have permission to modify this campaign'};
330
- app.campaign.status = status.trim();
331
- await app.saveCampaign();
332
- return {success: true, status: app.campaign.status};
326
+ const campaign = app.campaign;
327
+ const before = campaign.status;
328
+ campaign.status = status.trim();
329
+ if (await app.saveCampaign() === undefined) {
330
+ campaign.status = before;
331
+ return {success: false, error: NOT_SAVED};
332
+ }
333
+ return {success: true, status: app.campaign?.status};
333
334
  }),
334
335
 
335
336
  aiFunc('submitHitCampaign', 'dynamic submitHitCampaign(view view, string status)',
@@ -465,7 +466,8 @@ function designCampaignFunctions(): DG.Func[] {
465
466
  if (!app.stages.includes(stage))
466
467
  return {success: false, error: `Unknown stage '${stage}' — the stages are: ${app.stages.join(', ')}`};
467
468
  stageCol.set(row, stage, true);
468
- await app.saveCampaign(false);
469
+ if (await app.saveCampaign(false) === undefined)
470
+ return {success: false, error: `The row moved to ${stage}, but ${NOT_SAVED.toLowerCase()}`};
469
471
  return {success: true, row, stage};
470
472
  }),
471
473
 
@@ -481,7 +483,8 @@ function designCampaignFunctions(): DG.Func[] {
481
483
  return {success: false, error: 'No campaign is open'};
482
484
  if (!app.dataFrame?.col(TileCategoriesColName))
483
485
  return {success: false, error: 'This campaign has no stage column'};
484
- await app.setStages(stages.map((s) => s.trim()));
486
+ if (!await app.setStages(stages.map((s) => s.trim())))
487
+ return {success: false, error: `The stages changed, but ${NOT_SAVED.toLowerCase()}`};
485
488
  return {success: true, stages: app.stages};
486
489
  }),
487
490
 
@@ -1,13 +1,20 @@
1
+ import * as grok from 'datagrok-api/grok';
1
2
  import * as DG from 'datagrok-api/dg';
3
+ import {Scope} from '@datagrok-libraries/u2';
4
+ import type {Control} from '@datagrok-libraries/u2';
5
+ import {host} from '@datagrok-libraries/u2/dg';
2
6
  import {AppName, HitDesignTemplate, HitTriageTemplate, PeptiHitTemplate} from './types';
3
7
  import type {HitDesignApp} from './hit-design-app';
4
8
  import type {HitTriageApp} from './hit-triage-app';
9
+ import {CampaignIdKey} from './consts';
5
10
  import {_package} from '../package';
11
+ import * as api from '../package-api';
12
+ import {HitHome, HitHomeOptions, hitHome} from './shared/hit-home';
13
+ import {AnyCampaign, CampaignCatalogOptions, CampaignFamily} from './shared/campaign-catalog';
6
14
 
7
15
  export class HitBaseView<Ttemplate extends HitDesignTemplate | HitTriageTemplate | PeptiHitTemplate,
8
16
  Tapp extends HitDesignApp | HitTriageApp> extends DG.ViewBase {
9
17
  app: Tapp;
10
- protected deletedCampaigns: string[] = [];
11
18
  constructor(app: Tapp) {
12
19
  super();
13
20
 
@@ -16,9 +23,6 @@ export class HitBaseView<Ttemplate extends HitDesignTemplate | HitTriageTemplate
16
23
 
17
24
  get template(): Ttemplate {return this.app.template! as Ttemplate;}
18
25
 
19
- /** Info views implement this to rebuild their content. */
20
- init?(presetTemplate?: any): Promise<void>;
21
-
22
26
  /** Override to initialize the view based on the session. */
23
27
  onActivated(): void {
24
28
  }
@@ -29,17 +33,104 @@ export class HitBaseView<Ttemplate extends HitDesignTemplate | HitTriageTemplate
29
33
 
30
34
  async process(): Promise<any> {
31
35
  }
36
+ }
37
+
38
+ /** A campaign the landing cannot open for a reason the user is told (its template or its table is gone): an expected
39
+ * state of the data, not a failure of the app, so it is not logged as an error. */
40
+ export class CampaignUnavailableError extends Error {
41
+ constructor(reason: string) {
42
+ super(reason);
43
+ this.name = 'CampaignUnavailableError';
44
+ }
45
+ }
46
+
47
+ /** An app's landing ("Hit Design", "Hit Triage", …): its HitHome, and the campaign a link names opened over it. */
48
+ export abstract class HitLandingView<Ttemplate extends HitDesignTemplate | HitTriageTemplate | PeptiHitTemplate,
49
+ Tapp extends HitDesignApp | HitTriageApp> extends HitBaseView<Ttemplate, Tapp> {
50
+ protected home?: Control & HitHome;
51
+ /** Deleted in this page: a share listing may show their folders a while longer. */
52
+ protected deletedCampaigns: string[] = [];
53
+
54
+ /** [readme]: the app's help page in the package (README_HD.md), kept as the landing's `helpUrl` — the app gives it
55
+ * to the view the shell shows, whose help the platform shows (a help shown by hand loses to the panel's own
56
+ * page for the startup placeholder). */
57
+ constructor(app: Tapp, readme: string) {
58
+ super(app);
59
+ this.helpUrl = _package.webRoot + readme;
60
+ }
61
+
62
+ onActivated(): void {
63
+ grok.shell.windows.showHelp = true;
64
+ grok.shell.windows.help.showHelp(this.helpUrl);
65
+ }
66
+
67
+ protected abstract homeOptions(preset?: Ttemplate): HitHomeOptions<Ttemplate>;
32
68
 
69
+ /** Opens the campaign with this code; answers nothing when there is none the user may view. Throws when it cannot
70
+ * be opened. */
71
+ protected abstract checkCampaign(campaignId: string): Promise<unknown>;
72
+
73
+ /** Builds the landing again: the table reads the page's campaign list, the picker starts on `preset`. */
74
+ async init(preset?: Ttemplate): Promise<void> {
75
+ this.home?.dispose();
76
+ // a tree of its own, not the caller's: a campaign view's crumb asks for the landing from a scope that is closing
77
+ const owner = Scope.root('hit-home');
78
+ this.home = owner.build(() => hitHome<Ttemplate>(this.homeOptions(preset)));
79
+ this.home.own(() => owner.dispose());
80
+ this.root.replaceChildren(host(this.home));
81
+ }
82
+
83
+ /** The campaign's files, then what the database keeps of it (its last save, its lock, its V-iD links);
84
+ * rows the database fails to drop are only logged — the campaign is gone. */
33
85
  async deleteCampaign(appName: AppName, campaignId: string): Promise<void> {
34
86
  await _package.files.delete(`${appName}/campaigns/${campaignId}`);
35
87
  delete (_package.campaignsCache[appName] as {[name: string]: unknown} | undefined)?.[campaignId];
88
+ this.deletedCampaigns.push(campaignId);
89
+ await api.queries.deleteCampaignRecords(appName, campaignId).catch((e) => _package.logger.error(e));
36
90
  }
37
91
 
38
- /** The full campaign-deletion flow the UI and the AI share: delete the files,
39
- * hide the campaign from the cached list, and rebuild the view. */
92
+ /** The campaign deletion the UI and the assistant share: the files go, and the table drops the row. */
40
93
  async deleteCampaignAndRefresh(appName: AppName, campaignId: string): Promise<void> {
41
94
  await this.deleteCampaign(appName, campaignId);
42
- this.deletedCampaigns.push(campaignId);
43
- await this.init?.();
95
+ await this.home?.catalog.reload();
96
+ }
97
+
98
+ /** A campaign's name link, the assistant's open: a campaign that cannot open says why. */
99
+ async setCampaign(campaignId: string): Promise<void> {
100
+ await this.open(() => this.checkCampaign(campaignId), campaignId);
101
+ }
102
+
103
+ /** The campaign of the link the app was opened with (`?campaignId=`), opened over the landing; one that cannot open
104
+ * says why and leaves the landing in place. The router passes the link's id to the app's call: the address may have
105
+ * changed since. */
106
+ protected async openLinked(): Promise<void> {
107
+ const linked = this.app.parentCall.getParamValue(CampaignIdKey) ??
108
+ new URLSearchParams(location.search).get(CampaignIdKey);
109
+ if (linked)
110
+ await this.open(() => this.checkCampaign(linked), linked);
111
+ }
112
+
113
+ /** This app's campaigns table: whose settings it shares, what its balloons call a campaign. */
114
+ protected catalogOptions(family: CampaignFamily, label: (c: AnyCampaign) => string,
115
+ onLoaded?: (campaigns: readonly AnyCampaign[]) => void): CampaignCatalogOptions {
116
+ return {app: this.app.appName, family, deleted: this.deletedCampaigns, label, onLoaded,
117
+ open: (code) => this.setCampaign(code), remove: (code) => this.deleteCampaign(this.app.appName, code)};
118
+ }
119
+
120
+ private async open(check: () => Promise<unknown>, campaignId: string): Promise<void> {
121
+ const previous = this.app.campaign;
122
+ const table = this.app.dataFrame;
123
+ try {
124
+ await check();
125
+ }
126
+ catch (e) {
127
+ // the campaign still open saves as itself, not as the one that failed to open; one the app took whole stays
128
+ if (this.app.dataFrame === table)
129
+ this.app.campaign = previous;
130
+ if (!(e instanceof CampaignUnavailableError))
131
+ _package.logger.error(e);
132
+ grok.shell.error(`Campaign ${campaignId} could not be opened: ${e instanceof Error ? e.message : e}`);
133
+ this.app.setBaseUrl();
134
+ }
44
135
  }
45
136
  }
package/src/app/consts.ts CHANGED
@@ -38,6 +38,7 @@ export const i18n = {
38
38
  export const HDCampaignsGroupingLSKey = 'HDCampaignsGrouping';
39
39
  export const HDCampaignTableColumnsLSKey = 'HDCampaignTableColumns';
40
40
  export const HDCampaignsTableSortingLSKey = 'HDCampaignsTableSorting';
41
+ export const HDCampaignsCollapsedLSKey = 'HDCampaignsCollapsed';
41
42
 
42
43
  export enum CampaignGrouping {
43
44
  None = 'None',
@@ -47,36 +48,38 @@ export enum CampaignGrouping {
47
48
  LastModifiedUser = 'Last Modified User',
48
49
  }
49
50
 
50
- export type CampaignGroupingType = CampaignGrouping | `campaignFields.${string}`;
51
+ /** The column of the last saver's name — the caption the Last Modified User grouping is offered under too. */
52
+ export const LastModifiedByColumn = 'Last Modified by';
51
53
 
52
54
  export const DefaultCampaignTableInfoGetters = {
53
55
  'Name': (info: HitDesignCampaign) => info.friendlyName ?? info.name,
54
56
  'Code': (info: HitDesignCampaign) => info.name,
55
57
  'Created': (info: HitDesignCampaign) => info.createDate,
56
58
  'Author': (info: HitDesignCampaign) => info.authorUserFriendlyName ?? '',
57
- 'Last Modified by': (info: HitDesignCampaign) => info.lastModifiedUserName ?? '',
59
+ [LastModifiedByColumn]: (info: HitDesignCampaign) => info.lastModifiedUserName ?? '',
58
60
  'Molecules': (info: HitDesignCampaign) => (info.rowCount ?? 0).toString(),
59
61
  'Status': (info: HitDesignCampaign) => info.status,
60
62
  } as const;
61
63
 
62
- export type CampaignTableColumns = keyof typeof DefaultCampaignTableInfoGetters | `campaignFields.${string}`;
64
+ export const HDDefaultCampaignTableColumns = ['Code', 'Created', 'Author', LastModifiedByColumn, 'Molecules', 'Status'];
63
65
 
64
66
  export const HTCampaignsGroupingLSKey = 'HTCampaignsGrouping';
65
67
  export const HTCampaignTableColumnsLSKey = 'HTCampaignTableColumns';
66
68
  export const HTCampaignsTableSortingLSKey = 'HTCampaignsTableSorting';
69
+ export const HTCampaignsCollapsedLSKey = 'HTCampaignsCollapsed';
67
70
 
68
71
  export const HTDefaultCampaignTableInfoGetters = {
69
72
  'Name': (info: HitTriageCampaign) => info.friendlyName ?? info.name,
70
73
  'Code': (info: HitTriageCampaign) => info.name,
71
74
  'Created': (info: HitTriageCampaign) => info.createDate,
72
75
  'Author': (info: HitTriageCampaign) => info.authorUserFriendlyName ?? '',
73
- 'Last Modified by': (info: HitTriageCampaign) => info.lastModifiedUserName ?? '',
76
+ [LastModifiedByColumn]: (info: HitTriageCampaign) => info.lastModifiedUserName ?? '',
74
77
  'Total': (info: HitTriageCampaign) => (info.rowCount ?? 0).toString(),
75
78
  'Selected': (info: HitTriageCampaign) => (info.filteredRowCount ?? 0).toString(),
76
79
  'Status': (info: HitTriageCampaign) => info.status,
77
80
  } as const;
78
81
 
79
- export type HTCampaignTableColumns = keyof typeof HTDefaultCampaignTableInfoGetters | `campaignFields.${string}`;
82
+ export const HTDefaultCampaignTableColumns = ['Created', 'Author', 'Total', 'Selected', 'Status'];
80
83
 
81
84
  export const PepTriageDataSourceTag = 'pepTriageDataSource';
82
85
 
@@ -2,15 +2,24 @@ import * as grok from 'datagrok-api/grok';
2
2
  import {
3
3
  chemFunctionsDialog as _chemFunctionsDialog,
4
4
  } from '@datagrok-libraries/statistics/src/compute-functions/dialog';
5
- import {IChemFunctionsDialogResult, IComputeDialogResult, IDescriptorTree,
6
- HitTriageTemplate} from '../types';
5
+ import {IChemFunctionsDialogResult, IComputeDialogResult, IDescriptorTree, TemplateCompute} from '../types';
7
6
  import '../../../css/hit-triage.css';
8
7
  import {HitAppBase} from '../hit-app-base';
9
8
  import {HTFunctionOrderingLSKey} from '../consts';
10
9
 
10
+ /** The checkbox that flags a function to be calculated again every time a campaign opens. */
11
+ export const rerunOnOpenOption = {
12
+ label: 'Re-run when campaign opens',
13
+ tooltip: 'Recompute this function for the whole molecule column every time this campaign is ' +
14
+ 'opened. Useful for database lookups that may resolve after the molecule was first drawn.',
15
+ };
16
+
17
+ /** The descriptors a compute editor offers: the platform's chemistry descriptor groups. */
18
+ export const descriptorsTree = () => grok.chem.descriptorsTree() as Promise<IDescriptorTree>;
19
+
11
20
  export async function chemFunctionsDialog(app: HitAppBase<any>,
12
21
  onOk: (result: IComputeDialogResult) => void, onCancel: () => void,
13
- template: Omit<HitTriageTemplate, 'dataSourceType'>, dialog?: boolean,
22
+ template: {compute: TemplateCompute}, dialog?: boolean,
14
23
  // When true, each function/script/query gets a "re-run when campaign opens" checkbox whose state
15
24
  // is persisted in the campaign's compute config (see HitDesignApp.reComputeOnCampaignOpen).
16
25
  rerunOnOpen?: boolean,
@@ -20,13 +29,9 @@ export async function chemFunctionsDialog(app: HitAppBase<any>,
20
29
  onOk, onCancel,
21
30
  template,
22
31
  dialog,
23
- () => grok.chem.descriptorsTree() as Promise<IDescriptorTree>,
32
+ descriptorsTree,
24
33
  HTFunctionOrderingLSKey,
25
34
  undefined,
26
- rerunOnOpen ? {
27
- label: 'Re-run when campaign opens',
28
- tooltip: 'Recompute this function for the whole molecule column every time this campaign is ' +
29
- 'opened. Useful for database lookups that may resolve after the molecule was first drawn.',
30
- } : undefined,
35
+ rerunOnOpen ? rerunOnOpenOption : undefined,
31
36
  );
32
37
  }