From ca999c320a9725d559dc632d579cdcd448e1bfa5 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 4 Dec 2022 23:56:52 +0100 Subject: [PATCH] searchable resource and variables --- frontend/src/routes/resources.svelte | 44 ++++++++++++++++++++++++++-- frontend/src/routes/variables.svelte | 30 ++++++++++++++----- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/frontend/src/routes/resources.svelte b/frontend/src/routes/resources.svelte index 64022916e2..5f5e1939a6 100644 --- a/frontend/src/routes/resources.svelte +++ b/frontend/src/routes/resources.svelte @@ -46,6 +46,8 @@ import Tooltip from '$lib/components/Tooltip.svelte' import Tabs from '$lib/components/common/tabs/Tabs.svelte' import { Building } from 'svelte-lucide' + import ListFilters from '$lib/components/home/ListFilters.svelte' + import SearchItems from '$lib/components/SearchItems.svelte' type ResourceW = ListableResource & { canWrite: boolean } type ResourceTypeW = ResourceType & { canWrite: boolean } @@ -53,6 +55,8 @@ let resources: ResourceW[] | undefined let resourceTypes: ResourceTypeW[] | undefined + let filteredItems: (ResourceW & { marked?: string })[] | undefined = undefined + let resourceTypeViewer: Drawer let resourceTypeViewerObj = { rt: '', @@ -77,6 +81,26 @@ $: open = Boolean(deleteConfirmedCallback) + $: owners = Array.from( + new Set(filteredItems?.map((x) => x.path.split('/').slice(0, 2).join('/')) ?? []) + ).sort() + + $: types = Array.from(new Set(filteredItems?.map((x) => x.resource_type))).sort() + + let filter = '' + let ownerFilter: string | undefined = undefined + let typeFilter: string | undefined = undefined + + $: preFilteredItemsOwners = + ownerFilter == undefined + ? resources + : resources?.filter((x) => x.path.startsWith(ownerFilter ?? '')) + + $: preFilteredType = + typeFilter == undefined + ? preFilteredItemsOwners + : preFilteredItemsOwners?.filter((x) => x.resource_type == typeFilter) + async function loadResources(): Promise { resources = (await ResourceService.listResource({ workspace: $workspaceStore! })).map((x) => { return { @@ -231,6 +255,13 @@ + x.path + ' ' + x.resource_type + ' ' + x.description + ' '} +/> + {#if tab == 'workspace'} +
+ +
+ + +
{#if loading.resources} @@ -279,14 +316,15 @@ - {#if resources} - {#each resources as { path, description, resource_type, extra_perms, canWrite, is_oauth, is_linked, account, refresh_error, is_expired }} + {#if filteredItems} + {#each filteredItems as { path, description, resource_type, extra_perms, canWrite, is_oauth, is_linked, account, refresh_error, is_expired, marked }} resourceEditor?.initEdit?.(path)}>{path} resourceEditor?.initEdit?.(path)} + >{#if marked}{@html marked}{:else}{path}{/if} diff --git a/frontend/src/routes/variables.svelte b/frontend/src/routes/variables.svelte index b30975ef83..c5be2f213d 100644 --- a/frontend/src/routes/variables.svelte +++ b/frontend/src/routes/variables.svelte @@ -37,23 +37,34 @@ import { Building, DollarSign } from 'svelte-lucide' import Tooltip from '$lib/components/Tooltip.svelte' import SearchItems from '$lib/components/SearchItems.svelte' + import ListFilters from '$lib/components/home/ListFilters.svelte' type ListableVariableW = ListableVariable & { canWrite: boolean } let filter = '' - let variables: ListableVariableW[] = [] - let filteredItems: ListableVariableW[] = [] + let variables: ListableVariableW[] | undefined = undefined + let filteredItems: (ListableVariableW & { marked?: string })[] | undefined = undefined let contextualVariables: ContextualVariable[] = [] let shareModal: ShareModal let variableEditor: VariableEditor let loading = { - variables: true, contextual: true } let deleteConfirmedCallback: (() => void) | undefined = undefined $: open = Boolean(deleteConfirmedCallback) + $: owners = Array.from( + new Set(filteredItems?.map((x) => x.path.split('/').slice(0, 2).join('/')) ?? []) + ).sort() + + let ownerFilter: string | undefined = undefined + + $: preFilteredItems = + ownerFilter == undefined + ? variables + : variables?.filter((x) => x.path.startsWith(ownerFilter ?? '')) + // If relative, the dropdown is positioned relative to its button async function loadVariables(): Promise { variables = (await VariableService.listVariable({ workspace: $workspaceStore! })).map((x) => { @@ -62,8 +73,8 @@ ...x } }) - loading.variables = false } + async function loadContextualVariables(): Promise { contextualVariables = await VariableService.listContextualVariables({ workspace: $workspaceStore! @@ -91,7 +102,7 @@ x.path + ' ' + x.description} /> @@ -136,8 +147,10 @@
+ +
- {#if loading.variables} + {#if !filteredItems} {#each new Array(3) as _} @@ -153,14 +166,15 @@ - {#each filteredItems as { path, value, is_secret, description, extra_perms, canWrite, account, is_oauth, is_expired, refresh_error, is_linked }} + {#each filteredItems as { path, value, is_secret, description, extra_perms, canWrite, account, is_oauth, is_expired, refresh_error, is_linked, marked }} variableEditor.editVariable(path)} - href="#{path}">{path}{#if marked}{@html marked}{:else}{path}{/if}