Skip to content

Nifty - Create Task Action #16593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/nifty/actions/assign-task/assign-task.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "nifty-assign-task",
name: "Assign Task to Team Member",
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)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
nifty,
Expand Down
2 changes: 1 addition & 1 deletion components/nifty/actions/create-message/create-message.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "nifty-create-message",
name: "Create Message",
description: "Sends a new message in a team's discussion. [See the documentation](https://openapi.niftypm.com/api)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
nifty,
Expand Down
2 changes: 1 addition & 1 deletion components/nifty/actions/create-project/create-project.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "nifty-create-project",
name: "Create Project",
description: "Creates a new project in a designated portfolio. [See the documentation](https://openapi.niftypm.com/api#/Projects/ProjectAPIController_createProject)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
nifty,
Expand Down
113 changes: 113 additions & 0 deletions components/nifty/actions/create-task/create-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import nifty from "../../nifty.app.mjs";
import { parseObjectEntries } from "../../common/utils.mjs";

export default {
key: "nifty-create-task",
name: "Create Task",
description: "Creates a new task. [See the documentation](https://developers.niftypm.com/operation/operation-taskapicontroller_createtask)",
version: "0.0.1",
type: "action",
props: {
nifty,
projectId: {
propDefinition: [
nifty,
"projectId",
],
},
taskGroupId: {
propDefinition: [
nifty,
"taskGroupId",
(c) => ({
projectId: c.projectId,
}),
],
},
name: {
type: "string",
label: "Name",
description: "The name of the task",
},
description: {
type: "string",
label: "Description",
description: "A description of the task",
optional: true,
},
parentTaskId: {
propDefinition: [
nifty,
"taskId",
(c) => ({
projectId: c.projectId,
}),
],
label: "Parent Task ID",
description: "Enter a parent task ID to create this task as subtask of another task",
optional: true,
},
milestoneId: {
propDefinition: [
nifty,
"milestoneId",
(c) => ({
projectId: c.projectId,
}),
],
},
dueDate: {
type: "string",
label: "Due Date",
description: "Due date of the task in ISO-8601 format",
optional: true,
},
startDate: {
type: "string",
label: "Start Date",
description: "Start date of the task in ISO-8601 format",
optional: true,
},
assigneeIds: {
propDefinition: [
nifty,
"memberId",
],
type: "string[]",
label: "Assignee IDs",
description: "An array of assignee IDs to assign to the task",
optional: true,
},
labelIds: {
propDefinition: [
nifty,
"labelIds",
],
},
additionalFields: {
type: "object",
label: "Additional Fields",
description: "Additional fields to add to the task. [See the documentation](https://developers.niftypm.com/operation/operation-taskapicontroller_createtask)",
optional: true,
},
},
async run({ $ }) {
const response = await this.nifty.createTask({
$,
data: {
task_group_id: this.taskGroupId,
name: this.name,
description: this.description,
task_id: this.parentTaskId,
milestone_id: this.milestoneId,
due_date: this.dueDate,
start_date: this.startDate,
assignee_ids: this.assigneeIds,
labels: this.labelIds,
...parseObjectEntries(this.additionalFields),
},
});
$.export("$summary", `Successfully created task with ID: ${response.id}`);
return response;
},
};
26 changes: 26 additions & 0 deletions components/nifty/common/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,29 @@ export const clearObj = (obj) => {
: v,
}), {});
};

function optionalParseAsJSON(value) {
try {
return JSON.parse(value);
} catch (e) {
return value;
}
}

export function parseObjectEntries(value) {
if (!value) {
return {};
}
const obj = typeof value === "string"
? JSON.parse(value)
: value;
return Object.fromEntries(
Object.entries(obj).map(([
key,
value,
]) => [
key,
optionalParseAsJSON(value),
]),
);
}
Loading
Loading