Type grid utils

This commit is contained in:
Adria Navarro 2024-12-27 08:57:00 +01:00
parent de59cf9b6c
commit b0e5858768
4 changed files with 18 additions and 12 deletions

View File

@ -1,7 +1,7 @@
import { GeneratedIDPrefix, CellIDSeparator } from "./constants"
import { Helpers } from "@budibase/bbui"
export const parseCellID = cellId => {
export const parseCellID = (cellId: string | null) => {
if (!cellId) {
return { rowId: undefined, field: undefined }
}
@ -10,11 +10,11 @@ export const parseCellID = cellId => {
return { rowId: parts.join(CellIDSeparator), field }
}
export const getCellID = (rowId, fieldName) => {
export const getCellID = (rowId: string, fieldName: string) => {
return `${rowId}${CellIDSeparator}${fieldName}`
}
export const parseEventLocation = e => {
export const parseEventLocation = (e: MouseEvent & TouchEvent) => {
return {
x: e.clientX ?? e.touches?.[0]?.clientX,
y: e.clientY ?? e.touches?.[0]?.clientY,
@ -25,6 +25,6 @@ export const generateRowID = () => {
return `${GeneratedIDPrefix}${Helpers.uuid()}`
}
export const isGeneratedRowID = id => {
export const isGeneratedRowID = (id: string) => {
return id?.startsWith(GeneratedIDPrefix)
}

View File

@ -69,7 +69,7 @@ export const createActions = (context: StoreContext): MenuActions => {
let multiRowMode = false
if (get(selectedRowCount) > 1) {
const { rowId } = parseCellID(cellId)
if (get(selectedRows)[rowId]) {
if (rowId !== undefined && get(selectedRows)[rowId]) {
multiRowMode = true
}
}

View File

@ -101,6 +101,10 @@ export const deriveStores = (context: StoreContext) => {
const focusedRow = derived(
[focusedRowId, rowLookupMap],
([$focusedRowId, $rowLookupMap]) => {
if ($focusedRowId === undefined) {
return
}
if ($focusedRowId === NewRowID) {
return { _id: NewRowID }
}
@ -152,8 +156,8 @@ export const deriveStores = (context: StoreContext) => {
}
// Row indices
const sourceRowIndex = $rowLookupMap[sourceInfo.rowId]?.__idx
const targetRowIndex = $rowLookupMap[targetInfo.rowId]?.__idx
const sourceRowIndex = $rowLookupMap[sourceInfo.rowId!]?.__idx
const targetRowIndex = $rowLookupMap[targetInfo.rowId!]?.__idx
if (sourceRowIndex == null || targetRowIndex == null) {
return []
}
@ -164,8 +168,8 @@ export const deriveStores = (context: StoreContext) => {
upperRowIndex = Math.min(upperRowIndex, lowerRowIndex + 49)
// Column indices
const sourceColIndex = $columnLookupMap[sourceInfo.field].__idx || 0
const targetColIndex = $columnLookupMap[targetInfo.field].__idx || 0
const sourceColIndex = $columnLookupMap[sourceInfo.field!].__idx || 0
const targetColIndex = $columnLookupMap[targetInfo.field!].__idx || 0
const lowerColIndex = Math.min(sourceColIndex, targetColIndex)
const upperColIndex = Math.max(sourceColIndex, targetColIndex)

View File

@ -33,11 +33,13 @@ export const deriveStores = (context: StoreContext): DerivedValidationStore => {
// Extract row ID from all errored cell IDs
if (error) {
const { rowId } = parseCellID(key)
if (rowId !== undefined) {
if (!map[rowId]) {
map[rowId] = []
}
map[rowId].push(key)
}
}
})
return map
})