Skip to content

Commit 1b4822b

Browse files
committed
Massive improvements to props supporting async options
1 parent 58ded28 commit 1b4822b

File tree

16 files changed

+90
-65
lines changed

16 files changed

+90
-65
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
}),
1515
],
1616
type: "string[]",
17-
description: "Select which item columns to set values for.",
17+
description: "Select which item columns to set values for",
1818
reloadProps: true,
1919
},
2020
},
@@ -26,13 +26,14 @@ export default {
2626
const columnData = await this.monday.listColumns({
2727
boardId: +this.boardId,
2828
});
29+
console.log(columnData);
2930
for (const column of this.columns) {
3031
let description, options;
3132
options = getColumnOptions(columnData, column);
3233
if (column === "person") {
33-
description = "The ID of a person/user.";
34+
description = "The ID of a person/user";
3435
} else if (column === "date4") {
35-
description = "A date string in `YYYY-MM-DD` format, e.g. `2022-09-02`.";
36+
description = "A date string in `YYYY-MM-DD` format, e.g. `2022-09-02`";
3637
} else if (options) {
3738
description = `Select a value from the list for column "${column}".`;
3839
} else {

components/monday/actions/create-column/create-column.mjs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import constants from "../../common/constants.mjs";
22
import monday from "../../monday.app.mjs";
3+
import { ConfigurationError } from "@pipedream/platform";
34

45
export default {
56
key: "monday-create-column",
67
name: "Create Column",
78
description: "Creates a column. [See the documentation](https://developer.monday.com/api-reference/reference/columns#create-a-column)",
89
type: "action",
9-
version: "0.0.9",
10+
version: "0.1.0",
1011
props: {
1112
monday,
1213
boardId: {
@@ -18,45 +19,64 @@ export default {
1819
title: {
1920
type: "string",
2021
label: "Title",
21-
description: "The title of the new column.",
22+
description: "The title of the new column",
2223
},
2324
columnType: {
2425
type: "string",
2526
label: "Column Type",
26-
description: "The type of the new column.",
27+
description: "The type of the new column",
2728
options: constants.COLUMN_TYPE_OPTIONS,
2829
reloadProps: true,
2930
},
3031
description: {
3132
type: "string",
3233
label: "Description",
33-
description: "The description of the new column.",
34+
description: "The description of the new column",
3435
optional: true,
3536
},
3637
},
3738
async additionalProps() {
3839
const props = {};
39-
const defaults = {
40-
type: "string",
41-
label: "Defaults",
42-
description: "The new column's defaults. For use with column types `status` or `dropdown`. [See the documentation](https://developer.monday.com/api-reference/reference/columns#create-a-status-or-dropdown-column-with-custom-labels) for more information.",
43-
optional: true,
44-
};
45-
if (this.columnType === "status") {
46-
props.defaults = {
47-
...defaults,
48-
default: "{\"labels\":{\"1\":\"Option1\",\"2\":\"Option2\",\"3\":\"Option3\",\"4\": \"Option4\"}}",
49-
};
50-
}
51-
if (this.columnType === "dropdown") {
40+
if ([
41+
"status",
42+
"dropdown",
43+
].includes(this.columnType)) {
5244
props.defaults = {
53-
...defaults,
54-
default: "{\"settings\":{\"labels\":[{\"id\":1,\"name\":\"Option1\"}, {\"id\":2,\"name\":\"Option2\"}, {\"id\":3,\"name\":\"Option3\"}]}}",
45+
type: "string",
46+
label: "Custom Labels (Defaults)",
47+
description: "The new column's custom labels (defaults). For use with column types `status` or `dropdown`. Should be an object in the format `{ \"1\": \"Technology\", \"2\": \"Marketing\" }` where each key is the label ID and each value is the label text. [See the documentation](https://developer.monday.com/api-reference/reference/columns#create-a-status-or-dropdown-column-with-custom-labels) for more information.",
48+
optional: true,
5549
};
5650
}
5751
return props;
5852
},
5953
async run({ $ }) {
54+
let { defaults } = this;
55+
if (defaults) {
56+
try {
57+
if (this.columnType === "status") {
58+
defaults = JSON.stringify({
59+
labels: JSON.parse(defaults),
60+
});
61+
} else if (this.columnType === "dropdown") {
62+
const obj = JSON.parse(defaults);
63+
defaults = JSON.stringify({
64+
settings: {
65+
labels: Object.entries(obj).map(([
66+
id,
67+
name,
68+
]) => ({
69+
id: Number(id),
70+
name,
71+
})),
72+
},
73+
});
74+
}
75+
} catch (err) {
76+
throw new ConfigurationError(`Error parsing \`Custom Labels\` as JSON: "${err}"`);
77+
}
78+
}
79+
$.export("debug", defaults);
6080
const {
6181
data,
6282
errors,
@@ -66,11 +86,7 @@ export default {
6686
boardId: +this.boardId,
6787
title: this.title,
6888
columnType: this.columnType,
69-
defaults: this.defaults
70-
? typeof this.defaults !== "string"
71-
? JSON.stringify(this.defaults)
72-
: this.defaults
73-
: undefined,
89+
defaults,
7490
description: this.description,
7591
});
7692

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
name: "Create Item",
99
description: "Creates an item. [See the documentation](https://developer.monday.com/api-reference/reference/items#create-an-item)",
1010
type: "action",
11-
version: "0.1.0",
11+
version: "0.1.{{ts}}",
1212
props: {
1313
monday,
1414
boardId: {

components/monday/actions/create-subitem/create-subitem.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export default {
2626
}),
2727
],
2828
optional: false,
29-
description: "Select a parent item or provide an item ID.",
29+
description: "Select a parent item or provide an item ID",
3030
},
3131
itemName: {
3232
propDefinition: [
3333
monday,
3434
"itemName",
3535
],
36-
description: "The new subitem's name.",
36+
description: "The new subitem's name",
3737
},
3838
...commonCreateItem.props,
3939
},

components/monday/actions/create-update/create-update.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default {
3333
},
3434
parentId: {
3535
label: "Parent Update ID",
36-
description: "Select a parent update or provide an update ID.",
36+
description: "Select a parent update or provide an update ID",
3737
propDefinition: [
3838
monday,
3939
"updateId",

components/monday/actions/get-column-values/get-column-values.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
],
3030
type: "string[]",
3131
label: "Columns",
32-
description: "Select the column(s) to return data from.",
32+
description: "Select the column(s) to return data from",
3333
optional: true,
3434
},
3535
},

components/monday/actions/get-items-by-column-value/get-items-by-column-value.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default {
3535
label: "Value",
3636
description: `The value to search for.${options
3737
? ""
38-
: " [See the documentation](https://developer.monday.com/api-reference/reference/items-page-by-column-values#supported-and-unsupported-columns) for additional information about column values."} `,
38+
: " [See the documentation](https://developer.monday.com/api-reference/reference/items-page-by-column-values#supported-and-unsupported-columns) for additional information about column values"} `,
3939
options,
4040
},
4141
};

components/monday/actions/update-column-values/update-column-values.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
updateInfoBox: {
1717
type: "alert",
1818
alertType: "info",
19-
content: "See the [Column types reference](https://developer.monday.com/api-reference/reference/column-types-reference) to find the proper data structures for supported column types.",
19+
content: "See the [Column types reference](https://developer.monday.com/api-reference/reference/column-types-reference) to find the proper data structures for supported column types",
2020
},
2121
boardId: {
2222
...common.props.boardId,
@@ -50,7 +50,7 @@ export default {
5050
options: getColumnOptions(columns, id),
5151
};
5252
if (column.type === "file") {
53-
props[column.id].description += ". The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).";
53+
props[column.id].description += ". The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)";
5454
}
5555
}
5656
}

components/monday/common/utils.mjs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,25 @@ export function getColumnOptions(allColumnData, columnId) {
3333
)?.settings_str;
3434
if (columnOptions) {
3535
try {
36-
return Object.entries(JSON.parse(columnOptions).labels).map(
37-
([
38-
value,
39-
label,
40-
]) => ({
41-
label: label !== ""
42-
? label
43-
: value,
44-
value,
45-
}),
46-
);
36+
const labels = JSON.parse(columnOptions).labels;
37+
return Array.isArray(labels)
38+
? labels.map(({
39+
id, name,
40+
}) => ({
41+
label: name,
42+
value: id.toString(),
43+
}))
44+
: Object.entries(labels).map(
45+
([
46+
value,
47+
label,
48+
]) => ({
49+
label: label !== ""
50+
? label
51+
: value,
52+
value,
53+
}),
54+
);
4755
} catch (err) {
4856
console.log(`Error parsing options for column "${columnId}": ${err}`);
4957
}

components/monday/monday.app.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default {
1313
boardId: {
1414
type: "string",
1515
label: "Board ID",
16-
description: "Select a board, or provide a board ID.",
16+
description: "Select a board, or provide a board ID",
1717
async options({ page }) {
1818
return this.listBoardsOptions({
1919
page: page + 1,
@@ -34,7 +34,7 @@ export default {
3434
folderId: {
3535
type: "integer",
3636
label: "Folder ID",
37-
description: "Optionally select a folder to create the board in, or provide a folder ID.",
37+
description: "Optionally select a folder to create the board in, or provide a folder ID",
3838
optional: true,
3939
async options({ workspaceId }) {
4040
return this.listFolderOptions({
@@ -45,7 +45,7 @@ export default {
4545
workspaceId: {
4646
type: "integer",
4747
label: "Workspace ID",
48-
description: "Select a workspace to create the board in, or provide a workspace ID. If not specified, the **Main Workspace** will be used.",
48+
description: "Select a workspace to create the board in, or provide a workspace ID. If not specified, the **Main Workspace** will be used",
4949
optional: true,
5050
async options() {
5151
return this.listWorkspacesOptions();
@@ -54,18 +54,18 @@ export default {
5454
templateId: {
5555
type: "integer",
5656
label: "Board Template ID",
57-
description: "The board's template ID. You can obtain it from the URL when selecting the desired board (e.g. `https://{subdomain}.monday.com/boards/2419687965`) where `2419687965` is the template ID. [See the documentation](https://developer.monday.com/api-reference/reference/boards#create-a-board) for more information.",
57+
description: "The board's template ID. You can obtain it from the URL when selecting the desired board (e.g. `https://{subdomain}.monday.com/boards/2419687965`) where `2419687965` is the template ID. [See the documentation](https://developer.monday.com/api-reference/reference/boards#create-a-board) for more information",
5858
optional: true,
5959
},
6060
groupName: {
6161
type: "string",
6262
label: "Group Name",
63-
description: "The name of the new group.",
63+
description: "The name of the new group",
6464
},
6565
groupId: {
6666
type: "string",
6767
label: "Group ID",
68-
description: "Select a group or provide a group ID.",
68+
description: "Select a group or provide a group ID",
6969
optional: true,
7070
async options({ boardId }) {
7171
return this.listGroupsOptions({
@@ -98,7 +98,7 @@ export default {
9898
itemId: {
9999
type: "string",
100100
label: "Item ID",
101-
description: "Select an item or provide an item ID.",
101+
description: "Select an item or provide an item ID",
102102
optional: true,
103103
async options({
104104
boardId, prevContext,
@@ -112,7 +112,7 @@ export default {
112112
updateId: {
113113
type: "string",
114114
label: "Update ID",
115-
description: "Select an update or provide an update ID.",
115+
description: "Select an update or provide an update ID",
116116
optional: true,
117117
async options({
118118
page, boardId,
@@ -126,7 +126,7 @@ export default {
126126
column: {
127127
type: "string",
128128
label: "Column",
129-
description: "Select a column to watch for changes.",
129+
description: "Select a column to watch for changes",
130130
async options({ boardId }) {
131131
const columns = await this.listColumnOptions({
132132
boardId: +boardId,

0 commit comments

Comments
 (0)