@adaptabletools/adaptable-plugin-ipushpull 20.0.0-canary.6 → 20.0.0-canary.8

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-ipushpull",
3
- "version": "20.0.0-canary.6",
3
+ "version": "20.0.0-canary.8",
4
4
  "description": "",
5
5
  "homepage": "http://www.adaptabletools.com/",
6
6
  "author": {
@@ -102,58 +102,55 @@ export class PushPullModule extends AdaptableModuleBase {
102
102
  return this.ippService;
103
103
  }
104
104
  sendNewLiveData() {
105
- //we wait for the last sendNewLiveData to finish
106
- if (this.isSendingData == true) {
105
+ // We wait for the last sendNewLiveData to finish
106
+ if (this.isSendingData === true) {
107
107
  this.throttledRecomputeAndSendLiveDataEvent();
108
108
  return;
109
109
  }
110
- let currentLiveIPushPullReport = this.getIPPApi().getCurrentLiveIPushPullReport();
110
+ const currentLiveIPushPullReport = this.getIPPApi().getCurrentLiveIPushPullReport();
111
111
  if (currentLiveIPushPullReport) {
112
112
  this.isSendingData = true;
113
- let report = this.api.exportApi.getReportByName(currentLiveIPushPullReport.ReportName);
114
- let reportAsArray = this.api.exportApi.internalApi.getReportDataAsArray(report);
115
- const currentData = JSON.stringify(reportAsArray);
116
- if (currentData === this.lastData) {
117
- this.adaptable.logger.warn(EQUAL_DATA_ERR);
118
- this.isSendingData = false;
119
- return;
120
- }
121
- Promise.resolve()
122
- .then(() => {
123
- return new Promise((resolve, reject) => {
124
- if (reportAsArray) {
125
- resolve(reportAsArray);
126
- }
127
- else {
128
- reject('no data in the report');
129
- }
130
- });
113
+ this.api.exportApi
114
+ .getReportData(currentLiveIPushPullReport.ReportName, 'JSON')
115
+ .then((exportResultData) => {
116
+ if (exportResultData?.type !== 'json' || !exportResultData.data) {
117
+ throw new Error('No data in the report');
118
+ }
119
+ const reportDataAsArray = this.api.exportApi.internalApi.convertReportDataToArray(exportResultData.data);
120
+ const currentData = JSON.stringify(reportDataAsArray);
121
+ if (currentData === this.lastData) {
122
+ this.adaptable.logger.warn(EQUAL_DATA_ERR);
123
+ this.isSendingData = false;
124
+ throw new Error(EQUAL_DATA_ERR); // Using throw to exit the promise chain
125
+ }
126
+ return { reportDataAsArray, currentData };
131
127
  })
132
- .then((reportAsArray) => {
133
- return this.getIPPService().pushData(currentLiveIPushPullReport.Page, reportAsArray);
128
+ .then(({ reportDataAsArray, currentData }) => {
129
+ return this.getIPPService()
130
+ .pushData(currentLiveIPushPullReport.Page, reportDataAsArray)
131
+ .then(() => currentData); // Pass currentData to the next then
134
132
  })
135
- .then(() => {
133
+ .then((currentData) => {
136
134
  this.lastData = currentData;
135
+ this.adaptable.logger.success('All live report data sent');
136
+ this.isSendingData = false;
137
137
  return this.api.exportApi.internalApi.publishLiveLiveDataChangedEvent('ipushpull', 'LiveDataUpdated', currentLiveIPushPullReport);
138
138
  })
139
139
  .catch((reason) => {
140
- this.adaptable.logger.warn('Failed to send data to ipushpull for [' + currentLiveIPushPullReport.ReportName + ']', reason);
141
- this.stopLiveData();
142
- let errorMessage = 'Export Failed';
143
- if (reason) {
144
- errorMessage += ': ' + reason;
140
+ // Skip logging for expected cases
141
+ if (reason?.message !== EQUAL_DATA_ERR) {
142
+ this.isSendingData = false;
143
+ this.adaptable.logger.warn('Failed to send data to ipushpull for [' +
144
+ currentLiveIPushPullReport.ReportName +
145
+ ']', reason);
146
+ this.stopLiveData();
147
+ let errorMessage = 'Export Failed';
148
+ if (reason) {
149
+ errorMessage += ': ' + reason;
150
+ }
151
+ errorMessage += '. This live export has been cancelled.';
152
+ this.api.alertApi.showAlertError('ipushpull Export Error', errorMessage);
145
153
  }
146
- errorMessage += '. This live export has been cancelled.';
147
- this.api.alertApi.showAlertError('ipushpull Export Error', errorMessage);
148
- });
149
- Promise.resolve()
150
- .then(() => {
151
- this.adaptable.logger.success('All live report data sent');
152
- this.isSendingData = false;
153
- })
154
- .catch(() => {
155
- this.adaptable.logger.warn('Failed to send data');
156
- this.isSendingData = false;
157
154
  });
158
155
  }
159
156
  }
@@ -161,13 +158,16 @@ export class PushPullModule extends AdaptableModuleBase {
161
158
  this.getIPPService()
162
159
  .loadPage(iPushPullReport.Folder, iPushPullReport.Page)
163
160
  .then(() => {
164
- let report = this.api.exportApi.getReportByName(iPushPullReport.ReportName);
165
- if (report) {
166
- let reportAsArray = this.api.exportApi.internalApi.getReportDataAsArray(report);
167
- if (reportAsArray) {
168
- this.getIPPService().pushData(iPushPullReport.Page, reportAsArray);
169
- }
161
+ return this.api.exportApi.getReportData(iPushPullReport.ReportName, 'JSON');
162
+ })
163
+ .then((exportResultData) => {
164
+ if (exportResultData?.type === 'json' && exportResultData?.data) {
165
+ const reportDataAsArray = this.api.exportApi.internalApi.convertReportDataToArray(exportResultData.data);
166
+ return this.getIPPService().pushData(iPushPullReport.Page, reportDataAsArray);
170
167
  }
168
+ })
169
+ .catch((error) => {
170
+ this.adaptable.logger.warn(`Failed to send snapshot for report [${iPushPullReport.ReportName}]`, error);
171
171
  });
172
172
  }
173
173
  startLiveData(iPushPullReport) {