Skip to content

Commit ba3b874

Browse files
committed
updates
1 parent a8416fb commit ba3b874

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

components/nifty/actions/create-task/create-task.mjs

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

34
export default {
45
key: "nifty-create-task",
@@ -34,12 +35,6 @@ export default {
3435
description: "A description of the task",
3536
optional: true,
3637
},
37-
order: {
38-
type: "integer",
39-
label: "Order",
40-
description: "The order of the task",
41-
optional: true,
42-
},
4338
parentTaskId: {
4439
propDefinition: [
4540
nifty,
@@ -83,10 +78,16 @@ export default {
8378
description: "An array of assignee IDs to assign to the task",
8479
optional: true,
8580
},
86-
labels: {
87-
type: "string[]",
88-
label: "Labels",
89-
description: "An array of labels to add to the task",
81+
labelIds: {
82+
propDefinition: [
83+
nifty,
84+
"labelIds",
85+
],
86+
},
87+
additionalFields: {
88+
type: "object",
89+
label: "Additional Fields",
90+
description: "Additional fields to add to the task. [See the documentation](https://developers.niftypm.com/operation/operation-taskapicontroller_createtask)",
9091
optional: true,
9192
},
9293
},
@@ -97,13 +98,13 @@ export default {
9798
task_group_id: this.taskGroupId,
9899
name: this.name,
99100
description: this.description,
100-
order: this.order,
101101
task_id: this.parentTaskId,
102102
milestone_id: this.milestoneId,
103103
due_date: this.dueDate,
104104
start_date: this.startDate,
105105
assignee_ids: this.assigneeIds,
106-
labels: this.labels,
106+
labels: this.labelIds,
107+
...parseObjectEntries(this.additionalFields),
107108
},
108109
});
109110
$.export("$summary", `Successfully created task with ID: ${response.id}`);

components/nifty/common/utils.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,29 @@ export const clearObj = (obj) => {
1414
: v,
1515
}), {});
1616
};
17+
18+
function optionalParseAsJSON(value) {
19+
try {
20+
return JSON.parse(value);
21+
} catch (e) {
22+
return value;
23+
}
24+
}
25+
26+
export function parseObjectEntries(value) {
27+
if (!value) {
28+
return {};
29+
}
30+
const obj = typeof value === "string"
31+
? JSON.parse(value)
32+
: value;
33+
return Object.fromEntries(
34+
Object.entries(obj).map(([
35+
key,
36+
value,
37+
]) => [
38+
key,
39+
optionalParseAsJSON(value),
40+
]),
41+
);
42+
}

components/nifty/nifty.app.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ export default {
155155
})) || [];
156156
},
157157
},
158+
labelIds: {
159+
type: "string[]",
160+
label: "Label IDs",
161+
description: "An array of unique identifiers for the labels",
162+
optional: true,
163+
async options({ page }) {
164+
const { items } = await this.listLabels({
165+
params: {
166+
limit: LIMIT,
167+
offset: LIMIT * page,
168+
type: "others",
169+
},
170+
});
171+
172+
return items.map(({
173+
id: value, name: label,
174+
}) => ({
175+
label,
176+
value,
177+
}));
178+
},
179+
},
158180
},
159181
methods: {
160182
_baseUrl() {
@@ -240,6 +262,12 @@ export default {
240262
...opts,
241263
});
242264
},
265+
listLabels(opts = {}) {
266+
return this._makeRequest({
267+
path: "/labels",
268+
...opts,
269+
});
270+
},
243271
createHook(opts = {}) {
244272
return this._makeRequest({
245273
method: "POST",

0 commit comments

Comments
 (0)