Skip to content
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

feat(trello): card position and labels property for create card action #4703

Merged
merged 3 commits into from
May 16, 2024
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 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;
}
Loading