@datagrok/hit-triage 1.10.0 → 1.10.2
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/CHANGELOG.md +19 -0
- package/CREDITS.md +101 -0
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +1 -1
- package/src/app/dialogs/merge-table-dialog.ts +356 -0
- package/src/app/hit-app-base.ts +1 -1
- package/src/app/hit-design-app.ts +26 -42
- package/src/app/hit-design-views/info-view.ts +13 -11
- package/src/app/hit-triage-views/info-view.ts +14 -12
- package/src/app/types.ts +24 -1
- package/src/app/utils/merge-table.ts +364 -0
package/package.json
CHANGED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
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 {HitDesignApp} from '../hit-design-app';
|
|
6
|
+
import {HitDesignMergeClashStrategy, HitDesignMergeConfig, HitDesignMergeMode} from '../types';
|
|
7
|
+
import {
|
|
8
|
+
MERGE_ALLOWED_EXTENSIONS as ALLOWED_EXTENSIONS,
|
|
9
|
+
getFileInfoExtension as getExtension,
|
|
10
|
+
guessMoleculeColumn, guessVidColumn, isLocalUploadFileInfo,
|
|
11
|
+
mergeIntoCampaign, readFileInfoToDataFrame,
|
|
12
|
+
} from '../utils/merge-table';
|
|
13
|
+
import {_package} from '../../package';
|
|
14
|
+
|
|
15
|
+
const MODE_LABELS: Record<HitDesignMergeMode, string> = {
|
|
16
|
+
smiles: 'By canonical SMILES',
|
|
17
|
+
vid: 'By V-iD',
|
|
18
|
+
};
|
|
19
|
+
const CLASH_LABELS: Record<HitDesignMergeClashStrategy, string> = {
|
|
20
|
+
skip: 'Skip (keep campaign value)',
|
|
21
|
+
overwrite: 'Overwrite (use incoming value)',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const NONE_OPTION = '(none)';
|
|
25
|
+
|
|
26
|
+
function setChoiceItems(input: DG.InputBase<string | null>, items: string[], desired?: string | null): void {
|
|
27
|
+
(input as unknown as DG.ChoiceInput<string>).items = items;
|
|
28
|
+
if (desired != null && items.includes(desired))
|
|
29
|
+
input.value = desired;
|
|
30
|
+
else if (items.length > 0)
|
|
31
|
+
input.value = items[0];
|
|
32
|
+
else
|
|
33
|
+
input.value = null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function openMergeTableDialog<T extends HitDesignApp>(app: T): Promise<void> {
|
|
37
|
+
if (!app.dataFrame) {
|
|
38
|
+
grok.shell.error('Cannot merge: campaign has no data.');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const saved: HitDesignMergeConfig | undefined = app.campaign?.mergeConfig;
|
|
42
|
+
|
|
43
|
+
// Mutable dialog state
|
|
44
|
+
let incomingDf: DG.DataFrame | null = null;
|
|
45
|
+
let isLoadingFile = false;
|
|
46
|
+
// Re-entrancy guard — onValueChanged on the file input fires for both user actions and
|
|
47
|
+
// programmatic resets. We only want the validate-then-load behavior on user actions.
|
|
48
|
+
let suppressFileChange = false;
|
|
49
|
+
|
|
50
|
+
// ---- Inputs ----
|
|
51
|
+
const fileInput = ui.input.file('Source file', {
|
|
52
|
+
nullable: true,
|
|
53
|
+
tooltipText: `Pick a file from your computer or from a Datagrok file share.\n` +
|
|
54
|
+
`Allowed extensions: ${ALLOWED_EXTENSIONS.join(', ')}.\n` +
|
|
55
|
+
`Files picked from a share are remembered with the campaign and reloaded automatically next time.`,
|
|
56
|
+
onValueChanged: (v) => onFileChanged(v),
|
|
57
|
+
});
|
|
58
|
+
fileInput.input.setAttribute('placeholder', `Drop file or pick from share — ${ALLOWED_EXTENSIONS.join(', ')}`);
|
|
59
|
+
|
|
60
|
+
const modeInput = ui.input.choice<string>('Merge by', {
|
|
61
|
+
items: Object.values(MODE_LABELS),
|
|
62
|
+
value: MODE_LABELS[saved?.mode ?? 'vid'],
|
|
63
|
+
nullable: false,
|
|
64
|
+
tooltipText: 'Join key. "Canonical SMILES" matches by canonicalized molecule structure; ' +
|
|
65
|
+
'"V-iD" matches by the campaign\'s V-iD identifier.',
|
|
66
|
+
onValueChanged: () => runValidation(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const molColInput = ui.input.choice<string>('Molecule column (incoming)', {
|
|
70
|
+
items: [],
|
|
71
|
+
value: null as unknown as string,
|
|
72
|
+
nullable: true,
|
|
73
|
+
tooltipText: 'Column in the incoming table holding the molecules. ' +
|
|
74
|
+
'Required for SMILES merge. In V-iD merge it is optional — if set, ' +
|
|
75
|
+
'unmatched rows can be added to the campaign and registered with new V-iDs.',
|
|
76
|
+
onValueChanged: () => runValidation(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const vidColInput = ui.input.choice<string>('V-iD column (incoming)', {
|
|
80
|
+
items: [],
|
|
81
|
+
value: null as unknown as string,
|
|
82
|
+
nullable: true,
|
|
83
|
+
tooltipText: 'Column in the incoming table holding V-iD strings. Used as the join key when merging by V-iD.',
|
|
84
|
+
onValueChanged: () => runValidation(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const addRowsInput = ui.input.bool('Add unmatched rows', {
|
|
88
|
+
value: saved?.addNewRows ?? true,
|
|
89
|
+
tooltipText: 'When on, rows from the incoming table whose key is not present in the campaign are added as new rows. ' +
|
|
90
|
+
'When off, only existing rows are updated. ' +
|
|
91
|
+
'Disabled when no incoming molecule column is selected (nothing to register the new row with).',
|
|
92
|
+
onValueChanged: () => runValidation(),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const runComputeInput = ui.input.bool('Run compute on new rows', {
|
|
96
|
+
value: saved?.runComputeOnNewRows ?? true,
|
|
97
|
+
tooltipText: 'Run the campaign\'s compute pipeline (descriptors, functions, scripts, queries) on the incoming molecules ' +
|
|
98
|
+
'so new rows arrive with all calculated columns filled in. Disabled when no rows will be added.',
|
|
99
|
+
onValueChanged: () => runValidation(),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const clashInput = ui.input.choice<string>('On clashing data', {
|
|
103
|
+
items: Object.values(CLASH_LABELS),
|
|
104
|
+
value: CLASH_LABELS[saved?.clashStrategy ?? 'overwrite'],
|
|
105
|
+
nullable: false,
|
|
106
|
+
tooltipText: 'How to resolve cells that have a value on both sides for a matched row. ' +
|
|
107
|
+
'"Skip" keeps the existing campaign value; "Overwrite" replaces it with the incoming value. ' +
|
|
108
|
+
'Empty campaign cells are always filled from the incoming table regardless of this setting.',
|
|
109
|
+
onValueChanged: () => runValidation(),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const autoMergeOnOpenInput = ui.input.bool('Auto-merge on campaign open', {
|
|
113
|
+
value: saved?.autoMergeOnOpen ?? false,
|
|
114
|
+
tooltipText: 'When on, this file is re-read and merged into the campaign every time the ' +
|
|
115
|
+
'campaign is opened, using the configuration below. Compute is never re-run for this ' +
|
|
116
|
+
'implicit pass and the campaign is not auto-saved. ' +
|
|
117
|
+
'Only available for files picked from a Datagrok file share — local uploads cannot be ' +
|
|
118
|
+
're-read on open.',
|
|
119
|
+
onValueChanged: () => runValidation(),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const errorDiv = ui.divText('');
|
|
123
|
+
errorDiv.style.color = 'var(--failure)';
|
|
124
|
+
errorDiv.style.fontSize = '12px';
|
|
125
|
+
errorDiv.style.marginTop = '8px';
|
|
126
|
+
errorDiv.style.minHeight = '16px';
|
|
127
|
+
|
|
128
|
+
const inputsRoot = ui.divV([
|
|
129
|
+
fileInput.root,
|
|
130
|
+
modeInput.root,
|
|
131
|
+
molColInput.root,
|
|
132
|
+
vidColInput.root,
|
|
133
|
+
addRowsInput.root,
|
|
134
|
+
runComputeInput.root,
|
|
135
|
+
clashInput.root,
|
|
136
|
+
autoMergeOnOpenInput.root,
|
|
137
|
+
errorDiv,
|
|
138
|
+
]);
|
|
139
|
+
inputsRoot.style.minWidth = '420px';
|
|
140
|
+
|
|
141
|
+
// ---- Helpers reading current input state ----
|
|
142
|
+
const labelToMode = (label: string | null): HitDesignMergeMode =>
|
|
143
|
+
label === MODE_LABELS.vid ? 'vid' : 'smiles';
|
|
144
|
+
const labelToClash = (label: string | null): HitDesignMergeClashStrategy =>
|
|
145
|
+
label === CLASH_LABELS.overwrite ? 'overwrite' : 'skip';
|
|
146
|
+
const colChoiceValue = (input: DG.InputBase<string | null>): string | undefined => {
|
|
147
|
+
const v = input.value;
|
|
148
|
+
return v && v !== NONE_OPTION ? v : undefined;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// ---- Core validation / state machine ----
|
|
152
|
+
function runValidation(): void {
|
|
153
|
+
const mode = labelToMode(modeInput.value);
|
|
154
|
+
const fileLoaded = !!incomingDf && !isLoadingFile;
|
|
155
|
+
|
|
156
|
+
// Block / unblock inputs based on availability of incoming data + selected mode.
|
|
157
|
+
modeInput.enabled = fileLoaded;
|
|
158
|
+
molColInput.enabled = fileLoaded;
|
|
159
|
+
vidColInput.enabled = fileLoaded && mode === 'vid';
|
|
160
|
+
clashInput.enabled = fileLoaded;
|
|
161
|
+
|
|
162
|
+
const molCol = colChoiceValue(molColInput);
|
|
163
|
+
const vidCol = colChoiceValue(vidColInput);
|
|
164
|
+
|
|
165
|
+
// Disable downstream toggles when their precondition isn't met, but DON'T clobber the
|
|
166
|
+
// user's chosen value — the OK handler only honors them when they're effective, so the
|
|
167
|
+
// value sticks across input changes (e.g. the user briefly unsets the molecule column).
|
|
168
|
+
const canChooseAddRows = fileLoaded && !!molCol;
|
|
169
|
+
addRowsInput.enabled = canChooseAddRows;
|
|
170
|
+
|
|
171
|
+
const canRunCompute = canChooseAddRows && addRowsInput.value === true;
|
|
172
|
+
runComputeInput.enabled = canRunCompute;
|
|
173
|
+
|
|
174
|
+
// Auto-merge-on-open requires a remembered file path, i.e. a file from the share rather
|
|
175
|
+
// than a local upload. We don't clobber the user's value here — onOk gates it the same
|
|
176
|
+
// way as the other downstream flags.
|
|
177
|
+
const fi = fileInput.value;
|
|
178
|
+
const canAutoMergeOnOpen = !!fi && !isLocalUploadFileInfo(fi);
|
|
179
|
+
autoMergeOnOpenInput.enabled = canAutoMergeOnOpen;
|
|
180
|
+
|
|
181
|
+
let errorMessage = '';
|
|
182
|
+
if (isLoadingFile)
|
|
183
|
+
errorMessage = 'Reading file…';
|
|
184
|
+
else if (!fileLoaded)
|
|
185
|
+
errorMessage = 'Pick a source file to merge from.';
|
|
186
|
+
else if (mode === 'smiles' && !molCol)
|
|
187
|
+
errorMessage = 'Pick the molecule column from the incoming table.';
|
|
188
|
+
else if (mode === 'vid' && !vidCol)
|
|
189
|
+
errorMessage = 'Pick the V-iD column from the incoming table.';
|
|
190
|
+
|
|
191
|
+
errorDiv.textContent = errorMessage;
|
|
192
|
+
setOkEnabled(errorMessage === '');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ---- File loading ----
|
|
196
|
+
async function loadAndApplyFile(fi: DG.FileInfo, savedToApply: HitDesignMergeConfig | null): Promise<void> {
|
|
197
|
+
isLoadingFile = true;
|
|
198
|
+
incomingDf = null;
|
|
199
|
+
runValidation();
|
|
200
|
+
ui.setUpdateIndicator(inputsRoot, true, 'Reading file...');
|
|
201
|
+
try {
|
|
202
|
+
const df = await readFileInfoToDataFrame(fi);
|
|
203
|
+
if (!df) throw new Error('Empty result');
|
|
204
|
+
df.name = (fi.name ?? '').replace(/\.[^.]+$/, '');
|
|
205
|
+
await df.meta.detectSemanticTypes();
|
|
206
|
+
await grok.data.detectSemanticTypes(df);
|
|
207
|
+
incomingDf = df;
|
|
208
|
+
} catch (e) {
|
|
209
|
+
_package.logger.error(e);
|
|
210
|
+
grok.shell.error(`Failed to read "${fi.name}". Check that the file is accessible and well-formed.`);
|
|
211
|
+
incomingDf = null;
|
|
212
|
+
} finally {
|
|
213
|
+
ui.setUpdateIndicator(inputsRoot, false);
|
|
214
|
+
isLoadingFile = false;
|
|
215
|
+
}
|
|
216
|
+
populateColumnChoices(savedToApply);
|
|
217
|
+
if (savedToApply)
|
|
218
|
+
applySavedScalarChoices(savedToApply);
|
|
219
|
+
runValidation();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function populateColumnChoices(savedToApply: HitDesignMergeConfig | null): void {
|
|
223
|
+
if (!incomingDf) {
|
|
224
|
+
setChoiceItems(molColInput, []);
|
|
225
|
+
setChoiceItems(vidColInput, []);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const colNames = incomingDf.columns.toList().map((c) => c.name);
|
|
229
|
+
|
|
230
|
+
const molDesired = savedToApply?.molColName ?? guessMoleculeColumn(incomingDf)?.name ?? null;
|
|
231
|
+
const molItems = [NONE_OPTION, ...colNames];
|
|
232
|
+
setChoiceItems(molColInput, molItems, molDesired ?? NONE_OPTION);
|
|
233
|
+
|
|
234
|
+
const vidDesired = savedToApply?.vidColName ?? guessVidColumn(incomingDf)?.name ?? null;
|
|
235
|
+
const vidItems = [NONE_OPTION, ...colNames];
|
|
236
|
+
setChoiceItems(vidColInput, vidItems, vidDesired ?? NONE_OPTION);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function applySavedScalarChoices(savedToApply: HitDesignMergeConfig): void {
|
|
240
|
+
modeInput.value = MODE_LABELS[savedToApply.mode];
|
|
241
|
+
addRowsInput.value = savedToApply.addNewRows;
|
|
242
|
+
runComputeInput.value = savedToApply.runComputeOnNewRows;
|
|
243
|
+
clashInput.value = CLASH_LABELS[savedToApply.clashStrategy];
|
|
244
|
+
autoMergeOnOpenInput.value = savedToApply.autoMergeOnOpen ?? false;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function onFileChanged(fi: DG.FileInfo | null): Promise<void> {
|
|
248
|
+
if (suppressFileChange) return;
|
|
249
|
+
|
|
250
|
+
if (!fi) {
|
|
251
|
+
incomingDf = null;
|
|
252
|
+
populateColumnChoices(null);
|
|
253
|
+
runValidation();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const ext = getExtension(fi);
|
|
257
|
+
if (!ALLOWED_EXTENSIONS.includes(ext as typeof ALLOWED_EXTENSIONS[number])) {
|
|
258
|
+
// Defer the clear to break the change → handler → change loop, and to make sure
|
|
259
|
+
// we see the user's actual selection before reverting.
|
|
260
|
+
setTimeout(() => {
|
|
261
|
+
suppressFileChange = true;
|
|
262
|
+
try {
|
|
263
|
+
fileInput.value = null;
|
|
264
|
+
} finally {
|
|
265
|
+
suppressFileChange = false;
|
|
266
|
+
}
|
|
267
|
+
runValidation();
|
|
268
|
+
}, 0);
|
|
269
|
+
grok.shell.warning(`Unsupported file type ".${ext || '?'}". Allowed: ${ALLOWED_EXTENSIONS.join(', ')}.`);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
await loadAndApplyFile(fi, null);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---- Dialog ----
|
|
276
|
+
const dialog = ui.dialog('Merge with table');
|
|
277
|
+
dialog.add(inputsRoot);
|
|
278
|
+
dialog.onOK(async () => {
|
|
279
|
+
await onOk();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
function setOkEnabled(enabled: boolean): void {
|
|
283
|
+
const okBtn = dialog.getButton('OK');
|
|
284
|
+
if (!okBtn) return;
|
|
285
|
+
if (enabled) {
|
|
286
|
+
okBtn.removeAttribute('disabled');
|
|
287
|
+
okBtn.classList.remove('disabled');
|
|
288
|
+
} else {
|
|
289
|
+
okBtn.setAttribute('disabled', 'true');
|
|
290
|
+
okBtn.classList.add('disabled');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function onOk(): Promise<void> {
|
|
295
|
+
if (!incomingDf) return;
|
|
296
|
+
const mode = labelToMode(modeInput.value);
|
|
297
|
+
const molCol = colChoiceValue(molColInput);
|
|
298
|
+
const vidCol = colChoiceValue(vidColInput);
|
|
299
|
+
const fi = fileInput.value;
|
|
300
|
+
const filePath = fi && !isLocalUploadFileInfo(fi) ? fi.fullPath : undefined;
|
|
301
|
+
|
|
302
|
+
const cfg: HitDesignMergeConfig = {
|
|
303
|
+
mode,
|
|
304
|
+
filePath,
|
|
305
|
+
molColName: molCol,
|
|
306
|
+
vidColName: mode === 'vid' ? vidCol : undefined,
|
|
307
|
+
addNewRows: !!addRowsInput.value && !!molCol,
|
|
308
|
+
runComputeOnNewRows: !!runComputeInput.value && !!addRowsInput.value && !!molCol,
|
|
309
|
+
clashStrategy: labelToClash(clashInput.value),
|
|
310
|
+
// Auto-merge only makes sense when we have a remembered path to re-read on open.
|
|
311
|
+
autoMergeOnOpen: !!autoMergeOnOpenInput.value && !!filePath,
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const pg = DG.TaskBarProgressIndicator.create('Merging table into campaign...');
|
|
315
|
+
try {
|
|
316
|
+
await mergeIntoCampaign(app, incomingDf, cfg);
|
|
317
|
+
if (app.campaign) {
|
|
318
|
+
app.campaign.mergeConfig = cfg;
|
|
319
|
+
await app.saveCampaign(false);
|
|
320
|
+
}
|
|
321
|
+
grok.shell.info('Table merged into campaign.');
|
|
322
|
+
} catch (e) {
|
|
323
|
+
_package.logger.error(e);
|
|
324
|
+
grok.shell.error('Merge failed. See console for details.');
|
|
325
|
+
} finally {
|
|
326
|
+
pg.close();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
dialog.show();
|
|
331
|
+
// Initial state: nothing loaded yet, all dependent inputs disabled.
|
|
332
|
+
runValidation();
|
|
333
|
+
|
|
334
|
+
// If the campaign already has a remembered file path, try to recreate the FileInfo and
|
|
335
|
+
// walk through the same load → restore flow as a fresh user pick would.
|
|
336
|
+
if (saved?.filePath) {
|
|
337
|
+
try {
|
|
338
|
+
const exists = await grok.dapi.files.exists(saved.filePath);
|
|
339
|
+
if (!exists)
|
|
340
|
+
grok.shell.warning(`Saved merge file not found or not accessible: ${saved.filePath}`);
|
|
341
|
+
else {
|
|
342
|
+
const restoredFi = DG.FileInfo.fromString(saved.filePath, '');
|
|
343
|
+
suppressFileChange = true;
|
|
344
|
+
try {
|
|
345
|
+
fileInput.value = restoredFi;
|
|
346
|
+
} finally {
|
|
347
|
+
suppressFileChange = false;
|
|
348
|
+
}
|
|
349
|
+
await loadAndApplyFile(restoredFi, saved);
|
|
350
|
+
}
|
|
351
|
+
} catch (e) {
|
|
352
|
+
_package.logger.error(e);
|
|
353
|
+
grok.shell.warning('Could not restore previously saved merge file.');
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
package/src/app/hit-app-base.ts
CHANGED
|
@@ -14,7 +14,7 @@ export abstract class HitAppBase<T> {
|
|
|
14
14
|
public template?: T;
|
|
15
15
|
public baseUrl!: string;
|
|
16
16
|
public computeFunctions: ComputeFunctions;
|
|
17
|
-
|
|
17
|
+
public isJoining = false;
|
|
18
18
|
protected hasEditPermission = false;
|
|
19
19
|
private _appName: AppName;
|
|
20
20
|
public get appName(): AppName {return this._appName;}
|
|
@@ -22,7 +22,9 @@ import {filter} from 'rxjs/operators';
|
|
|
22
22
|
import {defaultPermissions, PermissionsDialog} from './dialogs/permissions-dialog';
|
|
23
23
|
import {getDefaultCampaignStorageSettings, getDefaultSharingSettings} from '../packageSettingsEditor';
|
|
24
24
|
import * as api from '../package-api';
|
|
25
|
-
import {registerMol
|
|
25
|
+
import {registerMol} from './utils/molreg';
|
|
26
|
+
import {autoMergeOnCampaignOpen, mergeIntoCampaign} from './utils/merge-table';
|
|
27
|
+
import {openMergeTableDialog} from './dialogs/merge-table-dialog';
|
|
26
28
|
|
|
27
29
|
export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> extends HitAppBase<T> {
|
|
28
30
|
multiView: DG.MultiView;
|
|
@@ -58,7 +60,8 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
|
-
* Correctly joins the incoming dataframe with the existing campaign dataframe
|
|
63
|
+
* Correctly joins the incoming dataframe with the existing campaign dataframe.
|
|
64
|
+
* Drag-n-drop entry point — uses SMILES-based join with the historical defaults.
|
|
62
65
|
* @param df Dataframe to be joined into existing campaign dataframe
|
|
63
66
|
*/
|
|
64
67
|
async handleJoiningDataframe(df: DG.DataFrame) {
|
|
@@ -89,49 +92,19 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
|
|
|
89
92
|
} else
|
|
90
93
|
chosenMolColName = molCols[0]!.name!;
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
const molCol = df.col(chosenMolColName);
|
|
94
|
-
if (!molCol) { // should not happen, but oh well
|
|
95
|
+
if (!df.col(chosenMolColName)) {
|
|
95
96
|
grok.shell.error('No molecule column found');
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
//merge into adding dataframe
|
|
108
|
-
this.unionDataframes(calcDf, df, HitDesignMolColName, molCol.name);
|
|
109
|
-
|
|
110
|
-
if (this.stages.length > 0 && this.dataFrame!.columns.contains(TileCategoriesColName)) {
|
|
111
|
-
const newTilesCol = df.columns.getOrCreate(TileCategoriesColName, DG.TYPE.STRING);
|
|
112
|
-
for (let i = 0; i < df.rowCount; i++) {
|
|
113
|
-
if (newTilesCol.isNone(i))
|
|
114
|
-
newTilesCol.set(i, this.stages[0], false);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// handle the VID column for new table
|
|
119
|
-
// joining data is not allowed to have the VID column, so remove it if it exists
|
|
120
|
-
if (df.columns.contains(ViDColName))
|
|
121
|
-
df.columns.remove(ViDColName);
|
|
122
|
-
|
|
123
|
-
const vidCol = df.columns.addNewString(ViDColName);
|
|
124
|
-
// batch register the molecules
|
|
125
|
-
const registeredVids = await registerMolsBatch(mols, this._campaignId!, this.appName);
|
|
126
|
-
for (let i = 0; i < df.rowCount; i++) {
|
|
127
|
-
const mol = molCol.get(i);
|
|
128
|
-
const vid = registeredVids.get(mol);
|
|
129
|
-
if (vid)
|
|
130
|
-
vidCol.set(i, vid);
|
|
131
|
-
}
|
|
132
|
-
//merge changes into existing dataframe
|
|
133
|
-
this.unionDataframes(df, this.dataFrame!, molCol.name, this.molColName);
|
|
134
|
-
this.saveCampaign(false);
|
|
100
|
+
await mergeIntoCampaign(this, df, {
|
|
101
|
+
mode: 'smiles',
|
|
102
|
+
molColName: chosenMolColName,
|
|
103
|
+
addNewRows: true,
|
|
104
|
+
runComputeOnNewRows: true,
|
|
105
|
+
clashStrategy: 'overwrite',
|
|
106
|
+
});
|
|
107
|
+
await this.saveCampaign(false);
|
|
135
108
|
}
|
|
136
109
|
|
|
137
110
|
public get submitParams() {
|
|
@@ -346,6 +319,13 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
|
|
|
346
319
|
await this.setCanEdit(this.campaign);
|
|
347
320
|
else
|
|
348
321
|
this.hasEditPermission = true; // if the campaign is new, obviously the user can edit it
|
|
322
|
+
|
|
323
|
+
// Implicit merge pass before the view is shown: only runs when the campaign carries a
|
|
324
|
+
// mergeConfig with autoMergeOnOpen and a remembered fileshare path. Compute is forced off
|
|
325
|
+
// and we deliberately do not save — the user can save manually after the merge.
|
|
326
|
+
if (campaignId && this.campaign?.mergeConfig?.autoMergeOnOpen && this.campaign.mergeConfig.filePath)
|
|
327
|
+
await autoMergeOnCampaignOpen(this);
|
|
328
|
+
|
|
349
329
|
const designV = this.designView;
|
|
350
330
|
this.currentDesignViewId = designV.name;
|
|
351
331
|
this.setBaseUrl();
|
|
@@ -575,9 +555,11 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
|
|
|
575
555
|
};
|
|
576
556
|
|
|
577
557
|
const calculateRibbon = ui.iconFA('wrench', getComputeDialog, 'Calculate additional properties');
|
|
558
|
+
const mergeTableButton = ui.iconFA('code-merge', () => {openMergeTableDialog(this);},
|
|
559
|
+
'Merge another table into the campaign');
|
|
578
560
|
const addNewRowButton = ui.icons.add(() => {this.dataFrame?.rows.addNew(null, true);}, 'Add new row');
|
|
579
561
|
const applyLayoutButton = ui.iconSvg('view-layout', () => {this.applyTemplateLayout(view);}, `Apply template layout ${this.template?.localLayoutPath ? '(Loaded from mounted file storage)' : '(Static)'}`);
|
|
580
|
-
this._refreshCampaignIcon = ui.icons.sync(async () => {this.refreshCampaign();});
|
|
562
|
+
this._refreshCampaignIcon = ui.icons.sync(async () => {this.refreshCampaign();}, 'Refresh');
|
|
581
563
|
ui.tooltip.bind(this._refreshCampaignIcon, () => this._refreshIconTooltip);
|
|
582
564
|
const permissionsButton = ui.iconFA('share', async () => {
|
|
583
565
|
await (new PermissionsDialog(this.campaign?.permissions)).show((res) => {
|
|
@@ -647,6 +629,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
|
|
|
647
629
|
ribbonButtons.unshift(designerButton);
|
|
648
630
|
}
|
|
649
631
|
ribbonButtons.unshift(calculateRibbon);
|
|
632
|
+
ribbonButtons.unshift(mergeTableButton);
|
|
650
633
|
ribbonButtons.unshift(addNewRowButton);
|
|
651
634
|
ribbonButtons.unshift(this._refreshCampaignIcon);
|
|
652
635
|
|
|
@@ -1062,6 +1045,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
|
|
|
1062
1045
|
authorUserFriendlyName: authorName,
|
|
1063
1046
|
lastModifiedUserName: grok.shell.user.friendlyName,
|
|
1064
1047
|
permissions,
|
|
1048
|
+
mergeConfig: this.campaign?.mergeConfig,
|
|
1065
1049
|
};
|
|
1066
1050
|
if (!this.hasEditPermission) {
|
|
1067
1051
|
grok.shell.error('You do not have permission to modify this campaign');
|
|
@@ -25,9 +25,14 @@ export class HitDesignInfoView
|
|
|
25
25
|
<T extends HitDesignTemplate = HitDesignTemplate, K extends HitDesignApp = HitDesignApp>
|
|
26
26
|
extends HitBaseView<T, K> {
|
|
27
27
|
currentGroupping: string = 'None';
|
|
28
|
+
protected _appHeader: HTMLElement | null = null;
|
|
29
|
+
protected _contentRoot: HTMLElement = ui.div([], {classes: 'hit-triage-info-view-container'});
|
|
28
30
|
constructor(app: K) {
|
|
29
31
|
super(app);
|
|
30
32
|
this.name = 'Hit Design';
|
|
33
|
+
this._appHeader = this.getAppHeader();
|
|
34
|
+
this.root.appendChild(ui.div([this._appHeader], {style: {marginLeft: '10px'}}));
|
|
35
|
+
this.root.appendChild(this._contentRoot);
|
|
31
36
|
grok.shell.windows.showHelp = true;
|
|
32
37
|
grok.shell.windows.help.showHelp(_package.webRoot + 'README_HD.md'); // TODO: Separate readme for Hit Design
|
|
33
38
|
this.checkCampaign().then((c) => {this.app.campaign = c; this.init();});
|
|
@@ -76,7 +81,6 @@ export class HitDesignInfoView
|
|
|
76
81
|
const continueCampaignsHeader = ui.h1(i18n.continueCampaigns);
|
|
77
82
|
|
|
78
83
|
const createNewCampaignHeader = ui.h1(i18n.createNewCampaignHeader, {style: {marginLeft: '10px'}});
|
|
79
|
-
const appHeader = this.getAppHeader();
|
|
80
84
|
|
|
81
85
|
const campaignAccordionDiv = ui.div();
|
|
82
86
|
const templatesDiv = ui.divH([]);
|
|
@@ -109,7 +113,7 @@ export class HitDesignInfoView
|
|
|
109
113
|
});
|
|
110
114
|
|
|
111
115
|
menu.show({element: sortingHeader, x: 120, y: sortingHeader.offsetTop + 30});
|
|
112
|
-
});
|
|
116
|
+
}, 'Group by');
|
|
113
117
|
groupIcon.style.marginBottom = '9px';
|
|
114
118
|
groupIcon.style.marginLeft = '8px';
|
|
115
119
|
groupIcon.style.fontSize = '15px';
|
|
@@ -152,7 +156,7 @@ export class HitDesignInfoView
|
|
|
152
156
|
|
|
153
157
|
// then add the custom fields
|
|
154
158
|
menu.show({element: sortingHeader, x: 100, y: sortingHeader.offsetTop + 30});
|
|
155
|
-
});
|
|
159
|
+
}, 'View');
|
|
156
160
|
ui.tooltip.bind(editColumnsIcon, 'Edit visible columns in campaigns table');
|
|
157
161
|
editColumnsIcon.style.marginBottom = '9px';
|
|
158
162
|
editColumnsIcon.style.marginLeft = '8px';
|
|
@@ -161,19 +165,17 @@ export class HitDesignInfoView
|
|
|
161
165
|
|
|
162
166
|
const refreshIcon = ui.iconFA('sync', async () => {
|
|
163
167
|
await this.refreshCampaignsTable();
|
|
164
|
-
});
|
|
168
|
+
}, 'Refresh');
|
|
165
169
|
refreshIcon.style.marginBottom = '9px';
|
|
166
170
|
refreshIcon.style.marginLeft = '8px';
|
|
167
171
|
refreshIcon.style.color = 'var(--blue-1)';
|
|
168
172
|
ui.tooltip.bind(refreshIcon, () => 'Refresh campaigns table');
|
|
169
173
|
const sortingHeader = ui.divH([continueCampaignsHeader, editColumnsIcon, groupIcon, refreshIcon], {style: {alignItems: 'center'}});
|
|
170
|
-
$(this.
|
|
171
|
-
this.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
contentDiv,
|
|
176
|
-
], {classes: 'hit-triage-info-view-container'}));
|
|
174
|
+
$(this._contentRoot).empty();
|
|
175
|
+
this._contentRoot.appendChild(ui.divV([sortingHeader], {style: {marginLeft: '10px'}}));
|
|
176
|
+
this._contentRoot.appendChild(this.campaignsTableRoot);
|
|
177
|
+
this._contentRoot.appendChild(createNewCampaignHeader);
|
|
178
|
+
this._contentRoot.appendChild(contentDiv);
|
|
177
179
|
await this.startNewCampaign(campaignAccordionDiv, templatesDiv, presetTemplate);
|
|
178
180
|
} finally {
|
|
179
181
|
ui.setUpdateIndicator(this.root, false);
|
|
@@ -26,9 +26,14 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
26
26
|
public readmePath = _package.webRoot + 'README_HT.md';
|
|
27
27
|
private dataSourceFunctionsMap: {[key: string]: DG.Func | DG.DataQuery} = {};
|
|
28
28
|
currentGroupping: string = 'None';
|
|
29
|
+
protected _appHeader: HTMLElement | null = null;
|
|
30
|
+
protected _contentRoot: HTMLElement = ui.div([], {classes: 'hit-triage-info-view-container'});
|
|
29
31
|
constructor(app: HitTriageApp) {
|
|
30
32
|
super(app);
|
|
31
33
|
this.name = 'Hit Triage';
|
|
34
|
+
this._appHeader = this.getAppHeader();
|
|
35
|
+
this.root.appendChild(ui.div([this._appHeader], {style: {marginLeft: '10px'}}));
|
|
36
|
+
this.root.appendChild(this._contentRoot);
|
|
32
37
|
grok.shell.windows.showHelp = true;
|
|
33
38
|
grok.shell.windows.help.showHelp(this.readmePath);
|
|
34
39
|
this.checkCampaign().then((c) => {this.app.campaign = c; this.init();});
|
|
@@ -87,7 +92,6 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
87
92
|
try {
|
|
88
93
|
const continueCampaignsHeader = ui.h1(i18n.continueCampaigns);
|
|
89
94
|
const createNewCampaignHeader = ui.h1(i18n.createNewCampaignHeader, {style: {marginLeft: '10px'}});
|
|
90
|
-
const appHeader = this.getAppHeader();
|
|
91
95
|
|
|
92
96
|
const campaignAccordionDiv = ui.div();
|
|
93
97
|
const templatesDiv = ui.div([], {classes: 'ui-form'});
|
|
@@ -119,7 +123,7 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
119
123
|
});
|
|
120
124
|
|
|
121
125
|
menu.show({element: sortingHeader, x: 120, y: sortingHeader.offsetTop + 30});
|
|
122
|
-
});
|
|
126
|
+
}, 'Group by');
|
|
123
127
|
groupIcon.style.marginBottom = '9px';
|
|
124
128
|
groupIcon.style.marginLeft = '8px';
|
|
125
129
|
groupIcon.style.fontSize = '15px';
|
|
@@ -161,7 +165,7 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
161
165
|
});
|
|
162
166
|
|
|
163
167
|
menu.show({element: sortingHeader, x: 100, y: sortingHeader.offsetTop + 30});
|
|
164
|
-
});
|
|
168
|
+
}, 'View');
|
|
165
169
|
ui.tooltip.bind(editColumnsIcon, 'Edit visible columns in campaigns table');
|
|
166
170
|
editColumnsIcon.style.marginBottom = '9px';
|
|
167
171
|
editColumnsIcon.style.marginLeft = '8px';
|
|
@@ -170,7 +174,7 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
170
174
|
|
|
171
175
|
const refreshIcon = ui.iconFA('sync', async () => {
|
|
172
176
|
await this.refreshCampaignsTable();
|
|
173
|
-
});
|
|
177
|
+
}, 'Refresh');
|
|
174
178
|
refreshIcon.style.marginBottom = '9px';
|
|
175
179
|
refreshIcon.style.marginLeft = '8px';
|
|
176
180
|
refreshIcon.style.color = 'var(--blue-1)';
|
|
@@ -178,14 +182,12 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
178
182
|
const sortingHeader = ui.divH([continueCampaignsHeader, editColumnsIcon, groupIcon, refreshIcon], {style: {alignItems: 'center'}});
|
|
179
183
|
|
|
180
184
|
await this.startNewCampaign(campaignAccordionDiv, templatesDiv, presetTemplate);
|
|
181
|
-
$(this.
|
|
182
|
-
this.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
campaignAccordionDiv,
|
|
188
|
-
], {classes: 'hit-triage-info-view-container'}));
|
|
185
|
+
$(this._contentRoot).empty();
|
|
186
|
+
this._contentRoot.appendChild(ui.divV([sortingHeader], {style: {marginLeft: '10px'}}));
|
|
187
|
+
this._contentRoot.appendChild(this.campaignsTableRoot);
|
|
188
|
+
this._contentRoot.appendChild(createNewCampaignHeader);
|
|
189
|
+
this._contentRoot.appendChild(templatesDiv);
|
|
190
|
+
this._contentRoot.appendChild(campaignAccordionDiv);
|
|
189
191
|
} catch (e) {
|
|
190
192
|
ui.setUpdateIndicator(this.root, false);
|
|
191
193
|
throw e;
|
package/src/app/types.ts
CHANGED
|
@@ -102,7 +102,30 @@ export type INewTemplateResult<T> = {
|
|
|
102
102
|
export type HitDesignTemplate = Omit<HitTriageTemplate, 'dataSourceType' | 'queryFunctionName'> &
|
|
103
103
|
{stages: string[]};
|
|
104
104
|
|
|
105
|
-
export type
|
|
105
|
+
export type HitDesignMergeMode = 'smiles' | 'vid';
|
|
106
|
+
export type HitDesignMergeClashStrategy = 'skip' | 'overwrite';
|
|
107
|
+
|
|
108
|
+
export type HitDesignMergeConfig = {
|
|
109
|
+
mode: HitDesignMergeMode,
|
|
110
|
+
// Only set when the source file lives on the Datagrok file share, so it can be reopened later
|
|
111
|
+
filePath?: string,
|
|
112
|
+
// Incoming column name to use as molecule source (required for SMILES mode, optional for VID mode)
|
|
113
|
+
molColName?: string,
|
|
114
|
+
// Incoming column name carrying V-iD values (only used in VID mode)
|
|
115
|
+
vidColName?: string,
|
|
116
|
+
addNewRows: boolean,
|
|
117
|
+
runComputeOnNewRows: boolean,
|
|
118
|
+
clashStrategy: HitDesignMergeClashStrategy,
|
|
119
|
+
// When true AND filePath is set, the file is automatically re-read and merged into the
|
|
120
|
+
// campaign every time the campaign is opened, before the design view is shown. Compute is
|
|
121
|
+
// never run for this implicit pass, and the campaign is not auto-saved.
|
|
122
|
+
autoMergeOnOpen?: boolean,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type HitDesignCampaign = Omit<HitTriageCampaign, 'filters' | 'ingest'> & {
|
|
126
|
+
tilesViewerFormSketch?: string,
|
|
127
|
+
mergeConfig?: HitDesignMergeConfig,
|
|
128
|
+
};
|
|
106
129
|
|
|
107
130
|
// todo: probably add some more stuff
|
|
108
131
|
export type PeptiHitTemplate = HitDesignTemplate & {toAtomiLevelProps?: {[key: string]: any}}
|