Skip to content

Commit

Permalink
Merge pull request #4703 from Javiink/main
Browse files Browse the repository at this point in the history
feat(trello): card position and labels property for create card action
  • Loading branch information
kishanprmr committed May 16, 2024
2 parents f616382 + 13fd130 commit f7e31bb
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/trello/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-trello",
"version": "0.3.6"
"version": "0.3.7"
}
14 changes: 14 additions & 0 deletions packages/pieces/community/trello/src/lib/actions/create-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export const createCard = createAction({
displayName: 'Task Description',
required: false,
}),
position: Property.StaticDropdown({
description: 'Place the card on top or bottom of the list',
displayName: 'Position',
required: false,
options: {
options: [
{ label: 'Top', value: 'top' },
{ label: 'Bottom', value: 'bottom' },
],
},
}),
labels: trelloCommon.board_labels,
},

async run(context) {
Expand All @@ -45,6 +57,8 @@ export const createCard = createAction({
body: {
name: context.propsValue['name'],
desc: context.propsValue['description'],
pos: context.propsValue['position'],
idLabels: context.propsValue['labels'],
},
queryParams: {},
};
Expand Down
70 changes: 64 additions & 6 deletions packages/pieces/community/trello/src/lib/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const trelloCommon = {
if (!auth || !board_id) {
return {
disabled: true,
placeholder: 'connect your account first and select board',
placeholder: 'connect your account first and select a board',
options: [],
};
}
Expand All @@ -74,8 +74,6 @@ export const trelloCommon = {
board_id as string
);

console.log(lists);

return {
options: lists.map((list: { id: string; name: string }) => ({
value: list.id,
Expand All @@ -93,7 +91,7 @@ export const trelloCommon = {
if (!auth || !board_id) {
return {
disabled: true,
placeholder: 'connect your account first and select board',
placeholder: 'connect your account first and select a board',
options: [],
};
}
Expand All @@ -104,8 +102,6 @@ export const trelloCommon = {
board_id as string
);

console.log(lists);

return {
options: lists.map((list: { id: string; name: string }) => ({
value: list.id,
Expand All @@ -114,6 +110,37 @@ export const trelloCommon = {
};
},
}),
board_labels: Property.MultiSelectDropdown({
displayName: 'Labels',
description: 'Assign labels to the card',
required: false,
refreshers: ['board_id'],
options: async ({ auth, board_id }) => {
if (!auth || !board_id) {
return {
disabled: true,
placeholder: 'connect your account first and select a board',
options: [],
};
}

const basicAuthProperty = auth as BasicAuthPropertyValue;
const labels = await listBoardLabels(
basicAuthProperty.username,
basicAuthProperty.password,
board_id as string
);

return {
options: labels.map(
(label: { id: string; name: string; color: string }) => ({
label: label.name || label.color,
value: label.id,
})
),
};
},
}),
create_webhook: async (
auth: BasicAuthPropertyValue,
list_id: string,
Expand Down Expand Up @@ -243,3 +270,34 @@ async function listBoardLists(apikey: string, token: string, board_id: string) {

return response.body;
}

/**
* Gets all the labels of a board
* @param apikey API Key
* @param token API Token
* @param board_id Board to fetch labels from
* @returns JSON Array of labels
*/
async function listBoardLabels(
apikey: string,
token: string,
board_id: string
) {
const request: HttpRequest = {
method: HttpMethod.GET,
url:
`${trelloCommon.baseUrl}boards/${board_id}/labels` +
`?key=` +
apikey +
`&token=` +
token,
headers: {
Accept: 'application/json',
},
};
const response = await httpClient.sendRequest<
{ id: string; name: string; color: string }[]
>(request);

return response.body;
}

0 comments on commit f7e31bb

Please sign in to comment.