@datagrok/hit-triage 1.9.2 → 1.10.1

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.
@@ -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, registerMolsBatch} from './utils/molreg';
25
+ import {registerMol} from './utils/molreg';
26
+ import {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
- const compute = this.campaign?.template?.compute ?? this.template?.compute;
100
- if (!compute) {
101
- grok.shell.warning('No compute functions found');
102
- return;
103
- }
104
- const mols = molCol.toList();
105
- const descriptors = compute.descriptors.enabled ? compute.descriptors.args ?? [] : [];
106
- const calcDf = await calculateCellValues(mols, descriptors, compute.functions, compute.scripts, compute.queries);
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() {
@@ -575,9 +548,11 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
575
548
  };
576
549
 
577
550
  const calculateRibbon = ui.iconFA('wrench', getComputeDialog, 'Calculate additional properties');
551
+ const mergeTableButton = ui.iconFA('code-merge', () => {openMergeTableDialog(this);},
552
+ 'Merge another table into the campaign');
578
553
  const addNewRowButton = ui.icons.add(() => {this.dataFrame?.rows.addNew(null, true);}, 'Add new row');
579
554
  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();});
555
+ this._refreshCampaignIcon = ui.icons.sync(async () => {this.refreshCampaign();}, 'Refresh');
581
556
  ui.tooltip.bind(this._refreshCampaignIcon, () => this._refreshIconTooltip);
