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 { getColumnIcon } from "../lib/utils"
import { debounce } from "../../../utils/utils"
import { FieldType, FormulaTypes } from "@budibase/types"
export let column
export let idx
@ -29,7 +30,14 @@
filter,
} = 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 open = false
@ -42,21 +50,20 @@
$: sortedBy = column.name === $sort.column
$: canMoveLeft = orderable && idx > 0
$: canMoveRight = orderable && idx < $renderedColumns.length - 1
$: ascendingLabel = ["number", "bigint"].includes(column.schema?.type)
? "low-high"
: "A-Z"
$: descendingLabel = ["number", "bigint"].includes(column.schema?.type)
? "high-low"
: "Z-A"
$: numericType = [FieldType.NUMBER, FieldType.BIGINT].includes(
column.schema?.type
)
$: ascendingLabel = numericType ? "low-high" : "A-Z"
$: descendingLabel = numericType ? "high-low" : "Z-A"
$: searchable = isColumnSearchable(column)
$: searching = searchValue != null
$: debouncedUpdateFilter(searchValue)
const isColumnSearchable = col => {
const type = col.schema.type
const { type, formulaType } = col.schema
return (
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 { FieldType } from "@budibase/types"
export const createStores = context => {
const { props } = context
@ -27,10 +28,12 @@ export const createActions = context => {
}
// Add overrides specific so the certain column type
if (type === "number") {
if (type === FieldType.NUMBER) {
inlineFilter.value = parseFloat(value)
inlineFilter.operator = "equal"
} else if (type === "array") {
} else if (type === FieldType.BIGINT) {
inlineFilter.operator = "equal"
} else if (type === FieldType.ARRAY) {
inlineFilter.operator = "contains"
}