From 8fe77cf15aae52bf3014e3fdfa133e560a45cf8e Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 21 Dec 2022 06:55:24 +0100 Subject: [PATCH] feat: add move to drawer for script and flows --- backend/windmill-api/openapi.yaml | 1 + frontend/src/lib/components/Dropdown.svelte | 11 +-- .../src/lib/components/FolderEditor.svelte | 5 +- frontend/src/lib/components/MoveDrawer.svelte | 84 +++++++++++++++++++ frontend/src/lib/components/Path.svelte | 4 +- frontend/src/lib/components/ShareModal.svelte | 13 +-- .../components/common/table/FlowRow.svelte | 14 +++- .../components/common/table/ScriptRow.svelte | 14 +++- .../lib/components/flows/previousResults.ts | 2 +- .../src/lib/components/home/ItemsList.svelte | 25 +++--- frontend/src/lib/script_helpers.ts | 8 +- .../src/routes/flows/get/[...path].svelte | 4 +- frontend/src/routes/folders.svelte | 6 +- frontend/src/routes/groups.svelte | 8 +- frontend/src/routes/resources.svelte | 5 +- frontend/src/routes/schedules.svelte | 5 +- .../src/routes/scripts/get/[...hash].svelte | 4 +- frontend/src/routes/variables.svelte | 5 +- lsp/Pipfile | 1 + python-client/wmill/wmill/client.py | 10 +++ 20 files changed, 179 insertions(+), 50 deletions(-) create mode 100644 frontend/src/lib/components/MoveDrawer.svelte diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index af4188c2a7..0b4e8a1839 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -4275,6 +4275,7 @@ components: - hash - path - summary + - description - content - created_by - created_at diff --git a/frontend/src/lib/components/Dropdown.svelte b/frontend/src/lib/components/Dropdown.svelte index f19f9a87ff..ab8fc29a39 100644 --- a/frontend/src/lib/components/Dropdown.svelte +++ b/frontend/src/lib/components/Dropdown.svelte @@ -36,16 +36,17 @@ dispatch('click', { item: item?.eventName }) } }} - class="block w-full whitespace-nowrap hover:drop-shadow-sm hover:bg-gray-50 hover:bg-opacity-30 px-4 py-2 text-sm text-gray-700 text-left {item.separatorTop - ? 'border-t' - : ''} {item.separatorBottom ? 'border-b' : ''} {item.type == 'delete' + class="block w-full whitespace-nowrap hover:drop-shadow-sm hover:bg-gray-50 hover:bg-opacity-30 + px-4 py-2 text-sm text-gray-700 text-left + {item.disabled ? 'bg-gray-100' : ''} + {item.separatorTop ? 'border-t' : ''} {item.separatorBottom ? 'border-b' : ''} {item.type == + 'delete' ? 'text-red-500' : ''}" role="menuitem" tabindex="-1" id="user-menu-item-{name}-{i}}" disabled={item.disabled} - class:disabled={item.disabled} > {#if item.icon} { folder = await FolderService.getFolder({ workspace: $workspaceStore!, name }) - can_write = folder.owners.includes('u/' + $userStore?.username) + can_write = + folder.owners.includes('u/' + $userStore?.username) || ($userStore?.is_admin ?? false) perms = Array.from( new Set( Object.entries(folder?.extra_perms ?? {}) @@ -216,7 +217,7 @@ (scripts/flows/apps/schedules/resources/variables) inside the folder - Admin An admin of a folder has read AND write access to all the elements inside the folders and can manage the permissions as well as add new admins + import { isOwner } from '$lib/utils' + import { createEventDispatcher } from 'svelte' + import { userStore, workspaceStore } from '$lib/stores' + import { Alert, Button, Drawer } from './common' + import DrawerContent from './common/drawer/DrawerContent.svelte' + import Path from './Path.svelte' + import { FlowService, ScriptService } from '$lib/gen' + + const dispatch = createEventDispatcher() + + type Kind = 'script' | 'resource' | 'schedule' | 'variable' | 'flow' | 'app' + + let kind: Kind + let initialPath: string = '' + let path: string = '' + + let drawer: Drawer + + let own = false + export async function openDrawer(initialPath_l: string, kind_l: Kind) { + kind = kind_l + initialPath = initialPath_l + drawer.openDrawer() + } + + $: $userStore && $workspaceStore && loadOwner() + + async function loadOwner() { + own = await isOwner(path, $userStore!, $workspaceStore!) + } + + async function updatePath() { + if (kind == 'flow') { + const flow = await FlowService.getFlowByPath({ + workspace: $workspaceStore!, + path: initialPath + }) + await FlowService.updateFlow({ + workspace: $workspaceStore!, + path: initialPath, + requestBody: { + path, + summary: flow.summary, + description: flow.description, + value: flow.value + } + }) + } else if (kind == 'script') { + const script = await ScriptService.getScriptByPath({ + workspace: $workspaceStore!, + path: initialPath + }) + await ScriptService.createScript({ + workspace: $workspaceStore!, + requestBody: { + ...script, + description: script.description ?? '', + lock: script.lock?.split('\n'), + parent_hash: script.hash, + path + } + }) + } + dispatch('update', path) + drawer.closeDrawer() + } + + + + +
+

Move {initialPath} to

+ {#if !own} + Since you do not own this item, you cannot move this item(you can however fork it!) + {/if} + + +
+
+ + diff --git a/frontend/src/lib/components/Path.svelte b/frontend/src/lib/components/Path.svelte index 37b7af8c77..33ad78bee7 100644 --- a/frontend/src/lib/components/Path.svelte +++ b/frontend/src/lib/components/Path.svelte @@ -350,7 +350,7 @@ > -
+