582
557
  const permissionsButton = ui.iconFA('share', async () => {
583
558
  await (new PermissionsDialog(this.campaign?.permissions)).show((res) => {
@@ -647,6 +622,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
647
622
  ribbonButtons.unshift(designerButton);
648
623
  }
649
624
  ribbonButtons.unshift(calculateRibbon);
625
+ ribbonButtons.unshift(mergeTableButton);
650
626
  ribbonButtons.unshift(addNewRowButton);
651
627
  ribbonButtons.unshift(this._refreshCampaignIcon);
652
628
 
@@ -1062,6 +1038,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
1062
1038
  authorUserFriendlyName: authorName,
1063
1039
  lastModifiedUserName: grok.shell.user.friendlyName,
1064
1040
  permissions,
1041
+ mergeConfig: this.campaign?.mergeConfig,
1065
1042
  };
1066
1043
  if (!this.hasEditPermission) {
1067
1044
  grok.shell.error('You do not have permission to modify this campaign');
@@ -9,7 +9,7 @@ import $ from 'cash-dom';
9
9
  import {CampaignGrouping, CampaignGroupingType, CampaignJsonName, CampaignTableColumns, DefaultCampaignTableInfoGetters, HitDesignCampaignIdKey, i18n} from '../consts';
10
10
  import {HitDesignCampaign, HitDesignTemplate} from '../types';
11
11
  import {addBreadCrumbsToRibbons, checkEditPermissions,
12
- checkViewPermissions, getGroupedCampaigns, getSavedCampaignsGrouping, getSavedCampaignsSorting, getSavedCampaignTableColumns, modifyUrl, popRibbonPannels,
12
+ checkViewPermissions, getGroupedCampaigns, getSavedCampaignsGrouping, getSavedCampaignsSorting, getSavedCampaignTableColumns, loadTemplate, modifyUrl, popRibbonPannels,
13
13
  processGroupingTable,
14
14
  SavedCampaignsTableSorting,
15
15
  setSavedCampaignsGrouping,
@@ -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.root).empty();
171
- this.root.appendChild(ui.div([
172
- ui.divV([appHeader, sortingHeader], {style: {marginLeft: '10px'}}),
173
- this.campaignsTableRoot,
174
- createNewCampaignHeader,
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);
@@ -197,7 +199,7 @@ export class HitDesignInfoView
197
199
  return;
198
200
  const templateName = templatesInput.value;
199
201
  const template: T = presetTemplate && presetTemplate.name === templateName ? presetTemplate :
200
- JSON.parse(await _package.files.readAsText(`${this.app.appName}/templates/${templateName}.json`));
202
+ await loadTemplate<T>(`${this.app.appName}/templates/${templateName}.json`);
201
203
  selectedTemplate = template;
202
204
  const newCampaignAccordeon = await this.getNewCampaignAccordeon(template);
203
205
  $(containerDiv).empty();
@@ -274,8 +276,8 @@ export class HitDesignInfoView
274
276
  this.app.campaign = campaign;
275
277
  }
276
278
  // Load the template and modify it
277
- const template: T = campaign.template ?? JSON.parse(
278
- await _package.files.readAsText(`${this.app.appName}/templates/${campaign.templateName}.json`),
279
+ const template: T = (campaign.template as T) ?? await loadTemplate<T>(
280
+ `${this.app.appName}/templates/${campaign.templateName}.json`,
279
281
  );
280
282
  // modify the template with path to the campaign's precalculated table
281
283
  await this.app.setTemplate(template, campaignId!);
@@ -1,7 +1,7 @@
1
1
  import * as grok from 'datagrok-api/grok';
2
2
  import * as ui from 'datagrok-api/ui';
3
3
  import * as DG from 'datagrok-api/dg';
4
- import {HitTriageCampaign, IFunctionArgs,
4
+ import {AppName, HitTriageCampaign, IFunctionArgs,
5
5
  HitTriageTemplate, HitTriageTemplateIngest, IngestType, HitTriageCampaignStatus,
6
6
  HitDesignTemplate} from './types';
7
7
  import {InfoView} from './hit-triage-views/info-view';
@@ -22,16 +22,17 @@ import '../../css/hit-triage.css';
22
22
  export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
23
23
  multiView: DG.MultiView;
24
24
 
25
- private _infoView: InfoView;
25
+ protected _infoView: InfoView;
26
26
  get infoView(): InfoView {return this._infoView;}
27
27
  private _pickView?: DG.TableView;
28
28
  private _submitView?: SubmitView;
29
29
 
30
- private _filterViewName = 'Hit triage | Pick';
31
- private _campaignFilters?: {[key: string]: any}[];
32
- private _campaignId?: string;
33
- private _dfName?: string;
34
- private _molColName?: string;
30
+ private _filterViewName = 'Hit Triage | Pick';
31
+ private _friendlyName?: string;
32
+ protected _campaignFilters?: {[key: string]: any}[];
33
+ protected _campaignId?: string;
34
+ protected _dfName?: string;
35
+ protected _molColName?: string;
35
36
  public _fileInputType?: IngestType;
36
37
 
37
38
  private _campaign?: HitTriageCampaign;
@@ -40,9 +41,10 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
40
41
  private currentPickViewId?: string;
41
42
  private _pickViewPromise?: Promise<void> | null = null;
42
43
 
43
- constructor(c: DG.FuncCall) {
44
- super(c, 'Hit Triage');
45
- this._infoView = new InfoView(this);
44
+ constructor(c: DG.FuncCall, appName: AppName = 'Hit Triage',
45
+ infoViewConstructor: (app: HitTriageApp) => InfoView = (app) => new InfoView(app)) {
46
+ super(c, appName);
47
+ this._infoView = infoViewConstructor(this);
46
48
  this.multiView = new DG.MultiView({viewFactories: {[this._infoView.name]: () => this._infoView}});
47
49
  this.multiView.tabs.onTabChanged.subscribe((_) => {
48
50
  if (this.multiView.currentView instanceof HitBaseView)
@@ -68,12 +70,19 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
68
70
  return this.campaign?.template?.submit ?? this.template?.submit;
69
71
  }
70
72
 
73
+ /** Hook for subclasses to prepare the dataframe after semantic type detection
74
+ * but before molecule column detection and calculations. */
75
+ protected async prepareDataFrame(_template: HitTriageTemplate): Promise<void> {
76
+ // base implementation does nothing
77
+ }
78
+
71
79
  public async setTemplate(template: HitTriageTemplate, presetFilters?: {[key: string]: any}[],
72
- campaignId?: string, ingestProps?: HitTriageTemplateIngest) {
80
+ campaignId?: string, ingestProps?: HitTriageTemplateIngest, friendlyName?: string) {
81
+ this._friendlyName = friendlyName ?? this._campaign?.friendlyName;
73
82
  this._pickView?.dataFrame && grok.shell.closeTable(this._pickView?.dataFrame);
74
83
  this._pickView = undefined;
75
84
  if (!campaignId) {
76
- campaignId = await this.getNewCampaignName('Hit Triage/campaigns', template.key);
85
+ campaignId = await this.getNewCampaignName(`${this.appName}/campaigns`, template.key);
77
86
  modifyUrl(CampaignIdKey, campaignId);
78
87
  } else if (ingestProps) {
79
88
  this._fileInputType = ingestProps.type;
@@ -101,6 +110,7 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
101
110
  });
102
111
  }
103
112
  await this.dataFrame.meta.detectSemanticTypes();
113
+ await this.prepareDataFrame(template);
104
114
  this._molColName = this.dataFrame.columns.bySemType(DG.SEMTYPE.MOLECULE)?.name ?? undefined;
105
115
  this._dfName = this.dataFrame.name ?? ingestProps?.query;
106
116
  this.dataFrame.name = this._dfName ?? this.dataFrame.name ?? 'Molecules';
@@ -138,6 +148,8 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
138
148
  else
139
149
  this.hasEditPermission = true; // if the campaign is new, obviously the user can edit it
140
150
 
151
+ this._filterViewName = `${this.appName} | ${this._friendlyName ?? this._campaignId ?? 'Pick'}`;
152
+
141
153
  const curView = grok.shell.v;
142
154
  const pickV = grok.shell.addView(this.pickView);
143
155
  this.currentPickViewId = pickV.name;
@@ -146,10 +158,11 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
146
158
  modifyUrl(CampaignIdKey, this._campaignId ?? this._campaign?.name ?? '');
147
159
 
148
160
  const newView = pickV;
161
+ const breadcrumbLabel = this._friendlyName ?? this._campaignId ?? 'Pick';
149
162
 
150
163
  setTimeout(() => {
151
164
  this._pickViewPromise && this._pickViewPromise.then(() => {
152
- const {sub} = addBreadCrumbsToRibbons(newView, 'Hit Triage', 'Pick', () => {
165
+ const {sub} = addBreadCrumbsToRibbons(newView, this.appName, breadcrumbLabel, () => {
153
166
  grok.shell.v = curView;
154
167
  newView.close();
155
168
  sub.unsubscribe();
@@ -270,7 +283,7 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
270
283
  this.dataFrame!.columns.addNewBool(HitSelectionColName).init(false);
271
284
 
272
285
  const view = DG.TableView.create(this.dataFrame!, false);
273
- const ribbons = view.getRibbonPanels();
286
+ let ribbons = view.getRibbonPanels();
274
287
  const calculateRibbon = ui.iconFA('wrench', getComputeDialog, 'Calculate additional properties');
275
288
  const submitButton = ui.bigButton('Submit', () => {
276
289
  const dialogContent = this._submitView?.render();
@@ -294,6 +307,17 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
294
307
  calculateRibbon,
295
308
  ...(this.hasEditPermission ? [permissionsButton] : []),
296
309
  ...(hasSubmit ? [] : [submitButton])]);
310
+ // remove project save button from the ribbon
311
+ ribbons.some((rg) => {
312
+ const saveBtnIdx = rg?.findIndex((r) => r?.textContent?.toLowerCase() === 'save') ?? -1;
313
+ if (saveBtnIdx !== -1) {
314
+ rg.splice(saveBtnIdx, 1);
315
+ return true;
316
+ }
317
+ return false;
318
+ });
319
+ // remove empty ribbon arrays
320
+ ribbons = ribbons.filter((r) => (r?.length ?? 0) > 0);
297
321
  view.setRibbonPanels(ribbons);
298
322
  view.name = this._filterViewName;
299
323
  setTimeout(async () => {
@@ -348,7 +372,7 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
348
372
  const filters = this.filterSettings!;
349
373
  const templateName = this.template!.name;
350
374
  const enrichedDf = this.dataFrame!;
351
- const campaignPrefix = `System:AppData/HitTriage/Hit Triage/campaigns/${campaignId}/`;
375
+ const campaignPrefix = `System:AppData/HitTriage/${this.appName}/campaigns/${campaignId}/`;
352
376
  const campaignName = campaignId ?? await saveCampaignDialog(campaignId);
353
377
  const columnSemTypes: {[_: string]: string} = {};
354
378
  enrichedDf.columns.toList().forEach((col) => columnSemTypes[col.name] = col.semType);
@@ -359,10 +383,11 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
359
383
  // if its first time save author as current user, else keep the same
360
384
  const authorUserId = this.campaign?.authorUserId ?? grok.shell.user.id;
361
385
  const permissions = this.campaign?.permissions ?? defaultPermissions;
362
-
386
+ const authorName = authorUserId ? this.campaign?.authorUserFriendlyName ?? (await grok.dapi.users.find(authorUserId))?.friendlyName : undefined;
363
387
 
364
388
  const campaign: HitTriageCampaign = {
365
389
  name: campaignName,
390
+ friendlyName: this._friendlyName ?? this.campaign?.friendlyName,
366
391
  templateName,
367
392
  filters: filters ?? {},
368
393
  ingest: {
@@ -379,6 +404,8 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
379
404
  template: this.template as HitDesignTemplate | undefined,
380
405
  columnTypes: colTypeMap,
381
406
  authorUserId,
407
+ authorUserFriendlyName: authorName,
408
+ lastModifiedUserName: grok.shell.user.friendlyName,
382
409
  permissions,
383
410
  };
384
411
 
@@ -390,7 +417,7 @@ export class HitTriageApp extends HitAppBase<HitTriageTemplate> {
390
417
  const csvDf = DG.DataFrame.fromColumns(
391
418
  enrichedDf.columns.toList().filter((col) => !col.name.startsWith('~')),
392
419
  ).toCsv();
393
- await _package.files.writeAsText(`Hit Triage/campaigns/${campaignId}/${CampaignTableName}`, csvDf);
420
+ await _package.files.writeAsText(`${this.appName}/campaigns/${campaignId}/${CampaignTableName}`, csvDf);
394
421
  const newLayout = this._pickView!.saveLayout();
395
422
  if (!newLayout)
396
423
  grok.shell.warning('Layout cound not be saved');