Skip to content

Commit 333f89b

Browse files
authored
Nifty - Create Task Action (#16593)
* create-task * pnpm-lock.yaml * updates * updates * updates
1 parent d926afb commit 333f89b

File tree

10 files changed

+280
-28
lines changed

10 files changed

+280
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "nifty-assign-task",
55
name: "Assign Task to Team Member",
66
description: "Assigns a specific task to a team member in Nifty. [See the documentation](https://openapi.niftypm.com/api#put-api-v1-0-tasks-task_id-assignees)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
nifty,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "nifty-create-message",
66
name: "Create Message",
77
description: "Sends a new message in a team's discussion. [See the documentation](https://openapi.niftypm.com/api)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
nifty,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "nifty-create-project",
88
name: "Create Project",
99
description: "Creates a new project in a designated portfolio. [See the documentation](https://openapi.niftypm.com/api#/Projects/ProjectAPIController_createProject)",
10-
version: "0.0.1",
10+
version: "0.0.2",
1111
type: "action",
1212
props: {
1313
nifty,
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import nifty from "../../nifty.app.mjs";
2+
import { parseObjectEntries } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "nifty-create-task",
6+
name: "Create Task",
7+
description: "Creates a new task. [See the documentation](https://developers.niftypm.com/operation/operation-taskapicontroller_createtask)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
nifty,
12+
projectId: {
13+
propDefinition: [
14+
nifty,
15+
"projectId",
16+
],
17+
},
18+
taskGroupId: {
19+
propDefinition: [
20+
nifty,
21+
"taskGroupId",
22+
(c) => ({
23+
projectId: c.projectId,
24+
}),
25+
],
26+
},
27+
name: {
28+
type: "string",
29+
label: "Name",
30+
description: "The name of the task",
31+
},
32+
description: {
33+
type: "string",
34+
label: "Description",
35+
description: "A description of the task",
36+
optional: true,
37+
},
38+
parentTaskId: {
39+
propDefinition: [
40+
nifty,
41+
"taskId",
42+
(c) => ({
43+
projectId: c.projectId,
44+
}),
45+
],
46+
label: "Parent Task ID",
47+
description: "Enter a parent task ID to create this task as subtask of another task",
48+
optional: true,
49+
},
50+
milestoneId: {
51+
propDefinition: [
52+
nifty,
53+
"milestoneId",
54+
(c) => ({
55+
projectId: c.projectId,
56+
}),
57+
],
58+
},
59+
dueDate: {
60+
type: "string",
61+
label: "Due Date",
62+
description: "Due date of the task in ISO-8601 format",
63+
optional: true,
64+
},
65+
startDate: {
66+
type: "string",
67+
label: "Start Date",
68+
description: "Start date of the task in ISO-8601 format",
69+
optional: true,
70+
},
71+
assigneeIds: {
72+
propDefinition: [
73+
nifty,
74+
"memberId",
75+
],
76+
type: "string[]",
77+
label: "Assignee IDs",
78+
description: "An array of assignee IDs to assign to the task",
79+
optional: true,
80+
},
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)",
91+
optional: true,
92+
},
93+
},
94+
async run({ $ }) {
95+
const response = await this.nifty.createTask({
96+
$,
97+
data: {
98+
task_group_id: this.taskGroupId,
99+
name: this.name,
100+
description: this.description,
101+
task_id: this.parentTaskId,
102+
milestone_id: this.milestoneId,
103+
due_date: this.dueDate,
104+
start_date: this.startDate,
105+
assignee_ids: this.assigneeIds,
106+
labels: this.labelIds,
107+
...parseObjectEntries(this.additionalFields),
108+
},
109+
});
110+
$.export("$summary", `Successfully created task with ID: ${response.id}`);
111+
return response;
112+
},
113+
};

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+
}

0 commit comments

Comments
 (0)