Add basic search implementation to data UI tables
This commit is contained in:
parent
6109a2983b
commit
9bdc1b824b
|
@ -11,10 +11,13 @@
|
||||||
import { TableNames } from "constants"
|
import { TableNames } from "constants"
|
||||||
import CreateEditRow from "./modals/CreateEditRow.svelte"
|
import CreateEditRow from "./modals/CreateEditRow.svelte"
|
||||||
import { fetchTableData } from "helpers/fetchTableData"
|
import { fetchTableData } from "helpers/fetchTableData"
|
||||||
import { Pagination } from "@budibase/bbui"
|
import { Layout, Pagination, Select, Input } from "@budibase/bbui"
|
||||||
|
import { OperatorOptions } from "constants/lucene"
|
||||||
|
|
||||||
const search = fetchTableData()
|
const search = fetchTableData()
|
||||||
let hideAutocolumns = true
|
let hideAutocolumns = true
|
||||||
|
let searchColumn
|
||||||
|
let searchValue
|
||||||
|
|
||||||
$: isUsersTable = $tables.selected?._id === TableNames.USERS
|
$: isUsersTable = $tables.selected?._id === TableNames.USERS
|
||||||
$: title = $tables.selected?.name
|
$: title = $tables.selected?.name
|
||||||
|
@ -22,12 +25,16 @@
|
||||||
$: type = $tables.selected?.type
|
$: type = $tables.selected?.type
|
||||||
$: isInternal = type !== "external"
|
$: isInternal = type !== "external"
|
||||||
$: id = $tables.selected?._id
|
$: id = $tables.selected?._id
|
||||||
$: fetchTable(id)
|
$: columnOptions = Object.keys($search.schema || {})
|
||||||
|
$: filter = buildFilter(searchColumn, searchValue)
|
||||||
|
$: fetchTable(id, filter)
|
||||||
|
|
||||||
const fetchTable = tableId => {
|
// Fetches new data whenever the table changes
|
||||||
|
const fetchTable = (tableId, filter) => {
|
||||||
search.update({
|
search.update({
|
||||||
tableId,
|
tableId,
|
||||||
schema,
|
schema,
|
||||||
|
filter,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
paginate: true,
|
paginate: true,
|
||||||
})
|
})
|
||||||
|
@ -40,6 +47,23 @@
|
||||||
sortOrder: e.detail.order,
|
sortOrder: e.detail.order,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Builds a filter expression to search with
|
||||||
|
const buildFilter = (column, value) => {
|
||||||
|
if (!column || !value) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: "string",
|
||||||
|
field: column,
|
||||||
|
operator: OperatorOptions.StartsWith.value,
|
||||||
|
value,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
$: console.log(filter)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
@ -55,6 +79,8 @@
|
||||||
allowEditing
|
allowEditing
|
||||||
disableSorting
|
disableSorting
|
||||||
>
|
>
|
||||||
|
<Layout noPadding gap="S">
|
||||||
|
<div class="buttons">
|
||||||
{#if isInternal}
|
{#if isInternal}
|
||||||
<CreateColumnButton />
|
<CreateColumnButton />
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -76,6 +102,16 @@
|
||||||
<!-- always have the export last -->
|
<!-- always have the export last -->
|
||||||
<ExportButton view={$tables.selected?._id} />
|
<ExportButton view={$tables.selected?._id} />
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="search">
|
||||||
|
<Select bind:value={searchColumn} options={columnOptions} />
|
||||||
|
<Input
|
||||||
|
updateOnChange={false}
|
||||||
|
on:change={e => (searchValue = e.detail)}
|
||||||
|
placeholder="Search"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
</Table>
|
</Table>
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
<Pagination
|
<Pagination
|
||||||
|
@ -89,6 +125,19 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.buttons {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--spacing-s);
|
||||||
|
}
|
||||||
|
.search {
|
||||||
|
display: grid;
|
||||||
|
align-items: center;
|
||||||
|
grid-template-columns: 200px 200px;
|
||||||
|
gap: var(--spacing-s);
|
||||||
|
}
|
||||||
.pagination {
|
.pagination {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
|
@ -164,7 +164,7 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--spacing-s);
|
gap: var(--spacing-s);
|
||||||
}
|
}
|
||||||
.popovers :global(button) {
|
.popovers :global(.spectrum-ActionButton) {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin-top: var(--spacing-l);
|
margin-top: var(--spacing-l);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue