Filter views
This commit is contained in:
parent
b121d64b79
commit
93bf76e1fe
|
@ -121,16 +121,10 @@ export const enrichDatasources = (
|
||||||
|
|
||||||
const dsTables = tables.list.filter(
|
const dsTables = tables.list.filter(
|
||||||
table =>
|
table =>
|
||||||
table.sourceId === datasource._id &&
|
table.sourceId === datasource._id && table._id !== TableNames.USERS
|
||||||
table._id !== TableNames.USERS &&
|
|
||||||
(!searchTerm ||
|
|
||||||
table.name?.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1)
|
|
||||||
)
|
)
|
||||||
const dsQueries = queries.list.filter(
|
const dsQueries = queries.list.filter(
|
||||||
query =>
|
query => query.datasourceId === datasource._id
|
||||||
query.datasourceId === datasource._id &&
|
|
||||||
(!searchTerm ||
|
|
||||||
query.name?.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const open = showDatasourceOpen({
|
const open = showDatasourceOpen({
|
||||||
|
@ -141,14 +135,46 @@ export const enrichDatasources = (
|
||||||
onlyOneSource: onlySource,
|
onlyOneSource: onlySource,
|
||||||
})
|
})
|
||||||
|
|
||||||
const show = !!(!searchTerm || dsQueries.length || dsTables.length)
|
const visibleDsQueries = dsQueries.filter(
|
||||||
|
q =>
|
||||||
|
!searchTerm ||
|
||||||
|
q.name?.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1
|
||||||
|
)
|
||||||
|
|
||||||
|
const visibleDsTables = dsTables
|
||||||
|
.map(t => ({
|
||||||
|
...t,
|
||||||
|
views: !searchTerm
|
||||||
|
? t.views
|
||||||
|
: Object.keys(t.views || {})
|
||||||
|
.filter(
|
||||||
|
viewName =>
|
||||||
|
viewName.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1
|
||||||
|
)
|
||||||
|
.reduce(
|
||||||
|
(acc, viewName) => ({ ...acc, [viewName]: t.views[viewName] }),
|
||||||
|
{}
|
||||||
|
),
|
||||||
|
}))
|
||||||
|
.filter(
|
||||||
|
table =>
|
||||||
|
!searchTerm ||
|
||||||
|
table.name?.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1 ||
|
||||||
|
Object.keys(table.views).length
|
||||||
|
)
|
||||||
|
|
||||||
|
const show = !!(
|
||||||
|
!searchTerm ||
|
||||||
|
visibleDsQueries.length ||
|
||||||
|
visibleDsTables.length
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
...datasource,
|
...datasource,
|
||||||
selected,
|
selected,
|
||||||
containsSelected,
|
containsSelected,
|
||||||
open,
|
open,
|
||||||
queries: dsQueries,
|
queries: visibleDsQueries,
|
||||||
tables: dsTables,
|
tables: visibleDsTables,
|
||||||
show,
|
show,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -142,7 +142,7 @@ describe("datasourceUtils", () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("given a valid search term, all entities are correctly filtered", () => {
|
it("given a valid search term, all tables are correctly filtered", () => {
|
||||||
const searchTerm = "ex"
|
const searchTerm = "ex"
|
||||||
|
|
||||||
const result = enrichDatasources(
|
const result = enrichDatasources(
|
||||||
|
|
Loading…
Reference in New Issue