From 605afca3b89dce5e2fda61c97fda22f920d08acf Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 22 Jun 2023 00:19:25 +0200 Subject: [PATCH] feat: editable resource types + rt in deployments --- backend/windmill-api/openapi.yaml | 3 +- .../src/lib/components/DeployWorkspace.svelte | 63 +++++++++-- .../src/lib/components/jobs/JobPreview.svelte | 2 +- .../(root)/(logged)/resources/+page.svelte | 101 ++++++++++++++++-- 4 files changed, 151 insertions(+), 18 deletions(-) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index f8875d4a18..58402eea54 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -6338,8 +6338,7 @@ components: EditResourceType: type: object properties: - schema: - type: string + schema: {} description: type: string diff --git a/frontend/src/lib/components/DeployWorkspace.svelte b/frontend/src/lib/components/DeployWorkspace.svelte index ab9eec8e3f..227f68c9ef 100644 --- a/frontend/src/lib/components/DeployWorkspace.svelte +++ b/frontend/src/lib/components/DeployWorkspace.svelte @@ -23,7 +23,15 @@ const dispatch = createEventDispatcher() - type Kind = 'script' | 'resource' | 'schedule' | 'variable' | 'flow' | 'app' | 'raw_app' + type Kind = + | 'script' + | 'resource' + | 'schedule' + | 'variable' + | 'flow' + | 'app' + | 'raw_app' + | 'resource_type' export let kind: Kind export let initialPath: string = '' @@ -60,7 +68,10 @@ dependencies = (await getDependencies(kind, path)).map((x) => ({ ...x, include: - kind == 'variable' || kind == 'resource' || (x.kind != 'variable' && x.kind != 'resource') + kind == 'variable' || + kind == 'resource' || + kind == 'resource_type' || + (x.kind != 'variable' && x.kind != 'resource' && x.kind != 'resource_type') })) dependencies.forEach((x) => { checkAlreadyExists(x.kind, x.path).then( @@ -123,9 +134,8 @@ } } - return recObj(res.value) + return [...recObj(res.value), { kind: 'resource_type', path: res.resource_type }] } - return [] } let toProcess = [{ kind, path }] @@ -176,6 +186,11 @@ workspace: workspaceToDeployTo!, path: path }) + } else if (kind == 'resource_type') { + return await ResourceService.existsResourceType({ + workspace: workspaceToDeployTo!, + path: path + }) } else { throw new Error(`Unknown kind ${kind}`) } @@ -313,6 +328,30 @@ } }) } + } else if (kind == 'resource_type') { + const resource = await ResourceService.getResourceType({ + workspace: $workspaceStore!, + path: path + }) + if (alreadyExists) { + await ResourceService.updateResourceType({ + workspace: workspaceToDeployTo!, + path: path, + requestBody: { + schema: resource.schema, + description: resource.description ?? '' + } + }) + } else { + await ResourceService.createResourceType({ + workspace: workspaceToDeployTo!, + requestBody: { + description: resource.description ?? '', + schema: resource.schema, + name: resource.name + } + }) + } } else if (kind == 'raw_app') { throw new Error('Raw app deploy not implemented yet') // const app = await RawAppService.getRawAppData({ @@ -393,6 +432,12 @@ path: path }) return resource.value + } else if (kind == 'resource_type') { + const resource = await ResourceService.getResourceType({ + workspace: workspace, + path: path + }) + return resource.schema } else if (kind == 'raw_app') { throw new Error('Raw app deploy not implemented yet') // const app = await RawAppService.getRawAppData({ @@ -473,8 +518,14 @@ Missing This {kind} doesn't exist and is not included in the deployment. Variable and Resources - are considered to be workspace specific and are never included by default.{#if kind == 'resource_type'} + Resource types are not re-deployed by default. We strongly recommend to add + shared resource types in 'admin' workspace, which will have them be shared to + every workspace. + {:else} + This {kind} doesn't exist and is not included in the deployment. Variables and Resources + are considered to be workspace specific and are never included by default. + {/if} {/if} diff --git a/frontend/src/lib/components/jobs/JobPreview.svelte b/frontend/src/lib/components/jobs/JobPreview.svelte index eb43f65111..482d4d15e8 100644 --- a/frontend/src/lib/components/jobs/JobPreview.svelte +++ b/frontend/src/lib/components/jobs/JobPreview.svelte @@ -16,7 +16,7 @@ import { faHourglassHalf } from '@fortawesome/free-solid-svg-icons' import { Badge } from '../common' - const POPUP_HEIGHT = 240 as const + const POPUP_HEIGHT = 320 as const export let id: string let job: Job | undefined = undefined diff --git a/frontend/src/routes/(root)/(logged)/resources/+page.svelte b/frontend/src/routes/(root)/(logged)/resources/+page.svelte index e2932dbf54..a694165385 100644 --- a/frontend/src/routes/(root)/(logged)/resources/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/resources/+page.svelte @@ -34,6 +34,7 @@ faCircle, faEdit, faFileExport, + faPen, faPlus, faRefresh, faSave, @@ -63,11 +64,17 @@ } let resourceTypeDrawer: Drawer + let editResourceTypeDrawer: Drawer let newResourceType = { name: '', schema: emptySchema(), description: '' } + let editResourceType = { + name: '', + schema: emptySchema(), + description: '' + } let resourceEditor: ResourceEditor | undefined let shareModal: ShareModal let appConnect: AppConnect @@ -165,6 +172,20 @@ loadResourceTypes() } + async function updateResourceType(): Promise { + await ResourceService.updateResourceType({ + workspace: $workspaceStore!, + path: editResourceType.name, + requestBody: { + schema: editResourceType.schema, + description: newResourceType.description + } + }) + editResourceTypeDrawer.closeDrawer?.() + sendUserToast('Resource type updated') + loadResourceTypes() + } + async function handleDeleteResourceType(name: string) { try { await ResourceService.deleteResourceType({ workspace: $workspaceStore!, path: name }) @@ -190,6 +211,16 @@ resourceTypeDrawer.openDrawer?.() } + async function startEditResourceType(name: string) { + const rt = await ResourceService.getResourceType({ workspace: $workspaceStore!, path: name }) + editResourceType = { + name: rt.name, + schema: rt.schema, + description: rt.description ?? '' + } + editResourceTypeDrawer.openDrawer?.() + } + $: { if ($workspaceStore && $userStore) { loadResources() @@ -268,6 +299,47 @@ + + + + + +
+ +