1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Standardise cell condition operators

This commit is contained in:
Andrew Kingston 2024-06-27 09:10:25 +01:00
parent 42162e711a
commit feffd80d11
No known key found for this signature in database
2 changed files with 98 additions and 75 deletions

View file

@ -134,8 +134,8 @@ a {
.spectrum--light,
.spectrum--lightest {
--drop-shadow: rgba(0, 0, 0, 0.075);
--spectrum-global-color-red-100: #ffebe7;
--spectrum-global-color-orange-100: #ffeccc;
--spectrum-global-color-red-100: #ffddd6;
--spectrum-global-color-orange-100: #ffdfad;
--spectrum-global-color-yellow-100: #fbf198;
--spectrum-global-color-green-100: #cef8e0;
--spectrum-global-color-seafoam-100: #cef7f3;

View file

@ -15,21 +15,36 @@
import { QueryUtils, Constants } from "@budibase/frontend-core"
import { generate } from "shortid"
import { FieldType } from "@budibase/types"
import { dndzone } from "svelte-dnd-action"
import { flip } from "svelte/animate"
export let componentInstance
export let bindings
export let value
const dispatch = createEventDispatcher()
const flipDuration = 130
let tempValue = []
let drawer
let dragDisabled = true
$: conditionCount = value?.length
$: conditionText = `${conditionCount || "No"} condition${
conditionCount !== 1 ? "s" : ""
} set`
$: valueTypeOptions = getValueTypeOptions(componentInstance.columnType)
$: type = componentInstance.columnType
$: valueTypeOptions = [
{
label: "Binding",
value: FieldType.STRING,
},
{
label: "Value",
value: type,
},
]
$: operatorOptions = QueryUtils.getValidOperatorsForType({ type })
const openDrawer = () => {
tempValue = cloneDeep(value || [])
@ -41,23 +56,6 @@
drawer.hide()
}
const getValueTypeOptions = type => {
let options = [
{
label: "Binding",
value: FieldType.STRING,
},
]
const operatorOptions = QueryUtils.getValidOperatorsForType({ type })
if (operatorOptions.length) {
options.push({
label: "Value",
value: type,
})
}
return options
}
const addCondition = () => {
const condition = {
id: generate(),
@ -76,10 +74,6 @@
tempValue = tempValue.filter(c => c.id !== condition.id)
}
const getOperatorOptions = condition => {
return QueryUtils.getValidOperatorsForType({ type: condition.valueType })
}
const onOperatorChange = (condition, newOperator) => {
const noValueOptions = [
Constants.OperatorOptions.Empty.value,
@ -92,31 +86,54 @@
}
}
const onValueTypeChange = (condition, newType) => {
const onValueTypeChange = condition => {
condition.referenceValue = null
// Ensure a valid operator is set
const validOperators = QueryUtils.getValidOperatorsForType({
type: newType,
}).map(x => x.value)
if (!validOperators.includes(condition.operator)) {
condition.operator =
validOperators[0] ?? Constants.OperatorOptions.Equals.value
onOperatorChange(condition, condition.operator)
}
const updateConditions = e => {
tempValue = e.detail.items
}
const handleFinalize = e => {
updateConditions(e)
dragDisabled = true
}
</script>
<ActionButton on:click={openDrawer}>{conditionText}</ActionButton>
<!-- svelte-ignore a11y-no-static-element-interactions -->
<Drawer bind:this={drawer} title="Conditions" on:drawerShow on:drawerHide>
<Button cta slot="buttons" on:click={save}>Save</Button>
<DrawerContent slot="body">
<div class="container">
<Layout noPadding>
{#if tempValue.length}
<div class="conditions">
{#each tempValue as condition}
<div
class="conditions"
use:dndzone={{
items: tempValue,
flipDurationMs: flipDuration,
dropTargetStyle: { outline: "none" },
dragDisabled,
}}
on:consider={updateConditions}
on:finalize={handleFinalize}
>
{#each tempValue as condition (condition.id)}
<div
class="condition"
class:update={condition.action === "update"}
animate:flip={{ duration: flipDuration }}
>
<div
class="handle"
aria-label="drag-handle"
style={dragDisabled ? "cursor: grab" : "cursor: grabbing"}
on:mousedown={() => (dragDisabled = false)}
>
<Icon name="DragHandle" size="XL" />
</div>
<span>Set background color to</span>
<ColorPicker
value={condition.color}
@ -125,7 +142,7 @@
<span>if value</span>
<Select
placeholder={null}
options={getOperatorOptions(condition)}
options={operatorOptions}
bind:value={condition.operator}
on:change={e => onOperatorChange(condition, e.detail)}
/>
@ -134,10 +151,11 @@
options={valueTypeOptions}
bind:value={condition.valueType}
placeholder={null}
on:change={e => onValueTypeChange(condition, e.detail)}
on:change={() => onValueTypeChange(condition)}
/>
<DrawerBindableInput
{bindings}
disabled={condition.noValue}
placeholder="Value"
value={condition.referenceValue}
on:change={e => (condition.referenceValue = e.detail)}
@ -154,6 +172,7 @@
size="S"
on:click={() => removeCondition(condition)}
/>
</div>
{/each}
</div>
{/if}
@ -174,10 +193,14 @@
margin: 0 auto;
}
.conditions {
display: flex;
flex-direction: column;
gap: var(--spacing-l);
}
.condition {
display: grid;
grid-template-columns: auto auto auto 1fr 1fr 1fr auto auto;
grid-template-columns: auto auto auto auto 1fr 1fr 1fr auto auto;
align-items: center;
grid-column-gap: var(--spacing-l);
grid-row-gap: var(--spacing-l);
}
</style>