@adaptabletools/adaptable-plugin-nocode-aggrid-cjs 17.0.0-canary.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.
- package/README.md +63 -0
- package/package.json +18 -0
- package/src/index.d.ts +24 -0
- package/src/index.js +131 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# AdapTable 'No Code' Plugin
|
|
2
|
+
|
|
3
|
+
The No Code Plugin allows end users to create an AdapTable instance at runtime from any JSON or Excel file that they provide.
|
|
4
|
+
|
|
5
|
+
It will dynamically instantiate a fully functional AdapTable including advanced features like state management and audit log, enabling Users to attach to the same source daily or multiple different sources.
|
|
6
|
+
|
|
7
|
+
## No Code Wizard
|
|
8
|
+
Once a JSON or Excel file has been selected (or dragged and droppped), the AdapTable No Code Wizard will appear.
|
|
9
|
+
|
|
10
|
+
It has 2 steps:
|
|
11
|
+
|
|
12
|
+
1. The Wizard will read the input file / JSON and list the available columns it contains, together with options for each column to change the DataType, and set editing, filtering, sorting, grouping and other properties.
|
|
13
|
+
|
|
14
|
+
2. A second (optional) step allows Users to set up many of the [Adaptable Options](https://docs.adaptabletools.com/guide/reference-options-overview) that would normally be configured at design-time, in order to ensure that the AdapTable instance suits their precise requirements.
|
|
15
|
+
|
|
16
|
+
> The source data must have one column that contains **unique values** which will be set as the Primary Key column (by convention this is the first column).
|
|
17
|
+
|
|
18
|
+
## Code Required
|
|
19
|
+
There is minimum code required to set up the No Code plugin.
|
|
20
|
+
|
|
21
|
+
A full example would be as follows:
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
import "@adaptabletools/adaptable/index.css";
|
|
25
|
+
import "@ag-grid-community/all-modules/dist/styles/ag-grid.css";
|
|
26
|
+
import "@ag-grid-community/all-modules/dist/styles/ag-theme-balham.css";
|
|
27
|
+
import nocode from "@adaptabletools/adaptable-plugin-nocode-aggrid";
|
|
28
|
+
import { AdaptableOptions} from "@adaptabletools/adaptable/types";
|
|
29
|
+
import { AllEnterpriseModules } from "@ag-grid-enterprise/all-modules";
|
|
30
|
+
import Adaptable from "@adaptabletools/adaptable/agGrid";
|
|
31
|
+
|
|
32
|
+
const adaptableOptions: AdaptableOptions = {
|
|
33
|
+
primaryKey: "",
|
|
34
|
+
userName: "Demo User",
|
|
35
|
+
adaptableId: "Nocode Plugin Demo",
|
|
36
|
+
plugins: [
|
|
37
|
+
nocode({
|
|
38
|
+
onInit: adaptableOptions => {
|
|
39
|
+
adaptableOptions.modules = AllEnterpriseModules;
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Adaptable.init(adaptableOptions).then((api) => {
|
|
46
|
+
console.log(api, "!!!");
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Example Project
|
|
51
|
+
Visit the [No Code Example Project](https://github.com/AdaptableTools/example-adaptable-nocode-aggrid) to see a basic example of how to set up the No Code plugin.
|
|
52
|
+
|
|
53
|
+
## Demo
|
|
54
|
+
Visit the [No Code Demo](https://demo.adaptabletools.com/admin/aggridnocodedemo) to see AdapTable running the No Code plugin.
|
|
55
|
+
|
|
56
|
+
## Help
|
|
57
|
+
Developers can learn how to access AdapTable programmatically at [AdapTable Documentation](https://docs.adaptabletools.com).
|
|
58
|
+
|
|
59
|
+
## Other AdapTable Resources
|
|
60
|
+
General information about Adaptable Tools is available at our [Website](http://www.adaptabletools.com)
|
|
61
|
+
|
|
62
|
+
## Support
|
|
63
|
+
For all support enquiries please email [`support@adaptabletools.com`](mailto:support@adaptabletools.com) or [raise a Support Ticket](https://adaptabletools.zendesk.com/hc/en-us/requests/new).
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adaptabletools/adaptable-plugin-nocode-aggrid-cjs",
|
|
3
|
+
"version": "17.0.0-canary.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"homepage": "http://www.adaptabletools.com/",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Jonny Wolfson",
|
|
8
|
+
"email": "jonny.wolfson@adaptabletools.com"
|
|
9
|
+
},
|
|
10
|
+
"main": "src/index.js",
|
|
11
|
+
"typings": "src/index.d.ts",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"tslib": "^2.3.0",
|
|
14
|
+
"xlsx": "^0.15.5",
|
|
15
|
+
"@adaptabletools/adaptable-cjs": "17.0.0-canary.1"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {}
|
|
18
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AdaptableOptions, AdaptablePlugin, AgGridConfig } from '@adaptabletools/adaptable/types';
|
|
3
|
+
export declare const readJSONFile: (file: File, toJSON?: (str: string) => Promise<any> | any) => Promise<unknown>;
|
|
4
|
+
export declare const readExcelFile: (file: File) => Promise<any>;
|
|
5
|
+
interface NoCodePluginOptions {
|
|
6
|
+
modules?: any[];
|
|
7
|
+
onInit?: (adaptableOptions: AdaptableOptions) => void | Promise<any>;
|
|
8
|
+
headerMessage?: React.ReactNode;
|
|
9
|
+
actionMessage?: React.ReactNode;
|
|
10
|
+
dropActionMessage?: React.ReactNode;
|
|
11
|
+
loadingMessage?: React.ReactNode;
|
|
12
|
+
theme?: 'dark' | 'light';
|
|
13
|
+
fetchData?: () => Promise<any>;
|
|
14
|
+
showFetchDataWizard?: boolean;
|
|
15
|
+
skipToWizard?: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare class NoCodePlugin extends AdaptablePlugin {
|
|
18
|
+
options: NoCodePluginOptions;
|
|
19
|
+
pluginId: string;
|
|
20
|
+
constructor(options?: NoCodePluginOptions);
|
|
21
|
+
beforeInit(adaptableOptions: AdaptableOptions, agGridOptions: AgGridConfig): Promise<unknown>;
|
|
22
|
+
}
|
|
23
|
+
declare const _default: (options?: NoCodePluginOptions) => NoCodePlugin;
|
|
24
|
+
export default _default;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readExcelFile = exports.readJSONFile = void 0;
|
|
4
|
+
const xlsx_1 = require("xlsx");
|
|
5
|
+
const agGrid_1 = require("@adaptabletools/adaptable-cjs/agGrid");
|
|
6
|
+
const types_1 = require("@adaptabletools/adaptable-cjs/types");
|
|
7
|
+
const package_json_1 = require("../package.json");
|
|
8
|
+
const package_json_2 = require("@adaptabletools/adaptable-cjs/package.json");
|
|
9
|
+
const suffix = package_json_1.name.endsWith('-cjs') ? '-cjs' : '';
|
|
10
|
+
if (package_json_1.version !== package_json_2.version) {
|
|
11
|
+
console.warn(`
|
|
12
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
13
|
+
!!!!!!! "@adaptabletools/adaptable-plugin-nocode${suffix}" (v @${package_json_1.version}) and "@adaptabletools/adaptable${suffix}" (v @${package_json_2.version}) have different versions - they should have the exact same version.
|
|
14
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
15
|
+
`);
|
|
16
|
+
}
|
|
17
|
+
const readJSONFile = async (file, toJSON) => {
|
|
18
|
+
const reader = new FileReader();
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
reader.onload = function (e) {
|
|
21
|
+
try {
|
|
22
|
+
const fn = toJSON || JSON.parse;
|
|
23
|
+
const json = fn(e.target.result);
|
|
24
|
+
Promise.resolve(json).then(resolve);
|
|
25
|
+
}
|
|
26
|
+
catch (ex) {
|
|
27
|
+
reject('Invalid JSON');
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
reader.onerror = function (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
};
|
|
33
|
+
reader.readAsText(file);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.readJSONFile = readJSONFile;
|
|
37
|
+
const readExcelFile = (file) => {
|
|
38
|
+
/* Boilerplate to set up FileReader */
|
|
39
|
+
const reader = new FileReader();
|
|
40
|
+
const asBinary = !!reader.readAsBinaryString;
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
reader.onload = (e) => {
|
|
43
|
+
const wb = (0, xlsx_1.read)(e.target.result, {
|
|
44
|
+
type: asBinary ? 'binary' : 'array',
|
|
45
|
+
cellDates: true,
|
|
46
|
+
});
|
|
47
|
+
// Get first worksheet
|
|
48
|
+
const wsname = wb.SheetNames[0];
|
|
49
|
+
const ws = wb.Sheets[wsname];
|
|
50
|
+
// Convert array of arrays
|
|
51
|
+
const data = xlsx_1.utils.sheet_to_json(ws, { header: 1 });
|
|
52
|
+
resolve(data);
|
|
53
|
+
};
|
|
54
|
+
reader.onerror = reject;
|
|
55
|
+
if (asBinary) {
|
|
56
|
+
reader.readAsBinaryString(file);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
reader.readAsArrayBuffer(file);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
exports.readExcelFile = readExcelFile;
|
|
64
|
+
const defaultOptions = {};
|
|
65
|
+
class NoCodePlugin extends types_1.AdaptablePlugin {
|
|
66
|
+
constructor(options) {
|
|
67
|
+
super(options);
|
|
68
|
+
this.pluginId = 'nocode-aggrid';
|
|
69
|
+
this.options = Object.assign(Object.assign({}, defaultOptions), options);
|
|
70
|
+
}
|
|
71
|
+
beforeInit(adaptableOptions, agGridOptions) {
|
|
72
|
+
const theme = this.options.theme ||
|
|
73
|
+
(typeof adaptableOptions.predefinedConfig === 'object' &&
|
|
74
|
+
adaptableOptions.predefinedConfig.Theme &&
|
|
75
|
+
adaptableOptions.predefinedConfig.Theme.CurrentTheme
|
|
76
|
+
? adaptableOptions.predefinedConfig.Theme.CurrentTheme
|
|
77
|
+
: null);
|
|
78
|
+
if (theme) {
|
|
79
|
+
document.documentElement.classList.add(`ab--theme-${theme}`);
|
|
80
|
+
}
|
|
81
|
+
let isJSON;
|
|
82
|
+
return new Promise((resolve) => {
|
|
83
|
+
new agGrid_1.AdaptableNoCodeWizard(adaptableOptions, {
|
|
84
|
+
fileAccept: '.json,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel',
|
|
85
|
+
helpText: this.options.headerMessage,
|
|
86
|
+
defaultActionMessage: this.options.actionMessage ||
|
|
87
|
+
'Click to select an Excel or JSON file to load — or drag it here',
|
|
88
|
+
dragOverActionMessage: this.options.dropActionMessage,
|
|
89
|
+
loadingMessage: this.options.loadingMessage,
|
|
90
|
+
fetchData: this.options.fetchData,
|
|
91
|
+
showFetchDataWizard: this.options.showFetchDataWizard,
|
|
92
|
+
skipToWizard: this.options.skipToWizard,
|
|
93
|
+
readFile: (file) => {
|
|
94
|
+
isJSON = (file.type && file.type.indexOf('json')) != -1 || file.name.endsWith('.json');
|
|
95
|
+
if (isJSON) {
|
|
96
|
+
return (0, exports.readJSONFile)(file);
|
|
97
|
+
}
|
|
98
|
+
return (0, exports.readExcelFile)(file);
|
|
99
|
+
},
|
|
100
|
+
onInit: ({ gridOptions, adaptableOptions: newAdaptableOptions }) => {
|
|
101
|
+
Object.keys(newAdaptableOptions).forEach((key) => {
|
|
102
|
+
adaptableOptions[key] = newAdaptableOptions[key];
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* Update the gridOptions with the new gridOptions
|
|
106
|
+
*/
|
|
107
|
+
if (agGridOptions.gridOptions) {
|
|
108
|
+
Object.assign(agGridOptions.gridOptions, gridOptions);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
agGridOptions.gridOptions = gridOptions;
|
|
112
|
+
}
|
|
113
|
+
let onInitResult = Promise.resolve(true);
|
|
114
|
+
if (this.options.onInit) {
|
|
115
|
+
onInitResult = this.options.onInit(adaptableOptions);
|
|
116
|
+
}
|
|
117
|
+
if (onInitResult && onInitResult.then) {
|
|
118
|
+
onInitResult.then(() => {
|
|
119
|
+
requestAnimationFrame(resolve);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
requestAnimationFrame(resolve);
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
},
|
|
127
|
+
}, agGridOptions);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.default = (options) => new NoCodePlugin(options);
|