@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
package/src/app/hit-app-base.ts
CHANGED
|
@@ -4,21 +4,30 @@ import * as ui from 'datagrok-api/ui';
|
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
import {_package} from '../package';
|
|
6
6
|
import {AppName, ComputeFunctions, HitDesignCampaign, HitTriageCampaign} from './types';
|
|
7
|
-
import {
|
|
7
|
+
import {CampaignJsonName, HitTriageComputeFunctionTag} from './consts';
|
|
8
8
|
import {discoverComputeFunctions} from '@datagrok-libraries/statistics/src/compute-functions/discovery';
|
|
9
9
|
import {checkEditPermissions} from './utils';
|
|
10
10
|
import * as api from '../package-api';
|
|
11
11
|
|
|
12
|
+
/** How many codes a first save tries before it gives up: each one taken by another session meanwhile. */
|
|
13
|
+
const MaxNewCodeAttempts = 20;
|
|
14
|
+
|
|
15
|
+
/** The campaign's lock stayed with another session for the whole wait: what "someone else might be editing" means. */
|
|
16
|
+
export class CampaignLockHeldError extends Error {}
|
|
17
|
+
|
|
12
18
|
export abstract class HitAppBase<T> {
|
|
13
19
|
public dataFrame?: DG.DataFrame;
|
|
14
20
|
public template?: T;
|
|
15
21
|
public baseUrl!: string;
|
|
16
22
|
public computeFunctions: ComputeFunctions;
|
|
17
|
-
public isJoining = false;
|
|
18
23
|
protected hasEditPermission = false;
|
|
19
24
|
public get canEdit(): boolean {return this.hasEditPermission;}
|
|
20
25
|
private _appName: AppName;
|
|
21
26
|
public get appName(): AppName {return this._appName;}
|
|
27
|
+
/** Who holds the campaign locks this app takes: the user, and this app's instance — a lock is dropped only by the
|
|
28
|
+
* session that took it, not by another tab of the same user. */
|
|
29
|
+
protected readonly lockHolder =
|
|
30
|
+
`${DG.User.current()?.friendlyName || DG.User.current()?.name || 'unknown'} · ${DG.Utils.randomString(6)}`;
|
|
22
31
|
public static molFileExtReaders: { ext: string; handlerFunc: DG.Func }[] = ['sdf', 'mol', 'smi', 'mol2']
|
|
23
32
|
.map((ext) => {
|
|
24
33
|
const handlerFunc =
|
|
@@ -42,11 +51,22 @@ export abstract class HitAppBase<T> {
|
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
protected async setCanEdit(campaign: HitTriageCampaign | HitDesignCampaign) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
this.hasEditPermission = await this.canEditCampaign(campaign);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether the user may edit `campaign`: always a new one (none, or no author yet). */
|
|
58
|
+
protected async canEditCampaign(campaign?: HitTriageCampaign | HitDesignCampaign): Promise<boolean> {
|
|
59
|
+
return !campaign?.authorUserId || !campaign.permissions ||
|
|
60
|
+
await checkEditPermissions(campaign.authorUserId, campaign.permissions);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The table's molecule columns, never a hidden `~` one (Chem's `~<column>.canonicalSmiles` cache, say). */
|
|
64
|
+
static moleculeColumns(df: DG.DataFrame): DG.Column[] {
|
|
65
|
+
return df.columns.bySemTypeAll(DG.SEMTYPE.MOLECULE).filter((col) => !col.name.startsWith('~'));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static moleculeColumn(df: DG.DataFrame): DG.Column | null {
|
|
69
|
+
return HitAppBase.moleculeColumns(df)[0] ?? null;
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
protected getFilterType(colName: string): DG.FILTER_TYPE {
|
|
@@ -82,6 +102,31 @@ export abstract class HitAppBase<T> {
|
|
|
82
102
|
return templateKey + '-' + ((postFixes[postFixes.length - 1] + 1).toString());
|
|
83
103
|
}
|
|
84
104
|
|
|
105
|
+
/** The code a campaign's first save writes under, its lock held: when another session saved a campaign under
|
|
106
|
+
* `campaignId` meanwhile, the next free code of the template's `key` is locked instead — the check is made under
|
|
107
|
+
* the lock, which every writer of a campaign holds, so two sessions never share a code. Throws, holding no lock,
|
|
108
|
+
* when no code could be locked; the caller reports it. */
|
|
109
|
+
protected async lockNewCampaignCode(campaignId: string, key: string): Promise<string> {
|
|
110
|
+
const numberOf = (code: string) => parseInt(code.substring(key.length + 1), 10) || 0;
|
|
111
|
+
for (let attempt = 0; attempt < MaxNewCodeAttempts; attempt++) {
|
|
112
|
+
const lock = await this.aquireAndWaitCampaignLock(campaignId);
|
|
113
|
+
if (!lock.aquired)
|
|
114
|
+
throw new CampaignLockHeldError(`Could not lock campaign ${campaignId} within 30 seconds`);
|
|
115
|
+
let free = false;
|
|
116
|
+
try {
|
|
117
|
+
free = !await _package.files.exists(`${this.appName}/campaigns/${campaignId}/${CampaignJsonName}`);
|
|
118
|
+
} finally {
|
|
119
|
+
if (!free)
|
|
120
|
+
await this.dropCampaignLock(campaignId);
|
|
121
|
+
}
|
|
122
|
+
if (free)
|
|
123
|
+
return campaignId;
|
|
124
|
+
const listed = await this.getNewCampaignName(`${this.appName}/campaigns`, key);
|
|
125
|
+
campaignId = `${key}-${Math.max(numberOf(campaignId) + 1, numberOf(listed))}`;
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`No free campaign code of ${key} after ${MaxNewCodeAttempts} attempts`);
|
|
128
|
+
}
|
|
129
|
+
|
|
85
130
|
public setBaseUrl() {
|
|
86
131
|
const title = document.title;
|
|
87
132
|
if (history.replaceState) {
|
|
@@ -93,94 +138,13 @@ export abstract class HitAppBase<T> {
|
|
|
93
138
|
}
|
|
94
139
|
}
|
|
95
140
|
|
|
96
|
-
/// creates a union of two dataframes based on a molecule column and adds to second dataframe
|
|
97
|
-
protected unionDataframes(df1: DG.DataFrame, df2: DG.DataFrame, molColName1: string, molColName2: string) {
|
|
98
|
-
const prevCol1Name = molColName1;
|
|
99
|
-
df1.col(molColName1)!.name = molColName2;
|
|
100
|
-
molColName1 = molColName2;
|
|
101
|
-
const df1MolCol: string[] | undefined = df1.col(molColName1)?.toList()
|
|
102
|
-
?.map((it) => _package.convertToSmiles(it));
|
|
103
|
-
const df2MolCol: string[] | undefined = df2.col(molColName2)?.toList()
|
|
104
|
-
?.map((it) => _package.convertToSmiles(it)); // here we do not filter out invalid molecules, because we need original indexes
|
|
105
|
-
if (!df1MolCol || !df2MolCol)
|
|
106
|
-
throw new Error('Molecule column not found'); // should not happen, but just in case
|
|
107
|
-
const df2MolMap = new Map<string, number>();
|
|
108
|
-
df2MolCol.forEach((it, i) => {
|
|
109
|
-
if (!!it && it !== 'MALFORMED_INPUT_VALUE')
|
|
110
|
-
df2MolMap.set(it, i);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// there might be cases where the columns do match but have different types (e.g. string vs int)
|
|
114
|
-
const setCorrectedColValue = (setWhereCol: DG.Column, fromCol: DG.Column, setRow: number, fromRow: number) => {
|
|
115
|
-
try {
|
|
116
|
-
if (setWhereCol.type === fromCol.type)
|
|
117
|
-
setWhereCol.set(setRow, fromCol.get(fromRow), false);
|
|
118
|
-
else if (setWhereCol.type === DG.COLUMN_TYPE.STRING)
|
|
119
|
-
setWhereCol.set(setRow, fromCol.getString(fromRow), false);
|
|
120
|
-
else if (setWhereCol.type === DG.COLUMN_TYPE.INT) {
|
|
121
|
-
const val = fromCol.get(fromRow);
|
|
122
|
-
if (typeof val === 'number')
|
|
123
|
-
setWhereCol.set(setRow, Math.round(val), false);
|
|
124
|
-
else if (typeof val === 'string' && val.length > 0 && !isNaN(Number(val)))
|
|
125
|
-
setWhereCol.set(setRow, Math.round(Number(val)), false);
|
|
126
|
-
} else if (setWhereCol.type === DG.COLUMN_TYPE.FLOAT) {
|
|
127
|
-
const val = fromCol.get(fromRow);
|
|
128
|
-
if (typeof val === 'number')
|
|
129
|
-
setWhereCol.set(setRow, val, false);
|
|
130
|
-
else if (typeof val === 'string' && val.length > 0 && !isNaN(Number(val)))
|
|
131
|
-
setWhereCol.set(setRow, Number(val), false);
|
|
132
|
-
} else // direct setting as fallback
|
|
133
|
-
setWhereCol.set(setRow, fromCol.get(fromRow), false);
|
|
134
|
-
} catch (e) {
|
|
135
|
-
_package.logger.error(`Error setting column value for column ${setWhereCol.name} at row ${setRow} from column ${fromCol.name} at row ${fromRow}: ${e}`);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
this.isJoining = true;
|
|
140
|
-
try {
|
|
141
|
-
// first check that all columns are there
|
|
142
|
-
const addedColNames: string[] = [];
|
|
143
|
-
for (const col of df1.columns) {
|
|
144
|
-
if (!df2.columns.contains(col.name)) {
|
|
145
|
-
const addedCol = df2.columns.addNew(col.name, col.type);
|
|
146
|
-
if (col.semType)
|
|
147
|
-
addedCol.semType = col.semType;
|
|
148
|
-
addedColNames.push(col.name);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
for (let i = 0; i < df1MolCol.length; i++) {
|
|
152
|
-
if (!df1MolCol[i] || df1MolCol[i] === 'MALFORMED_INPUT_VALUE')
|
|
153
|
-
continue; // skip invalid molecules
|
|
154
|
-
if (!df2MolMap.has(df1MolCol[i])) {
|
|
155
|
-
df2.rows.addNew(null, true);
|
|
156
|
-
for (const col of df1.columns)
|
|
157
|
-
setCorrectedColValue(df2.col(col.name)!, col, df2.rowCount - 1, i);
|
|
158
|
-
} else {
|
|
159
|
-
if (addedColNames.length > 0) {
|
|
160
|
-
const row = df2MolMap.get(df1MolCol[i])!;
|
|
161
|
-
for (const colName of addedColNames)
|
|
162
|
-
setCorrectedColValue(df2.col(colName)!, df1.col(colName)!, row, i);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
} finally {
|
|
167
|
-
setTimeout(() => {
|
|
168
|
-
this.isJoining = false;
|
|
169
|
-
}, 500);
|
|
170
|
-
df1.col(molColName1)!.name = prevCol1Name;
|
|
171
|
-
}
|
|
172
|
-
return df2;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
141
|
protected async aquireAndWaitCampaignLock(campaignId: string, maxWaitMs = 30_000): Promise<{aquired: boolean, expires_at?: null | string}> {
|
|
176
142
|
const startTime = Date.now();
|
|
177
143
|
let errorCount = 0;
|
|
178
144
|
let lastError: any = null;
|
|
179
|
-
const curUser = DG.User.current();
|
|
180
|
-
const curUserName = curUser ? curUser.friendlyName || curUser.name || 'unknown' : 'unknown';
|
|
181
145
|
while (Date.now() - startTime < maxWaitMs && errorCount < 5) {
|
|
182
146
|
try {
|
|
183
|
-
const result = await api.queries.acquireCampaignLock(this.appName, campaignId,
|
|
147
|
+
const result = await api.queries.acquireCampaignLock(this.appName, campaignId, this.lockHolder);
|
|
184
148
|
if (result && result.rowCount > 0) {
|
|
185
149
|
const res = {aquired: true, expires_at: result?.col('expires_at')?.getString(0)};
|
|
186
150
|
return res;
|
|
@@ -198,7 +162,14 @@ export abstract class HitAppBase<T> {
|
|
|
198
162
|
return {aquired: false, expires_at: null};
|
|
199
163
|
}
|
|
200
164
|
|
|
165
|
+
/** Lets this session's lock go without logging a save (nothing was written under it); a failure is only logged. */
|
|
166
|
+
protected async dropCampaignLock(campaignId: string): Promise<void> {
|
|
167
|
+
await api.queries.dropCampaignLock(this.appName, campaignId, this.lockHolder)
|
|
168
|
+
.catch((e) => _package.logger.error(e));
|
|
169
|
+
}
|
|
170
|
+
|
|
201
171
|
protected async releaseCampaignLock(campaignId: string): Promise<string | null> {
|
|
202
|
-
|
|
172
|
+
const df = await api.queries.releaseCampaignLock(this.appName, campaignId);
|
|
173
|
+
return df.rowCount > 0 ? df.col('updated_at')?.getString(0) || null : null;
|
|
203
174
|
}
|
|
204
175
|
}
|