Skip to content

Commit c1e43df

Browse files
committed
Parsing status options for columns
1 parent 43a3d33 commit c1e43df

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

components/monday/actions/common/common-create-item.mjs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import constants from "../../common/constants.mjs";
21
import { capitalizeWord } from "../../common/utils.mjs";
32
import monday from "../../monday.app.mjs";
43

@@ -22,12 +21,29 @@ export default {
2221
if (!this.columns) {
2322
return props;
2423
}
25-
let options;
24+
const columnData = await this.monday.listColumns({
25+
boardId: +this.boardId,
26+
});
2627
for (const column of this.columns) {
27-
let description;
28-
if (column === "status") {
29-
description = "The status of the item. [See more about status values here](https://view.monday.com/1073554546-ad9f20a427a16e67ded630108994c11b?r=use1).";
30-
options = constants.STATUS_OPTIONS;
28+
let description, options;
29+
const columnOptions = columnData.find(({ id }) => id === column)?.settings_str;
30+
if (columnOptions) {
31+
try {
32+
options = Object.entries(JSON.parse(columnOptions).labels).map(([
33+
value,
34+
label,
35+
]) => ({
36+
label: label !== ""
37+
? label
38+
: value,
39+
value,
40+
}));
41+
} catch (err) {
42+
console.log(`Error parsing options for column "${column}": ${err}`);
43+
}
44+
}
45+
if (column.endsWith("status")) {
46+
description = "A status value for the item. [See more about status values here](https://view.monday.com/1073554546-ad9f20a427a16e67ded630108994c11b?r=use1).";
3147
} else if (column === "person") {
3248
description = "The ID of a person/user.";
3349
} else if (column === "date4") {

components/monday/common/queries.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,23 @@ export default {
9898
boards (ids: [$boardId]) {
9999
columns {
100100
id
101+
settings_str
101102
title
102103
type
103104
}
104105
}
105106
}
106107
`,
108+
listColumnOptions: `
109+
query listColumnOptions ($boardId: ID!) {
110+
boards (ids: [$boardId]) {
111+
columns {
112+
id
113+
title
114+
}
115+
}
116+
}
117+
`,
107118
listUsers: `
108119
query {
109120
users (

components/monday/monday.app.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default {
128128
label: "Column",
129129
description: "Select a column to watch for changes.",
130130
async options({ boardId }) {
131-
const columns = await this.listColumns({
131+
const columns = await this.listColumnOptions({
132132
boardId: +boardId,
133133
});
134134
return columns
@@ -307,6 +307,15 @@ export default {
307307
},
308308
});
309309
},
310+
async listColumnOptions(variables) {
311+
const { data } = await this.makeRequest({
312+
query: queries.listColumnOptions,
313+
options: {
314+
variables,
315+
},
316+
});
317+
return data?.boards[0]?.columns;
318+
},
310319
async listColumns(variables) {
311320
const { data } = await this.makeRequest({
312321
query: queries.listColumns,

0 commit comments

Comments
 (0)