From 89c0d3b38967af49fa92eff9fd76b8cacb8644a2 Mon Sep 17 00:00:00 2001
From: melohagan <101575380+melohagan@users.noreply.github.com>
Date: Tue, 11 Jul 2023 14:01:55 +0100
Subject: [PATCH] Add BigInt type support (#11145) (#11195)
* Add BigInt type
* Allow BigInt columns to be added
* Sort fixes
* Add BigInt field
---
packages/bbui/src/Form/Core/TextField.svelte | 9 +++-
.../screenTemplates/utils/commonComponents.js | 1 +
.../DataTable/modals/CreateEditColumn.svelte | 1 +
.../design/settings/componentSettings.js | 1 +
.../controls/FilterEditor/FilterDrawer.svelte | 2 +-
.../builder/src/constants/backend/index.js | 4 ++
.../new/_components/componentStructure.json | 17 ++-----
packages/client/manifest.json | 51 +++++++++++++++++++
.../app/blocks/form/InnerFormBlock.svelte | 1 +
.../app/dynamic-filter/FilterModal.svelte | 2 +-
.../components/app/forms/BigIntField.svelte | 7 +++
.../src/components/app/forms/Field.svelte | 5 +-
.../client/src/components/app/forms/index.js | 1 +
packages/client/src/utils/blocks.js | 1 +
.../components/grid/cells/HeaderCell.svelte | 8 ++-
.../src/components/grid/lib/utils.js | 1 +
packages/frontend-core/src/fetch/DataFetch.js | 2 +-
.../server/src/integrations/base/sqlTable.ts | 3 ++
packages/server/src/integrations/utils.ts | 2 +-
packages/shared-core/src/filters.ts | 2 +-
packages/types/src/documents/app/row.ts | 1 +
21 files changed, 99 insertions(+), 23 deletions(-)
create mode 100644 packages/client/src/components/app/forms/BigIntField.svelte
diff --git a/packages/bbui/src/Form/Core/TextField.svelte b/packages/bbui/src/Form/Core/TextField.svelte
index acc2169a06..b3b0865c64 100644
--- a/packages/bbui/src/Form/Core/TextField.svelte
+++ b/packages/bbui/src/Form/Core/TextField.svelte
@@ -62,6 +62,13 @@
}
}
+ const getInputMode = type => {
+ if (type === "bigint") {
+ return "numeric"
+ }
+ return type === "number" ? "decimal" : "text"
+ }
+
onMount(() => {
focus = autofocus
if (focus) field.focus()
@@ -103,7 +110,7 @@
{type}
class="spectrum-Textfield-input"
style={align ? `text-align: ${align};` : ""}
- inputmode={type === "number" ? "decimal" : "text"}
+ inputmode={getInputMode(type)}
{autocomplete}
/>
diff --git a/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js b/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js
index 6fdedbe44c..ace5196bba 100644
--- a/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js
+++ b/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js
@@ -4,6 +4,7 @@ import { getSchemaForDatasource } from "../../../dataBinding"
const fieldTypeToComponentMap = {
string: "stringfield",
number: "numberfield",
+ bigint: "bigintfield",
options: "optionsfield",
array: "multifieldselect",
boolean: "booleanfield",
diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte
index 665175a435..6ffd7f8bb3 100644
--- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte
+++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte
@@ -330,6 +330,7 @@
FIELDS.NUMBER,
FIELDS.BOOLEAN,
FIELDS.FORMULA,
+ FIELDS.BIGINT,
]
// no-sql or a spreadsheet
if (!external || table.sql) {
diff --git a/packages/builder/src/components/design/settings/componentSettings.js b/packages/builder/src/components/design/settings/componentSettings.js
index b3b9fb6577..314391e77c 100644
--- a/packages/builder/src/components/design/settings/componentSettings.js
+++ b/packages/builder/src/components/design/settings/componentSettings.js
@@ -52,6 +52,7 @@ const componentMap = {
"field/sortable": SortableFieldSelect,
"field/string": FormFieldSelect,
"field/number": FormFieldSelect,
+ "field/bigint": FormFieldSelect,
"field/options": FormFieldSelect,
"field/boolean": FormFieldSelect,
"field/longform": FormFieldSelect,
diff --git a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte
index f56d7a78d4..e8bbb8a354 100644
--- a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte
+++ b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte
@@ -228,7 +228,7 @@
on:change={event => (filter.value = event.detail)}
{fillWidth}
/>
- {:else if ["string", "longform", "number", "formula"].includes(filter.type)}
+ {:else if ["string", "longform", "number", "bigint", "formula"].includes(filter.type)}
{:else if filter.type === "array" || (filter.type === "options" && filter.operator === "oneOf")}
onOperatorChange(filter, e.detail)}
placeholder={null}
/>
- {#if ["string", "longform", "number", "formula"].includes(filter.type)}
+ {#if ["string", "longform", "number", "bigint", "formula"].includes(filter.type)}
{:else if ["options", "array"].includes(filter.type)}
+ import StringField from "./StringField.svelte"
+
+ export let defaultValue
+
+
+
diff --git a/packages/client/src/components/app/forms/Field.svelte b/packages/client/src/components/app/forms/Field.svelte
index 5f11757c9c..5d4da5afef 100644
--- a/packages/client/src/components/app/forms/Field.svelte
+++ b/packages/client/src/components/app/forms/Field.svelte
@@ -33,7 +33,10 @@
formStep
)
- $: schemaType = fieldSchema?.type !== "formula" ? fieldSchema?.type : "string"
+ $: schemaType =
+ fieldSchema?.type !== "formula" && fieldSchema?.type !== "bigint"
+ ? fieldSchema?.type
+ : "string"
// Focus label when editing
let labelNode
diff --git a/packages/client/src/components/app/forms/index.js b/packages/client/src/components/app/forms/index.js
index 44c1516885..47701fe3a9 100644
--- a/packages/client/src/components/app/forms/index.js
+++ b/packages/client/src/components/app/forms/index.js
@@ -2,6 +2,7 @@ export { default as form } from "./Form.svelte"
export { default as fieldgroup } from "./FieldGroup.svelte"
export { default as stringfield } from "./StringField.svelte"
export { default as numberfield } from "./NumberField.svelte"
+export { default as bigintfield } from "./BigIntField.svelte"
export { default as optionsfield } from "./OptionsField.svelte"
export { default as multifieldselect } from "./MultiFieldSelect.svelte"
export { default as booleanfield } from "./BooleanField.svelte"
diff --git a/packages/client/src/utils/blocks.js b/packages/client/src/utils/blocks.js
index 214b48a4d2..0de0b55579 100644
--- a/packages/client/src/utils/blocks.js
+++ b/packages/client/src/utils/blocks.js
@@ -6,6 +6,7 @@ const schemaComponentMap = {
string: "stringfield",
options: "optionsfield",
number: "numberfield",
+ bigint: "bigintfield",
datetime: "datetimefield",
boolean: "booleanfield",
formula: "stringfield",
diff --git a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte
index 3604dd6d42..9219dd3f59 100644
--- a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte
+++ b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte
@@ -37,8 +37,12 @@
$: sortedBy = column.name === $sort.column
$: canMoveLeft = orderable && idx > 0
$: canMoveRight = orderable && idx < $renderedColumns.length - 1
- $: ascendingLabel = column.schema?.type === "number" ? "low-high" : "A-Z"
- $: descendingLabel = column.schema?.type === "number" ? "high-low" : "Z-A"
+ $: ascendingLabel = ["number", "bigint"].includes(column.schema?.type)
+ ? "low-high"
+ : "A-Z"
+ $: descendingLabel = ["number", "bigint"].includes(column.schema?.type)
+ ? "high-low"
+ : "Z-A"
const editColumn = () => {
dispatch("edit-column", column.schema)
diff --git a/packages/frontend-core/src/components/grid/lib/utils.js b/packages/frontend-core/src/components/grid/lib/utils.js
index 4006b3def6..d4298e6a1b 100644
--- a/packages/frontend-core/src/components/grid/lib/utils.js
+++ b/packages/frontend-core/src/components/grid/lib/utils.js
@@ -18,6 +18,7 @@ const TypeIconMap = {
link: "DataCorrelated",
formula: "Calculator",
json: "Brackets",
+ bigint: "TagBold",
}
export const getColumnIcon = column => {
diff --git a/packages/frontend-core/src/fetch/DataFetch.js b/packages/frontend-core/src/fetch/DataFetch.js
index f9d7fd2624..ea1cfdde77 100644
--- a/packages/frontend-core/src/fetch/DataFetch.js
+++ b/packages/frontend-core/src/fetch/DataFetch.js
@@ -155,7 +155,7 @@ export default class DataFetch {
let sortType = "string"
if (sortColumn) {
const type = schema?.[sortColumn]?.type
- sortType = type === "number" ? "number" : "string"
+ sortType = type === "number" || type === "bigint" ? "number" : "string"
}
this.options.sortType = sortType
diff --git a/packages/server/src/integrations/base/sqlTable.ts b/packages/server/src/integrations/base/sqlTable.ts
index c43ef7da29..62b13c4ef5 100644
--- a/packages/server/src/integrations/base/sqlTable.ts
+++ b/packages/server/src/integrations/base/sqlTable.ts
@@ -53,6 +53,9 @@ function generateSchema(
schema.float(key)
}
break
+ case FieldTypes.BIGINT:
+ schema.bigint(key)
+ break
case FieldTypes.BOOLEAN:
schema.boolean(key)
break
diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts
index 75deaf7f30..3f598ce986 100644
--- a/packages/server/src/integrations/utils.ts
+++ b/packages/server/src/integrations/utils.ts
@@ -48,7 +48,6 @@ const SQL_STRING_TYPE_MAP = {
blob: FieldTypes.STRING,
long: FieldTypes.STRING,
text: FieldTypes.STRING,
- bigint: FieldTypes.STRING,
}
const SQL_BOOLEAN_TYPE_MAP = {
@@ -59,6 +58,7 @@ const SQL_BOOLEAN_TYPE_MAP = {
const SQL_MISC_TYPE_MAP = {
json: FieldTypes.JSON,
+ bigint: FieldTypes.BIGINT,
}
const SQL_TYPE_MAP = {
diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts
index 7c2c34bf6b..54e0df92df 100644
--- a/packages/shared-core/src/filters.ts
+++ b/packages/shared-core/src/filters.ts
@@ -38,7 +38,7 @@ export const getValidOperatorsForType = (
}[] = []
if (type === "string") {
ops = stringOps
- } else if (type === "number") {
+ } else if (type === "number" || type === "bigint") {
ops = numOps
} else if (type === "options") {
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts
index 90c1e3fca8..a2295c4a42 100644
--- a/packages/types/src/documents/app/row.ts
+++ b/packages/types/src/documents/app/row.ts
@@ -15,6 +15,7 @@ export enum FieldType {
JSON = "json",
INTERNAL = "internal",
BARCODEQR = "barcodeqr",
+ BIGINT = "bigint",
}
export interface RowAttachment {