@datagrok/hit-triage 1.10.1 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/hit-triage",
3
3
  "friendlyName": "Hit Triage",
4
- "version": "1.10.1",
4
+ "version": "1.10.2",
5
5
  "author": {
6
6
  "name": "Davit Rizhinashvili",
7
7
  "email": "drizhinashvili@datagrok.ai"
@@ -3,40 +3,15 @@ import * as DG from 'datagrok-api/dg';
3
3
  import * as ui from 'datagrok-api/ui';
4
4
  import * as grok from 'datagrok-api/grok';
5
5
  import {HitDesignApp} from '../hit-design-app';
6
- import {HitAppBase} from '../hit-app-base';
7
6
  import {HitDesignMergeClashStrategy, HitDesignMergeConfig, HitDesignMergeMode} from '../types';
8
- import {guessMoleculeColumn, guessVidColumn, isLocalUploadFileInfo, mergeIntoCampaign} from '../utils/merge-table';
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';
9
13
  import {_package} from '../../package';
10
14
 
11
- // Mirrors the drag-n-drop path in HitDesignApp.handleUploadingDataframe: csv goes through
12
- // DG.DataFrame.fromCsv, anything else is delegated to a registered file-handler function.
13
- // HitAppBase.molFileExtReaders is statically filtered to only those extensions for which
14
- // the platform actually exposes a reader, so this list reflects what we can really parse.
15
- const ALLOWED_EXTENSIONS: string[] = ['csv', ...HitAppBase.molFileExtReaders.map((r) => r.ext)];
16
-
17
- function getExtension(fi: DG.FileInfo): string {
18
- const ext = fi.extension?.toLowerCase();
19
- if (ext) return ext;
20
- const name = fi.name?.toLowerCase() ?? '';
21
- const dot = name.lastIndexOf('.');
22
- return dot >= 0 ? name.slice(dot + 1) : '';
23
- }
24
-
25
- async function readFileInfoToDataFrame(fi: DG.FileInfo): Promise<DG.DataFrame | null> {
26
- const ext = getExtension(fi);
27
- if (ext === 'csv') {
28
- const text = await fi.readAsString();
29
- return DG.DataFrame.fromCsv(text);
30
- }
31
- const reader = HitAppBase.molFileExtReaders.find((r) => r.ext === ext);
32
- if (!reader) return null;
33
- const bytes = await fi.readAsBytes();
34
- if (!bytes) return null;
35
- const bytesArg = reader.handlerFunc.inputs[0].name;
36
- const result: any = await reader.handlerFunc.apply({[bytesArg]: bytes});
37
- return Array.isArray(result) ? result[0] : result;
38
- }
39
-
40
15
  const MODE_LABELS: Record<HitDesignMergeMode, string> = {
41
16
  smiles: 'By canonical SMILES',
42
17
  vid: 'By V-iD',
@@ -134,6 +109,16 @@ export async function openMergeTableDialog<T extends HitDesignApp>(app: T): Prom
134
109
  onValueChanged: () => runValidation(),
135
110
  });
136
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
+
137
122
  const errorDiv = ui.divText('');
138
123
  errorDiv.style.color = 'var(--failure)';
139
124
  errorDiv.style.fontSize = '12px';
@@ -148,6 +133,7 @@ export async function openMergeTableDialog<T extends HitDesignApp>(app: T): Prom
148
133
  addRowsInput.root,
149
134
  runComputeInput.root,
150
135
  clashInput.root,
136
+ autoMergeOnOpenInput.root,
151
137
  errorDiv,
152
138
  ]);
153
139
  inputsRoot.style.minWidth = '420px';
@@ -185,6 +171,13 @@ export async function openMergeTableDialog<T extends HitDesignApp>(app: T): Prom
185
171
  const canRunCompute = canChooseAddRows && addRowsInput.value === true;
186
172
  runComputeInput.enabled = canRunCompute;
187
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
+
188
181
  let errorMessage = '';
189
182
  if (isLoadingFile)
190
183
  errorMessage = 'Reading file…';
@@ -248,6 +241,7 @@ export async function openMergeTableDialog<T extends HitDesignApp>(app: T): Prom
248
241
  addRowsInput.value = savedToApply.addNewRows;
249
242
  runComputeInput.value = savedToApply.runComputeOnNewRows;
250
243
  clashInput.value = CLASH_LABELS[savedToApply.clashStrategy];
244
+ autoMergeOnOpenInput.value = savedToApply.autoMergeOnOpen ?? false;
251
245
  }
252
246
 
253
247
  async function onFileChanged(fi: DG.FileInfo | null): Promise<void> {
@@ -313,6 +307,8 @@ export async function openMergeTableDialog<T extends HitDesignApp>(app: T): Prom
313
307
  addNewRows: !!addRowsInput.value && !!molCol,
314
308
  runComputeOnNewRows: !!runComputeInput.value && !!addRowsInput.value && !!molCol,
315
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,
316
312
  };
317
313
 
318
314
  const pg = DG.TaskBarProgressIndicator.create('Merging table into campaign...');
@@ -23,7 +23,7 @@ import {defaultPermissions, PermissionsDialog} from './dialogs/permissions-dialo
23
23
  import {getDefaultCampaignStorageSettings, getDefaultSharingSettings} from '../packageSettingsEditor';
24
24
  import * as api from '../package-api';
25
25
  import {registerMol} from './utils/molreg';
26
- import {mergeIntoCampaign} from './utils/merge-table';
26
+ import {autoMergeOnCampaignOpen, mergeIntoCampaign} from './utils/merge-table';
27
27
  import {openMergeTableDialog} from './dialogs/merge-table-dialog';
28
28
 
