Refactor to use types for fields and add support for searching bigint columns

This commit is contained in:
Andrew Kingston 2023-10-13 09:36:50 +01:00
parent 6dfe2c22af
commit 804aab3e43
2 changed files with 21 additions and 11 deletions

View File

@ -5,6 +5,7 @@
import GridCell from "./GridCell.svelte" import GridCell from "./GridCell.svelte"
import { getColumnIcon } from "../lib/utils" import { getColumnIcon } from "../lib/utils"
import { debounce } from "../../../utils/utils" import { debounce } from "../../../utils/utils"
import { FieldType, FormulaTypes } from "@budibase/types"
export let column export let column
export let idx export let idx
@ -29,7 +30,14 @@
filter, filter,
} = getContext("grid") } = getContext("grid")
const searchableTypes = ["string", "options", "number", "array", "longform"] const searchableTypes = [
FieldType.STRING,
FieldType.OPTIONS,
FieldType.NUMBER,
FieldType.BIGINT,
FieldType.ARRAY,
FieldType.LONGFORM,
]
let anchor let anchor
let open = false let open = false
@ -42,21 +50,20 @@
$: sortedBy = column.name === $sort.column $: sortedBy = column.name === $sort.column
$: canMoveLeft = orderable && idx > 0 $: canMoveLeft = orderable && idx > 0
$: canMoveRight = orderable && idx < $renderedColumns.length - 1 $: canMoveRight = orderable && idx < $renderedColumns.length - 1
$: ascendingLabel = ["number", "bigint"].includes(column.schema?.type) $: numericType = [FieldType.NUMBER, FieldType.BIGINT].includes(
? "low-high" column.schema?.type
: "A-Z" )
$: descendingLabel = ["number", "bigint"].includes(column.schema?.type) $: ascendingLabel = numericType ? "low-high" : "A-Z"
? "high-low" $: descendingLabel = numericType ? "high-low" : "Z-A"
: "Z-A"
$: searchable = isColumnSearchable(column) $: searchable = isColumnSearchable(column)
$: searching = searchValue != null $: searching = searchValue != null
$: debouncedUpdateFilter(searchValue) $: debouncedUpdateFilter(searchValue)
const isColumnSearchable = col => { const isColumnSearchable = col => {
const type = col.schema.type const { type, formulaType } = col.schema
return ( return (
searchableTypes.includes(type) || searchableTypes.includes(type) ||
(type === "formula" && col.schema.formulaType === "static") (type === FieldType.FORMULA && formulaType === FormulaTypes.STATIC)
) )
} }

View File

@ -1,4 +1,5 @@
import { writable, get } from "svelte/store" import { writable, get } from "svelte/store"
import { FieldType } from "@budibase/types"
export const createStores = context => { export const createStores = context => {
const { props } = context const { props } = context
@ -27,10 +28,12 @@ export const createActions = context => {
} }
// Add overrides specific so the certain column type // Add overrides specific so the certain column type
if (type === "number") { if (type === FieldType.NUMBER) {
inlineFilter.value = parseFloat(value) inlineFilter.value = parseFloat(value)
inlineFilter.operator = "equal" inlineFilter.operator = "equal"
} else if (type === "array") { } else if (type === FieldType.BIGINT) {
inlineFilter.operator = "equal"
} else if (type === FieldType.ARRAY) {
inlineFilter.operator = "contains" inlineFilter.operator = "contains"
} }