Compare commits

...

3 Commits

Author SHA1 Message Date
Rıdvan Akca
d4ddde5279 feat(asana): add find task in project action 2024-06-07 12:37:36 +02:00
Rıdvan Akca
176d056aed feat(asana): add find project action 2024-06-07 12:30:01 +02:00
Rıdvan Akca
0526ec5b06 feat(asana): add create project action 2024-06-07 12:28:14 +02:00
5 changed files with 344 additions and 1 deletions

View File

@@ -0,0 +1,216 @@
import defineAction from '../../../../helpers/define-action.js';
import omitBy from 'lodash/omitBy.js';
import isEmpty from 'lodash/isEmpty.js';
export default defineAction({
name: 'Create project',
key: 'createProject',
description: 'Creates a new project.',
arguments: [
{
label: 'Workspace',
key: 'workspaceId',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listWorkspaces',
},
],
},
},
{
label: 'Team',
key: 'teamId',
type: 'dropdown',
required: false,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listTeams',
},
{
name: 'parameters.workspaceId',
value: '{parameters.workspaceId}',
},
],
},
},
{
label: 'Due date',
key: 'dueDate',
type: 'string',
required: false,
description: 'Example due on: 2019-09-15',
variables: true,
},
{
label: 'Name',
key: 'name',
type: 'string',
required: true,
description: '',
variables: true,
},
{
label: 'Notes',
key: 'notes',
type: 'string',
required: true,
description: 'You can format the notes using html.',
variables: true,
},
{
label: 'Is the notes rich text?',
key: 'richText',
type: 'dropdown',
required: false,
description: '',
variables: true,
options: [
{
label: 'No',
value: 'false',
},
{
label: 'Yes',
value: 'true',
},
],
},
{
label: 'Default View',
key: 'defaultView',
type: 'dropdown',
required: false,
description: '',
variables: true,
options: [
{
label: 'List',
value: 'list',
},
{
label: 'Board',
value: 'board',
},
{
label: 'Calendar',
value: 'calendar',
},
{
label: 'Timeline',
value: 'timeline',
},
],
},
{
label: 'Owner',
key: 'ownerId',
type: 'dropdown',
required: false,
dependsOn: ['parameters.workspaceId'],
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listUsers',
},
{
name: 'parameters.workspaceId',
value: '{parameters.workspaceId}',
},
],
},
},
{
label: 'Followers',
key: 'followerIds',
type: 'dynamic',
required: false,
description: '',
fields: [
{
label: 'Follower',
key: 'followerId',
type: 'dropdown',
required: false,
dependsOn: ['parameters.workspaceId'],
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listUsers',
},
{
name: 'parameters.workspaceId',
value: '{parameters.workspaceId}',
},
],
},
},
],
},
],
async run($) {
const {
workspaceId,
teamId,
dueDate,
name,
notes,
richText,
defaultView,
ownerId,
followerIds,
} = $.step.parameters;
const allFollowers = followerIds
.map((followerId) => followerId.followerId)
.filter(Boolean);
const data = {
workspace: workspaceId,
team: teamId,
due_on: dueDate,
name,
default_view: defaultView,
owner: ownerId,
followers: allFollowers,
};
if (richText === 'true') {
data.html_notes = notes;
} else {
data.notes = notes;
}
const filteredData = omitBy(data, isEmpty);
const response = await $.http.post('/1.0/projects', { data: filteredData });
$.setActionItem({
raw: response.data,
});
},
});

View File

@@ -0,0 +1,49 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Find project',
key: 'findProject',
description: 'Finds an existing project.',
arguments: [
{
label: 'Workspace',
key: 'workspaceId',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listWorkspaces',
},
],
},
},
{
label: 'Name',
key: 'name',
type: 'string',
required: true,
description: '',
variables: true,
},
],
async run($) {
const { workspaceId, name } = $.step.parameters;
const { data } = await $.http.get(
`/1.0/workspaces/${workspaceId}/projects`
);
const project = data.data.find((project) => project.name === name);
$.setActionItem({
raw: project,
});
},
});

View File

@@ -0,0 +1,69 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Find task in a project',
key: 'findTaskInProject',
description: 'Finds an existing task within a project.',
arguments: [
{
label: 'Workspace',
key: 'workspaceId',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listWorkspaces',
},
],
},
},
{
label: 'Project',
key: 'projectId',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listProjects',
},
{
name: 'parameters.workspaceId',
value: '{parameters.workspaceId}',
},
],
},
},
{
label: 'Task Name',
key: 'taskName',
type: 'string',
required: true,
description: '',
variables: true,
},
],
async run($) {
const { projectId, taskName } = $.step.parameters;
const { data } = await $.http.get(`/1.0/projects/${projectId}/tasks`);
const task = data.data.find((task) => task.name === taskName);
$.setActionItem({
raw: task,
});
},
});

View File

@@ -1,3 +1,6 @@
import createProject from './create-project/index.js';
import createTask from './create-task/index.js'; import createTask from './create-task/index.js';
import findProject from './find-project/index.js';
import findTaskInProject from './find-task-in-project/index.js';
export default [createTask]; export default [createProject, createTask, findProject, findTaskInProject];

View File

@@ -1,8 +1,14 @@
--- ---
favicon: /favicons/asana.svg favicon: /favicons/asana.svg
items: items:
- name: Create project
desc: Creates a new project.
- name: Create task - name: Create task
desc: Creates a new task. desc: Creates a new task.
- name: Find project
desc: Finds an existing project.
- name: Find task in a project
desc: Finds an existing task within a project.
--- ---
<script setup> <script setup>