@adaptabletools/adaptable-plugin-openfin 22.0.0-canary.0 → 22.0.0-canary.2

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 CHANGED
@@ -10,12 +10,12 @@ This plugin allows users to take advantage of some additional functionality cour
10
10
 
11
11
  ## Documentation & Demos
12
12
 
13
- Full details of how to install, configure and use the OpenFin plugin can be found at [AdapTable OpenFin Documentation](https://docs.adaptabletools.com/guide/integrations-openfin)
13
+ Full details of how to install, configure and use the OpenFin plugin can be found at [AdapTable OpenFin Documentation](https://www.adaptabletools.com/docs/integrations-openfin)
14
14
 
15
15
 
16
16
  ## Help
17
17
 
18
- Developers can learn how to access AdapTable programmatically at [AdapTable Documentation](https://docs.adaptabletools.com).
18
+ Developers can learn how to access AdapTable programmatically at [AdapTable Documentation](https://www.adaptabletools.com/docs).
19
19
 
20
20
  ## Other AdapTable Resources
21
21
 
@@ -27,4 +27,4 @@ For all support enquiries please email [`support@adaptabletools.com`](mailto:sup
27
27
 
28
28
  ## Licences
29
29
 
30
- Information on AdapTable Licences can be found at [Licensing AdapTable for AG Grid](https://docs.adaptabletools.com/guide/buying-adaptable-licensing).
30
+ Information on AdapTable Licences can be found at [Licensing AdapTable for AG Grid](https://www.adaptabletools.com/buy/buying-adaptable-licensing).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptabletools/adaptable-plugin-openfin",
3
- "version": "22.0.0-canary.0",
3
+ "version": "22.0.0-canary.2",
4
4
  "description": "",
5
5
  "homepage": "http://www.adaptabletools.com/",
6
6
  "author": {
@@ -4,13 +4,20 @@ import throttle from 'lodash/throttle';
4
4
  import { DEFAULT_LIVE_REPORT_THROTTLE_TIME, ALL_DATA_REPORT, SELECTED_DATA_REPORT, } from '@adaptabletools/adaptable/src/Utilities/Constants/GeneralConstants';
5
5
  export const EXCEL_VALIDATION_FAILED = 'excelValidationFailed';
6
6
  export class OpenFinModule extends AdaptableModuleBase {
7
+ isSendingData = false;
8
+ openFinService = null;
9
+ adaptable;
10
+ throttledRecomputeAndSendLiveDataEvent;
11
+ liveTimeoutId;
12
+ removeDataChangedListener;
13
+ removeGridRefreshedListener;
14
+ removeGridFilteredListener;
15
+ removeCellSelectionChangedListener;
16
+ removeRowSelectionChangedListener;
17
+ removeSheetChangedListener;
18
+ currentReportData;
7
19
  constructor(api) {
8
20
  super(ModuleConstants.OpenFinModuleId, ModuleConstants.OpenFinFriendlyName, 'download', null, 'Integrate AdapTable with the OpenFin container', api);
9
- this.isSendingData = false;
10
- this.openFinService = null;
11
- this.getCurrentReportColumns = () => {
12
- return this.currentReportData ? this.currentReportData.columns : [];
13
- };
14
21
  this.adaptable = api.internalApi.getAdaptableInstance();
15
22
  this.throttledRecomputeAndSendLiveDataEvent = throttle(() => this.sendInitialLiveData(), this.getThrottleTimeFromState());
16
23
  }
@@ -72,6 +79,9 @@ export class OpenFinModule extends AdaptableModuleBase {
72
79
  });
73
80
  }
74
81
  }
82
+ getCurrentReportColumns = () => {
83
+ return this.currentReportData ? this.currentReportData.columns : [];
84
+ };
75
85
  startLiveData(iOpenFinReport) {
76
86
  this.cleanup(); // just in case the previous report has not been stopped
77
87
  this.liveTimeoutId = setTimeout(() => {
@@ -16,9 +16,10 @@ if (typeof window !== 'undefined' && window.document) {
16
16
  }
17
17
  const CLICK_ALERT_BUTTON = 'adaptable-click-alert-button';
18
18
  export class OpenFinApiImpl extends ApiBase {
19
+ options;
20
+ OpenFinService = null;
19
21
  constructor(_adaptable, options) {
20
22
  super(_adaptable);
21
- this.OpenFinService = null;
22
23
  this.options = options;
23
24
  if (isRunningInOpenfin()) {
24
25
  addEventListener('notification-action', (event) => {
@@ -2,9 +2,7 @@
2
2
  // putting this here as we dont use it elswhere - so keeping it here until we redo the OpenFin one day...
3
3
  import { AdaptableLogger } from '@adaptabletools/adaptable/src/agGrid/AdaptableLogger';
4
4
  export class EventDispatcher {
5
- constructor() {
6
- this._subscriptions = new Array();
7
- }
5
+ _subscriptions = new Array();
8
6
  Subscribe(fn) {
9
7
  if (fn) {
10
8
  this._subscriptions.push(fn);
@@ -10,9 +10,41 @@ export function isExcelOpenfinLoaded() {
10
10
  return isRunningInOpenfin() && 'Excel' in fin.desktop;
11
11
  }
12
12
  export class OpenFinService {
13
+ adaptable;
14
+ options;
15
+ workbookName;
16
+ excelConnected = false;
17
+ connectedCallbacks = [];
18
+ activeWorksheet;
19
+ emitter;
13
20
  getOpenFinApi() {
14
21
  return this.adaptable.api.pluginsApi.getOpenFinPluginApi();
15
22
  }
23
+ onWorkbookRemoved = (event) => {
24
+ event.workbook.removeEventListener('workbookActivated', this.onWorkbookActivated);
25
+ const { workbook } = event;
26
+ this.adaptable.logger.info('Workbook closed:' + workbook.name + ', Stopping Openfin Live Excel');
27
+ this.getOpenFinApi().stopLiveData();
28
+ };
29
+ onWorkbookSaved = (event) => {
30
+ const NewName = event.workbook.name;
31
+ this.adaptable.logger.info('workbook saved', NewName);
32
+ //saving adds an extension, but the name does not have that
33
+ // however, not adding the extension will not find the workbook when we do getWorkBookByName
34
+ // and will crash the app
35
+ this.workbookName = NewName;
36
+ };
37
+ onWorkbookActivated = (event) => {
38
+ this.adaptable.logger.info('Workbook Activated: ' + event.target.name);
39
+ event.target.getWorksheets((ack) => {
40
+ this.adaptable.logger.info('getWorksheets:', ack);
41
+ });
42
+ };
43
+ onWorkbookAdded = (event) => {
44
+ this.adaptable.logger.success('Workbook Added: ' + event.workbook.name);
45
+ let workbook = event.workbook;
46
+ workbook.addEventListener('workbookActivated', this.onWorkbookActivated);
47
+ };
16
48
  getCurrentWorkbook(skipRetry) {
17
49
  if (!this.workbookName) {
18
50
  return this.waitForExcel().then(() => {
@@ -59,6 +91,21 @@ export class OpenFinService {
59
91
  });
60
92
  });
61
93
  }
94
+ onSheetChanged = (event) => {
95
+ this.emit('sheetchanged', event);
96
+ };
97
+ getRowContents = (rowIndex, columnCount) => {
98
+ return new Promise((resolve, reject) => {
99
+ try {
100
+ this.activeWorksheet.getRow('A' + rowIndex, columnCount, (row) => {
101
+ return resolve(row.map((x) => x.value));
102
+ });
103
+ }
104
+ catch (err) {
105
+ reject(err);
106
+ }
107
+ });
108
+ };
62
109
  doPushData(data, { address, clear }) {
63
110
  const OpenFinApi = this.getOpenFinApi();
64
111
  if (!OpenFinApi || !this.options || !isRunningInOpenfin()) {
@@ -110,6 +157,30 @@ export class OpenFinService {
110
157
  }));
111
158
  });
112
159
  }
160
+ onExcelConnected = () => {
161
+ this.excelConnected = true;
162
+ this.connectedCallbacks.forEach((fn) => fn());
163
+ this.connectedCallbacks.length = 0;
164
+ this.adaptable.logger.success('Excel Connected');
165
+ fin.desktop.Excel.addEventListener('workbookClosed', this.onWorkbookRemoved);
166
+ fin.desktop.Excel.addEventListener('workbookSaved', this.onWorkbookSaved);
167
+ fin.desktop.Excel.addEventListener('workbookAdded', this.onWorkbookAdded);
168
+ };
169
+ onExcelDisconnected = () => {
170
+ this.adaptable.logger.info('Excel Disconnected');
171
+ this.excelConnected = false;
172
+ this.initialisingExcel = null;
173
+ this.workbookName = undefined;
174
+ this.activeWorksheet = null;
175
+ fin.desktop.Excel.removeEventListener('workbookClosed', this.onWorkbookRemoved);
176
+ fin.desktop.Excel.removeEventListener('workbookSaved', this.onWorkbookSaved);
177
+ fin.desktop.Excel.removeEventListener('workbookAdded', this.onWorkbookAdded);
178
+ fin.desktop.ExcelService.removeEventListener('excelConnected', this.onExcelConnected);
179
+ fin.desktop.ExcelService.removeEventListener('excelDisconnected', this.onExcelDisconnected);
180
+ this.adaptable.logger.info('Excel closed stopping all Live Excel');
181
+ this.getOpenFinApi().stopLiveData();
182
+ };
183
+ initialisingExcel = null;
113
184
  initOpenFinExcel(callback) {
114
185
  if (this.excelConnected) {
115
186
  callback();
@@ -146,102 +217,36 @@ export class OpenFinService {
146
217
  });
147
218
  return this.initialisingExcel;
148
219
  }
220
+ waitForExcel = () => {
221
+ let startTime = Date.now();
222
+ const poolForExcel = (callback) => {
223
+ if (Date.now() - startTime > 20000) {
224
+ console.error(`Could not find any Excel instance.`);
225
+ return callback();
226
+ }
227
+ if (!fin.desktop.Excel || !fin.desktop.Excel.getWorkbooks) {
228
+ requestAnimationFrame(() => {
229
+ poolForExcel(callback);
230
+ });
231
+ }
232
+ else {
233
+ callback();
234
+ }
235
+ };
236
+ return new Promise((resolve) => {
237
+ poolForExcel(() => resolve(''));
238
+ });
239
+ };
149
240
  constructor(adaptable, options) {
150
241
  this.adaptable = adaptable;
151
- this.excelConnected = false;
152
- this.connectedCallbacks = [];
153
- this.onWorkbookRemoved = (event) => {
154
- event.workbook.removeEventListener('workbookActivated', this.onWorkbookActivated);
155
- const { workbook } = event;
156
- this.adaptable.logger.info('Workbook closed:' + workbook.name + ', Stopping Openfin Live Excel');
157
- this.getOpenFinApi().stopLiveData();
158
- };
159
- this.onWorkbookSaved = (event) => {
160
- const NewName = event.workbook.name;
161
- this.adaptable.logger.info('workbook saved', NewName);
162
- //saving adds an extension, but the name does not have that
163
- // however, not adding the extension will not find the workbook when we do getWorkBookByName
164
- // and will crash the app
165
- this.workbookName = NewName;
166
- };
167
- this.onWorkbookActivated = (event) => {
168
- this.adaptable.logger.info('Workbook Activated: ' + event.target.name);
169
- event.target.getWorksheets((ack) => {
170
- this.adaptable.logger.info('getWorksheets:', ack);
171
- });
172
- };
173
- this.onWorkbookAdded = (event) => {
174
- this.adaptable.logger.success('Workbook Added: ' + event.workbook.name);
175
- let workbook = event.workbook;
176
- workbook.addEventListener('workbookActivated', this.onWorkbookActivated);
177
- };
178
- this.onSheetChanged = (event) => {
179
- this.emit('sheetchanged', event);
180
- };
181
- this.getRowContents = (rowIndex, columnCount) => {
182
- return new Promise((resolve, reject) => {
183
- try {
184
- this.activeWorksheet.getRow('A' + rowIndex, columnCount, (row) => {
185
- return resolve(row.map((x) => x.value));
186
- });
187
- }
188
- catch (err) {
189
- reject(err);
190
- }
191
- });
192
- };
193
- this.onExcelConnected = () => {
194
- this.excelConnected = true;
195
- this.connectedCallbacks.forEach((fn) => fn());
196
- this.connectedCallbacks.length = 0;
197
- this.adaptable.logger.success('Excel Connected');
198
- fin.desktop.Excel.addEventListener('workbookClosed', this.onWorkbookRemoved);
199
- fin.desktop.Excel.addEventListener('workbookSaved', this.onWorkbookSaved);
200
- fin.desktop.Excel.addEventListener('workbookAdded', this.onWorkbookAdded);
201
- };
202
- this.onExcelDisconnected = () => {
203
- this.adaptable.logger.info('Excel Disconnected');
204
- this.excelConnected = false;
205
- this.initialisingExcel = null;
206
- this.workbookName = undefined;
207
- this.activeWorksheet = null;
208
- fin.desktop.Excel.removeEventListener('workbookClosed', this.onWorkbookRemoved);
209
- fin.desktop.Excel.removeEventListener('workbookSaved', this.onWorkbookSaved);
210
- fin.desktop.Excel.removeEventListener('workbookAdded', this.onWorkbookAdded);
211
- fin.desktop.ExcelService.removeEventListener('excelConnected', this.onExcelConnected);
212
- fin.desktop.ExcelService.removeEventListener('excelDisconnected', this.onExcelDisconnected);
213
- this.adaptable.logger.info('Excel closed stopping all Live Excel');
214
- this.getOpenFinApi().stopLiveData();
215
- };
216
- this.initialisingExcel = null;
217
- this.waitForExcel = () => {
218
- let startTime = Date.now();
219
- const poolForExcel = (callback) => {
220
- if (Date.now() - startTime > 20000) {
221
- console.error(`Could not find any Excel instance.`);
222
- return callback();
223
- }
224
- if (!fin.desktop.Excel || !fin.desktop.Excel.getWorkbooks) {
225
- requestAnimationFrame(() => {
226
- poolForExcel(callback);
227
- });
228
- }
229
- else {
230
- callback();
231
- }
232
- };
233
- return new Promise((resolve) => {
234
- poolForExcel(() => resolve(''));
235
- });
236
- };
237
- this.on = (eventName, callback) => {
238
- return this.emitter.on(eventName, callback);
239
- };
240
- this.emit = (eventName, data) => {
241
- return this.emitter.emit(eventName, data);
242
- };
243
242
  this.adaptable = adaptable;
244
243
  this.options = options;
245
244
  this.emitter = new Emitter();
246
245
  }
246
+ on = (eventName, callback) => {
247
+ return this.emitter.on(eventName, callback);
248
+ };
249
+ emit = (eventName, data) => {
250
+ return this.emitter.emit(eventName, data);
251
+ };
247
252
  }
@@ -17,13 +17,6 @@ const IS_OPENFIN = isRunningInOpenfin();
17
17
  class OpenFinViewPanelComponent extends React.Component {
18
18
  constructor(props) {
19
19
  super(props);
20
- this.onLiveDataChanged = (liveDataChangedInfo) => {
21
- if (liveDataChangedInfo.reportDestination == 'OpenFin' &&
22
- (liveDataChangedInfo.liveDataTrigger == 'Connected' ||
23
- liveDataChangedInfo.liveDataTrigger == 'Disconnected')) {
24
- this.forceUpdate();
25
- }
26
- };
27
20
  }
28
21
  componentDidMount() {
29
22
  this.props.api.eventApi.on('LiveDataChanged', this.onLiveDataChanged);
@@ -31,6 +24,13 @@ class OpenFinViewPanelComponent extends React.Component {
31
24
  componentWillUnmount() {
32
25
  this.props.api.eventApi.off('LiveDataChanged', this.onLiveDataChanged);
33
26
  }
27
+ onLiveDataChanged = (liveDataChangedInfo) => {
28
+ if (liveDataChangedInfo.reportDestination == 'OpenFin' &&
29
+ (liveDataChangedInfo.liveDataTrigger == 'Connected' ||
30
+ liveDataChangedInfo.liveDataTrigger == 'Disconnected')) {
31
+ this.forceUpdate();
32
+ }
33
+ };
34
34
  getOpenFinApi() {
35
35
  return this.props.api.pluginsApi.getOpenFinPluginApi();
36
36
  }
package/src/index.js CHANGED
@@ -30,44 +30,12 @@ const defaultOptions = {
30
30
  onValidationFailureInExcel: 'show-undo-notification',
31
31
  };
32
32
  class OpenFinPlugin extends AdaptablePlugin {
33
+ pluginId = 'openfin';
34
+ openFinApi;
35
+ OpenFinService;
36
+ openFinModule;
33
37
  constructor(options) {
34
38
  super(options);
35
- this.pluginId = 'openfin';
36
- this.rootReducer = (rootReducer) => {
37
- return {
38
- System: (state, action) => {
39
- let augmentedState = rootReducer.System(state, action);
40
- if (!state) {
41
- // required for store initialization
42
- // (idiomatic way of default parameter value in reducer is not feasible because the passed argument is already initialized by the System reducer)
43
- augmentedState = Object.assign({}, augmentedState, initialOpenFinState);
44
- }
45
- return OpenFinReducer(augmentedState, action);
46
- },
47
- };
48
- };
49
- this.reduxMiddleware = (adaptable) => (middlewareAPI) => {
50
- return (next) => {
51
- return (action) => {
52
- switch (action.type) {
53
- case OPENFIN_START_LIVE_DATA: {
54
- const actionTyped = action;
55
- this.openFinModule.startLiveData(actionTyped.openFinReport);
56
- middlewareAPI.dispatch(PopupRedux.PopupHideScreen());
57
- return next(action);
58
- }
59
- case OPENFIN_STOP_LIVE_DATA: {
60
- const actionTyped = action;
61
- this.openFinModule.stopLiveData(actionTyped.openFinReport);
62
- return next(action);
63
- }
64
- default: {
65
- return next(action);
66
- }
67
- }
68
- };
69
- };
70
- };
71
39
  this.options = {
72
40
  ...defaultOptions,
73
41
  ...options,
@@ -93,6 +61,41 @@ class OpenFinPlugin extends AdaptablePlugin {
93
61
  this.registerProperty('api', () => this.openFinApi);
94
62
  this.registerProperty('service', () => this.OpenFinService);
95
63
  }
64
+ rootReducer = (rootReducer) => {
65
+ return {
66
+ System: (state, action) => {
67
+ let augmentedState = rootReducer.System(state, action);
68
+ if (!state) {
69
+ // required for store initialization
70
+ // (idiomatic way of default parameter value in reducer is not feasible because the passed argument is already initialized by the System reducer)
71
+ augmentedState = Object.assign({}, augmentedState, initialOpenFinState);
72
+ }
73
+ return OpenFinReducer(augmentedState, action);
74
+ },
75
+ };
76
+ };
77
+ reduxMiddleware = (adaptable) => (middlewareAPI) => {
78
+ return (next) => {
79
+ return (action) => {
80
+ switch (action.type) {
81
+ case OPENFIN_START_LIVE_DATA: {
82
+ const actionTyped = action;
83
+ this.openFinModule.startLiveData(actionTyped.openFinReport);
84
+ middlewareAPI.dispatch(PopupRedux.PopupHideScreen());
85
+ return next(action);
86
+ }
87
+ case OPENFIN_STOP_LIVE_DATA: {
88
+ const actionTyped = action;
89
+ this.openFinModule.stopLiveData(actionTyped.openFinReport);
90
+ return next(action);
91
+ }
92
+ default: {
93
+ return next(action);
94
+ }
95
+ }
96
+ };
97
+ };
98
+ };
96
99
  afterInitStore(adaptable) {
97
100
  adaptable.adaptableModules.set(OpenFinModuleId, new OpenFinModule(adaptable.api));
98
101
  AdaptableViewPanelFactory.set(OpenFinModuleId, OpenFinViewPanelControl);