@adobe/helix-onedrive-support 11.0.6 → 11.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [11.1.0](https://github.com/adobe/helix-onedrive-support/compare/v11.0.6...v11.1.0) (2023-10-31)
2
+
3
+
4
+ ### Features
5
+
6
+ * support for non-persistent sessions and table filtering ([bba88fc](https://github.com/adobe/helix-onedrive-support/commit/bba88fcc3150490436af2d0944ed54a5c5517502))
7
+
1
8
  ## [11.0.6](https://github.com/adobe/helix-onedrive-support/compare/v11.0.5...v11.0.6) (2023-10-31)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-onedrive-support",
3
- "version": "11.0.6",
3
+ "version": "11.1.0",
4
4
  "description": "Helix OneDrive Support",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -145,6 +145,18 @@ function handleTable(container, segs, method, body) {
145
145
  });
146
146
  return null;
147
147
  }
148
+ if ((segs.length >= 3) && (segs[1] === 'filter') && (segs[2] === 'apply')) {
149
+ if (table.filters) {
150
+ throw new Error('Only one filter at a time supported currently!');
151
+ }
152
+ const { criteria } = JSON.parse(body);
153
+ if (criteria.filterOn !== 'values') {
154
+ throw new Error('Only value based filtering supported currently!');
155
+ }
156
+ const colName = segs[0];
157
+ table.filters = { column: colName, criteria };
158
+ return null;
159
+ }
148
160
  if (body) {
149
161
  ({ name, index = table.headerNames.length } = body);
150
162
  table.headerNames.splice(index, 0, name);
@@ -180,11 +192,25 @@ function handleTable(container, segs, method, body) {
180
192
  };
181
193
  }
182
194
  case 'range': {
195
+ if ((segs.length >= 2) && (segs[0] === 'visibleView') && (segs[1] === 'rows')) {
196
+ const colIdx = table.filters ? table.headerNames.indexOf(table.filters.column) : -1;
197
+ const result = [{ cellAddresses: [[0]], values: [table.headerNames] }];
198
+ for (const [i, row] of table.rows.entries()) {
199
+ if ((!table.filters) || table.filters.criteria.values.includes(row[colIdx])) {
200
+ result.push({ cellAddresses: [[i + 1]], values: [row] });
201
+ }
202
+ }
203
+ return { value: result };
204
+ }
183
205
  return {
184
206
  address: 'sheet!A1:B10',
185
207
  addressLocal: 'A1:B10',
186
208
  };
187
209
  }
210
+ case 'clearFilters': {
211
+ table.filters = null;
212
+ return {};
213
+ }
188
214
  default:
189
215
  if (body) {
190
216
  table.name = body.name;
@@ -388,7 +414,7 @@ export class OneDriveMock extends OneDrive {
388
414
  }
389
415
  } else if (segs[0] === 'createSession') {
390
416
  return {
391
- id: 'test-session-id',
417
+ id: JSON.parse(body).persistChanges ? 'test-session-id' : 'test-non-persistent-session-id',
392
418
  };
393
419
  } else if (segs[0] === 'refreshSession' || segs[0] === 'closeSession') {
394
420
  return {};
@@ -147,4 +147,32 @@ export class Table {
147
147
  range() {
148
148
  return new Range(this._oneDrive, `${this.uri}/range`, this._log);
149
149
  }
150
+
151
+ async clearFilters() {
152
+ await this._oneDrive.doFetch(`${this.uri}/clearFilters`, true, {
153
+ method: 'POST',
154
+ });
155
+ }
156
+
157
+ async applyFilter(column, criteria) {
158
+ await this._oneDrive.doFetch(`${this.uri}/columns/${column}/filter/apply`, true, {
159
+ method: 'POST',
160
+ body: JSON.stringify({ criteria }),
161
+ });
162
+ }
163
+
164
+ async getVisibleRowsAsObjectsWithAddresses(maxRows = -1) {
165
+ // +1 to maxRows since result is inclusive of header
166
+ const pathSuffix = maxRows !== -1 ? `?$top=${maxRows + 1}` : '';
167
+ const path = `${this.uri}/range/visibleView/rows${pathSuffix}`;
168
+ const resp = await this._oneDrive.doFetch(path);
169
+ const headers = resp.value.shift().values[0];
170
+ return resp.value.map((row) => ({
171
+ cellAddresses: row.cellAddresses[0],
172
+ data: headers.reduce(
173
+ (rowObj, colName, colIdx, _) => ({ ...rowObj, [colName]: row.values[0][colIdx] }),
174
+ {},
175
+ ),
176
+ }));
177
+ }
150
178
  }
@@ -23,13 +23,15 @@ export class Workbook extends NamedItemContainer {
23
23
  this._log = log;
24
24
  }
25
25
 
26
- async createSession() {
26
+ async createSession(persistChanges = true) {
27
27
  if (this._sessionId) {
28
28
  throw new StatusCodeError('This workbook is already associated with a session', 400);
29
29
  }
30
30
  const uri = `${this.uri}/createSession`;
31
31
  const result = await this._oneDrive.doFetch(uri, false, {
32
32
  method: 'POST',
33
+ headers: { 'Content-Type': 'application/json' },
34
+ body: JSON.stringify({ persistChanges }),
33
35
  });
34
36
  this._sessionId = result.id;
35
37
  return this._sessionId;