Skip to content

Commit

Permalink
Merge pull request #4663 from founderblocks-sils/patch-1
Browse files Browse the repository at this point in the history
feat(clickup): Assignee Dropdown for Create Comment Action
  • Loading branch information
abuaboud committed May 13, 2024
2 parents 58baa6b + c2165a2 commit ef15c33
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/clickup/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-clickup",
"version": "0.5.11"
"version": "0.5.12"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,30 @@ export const createClickupTaskComment = createAction({
displayName: 'Comment',
required: true,
}),
assignee_id: clickupCommon.single_assignee_id(
false,
'Assignee Id',
'ID of assignee for Task Comment'
),
},
async run(configValue) {
const { task_id, comment } = configValue.propsValue;

const user_request = await callClickUpApi(
HttpMethod.GET,
`/user`,
getAccessTokenOrThrow(configValue.auth),
{}
);
let assignee_id = configValue.propsValue.assignee_id;

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(
Expand All @@ -39,7 +50,7 @@ export const createClickupTaskComment = createAction({
getAccessTokenOrThrow(configValue.auth),
{
comment_text: comment,
assignee: user_request.body['user']['id'],
assignee: assignee_id,
notify_all: true,
}
);
Expand Down
101 changes: 73 additions & 28 deletions packages/pieces/community/clickup/src/lib/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -161,7 +164,7 @@ export const clickupCommon = {
}),
};
},
})
});
},
field_id: (required = false) =>
Property.Dropdown({
Expand All @@ -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) => {
Expand All @@ -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',
Expand Down Expand Up @@ -226,7 +231,7 @@ export const clickupCommon = {
}),
};
},
})
});
},
priority_id: (required = false) =>
Property.StaticDropdown({
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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),
];
Expand All @@ -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) {
Expand Down Expand Up @@ -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<string, unknown>
type_config: Record<string, unknown>;
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<{
Expand Down Expand Up @@ -504,9 +549,9 @@ export async function callClickUpApi<T extends HttpMessageBody = any>(
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<HttpResponse<T>> {
return await httpClient.sendRequest<T>({
method: method,
Expand All @@ -517,6 +562,6 @@ export async function callClickUpApi<T extends HttpMessageBody = any>(
},
headers,
body,
queryParams
})
queryParams,
});
}

0 comments on commit ef15c33

Please sign in to comment.