@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.
- package/.grokignore +2 -0
- package/.turbo/turbo-build.log +25 -3
- package/CHANGELOG.md +78 -0
- package/CLAUDE.md +87 -10
- package/README_HD.md +14 -14
- package/README_HT.md +6 -6
- package/README_PH.md +110 -0
- package/bdd/bdd.config.json +3 -1
- package/bdd/bindings/campaign.ts +626 -0
- package/bdd/bindings/hit-design.ts +36 -42
- package/bdd/bindings/landing.ts +839 -0
- package/bdd/bindings/pepti-hit.ts +35 -0
- package/bdd/features/campaign/crumbs.feature +22 -0
- package/bdd/features/campaign/grid.feature +56 -0
- package/bdd/features/campaign/merge.feature +105 -0
- package/bdd/features/campaign/molecule-vid.feature +40 -0
- package/bdd/features/campaign/permissions.feature +46 -0
- package/bdd/features/campaign/progress-tracker.feature +89 -0
- package/bdd/features/campaign/refresh-hint.feature +33 -0
- package/bdd/features/campaign/ribbon.feature +49 -0
- package/bdd/features/campaign/stage-choices.feature +39 -0
- package/bdd/features/campaign/submit.feature +135 -0
- package/bdd/features/campaign/tracker-cards.feature +46 -0
- package/bdd/features/campaign/view-only.feature +37 -0
- package/bdd/features/landing/campaign-deep-links.feature +61 -0
- package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
- package/bdd/features/landing/hit-design-campaigns.feature +153 -0
- package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
- package/bdd/features/landing/new-campaign.feature +69 -0
- package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
- package/bdd/features/landing/pepti-hit-landing.feature +132 -0
- package/bdd/features/pepti-hit/helm-edit.feature +47 -0
- package/bdd/features/templates/template-editor.feature +130 -0
- package/bdd/features/templates/template-picker.feature +112 -0
- package/bdd/features/templates/triage-forms.feature +59 -0
- package/bdd/fixtures/bar-chart.layout +1 -0
- package/bdd/fixtures/merge-local.csv +2 -0
- package/bdd/generated/campaign/crumbs.test.ts +33 -0
- package/bdd/generated/campaign/grid.test.ts +79 -0
- package/bdd/generated/campaign/merge.test.ts +134 -0
- package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
- package/bdd/generated/campaign/permissions.test.ts +58 -0
- package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
- package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
- package/bdd/generated/campaign/ribbon.test.ts +65 -0
- package/bdd/generated/campaign/stage-choices.test.ts +55 -0
- package/bdd/generated/campaign/submit.test.ts +167 -0
- package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
- package/bdd/generated/campaign/view-only.test.ts +51 -0
- package/bdd/generated/hit-design/campaign-column-metadata.test.ts +1 -0
- package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
- package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
- package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
- package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
- package/bdd/generated/landing/new-campaign.test.ts +78 -0
- package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
- package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
- package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
- package/bdd/generated/templates/template-editor.test.ts +137 -0
- package/bdd/generated/templates/template-picker.test.ts +119 -0
- package/bdd/generated/templates/triage-forms.test.ts +68 -0
- package/css/hit-triage.css +27 -23
- package/dist/package-test.js +690 -4
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +318 -73
- package/dist/package.js.map +1 -1
- package/package.json +11 -7
- package/queries/locks.sql +37 -0
- package/src/app/accordeons/layout-input.ts +52 -44
- package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
- package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
- package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
- package/src/app/accordeons/new-template-accordeon.ts +41 -24
- package/src/app/ai/view-functions.ts +22 -19
- package/src/app/base-view.ts +99 -8
- package/src/app/consts.ts +8 -5
- package/src/app/dialogs/functions-dialog.ts +14 -9
- package/src/app/dialogs/merge-table-dialog.ts +181 -325
- package/src/app/hit-app-base.ts +61 -90
- package/src/app/hit-design-app.ts +481 -886
- package/src/app/hit-design-views/info-view.ts +57 -407
- package/src/app/hit-design-views/submit-view.ts +216 -111
- package/src/app/hit-design-views/tiles-view.ts +168 -123
- package/src/app/hit-design-views/utils.css +0 -8
- package/src/app/hit-triage-app.ts +69 -38
- package/src/app/hit-triage-views/info-view.ts +70 -371
- package/src/app/pep-triage-app.ts +2 -2
- package/src/app/pep-triage-views/info-view.ts +42 -83
- package/src/app/pepti-hit-app.ts +32 -183
- package/src/app/pepti-hits-views/info-view.ts +15 -37
- package/src/app/shared/campaign-catalog.ts +408 -0
- package/src/app/shared/campaign-session.ts +557 -0
- package/src/app/shared/compute-editor.ts +274 -0
- package/src/app/shared/hit-home.ts +45 -0
- package/src/app/shared/new-campaign-form.ts +90 -0
- package/src/app/shared/permissions-editor.ts +93 -0
- package/src/app/shared/template-editor.ts +331 -0
- package/src/app/shared/template-picker.ts +154 -0
- package/src/app/utils/merge-table.ts +183 -78
- package/src/app/utils.ts +34 -325
- package/src/package-api.ts +29 -8
- package/src/package-test.ts +17 -2
- package/src/package.g.ts +12 -8
- package/src/package.ts +19 -7
- package/src/tests/ai.ts +244 -0
- package/src/tests/campaign-layout.ts +82 -0
- package/src/tests/campaign-session.ts +168 -0
- package/src/tests/campaigns.ts +23 -0
- package/src/tests/catalog.ts +156 -0
- package/src/tests/compat.ts +482 -0
- package/src/tests/compute.ts +165 -0
- package/src/tests/fixtures.ts +359 -0
- package/src/tests/merge.ts +149 -0
- package/src/tests/owners.ts +11 -0
- package/src/tests/save-lock.ts +932 -0
- package/src/tests/storage.ts +106 -0
- package/src/tests/template-editor.ts +538 -0
- package/src/tests/templates.ts +143 -0
- package/src/tests/triage-start.ts +81 -0
- package/src/tests/u2-guards.ts +384 -0
- package/src/tests/vid.ts +77 -0
- package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
- package/src/app/dialogs/permissions-dialog.ts +0 -66
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
/* A campaign open in Hit Design or PeptiHit: the platform TableView over its table, and everything the app adds to
|
|
2
|
+
it — the ribbon group, the crumb back to the landing, the address, what the grid's edits start, its menu items, a
|
|
3
|
+
dropped file, the check for other sessions' saves, the save feedback and the progress tracker. All of it is owned
|
|
4
|
+
by the view's host and ends when the view closes. The two apps differ only by {@link CampaignSessionOptions}. */
|
|
5
|
+
import * as grok from 'datagrok-api/grok';
|
|
6
|
+
import * as ui from 'datagrok-api/ui';
|
|
7
|
+
import * as DG from 'datagrok-api/dg';
|
|
8
|
+
import {ChoiceInput, Dialog, computed, signal, span, subscribe} from '@datagrok-libraries/u2';
|
|
9
|
+
import type {ReadonlySignal} from '@datagrok-libraries/u2';
|
|
10
|
+
import {ViewHost, funcForm, isView} from '@datagrok-libraries/u2/dg';
|
|
11
|
+
import type {RibbonAction, RibbonButton} from '@datagrok-libraries/u2/dg';
|
|
12
|
+
import type {HitDesignApp} from '../hit-design-app';
|
|
13
|
+
import {HitAppBase} from '../hit-app-base';
|
|
14
|
+
import {CampaignIdKey, HitDesignerFunctionTag, TileCategoriesColName, ViDColName, ViDSemType} from '../consts';
|
|
15
|
+
import {modifyUrl} from '../utils';
|
|
16
|
+
import {_package} from '../../package';
|
|
17
|
+
import * as api from '../../package-api';
|
|
18
|
+
import {openMergeTableDialog} from '../dialogs/merge-table-dialog';
|
|
19
|
+
import {MERGE_ALLOWED_EXTENSIONS, PlaceholderTag, readFileToDataFrame} from '../utils/merge-table';
|
|
20
|
+
import {showProgressTracker} from '../hit-design-views/tiles-view';
|
|
21
|
+
import {PermissionsEditor} from './permissions-editor';
|
|
22
|
+
|
|
23
|
+
export interface CampaignSessionOptions {
|
|
24
|
+
/** The column a design is entered in: Molecule (Hit Design) or Helm (PeptiHit). */
|
|
25
|
+
entryColumn: string;
|
|
26
|
+
/** Opens the editor of an entry cell: Chem's sketcher or the HELM editor. */
|
|
27
|
+
editor: string;
|
|
28
|
+
/** The grid menu's item that copies an entry into a new row. */
|
|
29
|
+
duplicateLabel: string;
|
|
30
|
+
/** An entry's V-iD is registered before its calculation (Hit Design), or after the calculation converted the
|
|
31
|
+
* entry into the molecule the V-iD is of (PeptiHit). */
|
|
32
|
+
registerFirst: boolean;
|
|
33
|
+
/** The designer function's button (Hit Design). */
|
|
34
|
+
designer: boolean;
|
|
35
|
+
/** The layout the view opens with: the campaign's, else the template's for a new campaign (both apps) or for any
|
|
36
|
+
* campaign without one (PeptiHit). The columns its viewers are bound to that the table lacks (a new campaign's
|
|
37
|
+
* computed ones) are added empty, so those viewers start empty instead of failing; a save leaves such a column out
|
|
38
|
+
* until it holds values. */
|
|
39
|
+
layout?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The session of a campaign view, as the app's saves see it. */
|
|
43
|
+
export interface CampaignSession {
|
|
44
|
+
readonly view: DG.TableView;
|
|
45
|
+
/** The view's host, which owns the session: it ends when the view closes. */
|
|
46
|
+
readonly host: ViewHost;
|
|
47
|
+
/** Another session saved the campaign since this one read it: the Refresh icon says so. */
|
|
48
|
+
readonly needsRefresh: ReadonlySignal<boolean>;
|
|
49
|
+
/** The save's feedback: the grid covered while it writes. */
|
|
50
|
+
saving(on: boolean): void;
|
|
51
|
+
/** The save waits for another session's lock: said in the status bar once the wait is noticeable. */
|
|
52
|
+
waitingForLock(on: boolean): void;
|
|
53
|
+
/** A save of this session ended at `updatedAt`: that is no other session's change. */
|
|
54
|
+
saved(updatedAt: string | null): void;
|
|
55
|
+
/** The progress tracker over the view, unless it is open already; answers its dialog. */
|
|
56
|
+
openTracker(): Dialog;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const NEW_CHANGES = 'New changes available. Click to refresh campaign.';
|
|
60
|
+
const MULTIPLE_MOLECULES = 'Multiple molecule columns found. ' +
|
|
61
|
+
'Please select the primary molecule column to be used for calculations.';
|
|
62
|
+
|
|
63
|
+
/** The session of `view`, built under the view's {@link ViewHost}: it ends when the view closes. */
|
|
64
|
+
export function openCampaignSession(app: HitDesignApp, view: DG.TableView,
|
|
65
|
+
options: CampaignSessionOptions): CampaignSession {
|
|
66
|
+
const host = ViewHost.of(view);
|
|
67
|
+
return host.build(() => {
|
|
68
|
+
const needsRefresh = signal(false);
|
|
69
|
+
const waiting = signal(false);
|
|
70
|
+
let cancelWaitNote: (() => void) | undefined;
|
|
71
|
+
let lastModified: string | null = null;
|
|
72
|
+
let checking = false;
|
|
73
|
+
let tracker: Dialog | undefined;
|
|
74
|
+
|
|
75
|
+
// before the signals: a layout without a grid is reset to one, which tells no one
|
|
76
|
+
if (options.layout !== undefined)
|
|
77
|
+
loadLayout(options.layout);
|
|
78
|
+
else
|
|
79
|
+
checkGrid();
|
|
80
|
+
const signals = host.signals;
|
|
81
|
+
prepareColumns();
|
|
82
|
+
follow();
|
|
83
|
+
chrome();
|
|
84
|
+
openEditorOnNew();
|
|
85
|
+
watchForChanges();
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
view, host, needsRefresh,
|
|
89
|
+
saving: (on) => {
|
|
90
|
+
const grid = view.grid;
|
|
91
|
+
if (grid)
|
|
92
|
+
ui.setUpdateIndicator(grid.root, on, 'Saving Campaign...');
|
|
93
|
+
},
|
|
94
|
+
waitingForLock: (on) => {
|
|
95
|
+
cancelWaitNote?.();
|
|
96
|
+
waiting.value = false;
|
|
97
|
+
if (on)
|
|
98
|
+
cancelWaitNote = host.scope.setTimeout(() => waiting.value = true, 500);
|
|
99
|
+
},
|
|
100
|
+
saved: (updatedAt) => {
|
|
101
|
+
lastModified = updatedAt;
|
|
102
|
+
needsRefresh.value = false;
|
|
103
|
+
},
|
|
104
|
+
openTracker,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
function openTracker(): Dialog {
|
|
108
|
+
if (!tracker?.isOpen.peek())
|
|
109
|
+
tracker = showProgressTracker(app, host);
|
|
110
|
+
return tracker;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The template's layout file again (read anew), else its stored layout; not saved by itself. */
|
|
114
|
+
async function applyTemplateLayout(): Promise<void> {
|
|
115
|
+
const template = app.template;
|
|
116
|
+
if (template?.localLayoutPath) {
|
|
117
|
+
try {
|
|
118
|
+
view.loadLayout(DG.ViewLayout.fromJson(await grok.dapi.files.readAsText(template.localLayoutPath)));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
grok.shell.error('Failed to apply layout from mounted file storage. Falling back to static layout');
|
|
123
|
+
_package.logger.error(e);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!template?.layoutViewState) {
|
|
127
|
+
grok.shell.error('No layout found');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
view.loadLayout(DG.ViewLayout.fromViewState(template.layoutViewState));
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
grok.shell.error('Failed to apply template layout. Check console for more details.');
|
|
135
|
+
_package.logger.error(e);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function loadLayout(viewState: string): void {
|
|
140
|
+
try {
|
|
141
|
+
const layout = DG.ViewLayout.fromViewState(viewState);
|
|
142
|
+
addBoundColumns(layout, view.dataFrame);
|
|
143
|
+
view.loadLayout(layout);
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
grok.shell.error('Failed to apply layout. Falling back to default layout.');
|
|
147
|
+
console.error(e);
|
|
148
|
+
}
|
|
149
|
+
checkGrid();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function checkGrid(): void {
|
|
153
|
+
if (!view.grid) {
|
|
154
|
+
grok.shell.error('Applied layout created view without grid. Resetting layout.');
|
|
155
|
+
view.resetLayout();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A Stage cell is a choice of the template's stages (a row in another stage keeps it until changed). V-iDs are
|
|
160
|
+
* the app's, never typed; they sort by their number (V000999 before V001000). */
|
|
161
|
+
function prepareColumns(): void {
|
|
162
|
+
const stages = app.stages;
|
|
163
|
+
if (stages.length > 0)
|
|
164
|
+
view.dataFrame.col(TileCategoriesColName)?.setTag(DG.TAGS.CHOICES, JSON.stringify(stages));
|
|
165
|
+
const vid = view.dataFrame.col(ViDColName);
|
|
166
|
+
if (!vid)
|
|
167
|
+
return;
|
|
168
|
+
vid.semType = ViDSemType;
|
|
169
|
+
vid.valueComparer = (a: string | null, b: string | null) =>
|
|
170
|
+
a === b ? 0 : a === null ? -1 : b === null ? 1 : parseInt(a.substring(1)) - parseInt(b.substring(1));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function openEditorOnNew(): void {
|
|
174
|
+
const entry = view.dataFrame.col(options.entryColumn);
|
|
175
|
+
if (entry && entry.toList().every((v) => !v))
|
|
176
|
+
grok.functions.call(options.editor, {cell: view.grid.cell(options.entryColumn, 0)});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** What the app does on the view: the address while it is current, the grid's edits and paint, the rows the user
|
|
180
|
+
* adds, its menu items, a dropped file. */
|
|
181
|
+
function follow(): void {
|
|
182
|
+
const df = view.dataFrame;
|
|
183
|
+
host.effect(() => {
|
|
184
|
+
if (!signals.isCurrent.value)
|
|
185
|
+
return;
|
|
186
|
+
grok.shell.windows.showHelp = false;
|
|
187
|
+
app.setBaseUrl();
|
|
188
|
+
modifyUrl(CampaignIdKey, app.campaignId ?? '');
|
|
189
|
+
});
|
|
190
|
+
// a layout replaces the grid: each grid's subscriptions go with it
|
|
191
|
+
host.effect(() => {
|
|
192
|
+
const grid = signals.grid.value;
|
|
193
|
+
if (grid === null)
|
|
194
|
+
return;
|
|
195
|
+
const vid = grid.col(ViDColName);
|
|
196
|
+
if (vid)
|
|
197
|
+
vid.editable = false;
|
|
198
|
+
subscribe(grid.onCellValueEdited, (cell) => void edited(cell));
|
|
199
|
+
subscribe(grid.onCellRender, (args) => paintDuplicateVid(args));
|
|
200
|
+
});
|
|
201
|
+
subscribe(df.onRowsAdded, () => {
|
|
202
|
+
if (app.joining === 0)
|
|
203
|
+
rowsAdded();
|
|
204
|
+
});
|
|
205
|
+
subscribe(grok.events.onContextMenu, (args) => contextMenu(args));
|
|
206
|
+
subscribe(grok.events.onFileImportRequest, (args) => fileDropped(args as DG.EventData<DG.FileImportArgs>));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function edited(cell: DG.GridCell): Promise<void> {
|
|
210
|
+
const column = cell.tableColumn?.name;
|
|
211
|
+
if (column === TileCategoriesColName) {
|
|
212
|
+
await app.saveCampaign(false);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const value = cell.cell.value;
|
|
216
|
+
const row = cell.tableRowIndex;
|
|
217
|
+
if (column !== options.entryColumn || row == null)
|
|
218
|
+
return;
|
|
219
|
+
// the app may have opened another campaign meanwhile: this view's work ends with it
|
|
220
|
+
const register = () => host.scope.isDisposed ? undefined :
|
|
221
|
+
app.registerRow(row).catch((e) => console.error('Failed to register molecule', e));
|
|
222
|
+
const calculate = () => host.scope.isDisposed ? undefined : app.performSingleCellCalculations(row, value);
|
|
223
|
+
try {
|
|
224
|
+
if (options.registerFirst) {
|
|
225
|
+
if (value)
|
|
226
|
+
await register();
|
|
227
|
+
await calculate();
|
|
228
|
+
} else {
|
|
229
|
+
await calculate();
|
|
230
|
+
await register();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
grok.shell.error('Failed to process molecule edit, check console for details');
|
|
235
|
+
console.error(e);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Every row without a stage gets the first one, and the editor opens on the last empty entry. */
|
|
240
|
+
function rowsAdded(): void {
|
|
241
|
+
const df = view.dataFrame;
|
|
242
|
+
const stages = app.stages;
|
|
243
|
+
const stageCol = df.col(TileCategoriesColName);
|
|
244
|
+
if (stages.length > 0 && stageCol) {
|
|
245
|
+
for (let i = 0; i < df.rowCount; i++) {
|
|
246
|
+
if (!stageCol.get(i) || stageCol.isNone(i))
|
|
247
|
+
stageCol.set(i, stages[0]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
let empty: DG.GridCell | null = null;
|
|
251
|
+
for (let i = 0; i < df.rowCount; i++) {
|
|
252
|
+
const cell = view.grid.cell(options.entryColumn, i);
|
|
253
|
+
if (cell && (cell.cell.value === '' || cell.cell.value === null))
|
|
254
|
+
empty = cell;
|
|
255
|
+
}
|
|
256
|
+
if (empty)
|
|
257
|
+
grok.functions.call(options.editor, {cell: empty});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function paintDuplicateVid(args: DG.GridCellRenderArgs): void {
|
|
261
|
+
const cell = args.cell;
|
|
262
|
+
const cache = app.duplicateVidCache;
|
|
263
|
+
if (!cache || !cell?.isTableCell || cell.tableColumn?.name !== ViDColName || (cell.tableRowIndex ?? -1) < 0)
|
|
264
|
+
return;
|
|
265
|
+
const value = cache.indexes[cell.tableRowIndex!];
|
|
266
|
+
if (cache.valueCounts[value] > 1)
|
|
267
|
+
args.cell.style.backColor = DG.Color.setAlpha(DG.Color.getCategoricalColor(value), 150);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function contextMenu(args: DG.EventData): void {
|
|
271
|
+
const viewer: DG.Viewer | undefined = args?.args?.context;
|
|
272
|
+
const item: DG.GridCell | undefined = args?.args?.item;
|
|
273
|
+
const menu: DG.Menu | undefined = args?.args?.menu;
|
|
274
|
+
if (viewer?.type !== DG.VIEWER.GRID || viewer.tableView?.id !== view.id || !menu ||
|
|
275
|
+
item?.tableColumn?.name !== options.entryColumn || !item.isTableCell)
|
|
276
|
+
return;
|
|
277
|
+
const df = view.dataFrame;
|
|
278
|
+
menu.item('Add new row', () => df.rows.addNew(null, true));
|
|
279
|
+
menu.item(options.duplicateLabel, () => {
|
|
280
|
+
const row = df.rows.addNew(null, true);
|
|
281
|
+
if (row.idx > -1)
|
|
282
|
+
df.cell(row.idx, options.entryColumn).value = item.cell?.value ?? '';
|
|
283
|
+
});
|
|
284
|
+
const value = item.cell?.value;
|
|
285
|
+
const row = item.tableRowIndex ?? -1;
|
|
286
|
+
if (value && row > -1) {
|
|
287
|
+
menu.item('Re-Run Calculations',
|
|
288
|
+
() => void app.performSingleCellCalculations(row, value).catch((e) => console.error(e)));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** A molecule file dropped on the view: into this campaign, or a table of its own. */
|
|
293
|
+
function fileDropped(args: DG.EventData<DG.FileImportArgs>): void {
|
|
294
|
+
const file = args?.args?.file;
|
|
295
|
+
const ext = file?.name?.split('.').pop()?.toLowerCase() ?? '';
|
|
296
|
+
if (!file || !isView(grok.shell.tv, view) || !MERGE_ALLOWED_EXTENSIONS.includes(ext))
|
|
297
|
+
return;
|
|
298
|
+
args.preventDefault();
|
|
299
|
+
void upload(file);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async function upload(file: File): Promise<void> {
|
|
303
|
+
let df: DG.DataFrame | null;
|
|
304
|
+
try {
|
|
305
|
+
df = await readFileToDataFrame(file);
|
|
306
|
+
if (!df)
|
|
307
|
+
throw new Error('Failed to read file');
|
|
308
|
+
df.name = file.name.slice(0, file.name.lastIndexOf('.'));
|
|
309
|
+
await df.meta.detectSemanticTypes();
|
|
310
|
+
await grok.data.detectSemanticTypes(df);
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
grok.shell.error('Hit Design Failed to read file');
|
|
314
|
+
console.error(e);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const table = df;
|
|
318
|
+
if (!HitAppBase.moleculeColumn(table)) {
|
|
319
|
+
grok.shell.addTableView(table);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const dialog = new Dialog('Uploading table with molecules', {name: 'upload-molecules'});
|
|
323
|
+
dialog.add(span('Add new table to workspace or join with existing Hit Design campaign'));
|
|
324
|
+
dialog.addButton('Add to workspace', () => {
|
|
325
|
+
dialog.close();
|
|
326
|
+
grok.shell.addTableView(table);
|
|
327
|
+
});
|
|
328
|
+
dialog.onOK(() => app.handleJoiningDataframe(table), {text: 'Add to existing campaign', primary: true});
|
|
329
|
+
host.show(dialog);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** The ribbon: the package's group after the platform's icons, the crumb back to the landing, Save left off, a
|
|
333
|
+
* status line for a view-only campaign and for a save waiting for another session's. */
|
|
334
|
+
function chrome(): void {
|
|
335
|
+
const template = app.template;
|
|
336
|
+
const actions: RibbonAction[] = [
|
|
337
|
+
{icon: 'sync', tooltip: 'Refresh Campaign', name: 'Refresh', run: () => app.refreshCampaign(),
|
|
338
|
+
hint: computed(() => needsRefresh.value ? NEW_CHANGES : null), hintDetail: 'New changes'},
|
|
339
|
+
{icon: 'plus', tooltip: 'Add new row', run: () => {view.dataFrame.rows.addNew(null, true);}},
|
|
340
|
+
{icon: 'code-merge', tooltip: 'Merge another table into the campaign',
|
|
341
|
+
text: 'Merge another table into the campaign...', run: () => openMergeTableDialog(app, host)},
|
|
342
|
+
{icon: 'wrench', tooltip: 'Calculate additional properties', text: 'Calculate additional properties...',
|
|
343
|
+
run: () => app.editCompute()},
|
|
344
|
+
];
|
|
345
|
+
const designer = options.designer ? DG.Func.find({meta: {role: HitDesignerFunctionTag}})
|
|
346
|
+
.find((f) => f.outputs.length === 1 && f.outputs[0].propertyType === DG.TYPE.DATA_FRAME) : undefined;
|
|
347
|
+
if (designer) {
|
|
348
|
+
actions.push({icon: 'pen-nib', tooltip: designer.description || designer.friendlyName,
|
|
349
|
+
text: `${designer.friendlyName}...`, run: () => runDesigner(designer)});
|
|
350
|
+
}
|
|
351
|
+
if (app.canEdit) {
|
|
352
|
+
actions.push({icon: 'users', tooltip: 'Edit campaign permissions', text: 'Edit campaign permissions...',
|
|
353
|
+
run: () => editPermissions()});
|
|
354
|
+
}
|
|
355
|
+
if (template?.layoutViewState || template?.localLayoutPath) {
|
|
356
|
+
const source = template.localLayoutPath ? 'Loaded from mounted file storage' : 'Static';
|
|
357
|
+
actions.push({icon: 'svg-view-layout', tooltip: `Apply template layout (${source})`,
|
|
358
|
+
run: () => applyTemplateLayout()});
|
|
359
|
+
}
|
|
360
|
+
const buttons: RibbonButton[] = [
|
|
361
|
+
...app.stages.length > 0 ? [{text: 'Progress tracker', run: () => {openTracker();}}] : [],
|
|
362
|
+
{text: 'Submit...', run: () => app.submitView?.render(), cls: 'hit-design-submit-button'},
|
|
363
|
+
];
|
|
364
|
+
host.ribbon({
|
|
365
|
+
hideSave: true, name: 'hit-design-actions', actions, buttons,
|
|
366
|
+
breadcrumbs: {parent: app.mainView, onClick: () => {
|
|
367
|
+
view.close();
|
|
368
|
+
void app.infoView.init();
|
|
369
|
+
}},
|
|
370
|
+
status: computed(() => !app.canEdit ? 'View only — changes are not saved' :
|
|
371
|
+
waiting.value ? 'Waiting for another session to finish saving…' : ''),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// pinned to the view: opening another campaign closes the view, and the dialog with it
|
|
376
|
+
function editPermissions(): Promise<void> {
|
|
377
|
+
const opened = app.campaign;
|
|
378
|
+
const code = app.campaignId!;
|
|
379
|
+
const name = opened?.friendlyName;
|
|
380
|
+
return PermissionsEditor.show(opened?.permissions, {
|
|
381
|
+
subject: name && name !== code ? `${code} (${name})` : code,
|
|
382
|
+
author: opened?.authorUserFriendlyName, host,
|
|
383
|
+
save: async (permissions) => {
|
|
384
|
+
const campaign = app.campaign;
|
|
385
|
+
if (!campaign)
|
|
386
|
+
return false;
|
|
387
|
+
const before = campaign.permissions;
|
|
388
|
+
campaign.permissions = permissions;
|
|
389
|
+
if (await app.saveCampaign(true) !== undefined)
|
|
390
|
+
return true;
|
|
391
|
+
campaign.permissions = before;
|
|
392
|
+
return false;
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** The designer function's form, the current row's molecule given to it; what it returns joins the campaign as a
|
|
398
|
+
* dropped table does. */
|
|
399
|
+
function runDesigner(designer: DG.Func): void {
|
|
400
|
+
const df = view.dataFrame;
|
|
401
|
+
const inputs: {[name: string]: unknown} = {};
|
|
402
|
+
const first = designer.inputs[0];
|
|
403
|
+
if (first?.semType === DG.SEMTYPE.MOLECULE && df.currentRowIdx >= 0) {
|
|
404
|
+
const molecule = _package.convertToSmiles(df.col(app.molColName)?.get(df.currentRowIdx));
|
|
405
|
+
if (molecule)
|
|
406
|
+
inputs[first.name] = molecule;
|
|
407
|
+
}
|
|
408
|
+
const call = designer.prepare(inputs);
|
|
409
|
+
const dialog = new Dialog(designer.friendlyName, {name: 'designer'});
|
|
410
|
+
dialog.add(() => funcForm(call));
|
|
411
|
+
dialog.onOK(async () => {
|
|
412
|
+
const progress = DG.TaskBarProgressIndicator.create(`Running ${designer.friendlyName}`);
|
|
413
|
+
try {
|
|
414
|
+
await call.call();
|
|
415
|
+
const result: DG.DataFrame | undefined = call.getOutputParamValue();
|
|
416
|
+
if (!result?.rowCount) {
|
|
417
|
+
grok.shell.warning(`${designer.friendlyName} returned an empty result`);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
await result.meta.detectSemanticTypes();
|
|
421
|
+
await grok.data.detectSemanticTypes(result);
|
|
422
|
+
await app.handleJoiningDataframe(result);
|
|
423
|
+
}
|
|
424
|
+
catch (e) {
|
|
425
|
+
grok.shell.error(`Failed to run ${designer.friendlyName}`);
|
|
426
|
+
_package.logger.error(e);
|
|
427
|
+
return false;
|
|
428
|
+
} finally {
|
|
429
|
+
progress.close();
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
host.show(dialog);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Every 3 s while the view is current and this session neither saves nor merges: has another session saved the
|
|
436
|
+
* campaign since? The check starts once the last save is read, also when that read failed (any save it then
|
|
437
|
+
* reads is news); a session closed meanwhile starts none. */
|
|
438
|
+
function watchForChanges(): void {
|
|
439
|
+
const campaignId = app.campaignId;
|
|
440
|
+
if (!campaignId)
|
|
441
|
+
return;
|
|
442
|
+
host.task(async (t) => {
|
|
443
|
+
try {
|
|
444
|
+
const known = lastModified;
|
|
445
|
+
const time = await lastSaved(campaignId);
|
|
446
|
+
// a save of this session that ended meanwhile told a later time
|
|
447
|
+
if (lastModified === known)
|
|
448
|
+
lastModified = time;
|
|
449
|
+
}
|
|
450
|
+
catch (e) {
|
|
451
|
+
console.error(e);
|
|
452
|
+
}
|
|
453
|
+
t.build(() => t.owner.setInterval(() => void checkForChanges(), 3000));
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async function lastSaved(campaignId: string): Promise<string | null> {
|
|
458
|
+
const df = await api.queries.getLastModified(app.appName, campaignId);
|
|
459
|
+
return df.rowCount > 0 ? df.col('updated_at')?.getString(0) ?? null : null;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
async function checkForChanges(): Promise<void> {
|
|
463
|
+
if (checking || needsRefresh.peek() || !signals.isCurrent.peek() || app.isSaving || app.joining > 0 ||
|
|
464
|
+
!app.campaignId)
|
|
465
|
+
return;
|
|
466
|
+
checking = true;
|
|
467
|
+
try {
|
|
468
|
+
const known = lastModified;
|
|
469
|
+
const time = await lastSaved(app.campaignId);
|
|
470
|
+
// a save of this session that started or ended meanwhile logs its own time
|
|
471
|
+
if (time && time !== known && lastModified === known && !app.isSaving && !host.scope.isDisposed) {
|
|
472
|
+
lastModified = time;
|
|
473
|
+
needsRefresh.value = true;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
catch (e) {
|
|
477
|
+
console.error(e);
|
|
478
|
+
} finally {
|
|
479
|
+
checking = false;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** The Primary Molecule Column of a joined table with several: answers null when the user cancels, or when the
|
|
486
|
+
* campaign view of `host`, which the dialog is pinned to, closes. */
|
|
487
|
+
export async function pickMoleculeColumn(names: string[], likely: string, host?: ViewHost): Promise<string | null> {
|
|
488
|
+
if (host?.scope.isDisposed)
|
|
489
|
+
return null;
|
|
490
|
+
let chosen: string | null = null;
|
|
491
|
+
const dialog = new Dialog('Select Primary Molecule Column', {name: 'primary-molecule-column'});
|
|
492
|
+
dialog.build(() => {
|
|
493
|
+
const input = new ChoiceInput({label: 'Primary Molecule Column', items: names, value: likely, nullable: false});
|
|
494
|
+
dialog.add(span(MULTIPLE_MOLECULES));
|
|
495
|
+
dialog.add(input);
|
|
496
|
+
dialog.onOK(() => {
|
|
497
|
+
chosen = input.peek();
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
await new Promise<void>((resolve) => {
|
|
501
|
+
dialog.onClose(() => resolve());
|
|
502
|
+
host ? host.show(dialog) : dialog.show();
|
|
503
|
+
});
|
|
504
|
+
return chosen;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** The columns the viewers of `layout` are bound to and `df` lacks yet (a new campaign's computed ones), added
|
|
508
|
+
* empty and marked: those viewers start empty instead of failing on a column that does not exist, and fill in as
|
|
509
|
+
* the calculations fill the columns. Which columns are bound is the platform's answer
|
|
510
|
+
* (`DG.ViewLayout.boundColumnNames`: a viewer's column settings, the Filters viewer's filters); a platform without
|
|
511
|
+
* it gets none added. The type is the app's guess, as the platform does not say what an absent column should hold:
|
|
512
|
+
* a column the layout's grid shows as text, or a filter other than a histogram is on, is a string one
|
|
513
|
+
* (`textColumns`), any other a number; a merge gives it the incoming column's type. A hidden `~` column is never
|
|
514
|
+
* added. */
|
|
515
|
+
function addBoundColumns(layout: DG.ViewLayout, df: DG.DataFrame): void {
|
|
516
|
+
const text = textColumns(layout.viewState);
|
|
517
|
+
for (const name of layout.boundColumnNames ?? []) {
|
|
518
|
+
if (!name.startsWith('~') && !df.columns.contains(name)) {
|
|
519
|
+
df.columns.addNew(name, text.has(name) ? DG.COLUMN_TYPE.STRING : DG.COLUMN_TYPE.FLOAT)
|
|
520
|
+
.setTag(PlaceholderTag, 'true');
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function textColumns(viewState: string): Set<string> {
|
|
526
|
+
const text = new Set<string>();
|
|
527
|
+
for (const o of layoutObjects(viewState)) {
|
|
528
|
+
if (typeof o.columnName === 'string' && o.cellType !== undefined && o.cellType !== 'number')
|
|
529
|
+
text.add(o.columnName);
|
|
530
|
+
if (o['#type'] === 'FiltersLook' && Array.isArray(o.filters)) {
|
|
531
|
+
for (const filter of o.filters as {[key: string]: unknown}[]) {
|
|
532
|
+
const name = filter?.column ?? filter?.columnName;
|
|
533
|
+
if (typeof name === 'string' && filter.type !== DG.FILTER_TYPE.HISTOGRAM)
|
|
534
|
+
text.add(name);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return text;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Every object of a layout's view state, each before the ones it holds. */
|
|
542
|
+
export function layoutObjects(viewState: string): {[key: string]: unknown}[] {
|
|
543
|
+
const objects: {[key: string]: unknown}[] = [];
|
|
544
|
+
const visit = (node: unknown): void => {
|
|
545
|
+
if (Array.isArray(node)) {
|
|
546
|
+
for (const item of node)
|
|
547
|
+
visit(item);
|
|
548
|
+
}
|
|
549
|
+
else if (node !== null && typeof node === 'object') {
|
|
550
|
+
objects.push(node as {[key: string]: unknown});
|
|
551
|
+
for (const value of Object.values(node))
|
|
552
|
+
visit(value);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
visit(JSON.parse(viewState));
|
|
556
|
+
return objects;
|
|
557
|
+
}
|