@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
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* Merge with table: a file from the user's computer or a share, merged into the campaign by canonical SMILES or by
|
|
2
|
+
V-iD. OK stays off, saying why in the footer, until the dialog has what the merge needs; the dependent inputs wait
|
|
3
|
+
for a file read. A file picked from a share is remembered with the campaign and read again when the dialog opens. */
|
|
2
4
|
import * as DG from 'datagrok-api/dg';
|
|
3
|
-
import * as ui from 'datagrok-api/ui';
|
|
4
5
|
import * as grok from 'datagrok-api/grok';
|
|
5
|
-
import {
|
|
6
|
+
import {BoolInput, ChoiceInput, Dialog, Form, computed, signal} from '@datagrok-libraries/u2';
|
|
7
|
+
import {Platform, ViewHost, fileInput} from '@datagrok-libraries/u2/dg';
|
|
8
|
+
import type {HitDesignApp} from '../hit-design-app';
|
|
6
9
|
import {HitDesignMergeClashStrategy, HitDesignMergeConfig, HitDesignMergeMode} from '../types';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
getFileInfoExtension as getExtension,
|
|
10
|
-
guessMoleculeColumn, guessVidColumn, isLocalUploadFileInfo,
|
|
11
|
-
mergeIntoCampaign, readFileInfoToDataFrame,
|
|
12
|
-
} from '../utils/merge-table';
|
|
10
|
+
import {MERGE_ALLOWED_EXTENSIONS as ALLOWED_EXTENSIONS, getFileInfoExtension as getExtension, guessMoleculeColumn,
|
|
11
|
+
guessVidColumn, isLocalUploadFileInfo, mergeIntoCampaign, readFileInfoToDataFrame} from '../utils/merge-table';
|
|
13
12
|
import {_package} from '../../package';
|
|
14
13
|
|
|
15
14
|
const MODE_LABELS: Record<HitDesignMergeMode, string> = {
|
|
@@ -23,334 +22,191 @@ const CLASH_LABELS: Record<HitDesignMergeClashStrategy, string> = {
|
|
|
23
22
|
|
|
24
23
|
const NONE_OPTION = '(none)';
|
|
25
24
|
|
|
26
|
-
function
|
|
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> {
|
|
25
|
+
export async function openMergeTableDialog(app: HitDesignApp, host: ViewHost): Promise<void> {
|
|
37
26
|
if (!app.dataFrame) {
|
|
38
27
|
grok.shell.error('Cannot merge: campaign has no data.');
|
|
39
28
|
return;
|
|
40
29
|
}
|
|
41
30
|
const saved: HitDesignMergeConfig | undefined = app.campaign?.mergeConfig;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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,
|
|
31
|
+
const dialog = new Dialog('Merge with table', {name: 'merge-table'});
|
|
32
|
+
const load = dialog.build(() => {
|
|
33
|
+
const incoming = signal<DG.DataFrame | null>(null);
|
|
34
|
+
const reading = signal(false);
|
|
35
|
+
const loaded = computed(() => incoming.value !== null && !reading.value);
|
|
36
|
+
const listed = computed(() => incoming.value ? Platform.listedColumns(incoming.value) : []);
|
|
37
|
+
const columns = computed(() => [NONE_OPTION, ...listed.value.map((c) => c.name)]);
|
|
38
|
+
const picked = (input: ChoiceInput) => {
|
|
39
|
+
const v = input.value;
|
|
40
|
+
return v && v !== NONE_OPTION ? v : undefined;
|
|
312
41
|
};
|
|
313
42
|
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
43
|
+
const file = fileInput('Source file', {
|
|
44
|
+
name: 'source-file', nullable: true, fill: true,
|
|
45
|
+
placeholder: `Drop file or pick from share — ${ALLOWED_EXTENSIONS.join(', ')}`,
|
|
46
|
+
tooltipText: `Pick a file from your computer or from a Datagrok file share.\n` +
|
|
47
|
+
`Allowed extensions: ${ALLOWED_EXTENSIONS.join(', ')}.\n` +
|
|
48
|
+
`Files picked from a share are remembered with the campaign and reloaded automatically next time.`,
|
|
49
|
+
// Enter takes the typed path; it does not press OK
|
|
50
|
+
onEnter: () => {},
|
|
51
|
+
onChanged: (fi) => void read(fi, null),
|
|
52
|
+
});
|
|
53
|
+
file.addValidator((fi) => fi && !ALLOWED_EXTENSIONS.includes(getExtension(fi)) ?
|
|
54
|
+
`Unsupported file type ".${getExtension(fi) || '?'}". Allowed: ${ALLOWED_EXTENSIONS.join(', ')}.` : null);
|
|
55
|
+
const fileFirst = computed(() => reading.value ? 'Reading the source file…' :
|
|
56
|
+
incoming.value === null ? 'Pick a source file first' : null);
|
|
57
|
+
const mode = new ChoiceInput({label: 'Merge by', name: 'merge-by', items: Object.values(MODE_LABELS),
|
|
58
|
+
value: MODE_LABELS[saved?.mode ?? 'vid'], nullable: false, disabled: fileFirst,
|
|
59
|
+
tooltipText: 'Join key. "Canonical SMILES" matches by canonicalized molecule structure; ' +
|
|
60
|
+
'"V-iD" matches by the campaign\'s V-iD identifier.'});
|
|
61
|
+
const byVid = computed(() => mode.value === MODE_LABELS.vid);
|
|
62
|
+
const molCol = new ChoiceInput({label: 'Molecule column (incoming)', name: 'molecule-column', items: columns,
|
|
63
|
+
value: NONE_OPTION, nullable: true, disabled: fileFirst,
|
|
64
|
+
tooltipText: 'Column in the incoming table holding the molecules. ' +
|
|
65
|
+
'Required for SMILES merge. In V-iD merge it is optional — if set, ' +
|
|
66
|
+
'unmatched rows can be added to the campaign and registered with new V-iDs.'});
|
|
67
|
+
const vidCol = new ChoiceInput({label: 'V-iD column (incoming)', name: 'vid-column', items: columns,
|
|
68
|
+
value: NONE_OPTION, nullable: true,
|
|
69
|
+
disabled: computed(() => fileFirst.value ?? (byVid.value ? null : 'Used only when merging by V-iD')),
|
|
70
|
+
tooltipText: 'Column in the incoming table holding V-iD strings. Used as the join key when merging by V-iD.'});
|
|
71
|
+
const addOff = computed(() => fileFirst.value ??
|
|
72
|
+
(picked(molCol) === undefined ? 'Pick the molecule column (incoming) first' : null));
|
|
73
|
+
const addRows = new BoolInput({label: 'Add unmatched rows', name: 'add-rows', value: saved?.addNewRows ?? true,
|
|
74
|
+
disabled: addOff,
|
|
75
|
+
tooltipText: 'When on, rows from the incoming table whose key is not present in the campaign ' +
|
|
76
|
+
'are added as new rows. ' +
|
|
77
|
+
'When off, only existing rows are updated. ' +
|
|
78
|
+
'Disabled when no incoming molecule column is selected (nothing to register the new row with).'});
|
|
79
|
+
const runCompute = new BoolInput({label: 'Run compute on new rows', name: 'run-compute',
|
|
80
|
+
value: saved?.runComputeOnNewRows ?? true,
|
|
81
|
+
disabled: computed(() => addOff.value ?? (addRows.value ? null : 'Turn on Add unmatched rows first')),
|
|
82
|
+
tooltipText: 'Run the campaign\'s compute pipeline (descriptors, functions, scripts, queries) ' +
|
|
83
|
+
'on the incoming molecules ' +
|
|
84
|
+
'so new rows arrive with all calculated columns filled in. Disabled when no rows will be added.'});
|
|
85
|
+
const clash = new ChoiceInput({label: 'On clashing data', name: 'on-clash', items: Object.values(CLASH_LABELS),
|
|
86
|
+
value: CLASH_LABELS[saved?.clashStrategy ?? 'overwrite'], nullable: false, disabled: fileFirst,
|
|
87
|
+
tooltipText: 'How to resolve cells that have a value on both sides for a matched row. ' +
|
|
88
|
+
'"Skip" keeps the existing campaign value; "Overwrite" replaces it with the incoming value. ' +
|
|
89
|
+
'Empty campaign cells are always filled from the incoming table regardless of this setting.'});
|
|
90
|
+
const autoMerge = new BoolInput({label: 'Auto-merge on campaign open', name: 'auto-merge',
|
|
91
|
+
value: saved?.autoMergeOnOpen ?? false,
|
|
92
|
+
disabled: computed(() => {
|
|
93
|
+
const fi = file.value;
|
|
94
|
+
return !fi ? 'Pick a source file first' : isLocalUploadFileInfo(fi) ?
|
|
95
|
+
'Only a file picked from a Datagrok file share is merged again on open' : null;
|
|
96
|
+
}),
|
|
97
|
+
tooltipText: 'When on, this file is re-read and merged into the campaign every time the ' +
|
|
98
|
+
'campaign is opened, using the configuration below. Compute is never re-run for this ' +
|
|
99
|
+
'implicit pass and the campaign is not auto-saved. ' +
|
|
100
|
+
'Only available for files picked from a Datagrok file share — local uploads cannot be ' +
|
|
101
|
+
're-read on open.'});
|
|
102
|
+
const form = new Form();
|
|
103
|
+
for (const input of [file, mode, molCol, vidCol, addRows, runCompute, clash, autoMerge])
|
|
104
|
+
form.add(input);
|
|
105
|
+
dialog.add(form);
|
|
106
|
+
|
|
107
|
+
dialog.okDisabled(computed(() => reading.value ? 'Reading file…' :
|
|
108
|
+
!loaded.value ? 'Pick a source file to merge from.' :
|
|
109
|
+
!byVid.value && picked(molCol) === undefined ? 'Pick the molecule column from the incoming table.' :
|
|
110
|
+
byVid.value && picked(vidCol) === undefined ? 'Pick the V-iD column from the incoming table.' : null),
|
|
111
|
+
{footer: true});
|
|
112
|
+
|
|
113
|
+
// a file read after another was picked is dropped: the box holds the later one
|
|
114
|
+
let turn = 0;
|
|
115
|
+
async function read(fi: DG.FileInfo | null, preset: HitDesignMergeConfig | null): Promise<void> {
|
|
116
|
+
const mine = ++turn;
|
|
117
|
+
incoming.value = null;
|
|
118
|
+
reading.value = false;
|
|
119
|
+
if (!fi || !ALLOWED_EXTENSIONS.includes(getExtension(fi)))
|
|
120
|
+
return;
|
|
121
|
+
reading.value = true;
|
|
122
|
+
let df: DG.DataFrame | null = null;
|
|
123
|
+
try {
|
|
124
|
+
df = await readFileInfoToDataFrame(fi);
|
|
125
|
+
if (!df)
|
|
126
|
+
throw new Error('Empty result');
|
|
127
|
+
df.name = (fi.name ?? '').replace(/\.[^.]+$/, '');
|
|
128
|
+
await df.meta.detectSemanticTypes();
|
|
129
|
+
await grok.data.detectSemanticTypes(df);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
_package.logger.error(e);
|
|
133
|
+
grok.shell.error(`Failed to read "${fi.name}". Check that the file is accessible and well-formed.`);
|
|
134
|
+
df = null;
|
|
135
|
+
}
|
|
136
|
+
if (mine !== turn)
|
|
137
|
+
return;
|
|
138
|
+
reading.value = false;
|
|
139
|
+
incoming.value = df;
|
|
140
|
+
if (!df)
|
|
141
|
+
return;
|
|
142
|
+
molCol.value = preset?.molColName ?? guessMoleculeColumn(listed.peek())?.name ?? NONE_OPTION;
|
|
143
|
+
vidCol.value = preset?.vidColName ?? guessVidColumn(listed.peek())?.name ?? NONE_OPTION;
|
|
144
|
+
if (preset) {
|
|
145
|
+
mode.value = MODE_LABELS[preset.mode];
|
|
146
|
+
addRows.value = preset.addNewRows;
|
|
147
|
+
runCompute.value = preset.runComputeOnNewRows;
|
|
148
|
+
clash.value = CLASH_LABELS[preset.clashStrategy];
|
|
149
|
+
autoMerge.value = preset.autoMergeOnOpen ?? false;
|
|
320
150
|
}
|
|
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
151
|
}
|
|
328
|
-
}
|
|
329
152
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
153
|
+
dialog.onOK(async () => {
|
|
154
|
+
const df = incoming.peek();
|
|
155
|
+
if (!df)
|
|
156
|
+
return false;
|
|
157
|
+
const molColName = picked(molCol);
|
|
158
|
+
const fi = file.peek();
|
|
159
|
+
const filePath = fi && !isLocalUploadFileInfo(fi) ? fi.fullPath : undefined;
|
|
160
|
+
const add = addRows.peek() && !!molColName;
|
|
161
|
+
const cfg: HitDesignMergeConfig = {
|
|
162
|
+
mode: byVid.peek() ? 'vid' : 'smiles',
|
|
163
|
+
filePath,
|
|
164
|
+
molColName,
|
|
165
|
+
vidColName: byVid.peek() ? picked(vidCol) : undefined,
|
|
166
|
+
addNewRows: add,
|
|
167
|
+
runComputeOnNewRows: add && runCompute.peek(),
|
|
168
|
+
clashStrategy: clash.peek() === CLASH_LABELS.overwrite ? 'overwrite' : 'skip',
|
|
169
|
+
// auto-merge needs a path to read again on open
|
|
170
|
+
autoMergeOnOpen: autoMerge.peek() && !!filePath,
|
|
171
|
+
};
|
|
172
|
+
const progress = DG.TaskBarProgressIndicator.create('Merging table into campaign...');
|
|
173
|
+
try {
|
|
174
|
+
await mergeIntoCampaign(app, df, cfg);
|
|
175
|
+
if (app.campaign) {
|
|
176
|
+
app.campaign.mergeConfig = cfg;
|
|
177
|
+
await app.saveCampaign(false);
|
|
348
178
|
}
|
|
349
|
-
|
|
179
|
+
grok.shell.info('Table merged into campaign.');
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
_package.logger.error(e);
|
|
183
|
+
grok.shell.error('Merge failed. See console for details.');
|
|
184
|
+
return false;
|
|
185
|
+
} finally {
|
|
186
|
+
progress.close();
|
|
350
187
|
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
188
|
+
});
|
|
189
|
+
return {file, read};
|
|
190
|
+
});
|
|
191
|
+
host.show(dialog, {width: 560});
|
|
192
|
+
|
|
193
|
+
if (!saved?.filePath)
|
|
194
|
+
return;
|
|
195
|
+
try {
|
|
196
|
+
if (!await grok.dapi.files.exists(saved.filePath)) {
|
|
197
|
+
grok.shell.warning(`Saved merge file not found or not accessible: ${saved.filePath}`);
|
|
198
|
+
return;
|
|
354
199
|
}
|
|
200
|
+
// the user may have closed the dialog or picked a file meanwhile
|
|
201
|
+
if (!dialog.isOpen.peek() || load.file.peek() !== null)
|
|
202
|
+
return;
|
|
203
|
+
const restored = DG.FileInfo.fromString(saved.filePath, '');
|
|
204
|
+
// the dialog's own onChanged would read it without the remembered choices
|
|
205
|
+
load.file.reset(restored);
|
|
206
|
+
await load.read(restored, saved);
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
_package.logger.error(e);
|
|
210
|
+
grok.shell.warning('Could not restore previously saved merge file.');
|
|
355
211
|
}
|
|
356
212
|
}
|