Skip to content

Commit cbd7547

Browse files
committed
updates
1 parent e7e84dd commit cbd7547

File tree

10 files changed

+49
-23
lines changed

10 files changed

+49
-23
lines changed

components/microsoft_excel/actions/add-row/add-row.mjs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
import {
3+
parseObject, getColumnLetter,
4+
} from "../../common/utils.mjs";
25

36
export default {
47
key: "microsoft_excel-add-row",
@@ -39,23 +42,23 @@ export default {
3942
},
4043
},
4144
async run({ $ }) {
42-
const { address } = await this.microsoftExcel.getUsedRange({
45+
const {
46+
address, columnCount,
47+
} = await this.microsoftExcel.getUsedRange({
4348
$,
4449
sheetId: this.sheetId,
4550
worksheet: this.worksheet,
4651
});
4752

4853
// get next row range
4954
const match = address.match(/^(.+!)?([A-Z]+)(\d+):([A-Z]+)(\d+)$/);
50-
const [
51-
, sheet = "",
52-
colStart,
53-
/* eslint-disable no-unused-vars */
54-
rowStart,
55-
colEnd,
56-
] = match;
5755
const nextRow = parseInt(match[5], 10) + 1;
58-
const range = `${sheet}${colStart}${nextRow}:${colEnd}${nextRow}`;
56+
const values = parseObject(this.values);
57+
if (values.length < columnCount) {
58+
values.length = columnCount;
59+
}
60+
const colEnd = getColumnLetter(values.length);
61+
const range = `A${nextRow}:${colEnd}${nextRow}`;
5962

6063
// insert range
6164
await this.microsoftExcel.insertRange({
@@ -76,7 +79,7 @@ export default {
7679
range,
7780
data: {
7881
values: [
79-
this.values,
82+
values,
8083
],
8184
},
8285
});

components/microsoft_excel/actions/find-row/find-row.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default {
5757
$,
5858
sheetId: this.sheetId,
5959
worksheet: this.worksheet,
60-
range: `${this.worksheet}!${this.column}1:${this.column}${rowCount}`,
60+
range: `${this.column}1:${this.column}${rowCount}`,
6161
});
6262
const values = rangeValues.map((v) => v[0]);
6363
const index = values.indexOf(this.value);
@@ -72,7 +72,7 @@ export default {
7272
$,
7373
sheetId: this.sheetId,
7474
worksheet: this.worksheet,
75-
range: `${this.worksheet}!A${row}:${lastColumn}${row}`,
75+
range: `A${row}:${lastColumn}${row}`,
7676
});
7777

7878
$.export("$summary", `Found value in row ${row}`);

components/microsoft_excel/actions/get-columns/get-columns.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
23

34
export default {
45
key: "microsoft_excel-get-columns",
@@ -46,12 +47,13 @@ export default {
4647
});
4748

4849
const values = {};
49-
for (const column of this.columns) {
50+
const columns = parseObject(this.columns);
51+
for (const column of columns) {
5052
const response = await this.microsoftExcel.getRange({
5153
$,
5254
sheetId: this.sheetId,
5355
worksheet: this.worksheet,
54-
range: `${this.worksheet}!${column}1:${column}${rowCount}`,
56+
range: `${column}1:${column}${rowCount}`,
5557
});
5658
values[column] = response.values.map((v) => v[0]);
5759
}

components/microsoft_excel/actions/get-spreadsheet/get-spreadsheet.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646
$,
4747
sheetId: this.sheetId,
4848
worksheet: this.worksheet,
49-
range: `${this.worksheet}!${this.range}`,
49+
range: `${this.range}`,
5050
})
5151
: await this.microsoftExcel.getUsedRange({
5252
$,

components/microsoft_excel/actions/update-cell/update-cell.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default {
4848
$,
4949
sheetId: this.sheetId,
5050
worksheet: this.worksheet,
51-
range: `${this.worksheet}!${this.cell}:${this.cell}`,
51+
range: `${this.cell}:${this.cell}`,
5252
data: {
5353
values: [
5454
[

components/microsoft_excel/actions/update-worksheet-tablerow/update-worksheet-tablerow.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
23

34
export default {
45
key: "microsoft_excel-update-worksheet-tablerow",
@@ -49,7 +50,7 @@ export default {
4950
microsoftExcel,
5051
"values",
5152
],
52-
description: "Represents the raw values of the specified range. The data returned could be of type string, number, or a boolean. Cells that contain errors return the error string.",
53+
description: "An array of values for the updated row. Each item in the array represents one cell. E.g. `[1, 2, 3]`",
5354
},
5455
},
5556
async run({ $ }) {
@@ -67,7 +68,9 @@ export default {
6768
tableId,
6869
rowId,
6970
data: {
70-
values: JSON.parse(values),
71+
values: [
72+
parseObject(values),
73+
],
7174
},
7275
});
7376

components/microsoft_excel/common/utils.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ export const parseObject = (obj) => {
1616
}
1717
return obj;
1818
};
19+
20+
export function getColumnLetter(index) {
21+
let letter = "";
22+
while (index > 0) {
23+
const mod = (index - 1) % 26;
24+
letter = String.fromCharCode(65 + mod) + letter;
25+
index = Math.floor((index - 1) / 26);
26+
}
27+
return letter;
28+
}

components/microsoft_excel/microsoft_excel.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default {
176176
}) {
177177
return this._makeRequest({
178178
method: "PATCH",
179-
path: `me/drive/items/${sheetId}/workbook/tables/${tableId}/rows/itemAt(index=${rowId})`,
179+
path: `me/drive/items/${sheetId}/workbook/tables/${tableId}/rows/ItemAt(index=${rowId})`,
180180
...args,
181181
});
182182
},

components/microsoft_excel/sources/common/base-webhook.mjs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,21 @@ export default {
5353
this.db.set("deltaToken", token);
5454
},
5555
async updateSubscription() {
56-
const hookId = this._getHookId();
57-
await this.microsoftExcel.updateSubscription({
58-
hookId,
56+
try {
57+
await this.microsoftExcel.deleteHook(this._getHookId("hookId"));
58+
} catch {
59+
// couldn't find webhook
60+
}
61+
62+
const { id } = await this.microsoftExcel.createHook({
5963
data: {
64+
changeType: "updated",
65+
notificationUrl: this.http.endpoint,
66+
resource: "me/drive/root",
6067
expirationDateTime: moment().add(30, "days"),
6168
},
6269
});
70+
this._setHookId(id);
6371
},
6472
path() {
6573
return this.folderId === "root"

components/microsoft_excel/sources/new-cell-value-changed/new-cell-value-changed.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default {
3939
const response = await this.microsoftExcel.getRange({
4040
sheetId: this.sheetId,
4141
worksheet: this.worksheet,
42-
range: `${this.worksheet}!${this.cell}:${this.cell}`,
42+
range: `${this.cell}:${this.cell}`,
4343
});
4444

4545
const value = response.values[0][0];

0 commit comments

Comments
 (0)