add resource type description in resource editor

This commit is contained in:
Ruben Fiszel
2024-01-23 21:40:39 +01:00
parent 3f29678a0b
commit 0b7bb2bd44
4 changed files with 93 additions and 80 deletions
+12 -10
View File
@@ -1947,7 +1947,7 @@ where
async fn tarball_workspace(
authed: ApiAuthed,
Extension(db): Extension<DB>,
Extension(user_db): Extension<UserDB>,
Path(w_id): Path<String>,
Query(ArchiveQueryParams {
archive_type,
@@ -1959,7 +1959,9 @@ async fn tarball_workspace(
include_schedules,
}): Query<ArchiveQueryParams>,
) -> Result<([(headers::HeaderName, String); 2], impl IntoResponse)> {
require_admin(authed.is_admin, &authed.username)?;
// require_admin(authed.is_admin, &authed.username)?;
let mut tx = user_db.begin(&authed).await?;
let tmp_dir = TempDir::new_in("/tmp/windmill/")?;
@@ -1978,7 +1980,7 @@ async fn tarball_workspace(
{
let folders = sqlx::query_as::<_, Folder>("SELECT * FROM folder WHERE workspace_id = $1")
.bind(&w_id)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
for folder in folders {
@@ -1998,7 +2000,7 @@ async fn tarball_workspace(
workspace_id = $1)",
)
.bind(&w_id)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
for script in scripts {
@@ -2053,7 +2055,7 @@ async fn tarball_workspace(
"SELECT * FROM resource WHERE workspace_id = $1 AND resource_type != 'state' AND resource_type != 'cache'",
&w_id
)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
for resource in resources {
@@ -2070,7 +2072,7 @@ async fn tarball_workspace(
"SELECT * FROM resource_type WHERE workspace_id = $1",
&w_id
)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
for resource_type in resource_types {
@@ -2089,7 +2091,7 @@ async fn tarball_workspace(
"SELECT * FROM flow WHERE workspace_id = $1 AND archived = false",
)
.bind(&w_id)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
for flow in flows {
@@ -2108,7 +2110,7 @@ async fn tarball_workspace(
"SELECT * FROM variable WHERE workspace_id = $1 AND is_secret = false"
})
.bind(&w_id)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
let mc = build_crypt(&mut db.begin().await?, &w_id).await?;
@@ -2139,7 +2141,7 @@ async fn tarball_workspace(
WHERE app.workspace_id = $1 AND app_version.id = app.versions[array_upper(app.versions, 1)]",
&w_id
)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
for app in apps {
@@ -2157,7 +2159,7 @@ async fn tarball_workspace(
WHERE workspace_id = $1",
&w_id
)
.fetch_all(&db)
.fetch_all(&mut *tx)
.await?;
for schedule in schedules {
@@ -513,8 +513,8 @@
</div>
{/if}
{:else if !emptyString(resourceTypeInfo?.description)}
<h2 class="mt-4 mb-2">Resource type description</h2>
<div>
<h3 class="mt-6 mb-2">{resourceTypeInfo?.name} description</h3>
<div class="text-sm">
<Markdown md={urlize(resourceTypeInfo?.description ?? '', 'md')} />
</div>
{/if}
@@ -1,7 +1,7 @@
<script lang="ts">
import type { Schema } from '$lib/common'
import { ResourceService, type Resource } from '$lib/gen'
import { canWrite, emptyString, isOwner } from '$lib/utils'
import { ResourceService, type Resource, type ResourceType } from '$lib/gen'
import { canWrite, emptyString, isOwner, urlize } from '$lib/utils'
import { createEventDispatcher } from 'svelte'
import { Alert, Button, Drawer, Skeleton } from './common'
import Path from './Path.svelte'
@@ -16,6 +16,7 @@
import { sendUserToast } from '$lib/toast'
import TestConnection from './TestConnection.svelte'
import { Save } from 'lucide-svelte'
import Markdown from 'svelte-exmarkdown'
let path = ''
let initialPath = ''
@@ -31,6 +32,7 @@
let loadingSchema = false
let linkedVars: string[] = []
let drawer: Drawer
let resourceTypeInfo: ResourceType | undefined = undefined
let rawCode: string | undefined = undefined
@@ -80,6 +82,7 @@
path: selectedResourceType
})
resourceTypeInfo = resourceType
if (resourceType.schema) {
resourceSchema = resourceType.schema as Schema
}
@@ -150,6 +153,12 @@
kind="resource"
/>
</div>
{#if !emptyString(resourceTypeInfo?.description)}
<h3 class="mt-4 mb-2">{resourceTypeInfo?.name} description</h3>
<div class="text-sm">
<Markdown md={urlize(resourceTypeInfo?.description ?? '', 'md')} />
</div>
{/if}
<div class="flex w-full justify-between max-w-lg items-center mt-4">
<Toggle
on:change={(e) => switchTab(e.detail)}
@@ -789,74 +789,76 @@
Filtering out certain sensitive folders from the sync will be available soon.
</Alert>
{#each gitSyncSettings as gitSyncSettingsElmt, idx}
<div class="flex mt-5 mb-1 gap-1 items-center text-xs">
<h6>Repository #{idx + 1}</h6>
<Button
color="light"
size="xs"
startIcon={{ icon: XCircle }}
iconOnly={true}
on:click={() => {
gitSyncSettings.splice(idx, 1)
gitSyncSettings = [...gitSyncSettings]
}}
/>
</div>
<div class="flex mt-5 mb-1 gap-1">
{#key gitSyncSettingsElmt}
<ResourcePicker
resourceType="git_repository"
initialValue={gitSyncSettingsElmt.git_repo_resource_path}
on:change={(ev) => {
gitSyncSettingsElmt.git_repo_resource_path = ev.detail
}}
/>
{#if Array.isArray(gitSyncSettings)}
{#each gitSyncSettings as gitSyncSettingsElmt, idx}
<div class="flex mt-5 mb-1 gap-1 items-center text-xs">
<h6>Repository #{idx + 1}</h6>
<Button
disabled={emptyString(gitSyncSettingsElmt.script_path)}
btnClasses="w-32 text-center"
color="dark"
on:click={() => runGitSyncTestJob(idx)}
size="xs">Test connection</Button
>
{/key}
</div>
<div class="flex mb-5 text-normal text-2xs gap-1">
{#if gitSyncSettings.filter((settings) => settings.git_repo_resource_path === gitSyncSettingsElmt.git_repo_resource_path).length > 1}
<span class="text-red-700">Using the same resource twice is not allowed.</span>
{/if}
{#if gitSyncTestJobs[idx].status !== undefined}
{#if gitSyncTestJobs[idx].status === 'running'}
<RotateCw size={14} />
{:else if gitSyncTestJobs[idx].status === 'success'}
<CheckCircle2 size={14} class="text-green-600" />
{:else}
<XCircle size={14} class="text-red-700" />
{/if}
Git sync resource checked via Windmill job
<a
target="_blank"
href={`/run/${gitSyncTestJobs[idx].jobId}?workspace=${$workspaceStore}`}
>
{gitSyncTestJobs[idx].jobId}
</a>WARNING: Only read permissions are verified.
{/if}
</div>
<div class="flex mt-5 mb-1 gap-1">
{#if gitSyncSettings}
<Toggle
disabled={emptyString(gitSyncSettingsElmt?.git_repo_resource_path)}
bind:checked={gitSyncSettingsElmt.use_individual_branch}
options={{
right: 'Create one branch per deployed script/flow/app',
rightTooltip:
"If set, Windmill will create a unique branch per script/flow/app being pushed, prefixed with 'wm_deploy/'."
color="light"
size="xs"
startIcon={{ icon: XCircle }}
iconOnly={true}
on:click={() => {
gitSyncSettings.splice(idx, 1)
gitSyncSettings = [...gitSyncSettings]
}}
/>
{/if}
</div>
{/each}
</div>
<div class="flex mt-5 mb-1 gap-1">
{#key gitSyncSettingsElmt}
<ResourcePicker
resourceType="git_repository"
initialValue={gitSyncSettingsElmt.git_repo_resource_path}
on:change={(ev) => {
gitSyncSettingsElmt.git_repo_resource_path = ev.detail
}}
/>
<Button
disabled={emptyString(gitSyncSettingsElmt.script_path)}
btnClasses="w-32 text-center"
color="dark"
on:click={() => runGitSyncTestJob(idx)}
size="xs">Test connection</Button
>
{/key}
</div>
<div class="flex mb-5 text-normal text-2xs gap-1">
{#if gitSyncSettings.filter((settings) => settings.git_repo_resource_path === gitSyncSettingsElmt.git_repo_resource_path).length > 1}
<span class="text-red-700">Using the same resource twice is not allowed.</span>
{/if}
{#if gitSyncTestJobs[idx].status !== undefined}
{#if gitSyncTestJobs[idx].status === 'running'}
<RotateCw size={14} />
{:else if gitSyncTestJobs[idx].status === 'success'}
<CheckCircle2 size={14} class="text-green-600" />
{:else}
<XCircle size={14} class="text-red-700" />
{/if}
Git sync resource checked via Windmill job
<a
target="_blank"
href={`/run/${gitSyncTestJobs[idx].jobId}?workspace=${$workspaceStore}`}
>
{gitSyncTestJobs[idx].jobId}
</a>WARNING: Only read permissions are verified.
{/if}
</div>
<div class="flex mt-5 mb-1 gap-1">
{#if gitSyncSettings}
<Toggle
disabled={emptyString(gitSyncSettingsElmt?.git_repo_resource_path)}
bind:checked={gitSyncSettingsElmt.use_individual_branch}
options={{
right: 'Create one branch per deployed script/flow/app',
rightTooltip:
"If set, Windmill will create a unique branch per script/flow/app being pushed, prefixed with 'wm_deploy/'."
}}
/>
{/if}
</div>
{/each}
{/if}
<div class="flex mt-5 mb-5 gap-1">
<Button
@@ -921,7 +923,7 @@ git push</code
<div class="flex mt-5 mb-5 gap-1">
<Button
color="blue"
disabled={gitSyncSettings.some((elmt) => emptyString(elmt.git_repo_resource_path))}
disabled={gitSyncSettings?.some((elmt) => emptyString(elmt.git_repo_resource_path))}
on:click={() => {
editWindmillGitSyncSettings()
console.log('Saving git sync settings', gitSyncSettings)