From c1e43df7eb74ce674e1e601e9ab1a6ed93e2c8a1 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Mon, 10 Feb 2025 23:27:27 -0300 Subject: [PATCH] Parsing status options for columns --- .../actions/common/common-create-item.mjs | 28 +++++++++++++++---- components/monday/common/queries.mjs | 11 ++++++++ components/monday/monday.app.mjs | 11 +++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/components/monday/actions/common/common-create-item.mjs b/components/monday/actions/common/common-create-item.mjs index 227282ced014e..d12f90b818338 100644 --- a/components/monday/actions/common/common-create-item.mjs +++ b/components/monday/actions/common/common-create-item.mjs @@ -1,4 +1,3 @@ -import constants from "../../common/constants.mjs"; import { capitalizeWord } from "../../common/utils.mjs"; import monday from "../../monday.app.mjs"; @@ -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") { diff --git a/components/monday/common/queries.mjs b/components/monday/common/queries.mjs index d335b1fd40e5f..0792bf8738012 100644 --- a/components/monday/common/queries.mjs +++ b/components/monday/common/queries.mjs @@ -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 ( diff --git a/components/monday/monday.app.mjs b/components/monday/monday.app.mjs index 9027828f501a2..d1a62e5fcd3c7 100644 --- a/components/monday/monday.app.mjs +++ b/components/monday/monday.app.mjs @@ -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 @@ -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,