@adaptabletools/adaptable-plugin-openfin 11.0.8 → 11.1.1-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptabletools/adaptable-plugin-openfin",
3
- "version": "11.0.8",
3
+ "version": "11.1.1-canary.0",
4
4
  "description": "",
5
5
  "homepage": "http://www.adaptabletools.com/",
6
6
  "author": {
@@ -20,6 +20,6 @@
20
20
  "redux": "4.0.5",
21
21
  "styled-components": "^4.4.1",
22
22
  "tslib": "^2.0.0",
23
- "@adaptabletools/adaptable": "11.0.8"
23
+ "@adaptabletools/adaptable": "11.1.1-canary.0"
24
24
  }
25
25
  }
@@ -160,125 +160,190 @@ class OpenFinModule extends AdaptableModuleBase_1.AdaptableModuleBase {
160
160
  const openFinService = this.getOpenFinService();
161
161
  this.removeSheetChangedListener = openFinService.on('sheetchanged', (event) => {
162
162
  const { data } = event;
163
- const { address, row, column, value } = data;
164
- if (address.split(':').length === 1) {
165
- // update on only 1 cell
166
- const columns = this.getCurrentReportColumns();
167
- const primaryKeyColumnId = this.adaptable.adaptableOptions.primaryKey;
168
- const primaryKeyColumnIndex = columns.findIndex((c) => c.columnId === primaryKeyColumnId);
169
- openFinService.getRowContents(row, columns.length).then((rowValues) => {
170
- var _a, _b, _c;
171
- const primaryKey = primaryKeyColumnIndex != -1 ? rowValues[primaryKeyColumnIndex] : null;
172
- const rowNode = this.api.gridApi.getRowNodeForPrimaryKey(primaryKey);
173
- const col = columns[column - 1];
174
- const columnId = col.columnId;
175
- const columnIsPrimaryKey = columnId === primaryKeyColumnId;
176
- if (rowNode && !columnIsPrimaryKey) {
177
- if (this.api.columnApi.getColumnFromId(columnId).readOnly) {
178
- logger_1.LogAdaptableWarning(`Can't update column ${columnId} as it is read-only`);
179
- }
180
- else if (!this.adaptable.isCellEditable(rowNode, this.adaptable.api.columnApi.getAgGridColumnForAdaptableColumn(columnId))) {
181
- logger_1.LogAdaptableWarning(`Can't update column cell in ${columnId} as it is read-only`);
163
+ const { row, column, width = 1, height = 1 } = data;
164
+ if (row === 1) {
165
+ //its an event coming from adaptable, so no need to do extra processing
166
+ return;
167
+ }
168
+ // if (address.split(':').length === 1) {
169
+ // update on only 1 cell
170
+ const columns = this.getCurrentReportColumns();
171
+ const primaryKeyColumnId = this.adaptable.adaptableOptions.primaryKey;
172
+ const primaryKeyColumnIndex = columns.findIndex((c) => c.columnId === primaryKeyColumnId);
173
+ const rows = [];
174
+ for (let r = 0; r < height; r++) {
175
+ rows.push(row + r);
176
+ }
177
+ const cols = [];
178
+ for (let c = 0; c < width; c++) {
179
+ cols.push(column + c);
180
+ }
181
+ const promises = rows.map((row) => {
182
+ return new Promise((resolveTop, rejectTop) => {
183
+ openFinService.getRowContents(row, columns.length).then((rowValues) => {
184
+ const primaryKey = primaryKeyColumnIndex != -1 ? rowValues[primaryKeyColumnIndex] : null;
185
+ const rowNode = this.api.gridApi.getRowNodeForPrimaryKey(primaryKey);
186
+ if (!rowNode || cols.includes(primaryKeyColumnIndex + 1)) {
187
+ // rejectTop(false);
188
+ resolveTop({
189
+ success: false,
190
+ failedValidationRules: [],
191
+ dataChangedInfos: [],
192
+ });
193
+ return;
182
194
  }
183
- else {
184
- const dataChangedInfo = this.api.internalApi.buildDataChangedInfo({
185
- oldValue: rowNode.data[columnId],
186
- newValue: value,
187
- column: this.api.columnApi.getColumnFromId(columnId),
188
- primaryKeyValue: primaryKey,
189
- rowNode,
190
- trigger: 'tick',
195
+ const promises = cols.map((column) => {
196
+ return new Promise((resolve, reject) => {
197
+ const newValue = rowValues[column - 1];
198
+ const col = columns[column - 1];
199
+ const columnId = col.columnId;
200
+ const columnIsPrimaryKey = columnId === primaryKeyColumnId;
201
+ const oldValue = rowNode.data[columnId];
202
+ if (newValue === undefined || newValue == oldValue) {
203
+ return resolve({ ignore: true });
204
+ }
205
+ if (columnIsPrimaryKey) {
206
+ return reject(`Cant edit a primary key column`);
207
+ // return resolve({ ignore: true });
208
+ }
209
+ if (this.api.columnApi.getColumnFromId(columnId).readOnly) {
210
+ const msg = `Can't update column ${columnId} as it is read-only`;
211
+ logger_1.LogAdaptableWarning(msg);
212
+ return reject(msg);
213
+ // return resolve({ ignore: true });
214
+ }
215
+ else if (!this.adaptable.isCellEditable(rowNode, this.adaptable.api.columnApi.getAgGridColumnForAdaptableColumn(columnId))) {
216
+ const msg = `Can't update column cell in ${columnId} as it is read-only`;
217
+ logger_1.LogAdaptableWarning(msg);
218
+ return reject(msg);
219
+ // return resolve({ ignore: true });
220
+ }
221
+ const dataChangedInfo = this.api.internalApi.buildDataChangedInfo({
222
+ oldValue,
223
+ newValue,
224
+ column: this.api.columnApi.getColumnFromId(columnId),
225
+ primaryKeyValue: primaryKey,
226
+ rowNode,
227
+ trigger: 'tick',
228
+ });
229
+ const failedValidationRules = this.adaptable.ValidationService.getValidationRulesForDataChange(dataChangedInfo);
230
+ if (failedValidationRules.length) {
231
+ return resolve({ failedValidationRules, dataChangedInfo });
232
+ }
233
+ resolve({ dataChangedInfo, failedValidationRules: [] });
191
234
  });
192
- const failedValidationRules = this.adaptable.ValidationService.getValidationRulesForDataChange(dataChangedInfo);
193
- const api = this.getOpenFinApi();
194
- const pluginOptions = api.getPluginOptions();
195
- if (failedValidationRules.length) {
196
- if (pluginOptions.onValidationFailureInExcel === 'override') {
197
- // push data back to excel
198
- if (this.getOpenFinApi().getCurrentLiveOpenFinReport()) {
199
- this.sendInitialLiveData();
200
- }
235
+ });
236
+ return Promise.allSettled(promises)
237
+ .then((results) => {
238
+ return results.reduce((acc, result) => {
239
+ if (result.status === 'rejected') {
240
+ acc.success = false;
241
+ return acc;
201
242
  }
202
- if (pluginOptions.onValidationFailureInExcel === 'show-notification' ||
203
- pluginOptions.onValidationFailureInExcel === 'show-undo-notification') {
204
- const textPredicate = this.adaptable.api.scopeApi.getScopeDescription(failedValidationRules[0].Scope) +
205
- ' ' +
206
- this.adaptable.api.predicateApi.predicateToString((_a = failedValidationRules[0].Rule) === null || _a === void 0 ? void 0 : _a.Predicate);
207
- const info = Object.assign({}, dataChangedInfo);
208
- delete info.rowNode;
209
- const alertOptions = api.getAlertOptions();
210
- alertOptions.actionHandlers = (_b = alertOptions.actionHandlers) !== null && _b !== void 0 ? _b : [];
211
- if (pluginOptions.onValidationFailureInExcel === 'show-undo-notification' &&
212
- !alertOptions.actionHandlers.find((handler) => handler.name === 'openfin-plugin:excel-undo')) {
213
- alertOptions.actionHandlers.push({
214
- name: 'openfin-plugin:excel-undo',
215
- handler: (button, context) => {
216
- try {
217
- this.sendInitialLiveData(true);
218
- }
219
- catch (ex) {
220
- console.error(ex);
221
- throw ex;
222
- }
223
- },
224
- });
225
- }
226
- this.adaptable.api.alertApi.displayAlert({
227
- dataChangedInfo: info,
228
- alertDefinition: {
229
- AlertProperties: {
230
- DisplayNotification: true,
231
- },
232
- MessageType: 'Error',
233
- Scope: {
234
- All: true,
235
- },
236
- Rule: { Predicate: (_c = failedValidationRules[0].Rule) === null || _c === void 0 ? void 0 : _c.Predicate },
237
- AlertForm: {
238
- Buttons: pluginOptions.onValidationFailureInExcel === 'show-undo-notification'
239
- ? [
240
- {
241
- Label: 'Undo change',
242
- Action: 'openfin-plugin:excel-undo',
243
- },
244
- ]
245
- : [],
246
- },
247
- },
248
- header: 'Excel Validation failed',
249
- message: textPredicate,
250
- });
251
- // api.showNotification({
252
- // title: 'Validation failed',
253
- // category: 'Error',
254
- // indicator: { text: 'Validation Error', type: 'failure' },
255
- // body: textPredicate,
256
- // buttons:
257
- // pluginOptions.onValidationFailureInExcel === 'show-undo-notification'
258
- // ? [
259
- // {
260
- // title: 'Undo change',
261
- // type: 'button',
262
- // cta: true,
263
- // onClick: {
264
- // task: 'undo-edit',
265
- // },
266
- // },
267
- // ]
268
- // : [],
269
- // customData: {
270
- // name: 'validation-failed',
271
- // dataChangedInfo: info,
272
- // },
273
- // });
243
+ if (result.value.ignore) {
244
+ return acc;
274
245
  }
275
- return;
276
- }
277
- this.api.gridApi.setCellValue(columnId, value, primaryKey);
246
+ acc.failedValidationRules.push(...result.value.failedValidationRules);
247
+ acc.dataChangedInfos.push(result.value.dataChangedInfo);
248
+ return acc;
249
+ }, {
250
+ success: true,
251
+ failedValidationRules: [],
252
+ dataChangedInfos: [],
253
+ });
254
+ })
255
+ .then(resolveTop);
256
+ });
257
+ });
258
+ });
259
+ Promise.all(promises)
260
+ .then((results) => {
261
+ const failedValidationRules = [];
262
+ const dataChangedInfos = [];
263
+ return results.reduce((acc, result) => {
264
+ if (!result.success) {
265
+ acc.success = false;
266
+ }
267
+ acc.failedValidationRules.push(...result.failedValidationRules);
268
+ acc.dataChangedInfos.push(...result.dataChangedInfos);
269
+ return acc;
270
+ }, { success: true, dataChangedInfos, failedValidationRules });
271
+ })
272
+ .then(({ success, dataChangedInfos, failedValidationRules }) => {
273
+ var _a, _b, _c;
274
+ const api = this.getOpenFinApi();
275
+ const pluginOptions = api.getPluginOptions();
276
+ if (!success) {
277
+ //push data back to excel as hard error occured
278
+ if (this.getOpenFinApi().getCurrentLiveOpenFinReport()) {
279
+ this.sendInitialLiveData();
280
+ }
281
+ return;
282
+ }
283
+ if (failedValidationRules.length) {
284
+ if (pluginOptions.onValidationFailureInExcel === 'override') {
285
+ // push data back to excel
286
+ if (this.getOpenFinApi().getCurrentLiveOpenFinReport()) {
287
+ this.sendInitialLiveData();
288
+ }
289
+ }
290
+ if (pluginOptions.onValidationFailureInExcel === 'show-notification' ||
291
+ pluginOptions.onValidationFailureInExcel === 'show-undo-notification') {
292
+ const textPredicate = this.adaptable.api.scopeApi.getScopeDescription(failedValidationRules[0].Scope) +
293
+ ' ' +
294
+ this.adaptable.api.predicateApi.predicateToString((_a = failedValidationRules[0].Rule) === null || _a === void 0 ? void 0 : _a.Predicate);
295
+ const info = Object.assign({}, dataChangedInfos[0]);
296
+ delete info.rowNode;
297
+ const alertOptions = api.getAlertOptions();
298
+ alertOptions.actionHandlers = (_b = alertOptions.actionHandlers) !== null && _b !== void 0 ? _b : [];
299
+ if (pluginOptions.onValidationFailureInExcel === 'show-undo-notification' &&
300
+ !alertOptions.actionHandlers.find((handler) => handler.name === 'openfin-plugin:excel-undo')) {
301
+ alertOptions.actionHandlers.push({
302
+ name: 'openfin-plugin:excel-undo',
303
+ handler: (button, context) => {
304
+ try {
305
+ this.sendInitialLiveData(true);
306
+ }
307
+ catch (ex) {
308
+ console.error(ex);
309
+ throw ex;
310
+ }
311
+ },
312
+ });
278
313
  }
314
+ this.adaptable.api.alertApi.displayAlert({
315
+ alertType: 'cellChanged',
316
+ dataChangedInfo: info,
317
+ alertDefinition: {
318
+ AlertProperties: {
319
+ DisplayNotification: true,
320
+ },
321
+ MessageType: 'Error',
322
+ Scope: {
323
+ All: true,
324
+ },
325
+ Rule: { Predicate: (_c = failedValidationRules[0].Rule) === null || _c === void 0 ? void 0 : _c.Predicate },
326
+ AlertForm: {
327
+ Buttons: pluginOptions.onValidationFailureInExcel === 'show-undo-notification'
328
+ ? [
329
+ {
330
+ Label: 'Undo change',
331
+ Action: 'openfin-plugin:excel-undo',
332
+ },
333
+ ]
334
+ : [],
335
+ },
336
+ },
337
+ header: 'Excel Validation failed',
338
+ message: textPredicate,
339
+ });
279
340
  }
341
+ return;
342
+ }
343
+ dataChangedInfos.forEach((info) => {
344
+ this.api.gridApi.setCellValue(info.column.columnId, info.newValue, info.primaryKeyValue);
280
345
  });
281
- }
346
+ });
282
347
  });
283
348
  }
284
349
  stopLiveData(_iOpenFinReport) {
@@ -5,6 +5,8 @@ export declare type ExcelSheetChangedEvent = {
5
5
  row: number;
6
6
  column: number;
7
7
  value: string | number;
8
+ width: number;
9
+ height: number;
8
10
  };
9
11
  };
10
12
  export interface IOpenFinService {