Filter at datasource navigator level

This commit is contained in:
Adria Navarro 2023-11-09 16:58:49 +01:00
parent bdfdac9f25
commit 699d4e0793
2 changed files with 27 additions and 18 deletions

View File

@ -66,11 +66,27 @@
views, views,
viewsV2 viewsV2
) )
const dsTables = tables.list.filter(
table =>
table.sourceId === datasource._id &&
table._id !== TableNames.USERS &&
(!searchTerm ||
table.name?.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1)
)
const dsQueries = queries.list.filter(
query =>
query.datasourceId === datasource._id &&
(!searchTerm ||
query.name?.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1)
)
return { return {
...datasource, ...datasource,
selected, selected,
containsSelected, containsSelected,
open: open || onlySource || !!searchTerm, open: open || onlySource || !!searchTerm,
queries: dsQueries,
tables: dsTables,
} }
}) })
} }
@ -206,10 +222,8 @@
</NavItem> </NavItem>
{#if datasource.open} {#if datasource.open}
<TableNavigator sourceId={datasource._id} {selectTable} {searchTerm} /> <TableNavigator tables={datasource.tables} {selectTable} />
{#each $queries.list.filter(query => query.datasourceId === datasource._id && (!searchTerm || query.name {#each datasource.queries as query}
?.toLowerCase()
?.indexOf(searchTerm.toLowerCase()) > -1)) as query}
<NavItem <NavItem
indentLevel={1} indentLevel={1}
icon="SQLQuery" icon="SQLQuery"

View File

@ -1,5 +1,10 @@
<script> <script>
import { tables, views, viewsV2, database } from "stores/backend" import {
tables as tablesStore,
views,
viewsV2,
database,
} from "stores/backend"
import { TableNames } from "constants" import { TableNames } from "constants"
import EditTablePopover from "./popovers/EditTablePopover.svelte" import EditTablePopover from "./popovers/EditTablePopover.svelte"
import EditViewPopover from "./popovers/EditViewPopover.svelte" import EditViewPopover from "./popovers/EditViewPopover.svelte"
@ -7,20 +12,10 @@
import { goto, isActive } from "@roxi/routify" import { goto, isActive } from "@roxi/routify"
import { userSelectedResourceMap } from "builderStore" import { userSelectedResourceMap } from "builderStore"
export let searchTerm export let tables
export let sourceId
export let selectTable export let selectTable
$: sortedTables = $tables.list $: sortedTables = tables.sort(alphabetical)
.filter(
table => table.sourceId === sourceId && table._id !== TableNames.USERS
)
.filter(
table =>
!searchTerm ||
table.name.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1
)
.sort(alphabetical)
const alphabetical = (a, b) => { const alphabetical = (a, b) => {
return a.name?.toLowerCase() > b.name?.toLowerCase() ? 1 : -1 return a.name?.toLowerCase() > b.name?.toLowerCase() ? 1 : -1
@ -43,7 +38,7 @@
icon={table._id === TableNames.USERS ? "UserGroup" : "Table"} icon={table._id === TableNames.USERS ? "UserGroup" : "Table"}
text={table.name} text={table.name}
selected={$isActive("./table/:tableId") && selected={$isActive("./table/:tableId") &&
$tables.selected?._id === table._id} $tablesStore.selected?._id === table._id}
on:click={() => selectTable(table._id)} on:click={() => selectTable(table._id)}
selectedBy={$userSelectedResourceMap[table._id]} selectedBy={$userSelectedResourceMap[table._id]}
> >