@adaptabletools/adaptable-plugin-interopio 18.0.0-canary.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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # AdapTable Interop Plugin Read Me
2
+
3
+ ## Help
4
+
5
+ Developers can learn how to access AdapTable programmatically at [AdapTable Documentation](https://docs.adaptabletools.com).
6
+
7
+ ## More Information
8
+
9
+ General information about Adaptable Tools is available at our [Website](http://www.adaptabletools.com)
10
+
11
+ ## Support
12
+
13
+ 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-interopio",
3
+ "version": "18.0.0-canary.0",
4
+ "description": "",
5
+ "homepage": "http://www.adaptabletools.com/",
6
+ "author": {
7
+ "name": "Jonny Wolfson",
8
+ "email": "jonny.wolfson@adaptabletools.com"
9
+ },
10
+ "typings": "src/index.d.ts",
11
+ "dependencies": {
12
+ "@interopio/browser": "^3.1.2",
13
+ "tslib": "^2.3.0",
14
+ "@adaptabletools/adaptable": "18.0.0-canary.0"
15
+ },
16
+ "type": "module",
17
+ "module": "src/index.js"
18
+ }
@@ -0,0 +1,9 @@
1
+ import { ApiBase } from '@adaptabletools/adaptable/src/Api/Implementation/ApiBase';
2
+ import { InteropioPluginApi } from '@adaptabletools/adaptable/src/Api/InteropioPluginApi';
3
+ import { IAdaptable } from '@adaptabletools/adaptable/src/AdaptableInterfaces/IAdaptable';
4
+ import { InteropioPluginOptions } from '../../../adaptable/src/AdaptableOptions/InteropioPluginOptions';
5
+ export declare class InteropioApiImpl extends ApiBase implements InteropioPluginApi {
6
+ private options;
7
+ constructor(adaptable: IAdaptable, options: InteropioPluginOptions);
8
+ getPluginOptions(): InteropioPluginOptions;
9
+ }
@@ -0,0 +1,10 @@
1
+ import { ApiBase } from '@adaptabletools/adaptable/src/Api/Implementation/ApiBase';
2
+ export class InteropioApiImpl extends ApiBase {
3
+ constructor(adaptable, options) {
4
+ super(adaptable);
5
+ this.options = options;
6
+ }
7
+ getPluginOptions() {
8
+ return this.options;
9
+ }
10
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { AdaptablePlugin } from '@adaptabletools/adaptable/types';
2
+ import { IAdaptable } from '@adaptabletools/adaptable/src/AdaptableInterfaces/IAdaptable';
3
+ import { InteropioApiImpl } from './InteropioApiImpl';
4
+ import { InteropioPluginOptions } from '../../../adaptable/src/AdaptableOptions/InteropioPluginOptions';
5
+ import * as Interop from '@interopio/browser';
6
+ declare class InteropioPlugin extends AdaptablePlugin {
7
+ options: InteropioPluginOptions;
8
+ pluginId: string;
9
+ adaptableInteropApi: InteropioApiImpl;
10
+ private adaptable?;
11
+ private interopApi;
12
+ constructor(options: InteropioPluginOptions, interopApi: Interop.IOConnectBrowser.API);
13
+ onAdaptableReady(adaptable: IAdaptable): void;
14
+ afterInitApi(adaptable: IAdaptable): void;
15
+ /**
16
+ * Interopio Notifications logic has two main parts:
17
+ * - a handler that is registered using the interop API;
18
+ * -- This handler is invoked when a notification action is clicked.
19
+ * -- We have a map in which we register actions for a given alert.
20
+ * - rising a notification using the Interopio API
21
+ * -- here for each action an interop method is registered
22
+ * -- information is passed to indicate which button and lert was clicked
23
+ * -- using this information the action map is populated
24
+ */
25
+ private integrateAdaptableAlerts;
26
+ }
27
+ declare const _default: (options: InteropioPluginOptions, interopioApi: Interop.IOConnectBrowser.API) => InteropioPlugin;
28
+ export default _default;
package/src/index.js ADDED
@@ -0,0 +1,109 @@
1
+ import { AdaptablePlugin, } from '@adaptabletools/adaptable/types';
2
+ import { InteropioApiImpl } from './InteropioApiImpl';
3
+ // if (version !== coreVersion) {
4
+ // console.warn(`
5
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6
+ // !!!!!!! "@adaptabletools/adaptable-plugin-interopio" (v @${version}) and "@adaptabletools/adaptable" (v @${coreVersion}) have different versions - they should have the exact same version.
7
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
+ // `);
9
+ // }
10
+ const defaultOptions = {
11
+ showAdaptableAlertsAsNotifications: true,
12
+ applicationName: 'Adaptable',
13
+ };
14
+ class InteropioPlugin extends AdaptablePlugin {
15
+ constructor(options, interopApi) {
16
+ super(options);
17
+ this.pluginId = 'interop';
18
+ this.options = Object.assign(Object.assign({}, defaultOptions), options);
19
+ this.interopApi = interopApi;
20
+ }
21
+ onAdaptableReady(adaptable) {
22
+ this.adaptable = adaptable;
23
+ this.integrateAdaptableAlerts();
24
+ }
25
+ afterInitApi(adaptable) {
26
+ this.adaptableInteropApi = new InteropioApiImpl(adaptable, this.options);
27
+ this.registerProperty('api', () => this.adaptableInteropApi);
28
+ }
29
+ /**
30
+ * Interopio Notifications logic has two main parts:
31
+ * - a handler that is registered using the interop API;
32
+ * -- This handler is invoked when a notification action is clicked.
33
+ * -- We have a map in which we register actions for a given alert.
34
+ * - rising a notification using the Interopio API
35
+ * -- here for each action an interop method is registered
36
+ * -- information is passed to indicate which button and lert was clicked
37
+ * -- using this information the action map is populated
38
+ */
39
+ async integrateAdaptableAlerts() {
40
+ var _a;
41
+ if (!this.options.showAdaptableAlertsAsNotifications) {
42
+ return;
43
+ }
44
+ /**
45
+ * A way to keep in memory what actions were registered for a given alert.
46
+ */
47
+ const actionsMap = new Map();
48
+ const ADAPTABLE_INTEROP_NOTIFICATION_HANDLER = `ADAPTABLE_INTEROP_NOTIFICATION_HANDLER_${Date.now()}}`;
49
+ const adaptableInteropNotificationHandler = ({ buttonId }) => {
50
+ const memoAction = actionsMap.get(buttonId);
51
+ if (memoAction) {
52
+ const { alert, button } = memoAction;
53
+ const context = {
54
+ alert: alert,
55
+ adaptableApi: this.adaptable.api,
56
+ userName: this.adaptable.adaptableOptions.userName,
57
+ adaptableId: this.adaptable.adaptableOptions.adaptableId,
58
+ formData: {},
59
+ };
60
+ this.adaptable.api.alertApi.internalApi.executeAlertButton(button, context);
61
+ // we need to delete all actions for the given alert
62
+ // because once the button is clicked, the notification is closed
63
+ for (const [key, value] of actionsMap.entries()) {
64
+ if (value.alert === alert) {
65
+ actionsMap.delete(key);
66
+ }
67
+ }
68
+ }
69
+ };
70
+ await this.interopApi.interop.register(ADAPTABLE_INTEROP_NOTIFICATION_HANDLER, adaptableInteropNotificationHandler);
71
+ (_a = this.adaptable) === null || _a === void 0 ? void 0 : _a.api.eventApi.on('AlertFired', (alertInfo) => {
72
+ var _a;
73
+ const adaptableAlert = alertInfo.alert;
74
+ const { header, message } = adaptableAlert;
75
+ const adaptableActions = [];
76
+ if (adaptableAlert.alertDefinition.AlertForm &&
77
+ typeof adaptableAlert.alertDefinition.AlertForm !== 'string' &&
78
+ Array.isArray((_a = adaptableAlert.alertDefinition.AlertForm) === null || _a === void 0 ? void 0 : _a.Buttons)) {
79
+ adaptableAlert.alertDefinition.AlertForm.Buttons.forEach(async (button, index) => {
80
+ const buttonId = `${button.Label}.${Date.now()}`;
81
+ const action = `adaptable-action-button-${button.Label}-${index}-${Date.now()}`;
82
+ const notificationAction = {
83
+ title: button.Label,
84
+ action,
85
+ };
86
+ if (button.Action) {
87
+ notificationAction.interop = {
88
+ method: ADAPTABLE_INTEROP_NOTIFICATION_HANDLER,
89
+ arguments: {
90
+ buttonId: buttonId,
91
+ },
92
+ };
93
+ }
94
+ actionsMap.set(buttonId, { alert: adaptableAlert, button });
95
+ adaptableActions.push(notificationAction);
96
+ });
97
+ }
98
+ const notificationOptions = {
99
+ title: header,
100
+ body: message,
101
+ actions: adaptableActions,
102
+ };
103
+ this.interopApi.notifications.raise(notificationOptions);
104
+ // Returning false prevents adaptable from showing the alert notification.
105
+ return false;
106
+ });
107
+ }
108
+ }
109
+ export default (options, interopioApi) => new InteropioPlugin(options, interopioApi);