@datagrok/api-samples 1.0.8 → 1.0.12
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 +9 -0
- package/dist/package-test.js +2 -2
- package/files/viewer-events/bar-chart/on-category-clicked.js +1 -0
- package/files/viewer-events/grid/on-cell-clicked.js +1 -0
- package/files/viewer-events/pc-plot/on-line-clicked.js +1 -0
- package/files/viewer-events/pie-chart/on-segment-clicked.js +1 -0
- package/files/viewer-events/scatter-plot/on-point-clicked.js +1 -0
- package/files/viewer-events/scatter-plot/on-rendered.js +1 -0
- package/layouts/demog-table-layout.json +329 -181
- package/package.json +17 -15
- package/scripts/dapi/files.js +40 -0
- package/scripts/dapi/projects-open.js +1 -1
- package/scripts/dapi/sticky-meta-1-tags.js +54 -0
- package/scripts/dapi/sticky-meta-2-semtype.js +33 -0
- package/scripts/data-access/db-master-details-manual.js +3 -2
- package/scripts/data-access/external/stock-prices.js +1 -1
- package/scripts/data-access/open-table-by-id.js +11 -3
- package/scripts/data-access/output-layouts.js +3 -1
- package/scripts/data-frame/advanced/data-frames-in-columns.js +4 -1
- package/scripts/data-frame/advanced/virtual-columns.js +1 -1
- package/scripts/data-frame/aggregation/unpivot.js +1 -1
- package/scripts/data-frame/column-access.js +1 -3
- package/scripts/data-frame/compare-tables.js +3 -2
- package/scripts/data-frame/construction/create-from-csv-format.js +3 -3
- package/scripts/data-frame/construction/create-from-typed-arrays.js +7 -2
- package/scripts/data-frame/construction/export-to-csv-advanced.js +14 -4
- package/scripts/data-frame/construction/export-to-csv-molblock.js +3 -0
- package/scripts/data-frame/construction/export-to-csv.js +1 -1
- package/scripts/data-frame/events/calculated-columns/creation.js +1 -1
- package/scripts/data-frame/events/calculated-columns/deletion.js +1 -1
- package/scripts/data-frame/events/calculated-columns/update.js +1 -1
- package/scripts/data-frame/join-link/link-tables-dynamic.js +3 -5
- package/scripts/data-frame/metadata/dataframe-meta.js +1 -1
- package/scripts/data-frame/modification/add-columns.js +1 -1
- package/scripts/data-frame/modification/append.js +1 -1
- package/scripts/data-frame/modification/calculated-columns/edit-formula.js +2 -2
- package/scripts/data-frame/modification/double-precision.js +26 -0
- package/scripts/data-frame/modification/manipulate.js +3 -3
- package/scripts/domains/chem/sketcher.js +2 -2
- package/scripts/events/form-creation.js +2 -2
- package/scripts/events/global-events.js +1 -1
- package/scripts/events/layout-events.js +5 -6
- package/scripts/events/viewer-data-events.js +11 -0
- package/scripts/functions/func-call.js +5 -0
- package/scripts/grid/advanced/cell-renderer.js +1 -1
- package/scripts/grid/advanced/format-formula.js +7 -0
- package/scripts/grid/advanced/link-click.js +3 -3
- package/scripts/grid/advanced/markup-link.js +6 -0
- package/scripts/grid/advanced/paint-counts.js +4 -1
- package/scripts/grid/{color-coding-conditional.js → color-coding/color-coding-conditional.js} +17 -10
- package/scripts/grid/color-coding/color-coding.js +5 -9
- package/scripts/grid/color-coding/get-cell-color.js +3 -5
- package/scripts/grid/column-cell-styles.js +10 -0
- package/scripts/grid/column-controlled-values.js +2 -2
- package/scripts/grid/data-format.js +4 -4
- package/scripts/grid/hit-test.js +1 -1
- package/scripts/grid/html-cells/html-table-cells.js +1 -1
- package/scripts/misc/audit/test-tracking.js +1 -1
- package/scripts/misc/user-settings-storage.js +48 -0
- package/scripts/scripting/files-for-scripting.js +24 -0
- package/scripts/scripting/grok-scripting.js +1 -1
- package/scripts/shell/last-error.js +1 -1
- package/scripts/shell/ui-parts.js +9 -9
- package/scripts/shell/windows/browse/customize-tree.js +3 -0
- package/scripts/ui/apps/bioreactor.js +5 -5
- package/scripts/ui/components/accordion.js +3 -3
- package/scripts/ui/components/tree-view-adv.js +4 -2
- package/scripts/ui/containers/splitters.js +13 -13
- package/scripts/ui/dialogs/wizard.js +8 -8
- package/scripts/ui/docking/docking.js +4 -1
- package/scripts/ui/handlers/markup-handlers.js +61 -0
- package/scripts/ui/inputs/advanced/all-input-types.js +37 -24
- package/scripts/ui/inputs/advanced/input-api.js +39 -0
- package/scripts/ui/inputs/advanced/input-events.js +10 -10
- package/scripts/ui/inputs/advanced/input-form.js +8 -8
- package/scripts/ui/inputs/choice-input.js +5 -5
- package/scripts/ui/inputs/column-combo-box.js +3 -3
- package/scripts/ui/inputs/column-inputs.js +3 -3
- package/scripts/ui/inputs/forms.js +10 -10
- package/scripts/ui/inputs/helm-input-ui.js +7 -0
- package/scripts/ui/inputs/inputs-events.js +8 -8
- package/scripts/ui/inputs/inputs-extended.js +2 -2
- package/scripts/ui/inputs/inputs.js +17 -15
- package/scripts/ui/inputs/molecule-input.js +1 -1
- package/scripts/ui/inputs/table-input.js +1 -1
- package/scripts/ui/inputs/tags-input.js +2 -2
- package/scripts/ui/inputs/typeahead-input.js +16 -17
- package/scripts/ui/inputs/validation/input-validators.js +11 -0
- package/scripts/ui/inputs/validation/script-param-validation.js +6 -0
- package/scripts/ui/inputs/validation/visible-enabled.js +9 -0
- package/scripts/ui/interactivity/drag-and-drop.js +3 -3
- package/scripts/ui/tooltips/tooltips.js +6 -2
- package/scripts/ui/viewers/advanced/attached-properties.js +5 -5
- package/scripts/ui/viewers/advanced/default-axis-type.js +1 -1
- package/scripts/ui/viewers/advanced/init-function.js +21 -0
- package/scripts/ui/viewers/advanced/init-script.js +15 -0
- package/scripts/ui/viewers/filters/add-single-filter.js +5 -5
- package/scripts/ui/viewers/filters/custom-filters.js +3 -3
- package/scripts/ui/viewers/filters/filter-group.js +6 -1
- package/scripts/ui/viewers/filters/multi-value-filter.js +1 -1
- package/scripts/ui/viewers/js viewers/chord-viewer.js +1 -1
- package/scripts/ui/viewers/js viewers/sankey-viewer.js +1 -1
- package/scripts/ui/viewers/js viewers/word-cloud.js +1 -1
- package/scripts/ui/viewers/scatter-plot-events.js +6 -1
- package/scripts/ui/viewers/trellis-plot-with-summary-viewer.js +3 -1
- package/scripts/ui/viewers/types/markup-advanced.js +1 -1
- package/scripts/ui/viewers/types/trellis-plot.js +13 -1
- package/scripts/ui/viewers/types/word-cloud.js +1 -1
- package/scripts/ui/views/default-views.js +3 -3
- package/scripts/ui/views/layouts.js +16 -17
- package/scripts/ui/views/multi-view.js +1 -1
- package/src/global.d.ts +13 -0
- package/src/package-test.ts +106 -16
- package/webpack.config.js +4 -1
- package/files.js +0 -39
- package/scripts/misc/user-data-storage.js +0 -49
- /package/scripts/scripting/{scripting.js → package-scripting.js} +0 -0
- /package/{scripts/ui/handlers → to fix}/dynamic-loading.js +0 -0
package/src/package-test.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {runTests, tests, TestContext, category, test as _test, delay} from '@datagrok-libraries/utils/src/test';
|
|
1
|
+
import { DataFrame, Script } from 'datagrok-api/dg';
|
|
2
|
+
import { runTests, tests, TestContext, category, test as _test, delay, initAutoTests as initCoreTests, expect, awaitCheck, before } from '@datagrok-libraries/utils/src/test';
|
|
4
3
|
export const _package = new DG.Package();
|
|
5
|
-
export {tests};
|
|
4
|
+
export { tests };
|
|
6
5
|
|
|
7
6
|
import './tests/test';
|
|
8
7
|
|
|
@@ -23,7 +22,26 @@ const skip = [
|
|
|
23
22
|
'add-single-filter',
|
|
24
23
|
'custom-filters',
|
|
25
24
|
'filter-group',
|
|
26
|
-
'dynamic-loading'
|
|
25
|
+
'dynamic-loading',
|
|
26
|
+
//performance
|
|
27
|
+
'read-strings',
|
|
28
|
+
'dataframe-access',
|
|
29
|
+
'1m-aggregation',
|
|
30
|
+
'100-million-rows',
|
|
31
|
+
'1-million-columns',
|
|
32
|
+
'network-diagram',
|
|
33
|
+
'output-layouts',
|
|
34
|
+
'file-browser'
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const scriptViewer = [
|
|
38
|
+
'parameterValidation',
|
|
39
|
+
'parameter validation',
|
|
40
|
+
'parameter expressions',
|
|
41
|
+
'docking',
|
|
42
|
+
'input-api',
|
|
43
|
+
'helm-input-ui',
|
|
44
|
+
'output-layouts'
|
|
27
45
|
];
|
|
28
46
|
|
|
29
47
|
//name: test
|
|
@@ -31,26 +49,98 @@ const skip = [
|
|
|
31
49
|
//input: string test {optional: true}
|
|
32
50
|
//input: object testContext {optional: true}
|
|
33
51
|
//output: dataframe result
|
|
34
|
-
export async function test(category: string, test: string, testContext: TestContext): Promise<
|
|
52
|
+
export async function test(category: string, test: string, testContext: TestContext): Promise<DataFrame> {
|
|
35
53
|
testContext = new TestContext(false, false);
|
|
36
|
-
const data = await runTests({category, test, testContext});
|
|
54
|
+
const data = await runTests({ category, test, testContext });
|
|
37
55
|
return DG.DataFrame.fromObjects(data)!;
|
|
38
56
|
}
|
|
57
|
+
interface ScriptObject {
|
|
58
|
+
[key: string]: () => Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let beforeArr : ScriptObject= {
|
|
62
|
+
['Scripts:ui:inputs'] : async () => {
|
|
63
|
+
await grok.functions.call("Helm:getHelmHelper");}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let beforeArrAdded : string[] = [];
|
|
39
67
|
|
|
40
68
|
//tags: init
|
|
41
69
|
export async function initTests() {
|
|
70
|
+
|
|
42
71
|
const scripts = await grok.dapi.scripts.filter('package.shortName = "ApiSamples"').list();
|
|
43
72
|
for (const script of scripts) {
|
|
44
|
-
|
|
73
|
+
let catName = ('Scripts:' + script.options.path as string).replaceAll('/', ':');
|
|
74
|
+
category(catName, () => {
|
|
75
|
+
if(!beforeArrAdded.includes(catName) && beforeArr[catName.replaceAll(' ', '')]){
|
|
76
|
+
before(async ()=>{
|
|
77
|
+
await beforeArr[catName.replaceAll(' ', '')]();
|
|
78
|
+
})
|
|
79
|
+
beforeArrAdded.push(catName);
|
|
80
|
+
}
|
|
81
|
+
|
|
45
82
|
_test(script.friendlyName, async () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
83
|
+
|
|
84
|
+
const annotation = `//name: ${script.friendlyName}
|
|
85
|
+
//language: javascript
|
|
86
|
+
`;
|
|
87
|
+
debugger
|
|
88
|
+
if (scriptViewer.includes(script.friendlyName))
|
|
89
|
+
await runScriptViewer(script);
|
|
90
|
+
else
|
|
91
|
+
await evaluateScript(script);
|
|
92
|
+
grok.shell.closeAll();
|
|
93
|
+
|
|
94
|
+
async function runScriptViewer(script: Script) {
|
|
95
|
+
const scriptResult = new Promise<boolean>(async (resolve) => {
|
|
96
|
+
script.script = `${annotation}\n${script.script}`;
|
|
97
|
+
const scriptView = DG.ScriptView.create(script);
|
|
98
|
+
grok.shell.addView(scriptView);
|
|
99
|
+
let timeout: any;
|
|
100
|
+
const subscription = grok.functions.onAfterRunAction.subscribe((funcCall) => {
|
|
101
|
+
if ((funcCall.func as any).script === script.script.replaceAll('\r', '')) {
|
|
102
|
+
if (timeout)
|
|
103
|
+
clearTimeout(timeout);
|
|
104
|
+
subscription.unsubscribe();
|
|
105
|
+
scriptView.close();
|
|
106
|
+
resolve(true);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
await delay(1000);
|
|
110
|
+
(document.getElementsByClassName("fa-play")[0] as any).click();
|
|
111
|
+
await delay(1000);
|
|
112
|
+
timeout = setTimeout(() => {
|
|
113
|
+
subscription.unsubscribe();
|
|
114
|
+
scriptView.close();
|
|
115
|
+
resolve(false);
|
|
116
|
+
}, 10000);
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
if (!(await scriptResult))
|
|
120
|
+
throw new Error(`Script ${'Scripts:' + script.options.path as string}.${script.friendlyName}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function evaluateScript(script: Script) {
|
|
124
|
+
let timeout: any;
|
|
125
|
+
const subscription = grok.functions.onAfterRunAction.subscribe((funcCall) => {
|
|
126
|
+
if ((funcCall.func as any).script === script.script.replaceAll('\r', '')) {
|
|
127
|
+
if (timeout)
|
|
128
|
+
clearTimeout(timeout);
|
|
129
|
+
subscription.unsubscribe();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
await script.apply();
|
|
133
|
+
timeout = setTimeout(() => {
|
|
134
|
+
subscription.unsubscribe();
|
|
135
|
+
throw new Error('Script didnt pass');
|
|
136
|
+
}, 10000);
|
|
137
|
+
}
|
|
138
|
+
}, skip.includes(script.friendlyName) ? { skipReason: 'skip' } : { timeout: 60000 });
|
|
54
139
|
});
|
|
55
140
|
}
|
|
56
141
|
}
|
|
142
|
+
|
|
143
|
+
//name: initAutoTests
|
|
144
|
+
export async function initAutoTests() {
|
|
145
|
+
await initCoreTests(_package, _package.getModule('package-test.js'));
|
|
146
|
+
}
|
package/webpack.config.js
CHANGED
|
@@ -2,12 +2,15 @@ const path = require('path');
|
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
mode: 'development',
|
|
5
|
+
cache: {
|
|
6
|
+
type: 'filesystem',
|
|
7
|
+
},
|
|
5
8
|
entry: {
|
|
6
9
|
test: {filename: 'package-test.js', library: {type: 'var', name: `apisamples_test`}, import: './src/package-test.ts'},
|
|
7
10
|
package: './src/package.ts',
|
|
8
11
|
},
|
|
9
12
|
resolve: {
|
|
10
|
-
extensions: ['.wasm', '.mjs', '.
|
|
13
|
+
extensions: ['.wasm', '.mjs', '.ts', '.json', '.js', '.tsx'],
|
|
11
14
|
},
|
|
12
15
|
module: {
|
|
13
16
|
rules: [
|
package/files.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
//tags: FileInfo
|
|
2
|
-
//help-url: https://datagrok.ai/help/develop/how-to/access-data
|
|
3
|
-
// JS API methods for working with files
|
|
4
|
-
|
|
5
|
-
(async () => {
|
|
6
|
-
|
|
7
|
-
let res = null;
|
|
8
|
-
|
|
9
|
-
// Write files
|
|
10
|
-
await grok.dapi.files.write('Samples:Files/testFile.dat', [0, 1, 2]);
|
|
11
|
-
await grok.dapi.files.writeAsText('Samples:Files/testFile.txt', 'testString');
|
|
12
|
-
|
|
13
|
-
// Rename
|
|
14
|
-
await grok.dapi.files.writeAsText('Samples:Files/forRename.txt', 'testString');
|
|
15
|
-
await grok.dapi.files.rename('Samples:Files/forRename.txt', 'renamed.txt');
|
|
16
|
-
|
|
17
|
-
// Read files
|
|
18
|
-
res = await grok.dapi.files.readAsBytes('Samples:Files/testFile.dat');
|
|
19
|
-
console.log(`readAsBytes: ${res}`);
|
|
20
|
-
res = await grok.dapi.files.readAsText('Samples:Files/testFile.txt');
|
|
21
|
-
console.log(`readAsText: ${res}`);
|
|
22
|
-
res = await grok.dapi.files.exists('Samples:Files/testFile.dat');
|
|
23
|
-
console.log(`testFile.dat exists: ${res}`);
|
|
24
|
-
|
|
25
|
-
// Search files
|
|
26
|
-
let recursive = true;
|
|
27
|
-
let searchPattern = 'world';
|
|
28
|
-
res = await grok.dapi.files.list('Samples:Files/geo', recursive, searchPattern);
|
|
29
|
-
console.log(`list: ${res}`);
|
|
30
|
-
|
|
31
|
-
// Move files
|
|
32
|
-
await grok.dapi.files.move(['Samples:Files/testFile.txt'], 'geo');
|
|
33
|
-
res = await grok.dapi.files.exists('Samples:Files/geo/testFile.txt');
|
|
34
|
-
console.log(`testFile.txt was moved to geo: ${res}`);
|
|
35
|
-
|
|
36
|
-
// Delete files
|
|
37
|
-
await grok.dapi.files.delete('Samples:Files/geo/testFile.txt');
|
|
38
|
-
await grok.dapi.files.delete('Samples:Files/testFile.dat');
|
|
39
|
-
})();
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// User data storage demo: Saving values to storage
|
|
2
|
-
|
|
3
|
-
const STORAGE_NAME = 'user-data-storage-demo';
|
|
4
|
-
|
|
5
|
-
let v = grok.shell.newView('demo: user data storage');
|
|
6
|
-
|
|
7
|
-
let age = ui.intInput('Age', 30);
|
|
8
|
-
let sex = ui.choiceInput('Sex', 'Male', ['Male', 'Female']);
|
|
9
|
-
let music = ui.multiChoiceInput('Music genres', null, ['Classic', 'Rock', 'Pop', 'Jazz']);
|
|
10
|
-
|
|
11
|
-
let inputs = [age, sex, music];
|
|
12
|
-
v.append(ui.inputs(inputs));
|
|
13
|
-
|
|
14
|
-
let storageButton = ui.iconFA('database', () => {
|
|
15
|
-
grok.dapi.userDataStorage.get(STORAGE_NAME).then((entities) => {
|
|
16
|
-
if (entities !== null && Object.keys(entities).length === 0)
|
|
17
|
-
grok.shell.info('Storage is empty. Try to post something to the storage');
|
|
18
|
-
else {
|
|
19
|
-
let menu = DG.Menu.popup();
|
|
20
|
-
for (let time of Object.keys(entities)) {
|
|
21
|
-
let values = JSON.parse(entities[time]);
|
|
22
|
-
menu.item(values.map(v => `${v.caption}: ${v.value}`).join(', '), () => {
|
|
23
|
-
for (let input of values)
|
|
24
|
-
inputs.find(i => i.caption === input.caption).load(input.value);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
menu.show();
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
storageButton.style.margin = '8px 24px 0 24px';
|
|
32
|
-
|
|
33
|
-
let postButton = ui.button('Post to storage', () => {
|
|
34
|
-
grok.shell.info(inputs.map((i) => `${i.caption}: ${i.stringValue}`).join('<br>'));
|
|
35
|
-
grok.dapi.userDataStorage.postValue(STORAGE_NAME, `${Math.floor(Math.random() * Math.floor(1000))}`,
|
|
36
|
-
JSON.stringify(inputs.map(i => {
|
|
37
|
-
return {caption: i.caption, value: i.save()};
|
|
38
|
-
})));
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
let clearButton = ui.button('Clear storage', () => {
|
|
42
|
-
grok.dapi.userDataStorage.remove(STORAGE_NAME, null);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
v.append(ui.divH([
|
|
46
|
-
storageButton,
|
|
47
|
-
postButton,
|
|
48
|
-
clearButton
|
|
49
|
-
]));
|
|
File without changes
|
|
File without changes
|