Add legacy in-memory filtering and sorting for views and external datasources
This commit is contained in:
parent
4db2ee1843
commit
889f5f8175
|
@ -80,7 +80,7 @@
|
|||
/>
|
||||
{/each}
|
||||
<div>
|
||||
<Button icon="AddCircle" size="S" cta on:click={addField}>
|
||||
<Button icon="AddCircle" secondary on:click={addField}>
|
||||
Add
|
||||
{fieldLabel}
|
||||
</Button>
|
||||
|
|
|
@ -12,22 +12,35 @@
|
|||
getDatasourceForProvider,
|
||||
getSchemaForDatasource,
|
||||
} from "builderStore/dataBinding"
|
||||
import FilterBuilder from "./FilterBuilder.svelte"
|
||||
import LuceneFilterBuilder from "./LuceneFilterBuilder.svelte"
|
||||
import { currentAsset } from "builderStore"
|
||||
import SaveFields from "../EventsEditor/actions/SaveFields.svelte"
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
export let value = {}
|
||||
export let value = []
|
||||
export let componentInstance
|
||||
let drawer
|
||||
let tempValue = Array.isArray(value) ? value : []
|
||||
let tempValue = value
|
||||
|
||||
$: schemaFields = getSchemaFields(componentInstance)
|
||||
$: numFilters = Array.isArray(tempValue)
|
||||
? tempValue.length
|
||||
: Object.keys(tempValue || {}).length
|
||||
$: dataSource = getDatasourceForProvider($currentAsset, componentInstance)
|
||||
$: schema = getSchemaForDatasource(dataSource)?.schema
|
||||
$: schemaFields = Object.values(schema || {})
|
||||
$: internalTable = dataSource?.type === "table"
|
||||
|
||||
const getSchemaFields = component => {
|
||||
const datasource = getDatasourceForProvider($currentAsset, component)
|
||||
const { schema } = getSchemaForDatasource(datasource)
|
||||
return Object.values(schema || {})
|
||||
// Reset value if value is wrong type for the datasource.
|
||||
// Lucene editor needs an array, and simple editor needs an object.
|
||||
$: {
|
||||
if (internalTable && !Array.isArray(value)) {
|
||||
tempValue = []
|
||||
dispatch("change", [])
|
||||
} else if (!internalTable && Array.isArray(value)) {
|
||||
tempValue = {}
|
||||
dispatch("change", {})
|
||||
}
|
||||
}
|
||||
|
||||
const saveFilter = async () => {
|
||||
|
@ -43,14 +56,35 @@
|
|||
<DrawerContent slot="body">
|
||||
<Layout>
|
||||
<Body size="S">
|
||||
{#if !Object.keys(tempValue || {}).length}
|
||||
{#if !numFilters}
|
||||
Add your first filter column.
|
||||
{:else}
|
||||
Results are filtered to only those which match all of the following
|
||||
constaints.
|
||||
{/if}
|
||||
</Body>
|
||||
<FilterBuilder bind:value={tempValue} {schemaFields} />
|
||||
{#if internalTable}
|
||||
<LuceneFilterBuilder bind:value={tempValue} {schemaFields} />
|
||||
{:else}
|
||||
<div class="fields">
|
||||
<SaveFields
|
||||
parameterFields={Array.isArray(value) ? {} : value}
|
||||
{schemaFields}
|
||||
valueLabel="Equals"
|
||||
on:change={e => (tempValue = e.detail)}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
</Layout>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
|
||||
<style>
|
||||
.fields {
|
||||
display: grid;
|
||||
column-gap: var(--spacing-l);
|
||||
row-gap: var(--spacing-s);
|
||||
align-items: center;
|
||||
grid-template-columns: auto 1fr auto 1fr auto;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
let pageNumber = 0
|
||||
|
||||
$: internalTable = dataSource?.type === "table"
|
||||
$: query = dataSource?.type === "table" ? buildLuceneQuery(filter) : null
|
||||
$: query = internalTable ? buildLuceneQuery(filter) : null
|
||||
$: hasNextPage = bookmarks[pageNumber + 1] != null
|
||||
$: hasPrevPage = pageNumber > 0
|
||||
$: getSchema(dataSource)
|
||||
|
@ -34,8 +34,8 @@
|
|||
if (internalTable) {
|
||||
rows = allRows
|
||||
} else {
|
||||
rows = sortRows(allRows, sortColumn, sortOrder)
|
||||
rows = limitRows(rows, limit)
|
||||
const sortedRows = sortRows(allRows, sortColumn, sortOrder)
|
||||
rows = limitRows(sortedRows, limit)
|
||||
}
|
||||
}
|
||||
$: actions = [
|
||||
|
@ -213,7 +213,7 @@
|
|||
}
|
||||
|
||||
const nextPage = async () => {
|
||||
if (!hasNextPage) {
|
||||
if (!hasNextPage || !internalTable) {
|
||||
return
|
||||
}
|
||||
const res = await API.searchTable({
|
||||
|
@ -244,7 +244,7 @@
|
|||
}
|
||||
|
||||
const prevPage = async () => {
|
||||
if (!hasPrevPage) {
|
||||
if (!hasPrevPage || !internalTable) {
|
||||
return
|
||||
}
|
||||
const res = await API.searchTable({
|
||||
|
|
Loading…
Reference in New Issue