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