also allow editable flow

This commit is contained in:
Ruben Fiszel
2022-07-24 11:27:36 +02:00
parent 8a951e8821
commit f402cc67c1
5 changed files with 77 additions and 22 deletions
+1 -1
View File
@@ -133,7 +133,7 @@ async fn list_flows(
"edited_by",
"edited_at",
"archived",
"schema",
"null schema",
"extra_perms",
])
.order_by("edited_at", lq.order_desc.unwrap_or(true))
+49 -3
View File
@@ -195,7 +195,7 @@ async fn list_scripts(
"created_by",
"created_at",
"archived",
"schema",
"null as schema",
"deleted",
"is_template",
"extra_perms",
@@ -252,16 +252,20 @@ async fn list_scripts(
}
#[derive(Deserialize, Serialize)]
struct SearchData {
struct SearchScriptData {
asks: Vec<ScriptSearch>,
}
#[derive(Deserialize, Serialize)]
struct ScriptSearch {
id: i32,
ask_id: i32,
summary: String,
app: String,
approved: bool,
is_trigger: bool,
views: i32,
votes: i32,
}
async fn list_hub_scripts(
@@ -282,7 +286,49 @@ async fn list_hub_scripts(
.send()
.await
.map_err(to_anyhow)?
.json::<SearchData>()
.json::<SearchScriptData>()
.await
.map_err(to_anyhow)?
.asks;
Ok(Json(rows))
}
#[derive(Deserialize, Serialize)]
struct SearchFlowData {
asks: Vec<FlowSearch>,
}
#[derive(Deserialize, Serialize)]
struct FlowSearch {
id: i32,
ask_id: i32,
summary: String,
app: String,
approved: bool,
is_trigger: bool,
views: i32,
votes: i32,
}
async fn list_hub_flows(
Authed {
email, username, ..
}: Authed,
Host(host): Host,
) -> JsonResult<Vec<ScriptSearch>> {
let http_client = reqwest::ClientBuilder::new()
.user_agent("windmill/beta")
.build()
.map_err(to_anyhow)?;
let rows = http_client
.get("https://hub.windmill.dev/searchFlowData?approved=true")
.header("X-email", email.unwrap_or_else(|| "".to_string()))
.header("X-username", username)
.header("X-hostname", host)
.send()
.await
.map_err(to_anyhow)?
.json::<SearchScriptData>()
.await
.map_err(to_anyhow)?
.asks;
+14 -14
View File
@@ -47,14 +47,14 @@
{#if tab == 'ui'}
<div class="flow-root w-full p-4">
<p class="font-black text-lg mb-6 w-full ml-2">
<span>{flow.value.modules.length} Steps </span>
<span>{flow?.value?.modules?.length} Steps </span>
<span class="mt-4" />
</p>
<ul class="-mb-8 w-full">
{#each flow.value.modules ?? [] as mod, i}
{#each flow?.value?.modules ?? [] as mod, i}
<li class="w-full">
<div class="relative pb-8 w-full">
{#if i < (flow.value.modules ?? []).length - 1}
{#if i < (flow?.value?.modules ?? []).length - 1}
<span
class="absolute top-4 left-4 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
@@ -70,33 +70,33 @@
<div class="min-w-0 flex-1 pt-1.5 flex justify-between space-x-4 w-full">
<div class="w-full">
<p class="text-sm text-gray-500">
{#if mod.value.type == FlowModuleValue.type.SCRIPT}
{#if mod?.value?.type == FlowModuleValue.type.SCRIPT}
Script at path <a
target="_blank"
href={scriptPathToHref(mod.value.path ?? '')}
class="font-medium text-gray-900">{mod.value.path}</a
href={scriptPathToHref(mod?.value?.path ?? '')}
class="font-medium text-gray-900">{mod?.value?.path}</a
>
{:else if mod.value.type == FlowModuleValue.type.RAWSCRIPT}
{:else if mod?.value?.type == FlowModuleValue.type.RAWSCRIPT}
<button
on:click={() => (open[i] = !open[i])}
class="mb-2 underline text-black"
>
Raw {mod.value.language} script {open[i] ? '(-)' : '(+)'}</button
Raw {mod?.value?.language} script {open[i] ? '(-)' : '(+)'}</button
>
{#if open[i]}
<div transition:slide class="border border-black p-2 bg-gray-50 w-full">
<Highlight
language={mod.value.language == 'deno' ? typescript : python}
code={mod.value.content}
language={mod?.value?.language == 'deno' ? typescript : python}
code={mod?.value?.content}
/>
</div>
{/if}
{:else if mod.value.type == FlowModuleValue.type.FLOW}
Flow at path {mod.value.path}
{:else if mod.value.type == FlowModuleValue.type.FORLOOPFLOW}
{:else if mod?.value?.type == FlowModuleValue.type.FLOW}
Flow at path {mod?.value?.path}
{:else if mod?.value?.type == FlowModuleValue.type.FORLOOPFLOW}
For loop over step {i}'s result':
<svelte:self flow={mod.value} embedded={true} />
<svelte:self flow={mod?.value} embedded={true} />
{/if}
</p>
</div>
+1
View File
@@ -118,6 +118,7 @@
<Tabs
tabs={[
['all', 'all'],
['hub', 'hub'],
['personal', `personal space (${$userStore?.username})`],
['groups', 'groups'],
['shared', 'shared']
+12 -4
View File
@@ -14,7 +14,14 @@
import type { Script } from '$lib/gen'
import { ScriptService } from '$lib/gen'
import { superadmin, userStore, workspaceStore, hubScripts } from '$lib/stores'
import { canWrite, getScriptByPath, groupBy, loadHubScripts, sendUserToast, truncateHash } from '$lib/utils'
import {
canWrite,
getScriptByPath,
groupBy,
loadHubScripts,
sendUserToast,
truncateHash
} from '$lib/utils'
import Badge from '$lib/components/Badge.svelte'
import CenteredPage from '$lib/components/CenteredPage.svelte'
import Dropdown from '$lib/components/Dropdown.svelte'
@@ -140,10 +147,11 @@
codeViewerPath = path
codeViewer.openModal()
}
loadHubScripts()
$: {
if ($workspaceStore && ($userStore || $superadmin)) {
loadScripts()
loadHubScripts()
}
}
</script>
@@ -186,11 +194,11 @@
<Tabs
tabs={[
['all', 'all'],
['hub', 'hub'],
['personal', `personal space (${$userStore?.username})`],
['groups', 'groups'],
['shared', 'shared'],
['examples', 'examples'],
['hub', 'hub']
['examples', 'examples']
]}
bind:tab
on:update={loadScripts}