From 6e165df01fcc9ed6758201523bcbf3289b19dee2 Mon Sep 17 00:00:00 2001 From: Lasse Schuirmann Date: Fri, 10 May 2024 09:37:00 +0200 Subject: [PATCH 1/2] clickup, create task comment: Allow setting assignee I've kept the original (weird) behaviour of setting the API user as assignee by default to not break past scenarios. --- .../actions/comments/create-task-comment.ts | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts b/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts index 7b9eef820c..6ccc00cc92 100644 --- a/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts +++ b/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts @@ -18,19 +18,24 @@ export const createClickupTaskComment = createAction({ displayName: 'Comment', required: true, }), + assignee_id: clickupCommon.assignee_id(), }, async run(configValue) { - const { task_id, comment } = configValue.propsValue; + const { task_id, comment, assignee_id } = configValue.propsValue; - const user_request = await callClickUpApi( - HttpMethod.GET, - `/user`, - getAccessTokenOrThrow(configValue.auth), - {} - ); + if (!assignee_id) { + const user_request = await callClickUpApi( + HttpMethod.GET, + `/user`, + getAccessTokenOrThrow(configValue.auth), + {} + ); + + if (user_request.body['user'] === undefined) { + throw 'Please connect to your ClickUp account'; + } - if (user_request.body['user'] === undefined) { - throw 'Please connect to your ClickUp account'; + assignee_id = user_request.body['user']['id']; } const response = await callClickUpApi( @@ -39,7 +44,7 @@ export const createClickupTaskComment = createAction({ getAccessTokenOrThrow(configValue.auth), { comment_text: comment, - assignee: user_request.body['user']['id'], + assignee: assignee_id, notify_all: true, } ); From c2165a26846bd2d555c9309a3c64de898cbd3fb7 Mon Sep 17 00:00:00 2001 From: Kishan Parmar Date: Mon, 13 May 2024 13:30:31 +0530 Subject: [PATCH 2/2] feat(clickup): add single assignee dropdwon --- .../pieces/community/clickup/package.json | 2 +- .../actions/comments/create-task-comment.ts | 12 ++- .../community/clickup/src/lib/common/index.ts | 101 +++++++++++++----- 3 files changed, 83 insertions(+), 32 deletions(-) diff --git a/packages/pieces/community/clickup/package.json b/packages/pieces/community/clickup/package.json index 8b422a21da..42ab8852d1 100644 --- a/packages/pieces/community/clickup/package.json +++ b/packages/pieces/community/clickup/package.json @@ -1,4 +1,4 @@ { "name": "@activepieces/piece-clickup", - "version": "0.5.11" + "version": "0.5.12" } \ No newline at end of file diff --git a/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts b/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts index 6ccc00cc92..8c4488c3db 100644 --- a/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts +++ b/packages/pieces/community/clickup/src/lib/actions/comments/create-task-comment.ts @@ -18,10 +18,16 @@ export const createClickupTaskComment = createAction({ displayName: 'Comment', required: true, }), - assignee_id: clickupCommon.assignee_id(), + assignee_id: clickupCommon.single_assignee_id( + false, + 'Assignee Id', + 'ID of assignee for Task Comment' + ), }, async run(configValue) { - const { task_id, comment, assignee_id } = configValue.propsValue; + const { task_id, comment } = configValue.propsValue; + + let assignee_id = configValue.propsValue.assignee_id; if (!assignee_id) { const user_request = await callClickUpApi( @@ -30,7 +36,7 @@ export const createClickupTaskComment = createAction({ getAccessTokenOrThrow(configValue.auth), {} ); - + if (user_request.body['user'] === undefined) { throw 'Please connect to your ClickUp account'; } diff --git a/packages/pieces/community/clickup/src/lib/common/index.ts b/packages/pieces/community/clickup/src/lib/common/index.ts index 1313e4533c..e8853f0a9f 100644 --- a/packages/pieces/community/clickup/src/lib/common/index.ts +++ b/packages/pieces/community/clickup/src/lib/common/index.ts @@ -45,7 +45,7 @@ export const clickupCommon = { }, }), space_id: (required = true, multi = false) => { - const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown + const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown; return Dropdown({ description: 'The ID of the ClickUp space to create the task in', displayName: 'Space', @@ -71,10 +71,10 @@ export const clickupCommon = { }), }; }, - }) + }); }, list_id: (required = true, multi = false) => { - const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown + const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown; return Dropdown({ description: 'The ID of the ClickUp space to create the task in', displayName: 'List', @@ -88,9 +88,12 @@ export const clickupCommon = { options: [], }; } - + const accessToken = getAccessTokenOrThrow(auth as OAuth2PropertyValue); - const lists: {name:string, id:string}[] = await listAllLists(accessToken, space_id as string) + const lists: { name: string; id: string }[] = await listAllLists( + accessToken, + space_id as string + ); return { disabled: false, @@ -102,9 +105,9 @@ export const clickupCommon = { }), }; }, - }) + }); }, - task_id: (required=true, label:string|undefined = undefined) => + task_id: (required = true, label: string | undefined = undefined) => Property.Dropdown({ description: 'The ID of the ClickUp task', displayName: label ?? 'Task Id', @@ -134,7 +137,7 @@ export const clickupCommon = { }, }), folder_id: (required = false, multi = false) => { - const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown + const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown; return Dropdown({ description: 'The ID of the ClickUp folder', displayName: 'Folder Id', @@ -161,7 +164,7 @@ export const clickupCommon = { }), }; }, - }) + }); }, field_id: (required = false) => Property.Dropdown({ @@ -174,13 +177,15 @@ export const clickupCommon = { if (!auth || !task_id || !list_id) { return { disabled: true, - placeholder: - 'connect your account first and select a task', + placeholder: 'connect your account first and select a task', options: [], }; } const accessToken = getAccessTokenOrThrow(auth as OAuth2PropertyValue); - const response = await listAccessibleCustomFields(accessToken, list_id as string); + const response = await listAccessibleCustomFields( + accessToken, + list_id as string + ); return { disabled: false, options: response.fields.map((field) => { @@ -193,7 +198,7 @@ export const clickupCommon = { }, }), status_id: (required = false, multi = false) => { - const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown + const Dropdown = multi ? Property.MultiSelectDropdown : Property.Dropdown; return Dropdown({ description: 'The ID of Clickup Issue Status', displayName: 'Status Id', @@ -226,7 +231,7 @@ export const clickupCommon = { }), }; }, - }) + }); }, priority_id: (required = false) => Property.StaticDropdown({ @@ -296,6 +301,47 @@ export const clickupCommon = { }; }, }), + single_assignee_id: ( + required = false, + displayName = 'Assignee Id', + description: string + ) => + Property.Dropdown({ + displayName: displayName, + description: description, + required, + refreshers: ['workspace_id'], + options: async ({ auth, workspace_id }) => { + if (!auth) { + return { + disabled: true, + placeholder: 'conncet your account first', + options: [], + }; + } + if (!workspace_id) { + return { + disabled: true, + placeholder: 'select workspace', + options: [], + }; + } + const accessToken = getAccessTokenOrThrow(auth as OAuth2PropertyValue); + const response = await listWorkspaceMembers( + accessToken, + workspace_id as string + ); + return { + disabled: false, + options: response.map((member) => { + return { + label: member.user.username, + value: member.user.id, + }; + }), + }; + }, + }), template_id: (required = false) => Property.Dropdown({ displayName: 'Template Id', @@ -388,10 +434,7 @@ export async function listSpaces(accessToken: string, workspaceId: string) { } export async function listAllLists(accessToken: string, spaceId: string) { - const responseFolders = await listFolders( - accessToken, - spaceId as string - ); + const responseFolders = await listFolders(accessToken, spaceId as string); const promises: Promise<{ lists: { id: string; name: string }[] }>[] = [ listFolderlessList(accessToken, spaceId as string), ]; @@ -405,7 +448,7 @@ export async function listAllLists(accessToken: string, spaceId: string) { lists = [...lists, ...listsResponses[i].lists]; } - return lists + return lists; } export async function listLists(accessToken: string, folderId: string) { @@ -440,22 +483,24 @@ export async function listFolders(accessToken: string, spaceId: string) { ).body; } -export async function listAccessibleCustomFields(accessToken: string, listId: string) { +export async function listAccessibleCustomFields( + accessToken: string, + listId: string +) { return ( await callClickUpApi<{ fields: { id: string; name: string; type: string; - type_config: Record + type_config: Record; date_created: string; - hide_from_guests: false + hide_from_guests: false; }[]; }>(HttpMethod.GET, `list/${listId}/field`, accessToken, undefined) ).body; } - async function listFolderlessList(accessToken: string, spaceId: string) { return ( await callClickUpApi<{ @@ -504,9 +549,9 @@ export async function callClickUpApi( method: HttpMethod, apiUrl: string, accessToken: string, - body: any|undefined, - queryParams: any|undefined = undefined, - headers: any|undefined = undefined + body: any | undefined, + queryParams: any | undefined = undefined, + headers: any | undefined = undefined ): Promise> { return await httpClient.sendRequest({ method: method, @@ -517,6 +562,6 @@ export async function callClickUpApi( }, headers, body, - queryParams - }) + queryParams, + }); }