Type grid utils
This commit is contained in:
parent
de59cf9b6c
commit
b0e5858768
|
@ -1,7 +1,7 @@
|
||||||
import { GeneratedIDPrefix, CellIDSeparator } from "./constants"
|
import { GeneratedIDPrefix, CellIDSeparator } from "./constants"
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
|
|
||||||
export const parseCellID = cellId => {
|
export const parseCellID = (cellId: string | null) => {
|
||||||
if (!cellId) {
|
if (!cellId) {
|
||||||
return { rowId: undefined, field: undefined }
|
return { rowId: undefined, field: undefined }
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,11 @@ export const parseCellID = cellId => {
|
||||||
return { rowId: parts.join(CellIDSeparator), field }
|
return { rowId: parts.join(CellIDSeparator), field }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCellID = (rowId, fieldName) => {
|
export const getCellID = (rowId: string, fieldName: string) => {
|
||||||
return `${rowId}${CellIDSeparator}${fieldName}`
|
return `${rowId}${CellIDSeparator}${fieldName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parseEventLocation = e => {
|
export const parseEventLocation = (e: MouseEvent & TouchEvent) => {
|
||||||
return {
|
return {
|
||||||
x: e.clientX ?? e.touches?.[0]?.clientX,
|
x: e.clientX ?? e.touches?.[0]?.clientX,
|
||||||
y: e.clientY ?? e.touches?.[0]?.clientY,
|
y: e.clientY ?? e.touches?.[0]?.clientY,
|
||||||
|
@ -25,6 +25,6 @@ export const generateRowID = () => {
|
||||||
return `${GeneratedIDPrefix}${Helpers.uuid()}`
|
return `${GeneratedIDPrefix}${Helpers.uuid()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isGeneratedRowID = id => {
|
export const isGeneratedRowID = (id: string) => {
|
||||||
return id?.startsWith(GeneratedIDPrefix)
|
return id?.startsWith(GeneratedIDPrefix)
|
||||||
}
|
}
|
|
@ -69,7 +69,7 @@ export const createActions = (context: StoreContext): MenuActions => {
|
||||||
let multiRowMode = false
|
let multiRowMode = false
|
||||||
if (get(selectedRowCount) > 1) {
|
if (get(selectedRowCount) > 1) {
|
||||||
const { rowId } = parseCellID(cellId)
|
const { rowId } = parseCellID(cellId)
|
||||||
if (get(selectedRows)[rowId]) {
|
if (rowId !== undefined && get(selectedRows)[rowId]) {
|
||||||
multiRowMode = true
|
multiRowMode = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,10 @@ export const deriveStores = (context: StoreContext) => {
|
||||||
const focusedRow = derived(
|
const focusedRow = derived(
|
||||||
[focusedRowId, rowLookupMap],
|
[focusedRowId, rowLookupMap],
|
||||||
([$focusedRowId, $rowLookupMap]) => {
|
([$focusedRowId, $rowLookupMap]) => {
|
||||||
|
if ($focusedRowId === undefined) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if ($focusedRowId === NewRowID) {
|
if ($focusedRowId === NewRowID) {
|
||||||
return { _id: NewRowID }
|
return { _id: NewRowID }
|
||||||
}
|
}
|
||||||
|
@ -152,8 +156,8 @@ export const deriveStores = (context: StoreContext) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Row indices
|
// Row indices
|
||||||
const sourceRowIndex = $rowLookupMap[sourceInfo.rowId]?.__idx
|
const sourceRowIndex = $rowLookupMap[sourceInfo.rowId!]?.__idx
|
||||||
const targetRowIndex = $rowLookupMap[targetInfo.rowId]?.__idx
|
const targetRowIndex = $rowLookupMap[targetInfo.rowId!]?.__idx
|
||||||
if (sourceRowIndex == null || targetRowIndex == null) {
|
if (sourceRowIndex == null || targetRowIndex == null) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -164,8 +168,8 @@ export const deriveStores = (context: StoreContext) => {
|
||||||
upperRowIndex = Math.min(upperRowIndex, lowerRowIndex + 49)
|
upperRowIndex = Math.min(upperRowIndex, lowerRowIndex + 49)
|
||||||
|
|
||||||
// Column indices
|
// Column indices
|
||||||
const sourceColIndex = $columnLookupMap[sourceInfo.field].__idx || 0
|
const sourceColIndex = $columnLookupMap[sourceInfo.field!].__idx || 0
|
||||||
const targetColIndex = $columnLookupMap[targetInfo.field].__idx || 0
|
const targetColIndex = $columnLookupMap[targetInfo.field!].__idx || 0
|
||||||
const lowerColIndex = Math.min(sourceColIndex, targetColIndex)
|
const lowerColIndex = Math.min(sourceColIndex, targetColIndex)
|
||||||
const upperColIndex = Math.max(sourceColIndex, targetColIndex)
|
const upperColIndex = Math.max(sourceColIndex, targetColIndex)
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,12 @@ export const deriveStores = (context: StoreContext): DerivedValidationStore => {
|
||||||
// Extract row ID from all errored cell IDs
|
// Extract row ID from all errored cell IDs
|
||||||
if (error) {
|
if (error) {
|
||||||
const { rowId } = parseCellID(key)
|
const { rowId } = parseCellID(key)
|
||||||
if (!map[rowId]) {
|
if (rowId !== undefined) {
|
||||||
map[rowId] = []
|
if (!map[rowId]) {
|
||||||
|
map[rowId] = []
|
||||||
|
}
|
||||||
|
map[rowId].push(key)
|
||||||
}
|
}
|
||||||
map[rowId].push(key)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return map
|
return map
|
||||||
|
|
Loading…
Reference in New Issue