|
|
@ -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> |
|
|
|