From 48c7ed129d14064e73dfbd797312004b1154fbe1 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 27 Nov 2022 19:58:48 +0100 Subject: [PATCH] iteration 1 on the hub script picker --- .../flows/pickers/PickHubScript.svelte | 8 +- .../src/lib/components/flows/pickers/model.ts | 8 +- frontend/src/routes/scripts.svelte | 82 ++++++------------- 3 files changed, 36 insertions(+), 62 deletions(-) diff --git a/frontend/src/lib/components/flows/pickers/PickHubScript.svelte b/frontend/src/lib/components/flows/pickers/PickHubScript.svelte index d98edb9b3e..aefd3a164e 100644 --- a/frontend/src/lib/components/flows/pickers/PickHubScript.svelte +++ b/frontend/src/lib/components/flows/pickers/PickHubScript.svelte @@ -10,7 +10,7 @@ let items: HubItem[] = [] - let filteredItems: Item[] | undefined = [] + let filteredItems: HubItem[] | undefined = [] let itemsFilter = '' let appFilter: string | undefined = undefined @@ -18,7 +18,7 @@ includeScore: false, keys: ['path', 'summay'] } - const fuse: Fuse = new Fuse(items, fuseOptions) + const fuse: Fuse = new Fuse(items, fuseOptions) $: { items = @@ -44,7 +44,7 @@
{#each apps as app} { appFilter = appFilter == app ? undefined : app }} @@ -67,7 +67,7 @@ dispatch('pick', obj) }} > -
+
{obj['summary'] ?? ''}
diff --git a/frontend/src/lib/components/flows/pickers/model.ts b/frontend/src/lib/components/flows/pickers/model.ts index 8e1ac2a32b..a0599ea1ce 100644 --- a/frontend/src/lib/components/flows/pickers/model.ts +++ b/frontend/src/lib/components/flows/pickers/model.ts @@ -1,5 +1,7 @@ export interface HubItem { - summary: String - path: String - version?: String + app: string; + summary: string + path: string + version?: string + ask_id: number } diff --git a/frontend/src/routes/scripts.svelte b/frontend/src/routes/scripts.svelte index c362f759bf..7ad2d10ecf 100644 --- a/frontend/src/routes/scripts.svelte +++ b/frontend/src/routes/scripts.svelte @@ -13,6 +13,7 @@ faCodeFork, faEdit, faEye, + faGlobe, faList, faPlay, faShare @@ -40,6 +41,8 @@ import CreateActions from '$lib/components/scripts/CreateActions.svelte' import HighlightCode from '$lib/components/HighlightCode.svelte' import Drawer from '$lib/components/common/drawer/Drawer.svelte' + import PickHubScript from '$lib/components/flows/pickers/PickHubScript.svelte' + import type { HubItem } from '$lib/components/flows/pickers/model' type Tab = 'all' | 'personal' | 'groups' | 'shared' | 'examples' | 'hub' type Section = [string, ScriptW[]] @@ -70,16 +73,11 @@ let codeViewer: Drawer let codeViewerContent: string = '' let codeViewerLanguage: 'deno' | 'python3' | 'go' | 'bash' = 'deno' - let codeViewerPath: string = '' + let codeViewerObj: HubItem | undefined = undefined $: filteredScripts = scriptFilter.length > 0 ? fuse.search(scriptFilter).map((value) => value.item) : scripts - $: filteredHub = - hubFilter.length > 0 - ? hubScriptsFuse.search(hubFilter).map((value) => value.item) - : $hubScripts ?? [] - $: { let defaults: string[] = [] @@ -130,11 +128,11 @@ sendUserToast(`Successfully archived script ${path}`) } - async function viewCode(path: string) { - const { content, language } = await getScriptByPath(path) + async function viewCode(obj: HubItem) { + const { content, language } = await getScriptByPath(obj.path) codeViewerContent = content codeViewerLanguage = language - codeViewerPath = path + codeViewerObj = obj codeViewer.openDrawer() } @@ -152,8 +150,20 @@ } - - + + +
+
@@ -216,57 +226,19 @@ {:else if sectionTab == 'hub'} -

+

Approved scripts from the WindmillHub All approved Deno scripts from the WindmillHub. Approved scripts have been reviewed by the Windmill team and are safe to use in - production. The hub only offers Deno scripts because Hub scripts are meant to be - solely used as building blocks of flows and are much more efficient to execute than - their Python counterparts. + production.

- -
+ +
{#if $hubScripts != undefined} - - - App - Summary - - - - {#each filteredHub ?? [] as { path, summary, app, ask_id }} - - {app} - - - | - hub's page - | - fork - - - {/each} - - + viewCode(e.detail)} /> {:else} - + Hub not reachable. If your environment is air gapped, contact sales@windmill.dev to setup a local mirror.