29
29
  export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> extends HitAppBase<T> {
@@ -319,6 +319,13 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
319
319
  await this.setCanEdit(this.campaign);
320
320
  else
321
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
+
322
329
  const designV = this.designView;
323
330
  this.currentDesignViewId = designV.name;
324
331
  this.setBaseUrl();
package/src/app/types.ts CHANGED
@@ -116,6 +116,10 @@ export type HitDesignMergeConfig = {
116
116
  addNewRows: boolean,
117
117
  runComputeOnNewRows: boolean,
118
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,
119
123
  }
120
124
 
121
125
  export type HitDesignCampaign = Omit<HitTriageCampaign, 'filters' | 'ingest'> & {
@@ -2,6 +2,7 @@
2
2
  import * as DG from 'datagrok-api/dg';
3
3
  import * as grok from 'datagrok-api/grok';
4
4
  import {HitDesignApp} from '../hit-design-app';
5
+ import {HitAppBase} from '../hit-app-base';
5
6
  import {HitDesignMergeConfig, HitDesignMergeMode, HitDesignTemplate} from '../types';
6
7
  import {HitDesignMolColName, TileCategoriesColName, ViDColName, ViDSemType} from '../consts';
7
8
  import {calculateCellValues} from './calculate-single-cell';
@@ -11,6 +12,35 @@ import {_package} from '../../package';
11
12
  const MOL_NAME_HINTS = ['molecule', 'smiles', 'mol', 'structure', 'canonical_smiles', 'canonicalsmiles'];
12
13
  const VID_NAME_HINTS = ['v-id', 'vid', 'v_id'];
13
14
 
15
+ // Mirrors the drag-n-drop path in HitDesignApp.handleUploadingDataframe: csv goes through
16
+ // DG.DataFrame.fromCsv, anything else is delegated to a registered file-handler function.
17
+ // HitAppBase.molFileExtReaders is statically filtered to only those extensions for which
18
+ // the platform actually exposes a reader, so this list reflects what we can really parse.
19
+ export const MERGE_ALLOWED_EXTENSIONS: string[] = ['csv', ...HitAppBase.molFileExtReaders.map((r) => r.ext)];
20
+
21
+ export function getFileInfoExtension(fi: DG.FileInfo): string {
22
+ const ext = fi.extension?.toLowerCase();
23
+ if (ext) return ext;
24
+ const name = fi.name?.toLowerCase() ?? '';
25
+ const dot = name.lastIndexOf('.');
26
+ return dot >= 0 ? name.slice(dot + 1) : '';
27
+ }
28
+
29
+ export async function readFileInfoToDataFrame(fi: DG.FileInfo): Promise<DG.DataFrame | null> {
30
+ const ext = getFileInfoExtension(fi);
31
+ if (ext === 'csv') {
32
+ const text = await fi.readAsString();
33
+ return DG.DataFrame.fromCsv(text);
34
+ }
35
+ const reader = HitAppBase.molFileExtReaders.find((r) => r.ext === ext);
36
+ if (!reader) return null;
37
+ const bytes = await fi.readAsBytes();
38
+ if (!bytes) return null;
39
+ const bytesArg = reader.handlerFunc.inputs[0].name;
40
+ const result: any = await reader.handlerFunc.apply({[bytesArg]: bytes});
41
+ return Array.isArray(result) ? result[0] : result;
42
+ }
43
+
14
44
  export function guessMoleculeColumn(df: DG.DataFrame): DG.Column | null {
15
45
  const cols = df.columns.toList();
16
46
  const semCols = cols.filter((c) => c.semType === DG.SEMTYPE.MOLECULE);
@@ -295,3 +325,40 @@ export async function mergeIntoCampaign<T extends HitDesignTemplate>(
295
325
 
296
326
  campDf.fireValuesChanged();
297
327
  }
328
+
329
+ /**
330
+ * Runs the implicit "auto-merge on campaign open" pass: if the campaign has a saved
331
+ * mergeConfig with `autoMergeOnOpen` set and a `filePath` from the file share, re-read the
332
+ * file and merge it into the campaign in-place. Compute is force-disabled for this pass
333
+ * and the campaign is NOT saved — the merged state lives in memory until the user saves
334
+ * it themselves. Failures are logged and surfaced as a warning balloon; they never bubble
335
+ * up to the open flow so the campaign still opens.
336
+ */
337
+ export async function autoMergeOnCampaignOpen<T extends HitDesignTemplate>(
338
+ app: HitDesignApp<T>,
339
+ ): Promise<void> {
340
+ const cfg = app.campaign?.mergeConfig;
341
+ if (!cfg?.autoMergeOnOpen || !cfg.filePath) return;
342
+ if (!app.dataFrame) return;
343
+ try {
344
+ const exists = await grok.dapi.files.exists(cfg.filePath);
345
+ if (!exists) {
346
+ grok.shell.warning(`Auto-merge: source file not found or not accessible: ${cfg.filePath}`);
347
+ return;
348
+ }
349
+ const fi = DG.FileInfo.fromString(cfg.filePath, '');
350
+ const df = await readFileInfoToDataFrame(fi);
351
+ if (!df) {
352
+ grok.shell.warning('Auto-merge: could not read the saved source file; merge skipped.');
353
+ return;
354
+ }
355
+ await df.meta.detectSemanticTypes();
356
+ await grok.data.detectSemanticTypes(df);
357
+ // Compute pipeline never runs on the implicit pass — only structural data flows in.
358
+ const passCfg: HitDesignMergeConfig = {...cfg, runComputeOnNewRows: false};
359
+ await mergeIntoCampaign(app, df, passCfg);
360
+ } catch (e) {
361
+ _package.logger.error(e);
362
+ grok.shell.warning('Auto-merge failed; opening the campaign without merging.');
363
+ }
364
+ }