@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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/hit-triage",
3
3
  "friendlyName": "Hit Triage",
4
- "version": "1.10.9",
4
+ "version": "1.11.0",
5
5
  "author": {
6
6
  "name": "Davit Rizhinashvili",
7
7
  "email": "drizhinashvili@datagrok.ai"
@@ -18,19 +18,23 @@
18
18
  "dependencies": {
19
19
  "@datagrok-libraries/test": "^1.4.1",
20
20
  "cash-dom": "8.1.5",
21
- "datagrok-api": "^1.27.0",
22
21
  "rxjs": "6.6.7",
23
22
  "typeahead-standalone": "4.14.1",
24
23
  "uuid": "^11.1.1",
25
- "@datagrok-libraries/compute-utils": "^1.47.0",
26
- "@datagrok-libraries/bio": "^6.0.8",
27
- "@datagrok-libraries/utils": "^4.7.9",
28
- "@datagrok-libraries/statistics": "^1.12.15"
24
+ "@datagrok-libraries/bio": "^6.1.0",
25
+ "@datagrok-libraries/compute-utils": "^1.48.0",
26
+ "@datagrok-libraries/statistics": "^1.13.0",
27
+ "@datagrok-libraries/u2": "^1.0.0",
28
+ "datagrok-api": "^1.28.1",
29
+ "@datagrok-libraries/utils": "^4.8.0"
30
+ },
31
+ "overrides": {
32
+ "uuid": "^11.1.1"
29
33
  },
30
34
  "devDependencies": {
31
35
  "@types/uuid": "^9.0.2",
32
36
  "@playwright/test": "^1.62.1",
33
- "@datagrok-libraries/bdd": "^0.1.0"
37
+ "@datagrok-libraries/bdd": "^1.0.0"
34
38
  },
35
39
  "canEdit": [
36
40
  "Administrators"
package/queries/locks.sql CHANGED
@@ -46,4 +46,41 @@ SELECT updated_at
46
46
  FROM hitdesign.update_logs
47
47
  WHERE app_name = @appName
48
48
  AND campaign_id = @campaignId;
49
+ --end
50
+
51
+ --name: getLastModifiedAll
52
+ --description: Get the last save time of every campaign of an app.
53
+ --connection: HitTriage:hitdesign
54
+ --input: string appName
55
+ SELECT campaign_id, updated_at
56
+ FROM hitdesign.update_logs
57
+ WHERE app_name = @appName;
58
+ --end
59
+
60
+ --name: dropCampaignLock
61
+ --description: Drop the caller's lock without logging a save: the campaign was not written under it. A lock another session holds stays.
62
+ --connection: HitTriage:hitdesign
63
+ --input: string appName
64
+ --input: string campaignId
65
+ --input: string lockedBy
66
+ DELETE FROM hitdesign.campaign_locks
67
+ WHERE app_name = @appName
68
+ AND campaign_id = @campaignId
69
+ AND locked_by = @lockedBy
70
+ RETURNING campaign_id;
71
+ --end
72
+
73
+ --name: deleteCampaignRecords
74
+ --description: Remove what the database keeps of a deleted campaign: its last save, its lock and its V-iD links.
75
+ --connection: HitTriage:hitdesign
76
+ --input: string appName
77
+ --input: string campaignId
78
+ WITH logs AS (
79
+ DELETE FROM hitdesign.update_logs WHERE app_name = @appName AND campaign_id = @campaignId RETURNING 1
80
+ ), locks AS (
81
+ DELETE FROM hitdesign.campaign_locks WHERE app_name = @appName AND campaign_id = @campaignId RETURNING 1
82
+ ), vids AS (
83
+ DELETE FROM hitdesign.campaign_vids WHERE app_name = @appName AND campaign_id = @campaignId RETURNING 1
84
+ )
85
+ SELECT (SELECT COUNT(*) FROM logs) + (SELECT COUNT(*) FROM locks) + (SELECT COUNT(*) FROM vids) AS removed;
49
86
  --end
@@ -2,52 +2,60 @@ import * as DG from 'datagrok-api/dg';
2
2
  import * as ui from 'datagrok-api/ui';
3
3
  import * as grok from 'datagrok-api/grok';
4
4
 
5
- export function getLayoutInput() {
6
- const dataFileProp = DG.Property.fromOptions({name: 'layout', caption: 'Layout', type: 'file'});
7
- const dataFileInput = DG.InputBase.forProperty(dataFileProp);
8
- let layout: DG.ViewLayout | null = null;
9
- let layoutViewState: string | null = null;
10
- // if the file is local, we can store it in a variable
11
- let localFilePath: string | null = null;
5
+ /** A template's layout: the view state of a .layout file, and the file's path when it lives on a share, where
6
+ * "Apply template layout" reads it again. */
7
+ export interface TemplateLayout {
8
+ viewState: string;
9
+ localPath: string | null;
10
+ }
11
+
12
+ /** The platform's file input a template's layout is picked with, from the computer or a share. */
13
+ export function layoutFileInput(): DG.InputBase<DG.FileInfo | null> {
14
+ return DG.InputBase.forProperty(DG.Property.fromOptions({name: 'layout', caption: 'Layout', type: 'file'}));
15
+ }
16
+
17
+ /** The layout `file` holds; null when it holds none. */
18
+ export async function readLayout(file: DG.FileInfo): Promise<TemplateLayout | null> {
19
+ let layout: DG.ViewLayout | null;
20
+ try {
21
+ layout = DG.ViewLayout.fromJson(await file.readAsString());
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ if (!layout)
27
+ return null;
28
+ // a share's path is namespaced by its connection ("System:AppData/…"); a file from the computer or memory is not
29
+ const onShare = !!file.fullPath?.includes(':') && await grok.dapi.files.exists(file.fullPath).catch(() => false);
30
+ return {viewState: layout.viewState, localPath: onShare ? file.fullPath : null};
31
+ }
32
+
33
+ /** A file in memory holding `layout`, under its share path or `<name>.layout`: what a file input shows for a layout
34
+ * that is already a template's, read back by {@link readLayout} as it was. */
35
+ export function layoutFile(layout: TemplateLayout, name: string): DG.FileInfo {
36
+ return DG.FileInfo.fromString(layout.localPath ?? `${name}.layout`,
37
+ DG.ViewLayout.fromViewState(layout.viewState).toJson());
38
+ }
39
+
40
+ /** The layout input of the Hit Triage and PepTriage editors; a clone's layout (`preset`) is there from the start. */
41
+ export function getLayoutInput(preset?: {name: string, layoutViewState?: string, localLayoutPath?: string}) {
42
+ const dataFileInput = layoutFileInput();
43
+ let layout: TemplateLayout | null = preset?.layoutViewState ?
44
+ {viewState: preset.layoutViewState, localPath: preset.localLayoutPath ?? null} : null;
12
45
  let error: string | null = null;
46
+ let reads = 0;
13
47
  dataFileInput.onChanged.subscribe(async (_) => {
14
- const f: DG.FileInfo = dataFileInput.value;
15
- if (f) {
16
- try {
17
- const exists = f.fullPath ? await grok.dapi.files.exists(f.fullPath) : false;
18
- localFilePath = exists ? f.fullPath : null;
19
- } catch (e) {
20
- localFilePath = null;
21
- }
22
- try {
23
- const contentString = await f.readAsString();
24
- const l = DG.ViewLayout.fromJson(contentString);
25
- if (l) {
26
- layout = l;
27
- layoutViewState = l.viewState;
28
- error = null;
29
- } else {
30
- layout = null;
31
- layoutViewState = null;
32
- localFilePath = null;
33
- error = 'Invalid layout file';
34
- }
35
- } catch (e) {
36
- layout = null;
37
- layoutViewState = null;
38
- localFilePath = null;
39
- error = 'Invalid layout file';
40
- }
41
- dataFileInput.input.classList[(error ? 'add' : 'remove')]('d4-invalid');
42
- } else {
43
- layout = null;
44
- layoutViewState = null;
45
- localFilePath = null;
46
- }
48
+ const read = ++reads;
49
+ const f: DG.FileInfo | null = dataFileInput.value;
50
+ const found = f ? await readLayout(f) : null;
51
+ if (read !== reads)
52
+ return;
53
+ layout = found;
54
+ error = f && !found ? 'Invalid layout file' : null;
55
+ dataFileInput.input.classList.toggle('d4-invalid', error !== null);
47
56
  });
48
57
  ui.tooltip.bind(dataFileInput.root, () => error ? error : 'Select a layout file');
49
- return {
50
- dataFileInput, getLayout: () => layout, getLayoutViewState: () => layoutViewState,
51
- getLocalFilePath: () => localFilePath,
52
- };
58
+ if (layout !== null)
59
+ dataFileInput.value = layoutFile(layout, preset!.name);
60
+ return {dataFileInput, getLayoutViewState: () => layout?.viewState ?? null};
53
61
  }
@@ -1,10 +1,12 @@
1
1
  /* eslint-disable max-len */
2
+ import * as grok from 'datagrok-api/grok';
2
3
  import * as DG from 'datagrok-api/dg';
3
4
  import * as ui from 'datagrok-api/ui';
4
- import * as grok from 'datagrok-api/grok';
5
- import {_package} from '../../package';
5
+ import {Scope, button, computed, signal} from '@datagrok-libraries/u2';
6
+ import type {LabelColumn} from '@datagrok-libraries/u2';
6
7
  import {CampaignFieldTypes, HitTriageTemplate, IngestType} from '../types';
7
8
  import * as C from '../consts';
9
+ import {HitAppBase} from '../hit-app-base';
8
10
  import '../../../css/hit-triage.css';
9
11
 
10
12
  export type INewCampaignResult = {
@@ -16,24 +18,32 @@ export type INewCampaignResult = {
16
18
  }
17
19
 
18
20
  export type CampaignAccordeonOptions = {
21
+ /** The scope the form lives in: it is built after an await, with no builder around. */
22
+ owner: Scope,
23
+ /** The label column of the Template row above the form: the form's captions set its width. */
24
+ column?: LabelColumn,
25
+ /** What Start does with the data; Start stays busy until it is done. */
26
+ start: (result: INewCampaignResult) => Promise<unknown>,
19
27
  extraFormElements?: HTMLElement[],
20
28
  getExtraData?: () => {[key: string]: any},
21
29
  }
22
30
 
23
- type HitTriageCampaignAccordeon = {
24
- promise: Promise<INewCampaignResult>,
25
- root: HTMLElement,
26
- cancelPromise: Promise<void>
27
- }
28
- /** Creates a new campaign accordeon
29
- * @param {HitTriageTemplate}template template for the campaign. it contains file source type and
31
+ const EMPTY = 'Value can\'t be empty';
32
+
33
+ /** Creates the new campaign form of Hit Triage and PepTriage: the campaign name, the data source (a file, or the
34
+ * template's function and its parameters), the template's fields, and Start — disabled while the data or a required
35
+ * value is missing, the reason its tooltip.
36
+ * @param {HitTriageTemplate} template template for the campaign. it contains file source type and
30
37
  * additional campaign fields
31
- * @return {HitTriageCampaignAccordeon} Object containing root element, promise for the campaign result and cancel
38
+ * @return {Promise<HTMLElement>} the form
32
39
  */
33
40
  export async function newCampaignAccordeon(template: HitTriageTemplate,
34
41
  dataSourceFunctionsMap: {[key: string]: DG.Func | DG.DataQuery},
35
- dataSourceTag: string = C.HitTriageDataSourceTag,
36
- options?: CampaignAccordeonOptions): Promise<HitTriageCampaignAccordeon> {
42
+ dataSourceTag: string,
43
+ options: CampaignAccordeonOptions): Promise<HTMLElement> {
44
+ // the platform inputs report their edits here, and Start's reason is read again
45
+ const edits = signal(0);
46
+ const edited = () => edits.value++;
37
47
  const errorDiv = ui.divText('', {style: {color: 'red'}});
38
48
  // handling file input
39
49
  let fileDf: DG.DataFrame | null = null;
@@ -43,7 +53,7 @@ export async function newCampaignAccordeon(template: HitTriageTemplate,
43
53
  if (!fileDf)
44
54
  return;
45
55
  await fileDf.meta.detectSemanticTypes();
46
- const molcol = fileDf.columns.bySemType(DG.SEMTYPE.MOLECULE);
56
+ const molcol = HitAppBase.moleculeColumn(fileDf);
47
57
  if (!molcol) {
48
58
  errorDiv.innerText = 'No molecules column found';
49
59
  return;
@@ -52,6 +62,8 @@ export async function newCampaignAccordeon(template: HitTriageTemplate,
52
62
  errorDiv.innerText = '';
53
63
  } catch (e) {
54
64
  errorDiv.innerText = 'Error parsing file';
65
+ } finally {
66
+ edited();
55
67
  }
56
68
  };
57
69
 
@@ -68,15 +80,21 @@ export async function newCampaignAccordeon(template: HitTriageTemplate,
68
80
  });
69
81
  }
70
82
  let funcCall: DG.FuncCall | null = null;
83
+ let funcCallScope: Scope | undefined;
71
84
  // each data source function can have some parameters like for example number of rows to return
72
85
  // whenever user selects a function we create a FuncCall object and get an editor for it
73
86
  const onDataFunctionChange = async () => {
74
87
  const func = dataSourceFunctionsMap[dataSourceFunctionInput.value!];
75
88
  funcCall = func.prepare();
89
+ funcCallScope?.dispose();
90
+ funcCallScope = options.owner.child('data-source-call');
91
+ for (const param of funcCall.inputParams.values())
92
+ funcCallScope.subscribe(param.onChanged, edited);
76
93
  const editor = await funcCall.getEditor();
77
94
  editor.classList.remove('ui-form');
78
95
  funcEditorDiv.innerHTML = '';
79
96
  funcEditorDiv.appendChild(editor);
97
+ edited();
80
98
  };
81
99
  const funcEditorDiv = ui.div([]);
82
100
  const dataSourceFunctionInput = ui.input.choice(
@@ -104,7 +122,8 @@ export async function newCampaignAccordeon(template: HitTriageTemplate,
104
122
  {name: field.name, type: CampaignFieldTypes[field.type as keyof typeof CampaignFieldTypes],
105
123
  nullable: !field.required, ...(field.semtype ? {semType: field.semtype} : {})}));
106
124
  const campaignPropsObject: {[key: string]: any} = {};
107
- const campaignPropsForm = campaignProps.length ? ui.input.form(campaignPropsObject, campaignProps) : ui.div();
125
+ const campaignPropsForm = campaignProps.length ?
126
+ ui.input.form(campaignPropsObject, campaignProps, {onValueChanged: edited}) : ui.div();
108
127
  campaignPropsForm.classList.remove('ui-form');
109
128
  // displaying function editor or file input depending on the data source type
110
129
  if (template.dataSourceType === 'File') {
@@ -115,48 +134,66 @@ export async function newCampaignAccordeon(template: HitTriageTemplate,
115
134
  functionInputDiv.style.display = 'inherit';
116
135
  }
117
136
 
137
+ const isEmpty = (value: unknown) => value === null || value === undefined || value === '';
138
+ const problem = computed(() => {
139
+ edits.value;
140
+ if (template.dataSourceType === 'File' && !fileDf)
141
+ return 'Pick a file';
142
+ if (template.dataSourceType !== 'File') {
143
+ const param = [...funcCall?.inputParams.values() ?? []].find((p) => !p.property.nullable && isEmpty(p.value));
144
+ if (param)
145
+ return `${param.property.caption || param.name}: ${EMPTY}`;
146
+ }
147
+ const field = template.campaignFields.find((f) => f.required && isEmpty(campaignPropsObject[f.name]));
148
+ return field ? `${field.name}: ${EMPTY}` : null;
149
+ });
150
+
151
+ const dataOf = async (): Promise<INewCampaignResult> => {
152
+ const friendlyName = campaignNameInput.value?.trim() || undefined;
153
+ const extraData = options.getExtraData?.();
154
+ if (template.dataSourceType === 'File')
155
+ return {df: fileDf!, type: 'File', campaignProps: campaignPropsObject, friendlyName, extraData};
156
+ const funcCallInputs: {[key: string]: any} = {};
157
+ for (const [key, value] of Object.entries(funcCall!.inputs))
158
+ funcCallInputs[key] = value;
159
+ const df: DG.DataFrame = await dataSourceFunctionsMap[dataSourceFunctionInput.value!].apply(funcCallInputs);
160
+ return {df, type: 'Query', campaignProps: campaignPropsObject, friendlyName, extraData};
161
+ };
162
+ const busy = signal(false);
163
+ const startCampaignButton = options.owner.build(() => button(C.i18n.StartCampaign, async () => {
164
+ busy.value = true;
165
+ try {
166
+ const data = await dataOf();
167
+ if (data.df.rowCount === 0) {
168
+ grok.shell.warning(`${template.dataSourceType === 'File' ? 'The file has' : `${dataSourceFunctionInput.value} returned`} ` +
169
+ 'no rows, so no campaign was created');
170
+ return;
171
+ }
172
+ await options.start(data);
173
+ } finally {
174
+ busy.value = false;
175
+ }
176
+ }, {primary: true, disabled: computed(() => busy.value ? 'Starting…' : problem.value)}));
177
+
118
178
  const form = ui.div([
119
179
  campaignNameInput.root,
120
- ...(options?.extraFormElements ?? []),
180
+ ...(options.extraFormElements ?? []),
121
181
  dataInputsDiv,
122
182
  ...(campaignProps.length ? [campaignPropsForm] : [])]);
123
- const buttonsDiv = ui.buttonsInput([]); // div for create and cancel buttons
124
- form.appendChild(buttonsDiv);
125
- const promise = new Promise<INewCampaignResult>((resolve) => {
126
- const onOkProxy = async () => {
127
- if (template.dataSourceType === 'File') {
128
- if (!fileDf) {
129
- grok.shell.error('No file selected');
130
- return;
131
- }
132
- const df = fileDf;
133
- df.name = fileDf.name;
134
- const name = campaignNameInput.value?.trim() || undefined;
135
- const extraData = options?.getExtraData?.();
136
- resolve({df, type: 'File', campaignProps: campaignPropsObject, friendlyName: name, extraData});
137
- } else {
138
- const func = dataSourceFunctionsMap[dataSourceFunctionInput.value!];
139
- if (!func) {
140
- grok.shell.error('No function selected');
141
- return;
142
- }
143
- const funcCallInputs: {[key: string]: any} = {};
144
- Object.entries(funcCall!.inputs).forEach(([key, value]) => {
145
- funcCallInputs[key] = value;
146
- });
147
- const df: DG.DataFrame = await func.apply(funcCallInputs);
148
- const name = campaignNameInput.value?.trim() || undefined;
149
- const extraData = options?.getExtraData?.();
150
- resolve({df, type: 'Query', campaignProps: campaignPropsObject, friendlyName: name, extraData});
151
- };
152
- };
153
- const startCampaignButton = ui.bigButton(C.i18n.StartCampaign, () => onOkProxy());
154
- buttonsDiv.appendChild(startCampaignButton);
155
- });
156
-
157
- const cancelPromise = new Promise<void>((resolve) => {
158
- const _cancelButton = ui.button(C.i18n.cancel, () => resolve());
159
- //buttonsDiv.appendChild(cancelButton);
160
- });
161
- return {promise, root: form, cancelPromise};
183
+ const buttons = ui.buttonsInput([]);
184
+ buttons.appendChild(startCampaignButton);
185
+ form.appendChild(buttons);
186
+ // the platform form around the rows, as the landing had it: one label column, START at the form's end
187
+ const root = ui.div([form], 'ui-form');
188
+ const column = options.column;
189
+ if (column && typeof ResizeObserver !== 'undefined') {
190
+ const observer = new ResizeObserver(() => column.report(root, Math.max(0, ...Array.from(root
191
+ .querySelectorAll<HTMLElement>('label.ui-input-label')).filter((label) => label.textContent).map((label) => label.offsetWidth))));
192
+ observer.observe(root);
193
+ options.owner.own(() => {
194
+ observer.disconnect();
195
+ column.leave(root);
196
+ });
197
+ }
198
+ return root;
162
199
  }
@@ -1,23 +1,6 @@
1
- /* eslint-disable max-len */
2
1
  import * as DG from 'datagrok-api/dg';
3
- import * as ui from 'datagrok-api/ui';
4
- import * as grok from 'datagrok-api/grok';
5
- import {CampaignFieldTypes, HitDesignTemplate} from '../types';
6
- import {HitDesignMolColName, PeptiHitHelmColName, TileCategoriesColName, ViDColName, i18n} from '../consts';
7
- // @ts-ignore
8
- import '../../../css/hit-triage.css';
9
-
10
- type NewHitDesignCampaignRes = {
11
- df: DG.DataFrame,
12
- campaignProps: {[key: string]: any}
13
- name: string,
14
- }
15
-
16
- type HitDesignCampaignAccordeon = {
17
- promise: Promise<NewHitDesignCampaignRes>,
18
- root: HTMLElement,
19
- cancelPromise: Promise<void>
20
- }
2
+ import {HitDesignTemplate} from '../types';
3
+ import {HitDesignMolColName, PeptiHitHelmColName, TileCategoriesColName, ViDColName} from '../consts';
21
4
 
22
5
  /** The initial one-row dataframe a new Hit Design / PeptiHit campaign starts from. */
23
6
  export function createNewHitDesignDataFrame(template: HitDesignTemplate, peptiHit = false): DG.DataFrame {
@@ -33,7 +16,7 @@ export function createNewHitDesignDataFrame(template: HitDesignTemplate, peptiHi
33
16
 
34
17
  const molCol = df.columns.addNew(HitDesignMolColName, DG.TYPE.STRING);
35
18
  molCol.semType = DG.SEMTYPE.MOLECULE;
36
- molCol.meta.units = DG.UNITS.Molecule.SMILES;
19
+ molCol.meta.units = DG.UNITS.Molecule.MOLBLOCK;
37
20
  molCol.set(0, null);
38
21
  if (template?.stages?.length > 0) {
39
22
  const tileCategoryCol = df.columns.addNew(TileCategoriesColName, DG.TYPE.STRING);
@@ -42,50 +25,3 @@ export function createNewHitDesignDataFrame(template: HitDesignTemplate, peptiHi
42
25
  df.columns.addNew(ViDColName, DG.TYPE.STRING);
43
26
  return df;
44
27
  }
45
-
46
- export function newHitDesignCampaignAccordeon(template: HitDesignTemplate, peptiHit = false): HitDesignCampaignAccordeon {
47
- const df = createNewHitDesignDataFrame(template, peptiHit);
48
-
49
- // campaign properties. each template might have number of additional fields that should
50
- // be filled by user for the campaign. they are cast into DG.Property objects and displayed as a form
51
- const campaignProps = template.campaignFields
52
- .map((field) => field.type === DG.SEMTYPE.MOLECULE ?
53
- ({...field, type: 'String', semtype: DG.SEMTYPE.MOLECULE}) : field)
54
- .map((field) =>
55
- DG.Property.fromOptions(
56
- {name: field.name, type: CampaignFieldTypes[field.type as keyof typeof CampaignFieldTypes],
57
- nullable: !field.required, ...(field.semtype ? {semType: field.semtype} : {})}));
58
- const campaignPropsObject: {[key: string]: any} = {};
59
- const campaignNameInput = ui.input.string('Campaign Name', {tooltipText: 'New campaign name. If empty, campaign code will be used.'});
60
- const campaignPropsForm = ui.input.form(campaignPropsObject, campaignProps);
61
- campaignPropsForm.prepend(campaignNameInput.root);
62
- campaignPropsForm.classList.remove('ui-form');
63
- const form = ui.div([
64
- ...(template.campaignFields?.length > 0 ? []: []),
65
- campaignPropsForm,
66
- ]);
67
-
68
- const buttonsDiv = ui.buttonsInput([]); // div for create and cancel buttons
69
- form.appendChild(buttonsDiv);
70
- const okPromise = new Promise<NewHitDesignCampaignRes>((resolve) => {
71
- const startCampaignButton = ui.bigButton(i18n.StartCampaign,
72
- () => {
73
- for (const field of template.campaignFields) {
74
- if (field.required) {
75
- if (!campaignPropsObject[field.name] || campaignPropsObject[field.name] === '') {
76
- grok.shell.error(`Field '${field.name}' is required`);
77
- return;
78
- }
79
- }
80
- }
81
- resolve({df, campaignProps: campaignPropsObject, name: campaignNameInput.value});
82
- });
83
- buttonsDiv.appendChild(startCampaignButton);
84
- });
85
- const cancelPromise = new Promise<void>((resolve) => {
86
- const _cancelButton = ui.button(i18n.cancel, () => resolve());
87
- //buttonsDiv.appendChild(cancelButton);
88
- });
89
-
90
- return {promise: okPromise, root: form, cancelPromise};
91
- }
@@ -3,16 +3,15 @@ import * as DG from 'datagrok-api/dg';
3
3
  import * as ui from 'datagrok-api/ui';
4
4
  import * as grok from 'datagrok-api/grok';
5
5
  import {_package} from '../../package';
6
- import {CampaignFieldTypes, HitTriageCampaignField, HitTriageCampaignFieldType,
7
- IComputeDialogResult, PepTriageTemplate, IngestType, INewTemplateResult} from '../types';
6
+ import {IComputeDialogResult, PepTriageTemplate, IngestType, INewTemplateResult} from '../types';
8
7
  import * as C from '../consts';
9
8
  import '../../../css/hit-triage.css';
10
9
  import {chemFunctionsDialog} from '../dialogs/functions-dialog';
11
- import {ItemType, ItemsGrid} from '@datagrok-libraries/utils/src/items-grid';
12
10
  import {HitAppBase} from '../hit-app-base';
13
11
  import {getLayoutInput} from './layout-input';
14
12
  import {getFuncPackageNameSafe, loadTemplate} from '../utils';
15
- import {getCampaignFieldEditors, saveTemplate} from './new-template-accordeon';
13
+ import {getCampaignFieldEditors, showTemplateInputError} from './new-template-accordeon';
14
+ import {freeKey, freeName} from '../shared/template-editor';
16
15
 
17
16
 
18
17
  export async function createPepTriageTemplateAccordeon(app: HitAppBase<any>,
@@ -43,33 +42,37 @@ export async function createPepTriageTemplateAccordeon(app: HitAppBase<any>,
43
42
  submitFunctionInput.nullable = true;
44
43
  submitFunctionInput.fireChanged();
45
44
  submitFunctionInput.setTooltip('Select function to be called upon submitting');
46
- const layoutInput = getLayoutInput();
45
+ const layoutInput = getLayoutInput(preset);
47
46
  const errorDiv = ui.divText('Template name is empty or already exists', {classes: 'hit-triage-error-div'});
48
47
  const keyErrorDiv = ui.divText('Template key is empty or already exists', {classes: 'hit-triage-error-div'});
49
48
 
50
- const templateNameInput = ui.input.string('Name', {value: preset ? `${preset.name} (copy)` : '', onValueChanged: (value) => {
51
- if (value === '' || availableTemplates.includes(value)) {
52
- templateNameInput.root.style.borderBottom = '1px solid red';
53
- errorDiv.style.opacity = '100%';
54
- } else {
55
- templateNameInput.root.style.borderBottom = 'none';
56
- errorDiv.style.opacity = '0%';
49
+ const nameProblem = () => !templateNameInput.value?.trim() || availableTemplates.includes(templateNameInput.value) ?
50
+ 'Template name is empty or already exists' : null;
51
+ const keyProblem = () => !templateKeyInput.value?.trim() || availableTemplateKeys.includes(templateKeyInput.value) ?
52
+ 'Template key is empty or already exists' : null;
53
+ const seqColProblem = () => seqColInput.value?.trim() ? null : 'Sequence column name is required';
54
+ let createTemplateButton: HTMLButtonElement | null = null;
55
+ let createProblem: string | null = null;
56
+ let createDisabled = false;
57
+ function updateCreate() {
58
+ createProblem = nameProblem() ?? keyProblem() ?? seqColProblem();
59
+ if (createTemplateButton && (createProblem !== null) !== createDisabled) {
60
+ createDisabled = createProblem !== null;
61
+ ui.setDisabled(createTemplateButton, createDisabled, () => createProblem);
57
62
  }
63
+ }
64
+
65
+ const templateNameInput = ui.input.string('Name', {value: preset ? freeName(preset.name, new Set(availableTemplates.map((n) => n.toLowerCase()))) : '', onValueChanged: () => {
66
+ showTemplateInputError(templateNameInput, errorDiv, nameProblem() !== null);
67
+ updateCreate();
58
68
  }});
59
- const templateKeyInput = ui.input.string('Key', {value: preset ? `${preset.key}-copy` : '', onValueChanged: (value) => {
60
- if (value === '' || availableTemplateKeys.includes(value)) {
61
- templateKeyInput.root.style.borderBottom = '1px solid red';
62
- keyErrorDiv.style.opacity = '100%';
63
- } else {
64
- templateKeyInput.root.style.borderBottom = 'none';
65
- keyErrorDiv.style.opacity = '0%';
66
- }
69
+ const templateKeyInput = ui.input.string('Key', {value: preset ? freeKey(preset.key, new Set(availableTemplateKeys.map((k) => k.toLowerCase()))) : '', onValueChanged: () => {
70
+ showTemplateInputError(templateKeyInput, keyErrorDiv, keyProblem() !== null);
71
+ updateCreate();
67
72
  }});
68
73
 
69
74
  templateKeyInput.setTooltip('Template key used for campaign prefix');
70
75
  templateNameInput.setTooltip('Template name');
71
- templateNameInput.root.style.borderBottom = 'none';
72
- templateKeyInput.root.style.borderBottom = 'none';
73
76
  errorDiv.style.opacity = '0%';
74
77
  keyErrorDiv.style.opacity = '0%';
75
78
 
@@ -79,13 +82,8 @@ export async function createPepTriageTemplateAccordeon(app: HitAppBase<any>,
79
82
  const seqColErrorDiv = ui.divText('Sequence column name is required', {classes: 'hit-triage-error-div'});
80
83
  seqColErrorDiv.style.opacity = '0%';
81
84
  seqColInput.onChanged.subscribe(() => {
82
- if (!seqColInput.value?.trim()) {
83
- seqColInput.root.style.borderBottom = '1px solid red';
84
- seqColErrorDiv.style.opacity = '100%';
85
- } else {
86
- seqColInput.root.style.borderBottom = 'none';
87
- seqColErrorDiv.style.opacity = '0%';
88
- }
85
+ showTemplateInputError(seqColInput, seqColErrorDiv, seqColProblem() !== null);
86
+ updateCreate();
89
87
  });
90
88
 
91
89
  const molColInput = ui.input.string('Molecule Column', {value: preset?.moleculeColumnName ?? '', nullable: true});
@@ -150,16 +148,9 @@ export async function createPepTriageTemplateAccordeon(app: HitAppBase<any>,
150
148
  const promise = new Promise<PepTriageTemplate>((resolve) => {
151
149
  async function onOkProxy() {
152
150
  funcInput.okProxy();
153
- if (errorDiv.style.opacity === '100%') {
154
- grok.shell.error('Template name is empty or already exists');
155
- return;
156
- }
157
- if (keyErrorDiv.style.opacity === '100%') {
158
- grok.shell.error('Template key is empty or already exists');
159
- return;
160
- }
161
- if (!seqColInput.value?.trim()) {
162
- grok.shell.error('Sequence column name is required');
151
+ const problem = nameProblem() ?? keyProblem() ?? seqColProblem();
152
+ if (problem) {
153
+ grok.shell.error(problem);
163
154
  return;
164
155
  }
165
156
  const submitFunction = submitFunctionInput.value ? submitFunctionsMap[submitFunctionInput.value] : undefined;
@@ -196,12 +187,19 @@ export async function createPepTriageTemplateAccordeon(app: HitAppBase<any>,
196
187
  ...(submitFunction ? {submit: {fName: submitFunction.name, package: getFuncPackageNameSafe(submitFunction)}} : {}),
197
188
  queryFunctionName: (ingestTypeInput.value === 'Query') ? dataSourceFunctionInput.value ?? undefined : undefined,
198
189
  };
199
- _package.files.writeAsText(`${templatesFolder}/${out.name}.json`, JSON.stringify(out));
190
+ try {
191
+ await _package.files.writeAsText(`${templatesFolder}/${out.name}.json`, JSON.stringify(out));
192
+ }
193
+ catch (e) {
194
+ grok.shell.error(`Could not save template ${out.name}: ${e instanceof Error ? e.message : e}`);
195
+ return;
196
+ }
200
197
  grok.shell.info('Template created successfully');
201
198
  resolve(out);
202
199
  }
203
- const createTemplateButton = ui.bigButton(C.i18n.createTemplate, () => onOkProxy());
200
+ createTemplateButton = ui.bigButton(C.i18n.createTemplate, () => onOkProxy());
204
201
  buttonsContainerDiv.appendChild(createTemplateButton);
202
+ updateCreate();
205
203
  });
206
204
 
207
205
  return {root: form, template: promise, cancelPromise};