From a90b58b6db5f32d251c4b0a81dd864660dcc1e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Tue, 16 Jan 2024 16:33:41 +0300 Subject: [PATCH 1/6] feat(google-tasks): add update task action --- .../src/apps/google-tasks/actions/index.js | 3 +- .../google-tasks/actions/update-task/index.js | 108 ++++++++++++++++++ .../apps/google-tasks/dynamic-data/index.js | 3 +- .../dynamic-data/list-tasks/index.js | 40 +++++++ .../docs/pages/apps/google-tasks/actions.md | 2 + 5 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 packages/backend/src/apps/google-tasks/actions/update-task/index.js create mode 100644 packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js diff --git a/packages/backend/src/apps/google-tasks/actions/index.js b/packages/backend/src/apps/google-tasks/actions/index.js index 62c5889b..5a5941db 100644 --- a/packages/backend/src/apps/google-tasks/actions/index.js +++ b/packages/backend/src/apps/google-tasks/actions/index.js @@ -1,3 +1,4 @@ import findTask from './find-task/index.js'; +import updateTask from './update-task/index.js'; -export default [findTask]; +export default [findTask, updateTask]; diff --git a/packages/backend/src/apps/google-tasks/actions/update-task/index.js b/packages/backend/src/apps/google-tasks/actions/update-task/index.js new file mode 100644 index 00000000..e38aefaf --- /dev/null +++ b/packages/backend/src/apps/google-tasks/actions/update-task/index.js @@ -0,0 +1,108 @@ +import defineAction from '../../../../helpers/define-action.js'; + +export default defineAction({ + name: 'Update task', + key: 'updateTask', + description: 'Updates an existing task.', + arguments: [ + { + label: 'Task List', + key: 'taskListId', + type: 'dropdown', + required: true, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTaskLists', + }, + ], + }, + }, + { + label: 'Task', + key: 'taskId', + type: 'dropdown', + required: true, + description: 'Ensure that you choose a list before proceeding.', + variables: true, + dependsOn: ['parameters.taskListId'], + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTasks', + }, + { + name: 'parameters.taskListId', + value: '{parameters.taskListId}', + }, + ], + }, + }, + { + label: 'Title', + key: 'title', + type: 'string', + required: false, + description: 'Provide a new title for the revised task.', + variables: true, + }, + { + label: 'Status', + key: 'status', + type: 'dropdown', + required: false, + description: + 'Specify the status of the updated task. If you opt for a custom value, enter either "needsAttention" or "completed."', + variables: true, + options: [ + { label: 'Incomplete', value: 'needsAction' }, + { label: 'Complete', value: 'completed' }, + ], + }, + { + label: 'Notes', + key: 'notes', + type: 'string', + required: false, + description: 'Provide a note for the revised task.', + variables: true, + }, + { + label: 'Due Date', + key: 'due', + type: 'string', + required: false, + description: + 'Specify the deadline for the task (as a RFC 3339 timestamp).', + variables: true, + }, + ], + + async run($) { + const { taskListId, taskId, title, status, notes, due } = $.step.parameters; + + const body = { + title, + status, + notes, + due, + }; + + const { data } = await $.http.patch( + `/tasks/v1/lists/${taskListId}/tasks/${taskId}`, + body + ); + + $.setActionItem({ + raw: data, + }); + }, +}); diff --git a/packages/backend/src/apps/google-tasks/dynamic-data/index.js b/packages/backend/src/apps/google-tasks/dynamic-data/index.js index 4ef1c1a9..71940ffd 100644 --- a/packages/backend/src/apps/google-tasks/dynamic-data/index.js +++ b/packages/backend/src/apps/google-tasks/dynamic-data/index.js @@ -1,3 +1,4 @@ import listTaskLists from './list-task-lists/index.js'; +import listTasks from './list-tasks/index.js'; -export default [listTaskLists]; +export default [listTaskLists, listTasks]; diff --git a/packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js b/packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js new file mode 100644 index 00000000..534dbdbb --- /dev/null +++ b/packages/backend/src/apps/google-tasks/dynamic-data/list-tasks/index.js @@ -0,0 +1,40 @@ +export default { + name: 'List tasks', + key: 'listTasks', + + async run($) { + const tasks = { + data: [], + }; + const taskListId = $.step.parameters.taskListId; + + const params = { + maxResults: 100, + pageToken: undefined, + }; + + if (!taskListId) { + return tasks; + } + + do { + const { data } = await $.http.get(`/tasks/v1/lists/${taskListId}/tasks`, { + params, + }); + params.pageToken = data.nextPageToken; + + if (data.items) { + for (const task of data.items) { + if (task.title !== '') { + tasks.data.push({ + value: task.id, + name: task.title, + }); + } + } + } + } while (params.pageToken); + + return tasks; + }, +}; diff --git a/packages/docs/pages/apps/google-tasks/actions.md b/packages/docs/pages/apps/google-tasks/actions.md index 118f2a77..f53be795 100644 --- a/packages/docs/pages/apps/google-tasks/actions.md +++ b/packages/docs/pages/apps/google-tasks/actions.md @@ -3,6 +3,8 @@ favicon: /favicons/google-tasks.svg items: - name: Find task desc: Looking for an incomplete task. + - name: Update task + desc: Updates an existing task. --- + + From cab040c74a0d7444b67432c8a5acebf27f00e4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Tue, 16 Jan 2024 17:25:25 +0300 Subject: [PATCH 5/6] feat(google-tasks): add new tasks trigger --- .../src/apps/google-tasks/triggers/index.js | 3 +- .../google-tasks/triggers/new-tasks/index.js | 53 +++++++++++++++++++ .../docs/pages/apps/google-tasks/triggers.md | 2 + 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js diff --git a/packages/backend/src/apps/google-tasks/triggers/index.js b/packages/backend/src/apps/google-tasks/triggers/index.js index 6b2b05ca..41a30e9d 100644 --- a/packages/backend/src/apps/google-tasks/triggers/index.js +++ b/packages/backend/src/apps/google-tasks/triggers/index.js @@ -1,3 +1,4 @@ import newTaskLists from './new-task-lists/index.js'; +import newTasks from './new-tasks/index.js'; -export default [newTaskLists]; +export default [newTaskLists, newTasks]; diff --git a/packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js b/packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js new file mode 100644 index 00000000..0b88b330 --- /dev/null +++ b/packages/backend/src/apps/google-tasks/triggers/new-tasks/index.js @@ -0,0 +1,53 @@ +import defineTrigger from '../../../../helpers/define-trigger.js'; + +export default defineTrigger({ + name: 'New tasks', + key: 'newTasks', + pollInterval: 15, + description: 'Triggers when a new task is created.', + arguments: [ + { + label: 'Task List', + key: 'taskListId', + type: 'dropdown', + required: true, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTaskLists', + }, + ], + }, + }, + ], + + async run($) { + const taskListId = $.step.parameters.taskListId; + + const params = { + maxResults: 100, + pageToken: undefined, + }; + + do { + const { data } = await $.http.get(`/tasks/v1/lists/${taskListId}/tasks`); + params.pageToken = data.nextPageToken; + + if (data.items?.length) { + for (const task of data.items) { + $.pushTriggerItem({ + raw: task, + meta: { + internalId: task.etag, + }, + }); + } + } + } while (params.pageToken); + }, +}); diff --git a/packages/docs/pages/apps/google-tasks/triggers.md b/packages/docs/pages/apps/google-tasks/triggers.md index b92a3bd8..ad8ed507 100644 --- a/packages/docs/pages/apps/google-tasks/triggers.md +++ b/packages/docs/pages/apps/google-tasks/triggers.md @@ -3,6 +3,8 @@ favicon: /favicons/google-tasks.svg items: - name: New task lists desc: Triggers when a new task list is created. + - name: New tasks + desc: Triggers when a new task is created. ---