Skip to content

Commit

Permalink
Parsing status options for columns
Browse files Browse the repository at this point in the history
  • Loading branch information
GTFalcao committed Feb 11, 2025
1 parent 43a3d33 commit c1e43df
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
28 changes: 22 additions & 6 deletions components/monday/actions/common/common-create-item.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import constants from "../../common/constants.mjs";
import { capitalizeWord } from "../../common/utils.mjs";
import monday from "../../monday.app.mjs";

Expand All @@ -22,12 +21,29 @@ export default {
if (!this.columns) {
return props;
}
let options;
const columnData = await this.monday.listColumns({
boardId: +this.boardId,
});
for (const column of this.columns) {
let description;
if (column === "status") {
description = "The status of the item. [See more about status values here](https://view.monday.com/1073554546-ad9f20a427a16e67ded630108994c11b?r=use1).";
options = constants.STATUS_OPTIONS;
let description, options;
const columnOptions = columnData.find(({ id }) => id === column)?.settings_str;
if (columnOptions) {
try {
options = Object.entries(JSON.parse(columnOptions).labels).map(([
value,
label,
]) => ({
label: label !== ""
? label
: value,
value,
}));
} catch (err) {
console.log(`Error parsing options for column "${column}": ${err}`);
}
}
if (column.endsWith("status")) {
description = "A status value for the item. [See more about status values here](https://view.monday.com/1073554546-ad9f20a427a16e67ded630108994c11b?r=use1).";
} else if (column === "person") {
description = "The ID of a person/user.";
} else if (column === "date4") {
Expand Down
11 changes: 11 additions & 0 deletions components/monday/common/queries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,23 @@ export default {
boards (ids: [$boardId]) {
columns {
id
settings_str
title
type
}
}
}
`,
listColumnOptions: `
query listColumnOptions ($boardId: ID!) {
boards (ids: [$boardId]) {
columns {
id
title
}
}
}
`,
listUsers: `
query {
users (
Expand Down
11 changes: 10 additions & 1 deletion components/monday/monday.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default {
label: "Column",
description: "Select a column to watch for changes.",
async options({ boardId }) {
const columns = await this.listColumns({
const columns = await this.listColumnOptions({
boardId: +boardId,
});
return columns
Expand Down Expand Up @@ -307,6 +307,15 @@ export default {
},
});
},
async listColumnOptions(variables) {
const { data } = await this.makeRequest({
query: queries.listColumnOptions,
options: {
variables,
},
});
return data?.boards[0]?.columns;
},
async listColumns(variables) {
const { data } = await this.makeRequest({
query: queries.listColumns,
Expand Down

0 comments on commit c1e43df

Please sign in to comment.