diff --git a/packages/backend/src/apps/miro/actions/copy-board/index.ts b/packages/backend/src/apps/miro/actions/copy-board/index.ts new file mode 100644 index 00000000..c88942d4 --- /dev/null +++ b/packages/backend/src/apps/miro/actions/copy-board/index.ts @@ -0,0 +1,116 @@ +import defineAction from '../../../../helpers/define-action'; + +export default defineAction({ + name: 'Copy board', + key: 'copyBoard', + description: 'Creates a copy of an existing board.', + arguments: [ + { + label: 'Original board', + key: 'originalBoard', + type: 'dropdown' as const, + required: true, + description: 'The board that you want to copy.', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listBoards', + }, + ], + }, + }, + { + label: 'Title', + key: 'title', + type: 'string' as const, + required: true, + description: 'Title for the board.', + variables: true, + }, + { + label: 'Description', + key: 'description', + type: 'string' as const, + required: false, + description: 'Description of the board.', + variables: true, + }, + { + label: 'Team Access', + key: 'teamAccess', + type: 'dropdown' as const, + required: false, + description: + 'Team access to the board. Can be private, view, comment or edit. Default: private.', + variables: true, + options: [ + { + label: 'Private - nobody in the team can find and access the board', + value: 'private', + }, + { + label: 'View - any team member can find and view the board', + value: 'view', + }, + { + label: 'Comment - any team member can find and comment the board', + value: 'comment', + }, + { + label: 'Edit - any team member can find and edit the board', + value: 'edit', + }, + ], + }, + { + label: 'Access Via Link', + key: 'accessViaLink', + type: 'dropdown' as const, + required: false, + description: + 'Access to the board by link. Can be private, view, comment. Default: private.', + variables: true, + options: [ + { + label: 'Private - only you have access to the board', + value: 'private', + }, + { + label: 'View - can view, no sign-in required', + value: 'view', + }, + { + label: 'Comment - can comment, no sign-in required', + value: 'comment', + }, + ], + }, + ], + + async run($) { + const params = { + copy_from: $.step.parameters.originalBoard, + }; + + const body = { + name: $.step.parameters.title, + description: $.step.parameters.description, + policy: { + sharingPolicy: { + access: $.step.parameters.accessViaLink || 'private', + teamAccess: $.step.parameters.teamAccess || 'private', + }, + }, + }; + + const { data } = await $.http.put('/v2/boards', body, { params }); + + $.setActionItem({ + raw: data, + }); + }, +}); diff --git a/packages/backend/src/apps/miro/actions/index.ts b/packages/backend/src/apps/miro/actions/index.ts index 3b3c2ee7..24f3edaf 100644 --- a/packages/backend/src/apps/miro/actions/index.ts +++ b/packages/backend/src/apps/miro/actions/index.ts @@ -1,3 +1,4 @@ +import copyBoard from './copy-board'; import createBoard from './create-board'; -export default [createBoard]; +export default [copyBoard, createBoard]; diff --git a/packages/backend/src/apps/miro/dynamic-data/index.ts b/packages/backend/src/apps/miro/dynamic-data/index.ts new file mode 100644 index 00000000..b1d11dac --- /dev/null +++ b/packages/backend/src/apps/miro/dynamic-data/index.ts @@ -0,0 +1,3 @@ +import listBoards from './list-boards'; + +export default [listBoards]; diff --git a/packages/backend/src/apps/miro/dynamic-data/list-boards/index.ts b/packages/backend/src/apps/miro/dynamic-data/list-boards/index.ts new file mode 100644 index 00000000..9ef3f55d --- /dev/null +++ b/packages/backend/src/apps/miro/dynamic-data/list-boards/index.ts @@ -0,0 +1,46 @@ +import { IGlobalVariable, IJSONObject } from '@automatisch/types'; + +type ResponseBody = { + data: { + data: { + id: number; + name: string; + }[]; + links: { + next: string; + }; + }; +}; + +export default { + name: 'List boards', + key: 'listBoards', + + async run($: IGlobalVariable) { + const boards: { + data: IJSONObject[]; + } = { + data: [], + }; + + let next; + do { + const { + data: { data, links }, + }: ResponseBody = await $.http.get('/v2/boards'); + + next = links?.next; + + if (data.length) { + for (const board of data) { + boards.data.push({ + value: board.id, + name: board.name, + }); + } + } + } while (next); + + return boards; + }, +}; diff --git a/packages/backend/src/apps/miro/index.ts b/packages/backend/src/apps/miro/index.ts index 4a253905..685bca28 100644 --- a/packages/backend/src/apps/miro/index.ts +++ b/packages/backend/src/apps/miro/index.ts @@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; import auth from './auth'; import actions from './actions'; +import dynamicData from './dynamic-data'; export default defineApp({ name: 'Miro', @@ -15,4 +16,5 @@ export default defineApp({ beforeRequest: [addAuthHeader], auth, actions, + dynamicData, }); diff --git a/packages/docs/pages/apps/miro/actions.md b/packages/docs/pages/apps/miro/actions.md index b7bd7a14..b20693f3 100644 --- a/packages/docs/pages/apps/miro/actions.md +++ b/packages/docs/pages/apps/miro/actions.md @@ -3,6 +3,8 @@ favicon: /favicons/miro.svg items: - name: Create board desc: Creates a new board. + - name: Copy board + desc: Creates a copy of an existing board. ---