feat(miro): add copy board action

This commit is contained in:
Rıdvan Akca
2023-09-27 11:10:47 +03:00
committed by Faruk AYDIN
parent c2744c5569
commit a95b500e42
6 changed files with 171 additions and 1 deletions

View File

@@ -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,
});
},
});

View File

@@ -1,3 +1,4 @@
import copyBoard from './copy-board';
import createBoard from './create-board'; import createBoard from './create-board';
export default [createBoard]; export default [copyBoard, createBoard];

View File

@@ -0,0 +1,3 @@
import listBoards from './list-boards';
export default [listBoards];

View File

@@ -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;
},
};

View File

@@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header'; import addAuthHeader from './common/add-auth-header';
import auth from './auth'; import auth from './auth';
import actions from './actions'; import actions from './actions';
import dynamicData from './dynamic-data';
export default defineApp({ export default defineApp({
name: 'Miro', name: 'Miro',
@@ -15,4 +16,5 @@ export default defineApp({
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
actions, actions,
dynamicData,
}); });

View File

@@ -3,6 +3,8 @@ favicon: /favicons/miro.svg
items: items:
- name: Create board - name: Create board
desc: Creates a new board. desc: Creates a new board.
- name: Copy board
desc: Creates a copy of an existing board.
--- ---
<script setup> <script setup>