Use existing _id values for non DS+ in tables, trusting that they are unique
This commit is contained in:
parent
20ed18a0e2
commit
0b8199be74
|
@ -10,6 +10,8 @@ export const DefaultColumnWidth = 200
|
||||||
export const MinColumnWidth = 80
|
export const MinColumnWidth = 80
|
||||||
export const NewRowID = "new"
|
export const NewRowID = "new"
|
||||||
export const BlankRowID = "blank"
|
export const BlankRowID = "blank"
|
||||||
|
export const GeneratedIDPrefix = "‽‽"
|
||||||
|
export const CellIDSeparator = "‽‽"
|
||||||
export const RowPageSize = 100
|
export const RowPageSize = 100
|
||||||
export const FocusedCellMinOffset = ScrollBarSize * 3
|
export const FocusedCellMinOffset = ScrollBarSize * 3
|
||||||
export const ControlsHeight = 50
|
export const ControlsHeight = 50
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
// We can't use "-" as a separator as this can be present in the ID
|
import { GeneratedIDPrefix, CellIDSeparator } from "./constants"
|
||||||
// or column name, so we use something very unusual to avoid this problem
|
import { Helpers } from "@budibase/bbui"
|
||||||
const JOINING_CHARACTER = "‽‽"
|
|
||||||
|
|
||||||
export const parseCellID = cellId => {
|
export const parseCellID = cellId => {
|
||||||
if (!cellId) {
|
if (!cellId) {
|
||||||
return { rowId: undefined, field: undefined }
|
return { rowId: undefined, field: undefined }
|
||||||
}
|
}
|
||||||
const parts = cellId.split(JOINING_CHARACTER)
|
const parts = cellId.split(CellIDSeparator)
|
||||||
const field = parts.pop()
|
const field = parts.pop()
|
||||||
return { rowId: parts.join(JOINING_CHARACTER), field }
|
return { rowId: parts.join(CellIDSeparator), field }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCellID = (rowId, fieldName) => {
|
export const getCellID = (rowId, fieldName) => {
|
||||||
return `${rowId}${JOINING_CHARACTER}${fieldName}`
|
return `${rowId}${CellIDSeparator}${fieldName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parseEventLocation = e => {
|
export const parseEventLocation = e => {
|
||||||
|
@ -21,3 +20,11 @@ export const parseEventLocation = e => {
|
||||||
y: e.clientY ?? e.touches?.[0]?.clientY,
|
y: e.clientY ?? e.touches?.[0]?.clientY,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const generateRowID = () => {
|
||||||
|
return `${GeneratedIDPrefix}${Helpers.uuid()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isGeneratedRowID = id => {
|
||||||
|
return id?.startsWith(GeneratedIDPrefix)
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import { writable, derived, get } from "svelte/store"
|
import { writable, derived, get } from "svelte/store"
|
||||||
import { fetchData } from "../../../fetch"
|
import { fetchData } from "../../../fetch"
|
||||||
import { NewRowID, RowPageSize } from "../lib/constants"
|
import { NewRowID, RowPageSize } from "../lib/constants"
|
||||||
import { getCellID, parseCellID } from "../lib/utils"
|
import {
|
||||||
|
generateRowID,
|
||||||
|
getCellID,
|
||||||
|
isGeneratedRowID,
|
||||||
|
parseCellID,
|
||||||
|
} from "../lib/utils"
|
||||||
import { tick } from "svelte"
|
import { tick } from "svelte"
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
import { sleep } from "../../../utils/utils"
|
import { sleep } from "../../../utils/utils"
|
||||||
|
@ -634,10 +639,10 @@ export const createActions = context => {
|
||||||
newRow = newRows[i]
|
newRow = newRows[i]
|
||||||
|
|
||||||
// Ensure we have a unique _id.
|
// Ensure we have a unique _id.
|
||||||
// This means generating one for non DS+, overwriting any that may already
|
// We generate one for non DS+ where required, but trust that any existing
|
||||||
// exist as we cannot allow duplicates.
|
// _id values are unique (e.g. Mongo)
|
||||||
if (!$hasBudibaseIdentifiers) {
|
if (!$hasBudibaseIdentifiers && !newRow._id?.length) {
|
||||||
newRow._id = Helpers.uuid()
|
newRow._id = generateRowID()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rowCacheMap[newRow._id]) {
|
if (!rowCacheMap[newRow._id]) {
|
||||||
|
@ -674,7 +679,7 @@ export const createActions = context => {
|
||||||
let clone = { ...row }
|
let clone = { ...row }
|
||||||
delete clone.__idx
|
delete clone.__idx
|
||||||
delete clone.__metadata
|
delete clone.__metadata
|
||||||
if (!get(hasBudibaseIdentifiers)) {
|
if (!get(hasBudibaseIdentifiers) && isGeneratedRowID(clone._id)) {
|
||||||
delete clone._id
|
delete clone._id
|
||||||
}
|
}
|
||||||
return clone
|
return clone
|
||||||
|
|
Loading…
Reference in New Issue