Switching to an explicit select for the OR/AND options in the filter.
This commit is contained in:
parent
129c966226
commit
dee15b6415
|
@ -9,7 +9,6 @@
|
||||||
Input,
|
Input,
|
||||||
Layout,
|
Layout,
|
||||||
Select,
|
Select,
|
||||||
Toggle,
|
|
||||||
Label,
|
Label,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
@ -17,7 +16,7 @@
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
import { LuceneUtils, Constants } from "@budibase/frontend-core"
|
import { LuceneUtils, Constants } from "@budibase/frontend-core"
|
||||||
import { getFields } from "helpers/searchFields"
|
import { getFields } from "helpers/searchFields"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher, onMount } from "svelte"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -33,6 +32,11 @@
|
||||||
$: fieldOptions = enrichedSchemaFields.map(field => field.name) || []
|
$: fieldOptions = enrichedSchemaFields.map(field => field.name) || []
|
||||||
$: valueTypeOptions = allowBindings ? ["Value", "Binding"] : ["Value"]
|
$: valueTypeOptions = allowBindings ? ["Value", "Binding"] : ["Value"]
|
||||||
|
|
||||||
|
let behaviourValue
|
||||||
|
const behaviourOptions = [
|
||||||
|
{ value: "and", label: "Match all of the following filters" },
|
||||||
|
{ value: "or", label: "Match any of the following filters" },
|
||||||
|
]
|
||||||
const addFilter = () => {
|
const addFilter = () => {
|
||||||
filters = [
|
filters = [
|
||||||
...filters,
|
...filters,
|
||||||
|
@ -99,6 +103,10 @@
|
||||||
const schema = enrichedSchemaFields.find(x => x.name === field)
|
const schema = enrichedSchemaFields.find(x => x.name === field)
|
||||||
return schema?.constraints?.inclusion || []
|
return schema?.constraints?.inclusion || []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
behaviourValue = allOr ? "or" : "and"
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<DrawerContent>
|
<DrawerContent>
|
||||||
|
@ -114,88 +122,98 @@
|
||||||
</Body>
|
</Body>
|
||||||
{#if filters?.length}
|
{#if filters?.length}
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
{#each filters as filter, idx}
|
<Select
|
||||||
<Select
|
label="Behaviour"
|
||||||
bind:value={filter.field}
|
value={behaviourValue}
|
||||||
options={fieldOptions}
|
options={behaviourOptions}
|
||||||
on:change={e => onFieldChange(filter, e.detail)}
|
getOptionLabel={opt => opt.label}
|
||||||
placeholder="Column"
|
getOptionValue={opt => opt.value}
|
||||||
/>
|
on:change={e => (allOr = e.detail === "or")}
|
||||||
<Select
|
placeholder={null}
|
||||||
disabled={!filter.field}
|
/>
|
||||||
options={LuceneUtils.getValidOperatorsForType(filter.type)}
|
</div>
|
||||||
bind:value={filter.operator}
|
<div>
|
||||||
on:change={e => onOperatorChange(filter, e.detail)}
|
<div class="filter-label">
|
||||||
placeholder={null}
|
<Label>Filters</Label>
|
||||||
/>
|
</div>
|
||||||
<Select
|
<div class="fields">
|
||||||
disabled={filter.noValue || !filter.field}
|
{#each filters as filter, idx}
|
||||||
options={valueTypeOptions}
|
<Select
|
||||||
bind:value={filter.valueType}
|
bind:value={filter.field}
|
||||||
placeholder={null}
|
options={fieldOptions}
|
||||||
/>
|
on:change={e => onFieldChange(filter, e.detail)}
|
||||||
{#if filter.valueType === "Binding"}
|
placeholder="Column"
|
||||||
<DrawerBindableInput
|
|
||||||
disabled={filter.noValue}
|
|
||||||
title={`Value for "${filter.field}"`}
|
|
||||||
value={filter.value}
|
|
||||||
placeholder="Value"
|
|
||||||
{panel}
|
|
||||||
{bindings}
|
|
||||||
on:change={event => (filter.value = event.detail)}
|
|
||||||
/>
|
/>
|
||||||
{:else if ["string", "longform", "number", "formula"].includes(filter.type)}
|
<Select
|
||||||
<Input disabled={filter.noValue} bind:value={filter.value} />
|
disabled={!filter.field}
|
||||||
{:else if ["options", "array"].includes(filter.type)}
|
options={LuceneUtils.getValidOperatorsForType(filter.type)}
|
||||||
<Combobox
|
bind:value={filter.operator}
|
||||||
disabled={filter.noValue}
|
on:change={e => onOperatorChange(filter, e.detail)}
|
||||||
options={getFieldOptions(filter.field)}
|
placeholder={null}
|
||||||
bind:value={filter.value}
|
|
||||||
/>
|
/>
|
||||||
{:else if filter.type === "boolean"}
|
<Select
|
||||||
<Combobox
|
disabled={filter.noValue || !filter.field}
|
||||||
disabled={filter.noValue}
|
options={valueTypeOptions}
|
||||||
options={[
|
bind:value={filter.valueType}
|
||||||
{ label: "True", value: "true" },
|
placeholder={null}
|
||||||
{ label: "False", value: "false" },
|
|
||||||
]}
|
|
||||||
bind:value={filter.value}
|
|
||||||
/>
|
/>
|
||||||
{:else if filter.type === "datetime"}
|
{#if filter.valueType === "Binding"}
|
||||||
<DatePicker
|
<DrawerBindableInput
|
||||||
disabled={filter.noValue}
|
disabled={filter.noValue}
|
||||||
enableTime={!getSchema(filter).dateOnly}
|
title={`Value for "${filter.field}"`}
|
||||||
timeOnly={getSchema(filter).timeOnly}
|
value={filter.value}
|
||||||
bind:value={filter.value}
|
placeholder="Value"
|
||||||
|
{panel}
|
||||||
|
{bindings}
|
||||||
|
on:change={event => (filter.value = event.detail)}
|
||||||
|
/>
|
||||||
|
{:else if ["string", "longform", "number", "formula"].includes(filter.type)}
|
||||||
|
<Input disabled={filter.noValue} bind:value={filter.value} />
|
||||||
|
{:else if ["options", "array"].includes(filter.type)}
|
||||||
|
<Combobox
|
||||||
|
disabled={filter.noValue}
|
||||||
|
options={getFieldOptions(filter.field)}
|
||||||
|
bind:value={filter.value}
|
||||||
|
/>
|
||||||
|
{:else if filter.type === "boolean"}
|
||||||
|
<Combobox
|
||||||
|
disabled={filter.noValue}
|
||||||
|
options={[
|
||||||
|
{ label: "True", value: "true" },
|
||||||
|
{ label: "False", value: "false" },
|
||||||
|
]}
|
||||||
|
bind:value={filter.value}
|
||||||
|
/>
|
||||||
|
{:else if filter.type === "datetime"}
|
||||||
|
<DatePicker
|
||||||
|
disabled={filter.noValue}
|
||||||
|
enableTime={!getSchema(filter).dateOnly}
|
||||||
|
timeOnly={getSchema(filter).timeOnly}
|
||||||
|
bind:value={filter.value}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<DrawerBindableInput disabled />
|
||||||
|
{/if}
|
||||||
|
<Icon
|
||||||
|
name="Duplicate"
|
||||||
|
hoverable
|
||||||
|
size="S"
|
||||||
|
on:click={() => duplicateFilter(filter.id)}
|
||||||
/>
|
/>
|
||||||
{:else}
|
<Icon
|
||||||
<DrawerBindableInput disabled />
|
name="Close"
|
||||||
{/if}
|
hoverable
|
||||||
<Icon
|
size="S"
|
||||||
name="Duplicate"
|
on:click={() => removeFilter(filter.id)}
|
||||||
hoverable
|
/>
|
||||||
size="S"
|
{/each}
|
||||||
on:click={() => duplicateFilter(filter.id)}
|
</div>
|
||||||
/>
|
|
||||||
<Icon
|
|
||||||
name="Close"
|
|
||||||
hoverable
|
|
||||||
size="S"
|
|
||||||
on:click={() => removeFilter(filter.id)}
|
|
||||||
/>
|
|
||||||
{/each}
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="bottom">
|
<div class="bottom">
|
||||||
<Button icon="AddCircle" size="M" secondary on:click={addFilter}>
|
<Button icon="AddCircle" size="M" secondary on:click={addFilter}>
|
||||||
Add filter
|
Add filter
|
||||||
</Button>
|
</Button>
|
||||||
<div class="toggle">
|
|
||||||
<Toggle
|
|
||||||
value={allOr}
|
|
||||||
on:change={event => (allOr = event.detail)}
|
|
||||||
/><Label size="L">OR conditions</Label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
</div>
|
</div>
|
||||||
|
@ -216,10 +234,8 @@
|
||||||
grid-template-columns: 1fr 120px 120px 1fr auto auto;
|
grid-template-columns: 1fr 120px 120px 1fr auto auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle {
|
.filter-label {
|
||||||
display: flex;
|
margin-bottom: var(--spacing-s);
|
||||||
align-items: center;
|
|
||||||
padding-right: var(--spacing-s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.bottom {
|
.bottom {
|
||||||
|
|
Loading…
Reference in New Issue