1
0
Fork 0
mirror of synced 2024-09-10 06:26:02 +12:00

More simplification of columns

This commit is contained in:
Andrew Kingston 2024-06-24 14:02:35 +01:00
parent 6acffc7e64
commit 9b33ee1cee
No known key found for this signature in database
7 changed files with 27 additions and 26 deletions

View file

@ -9,7 +9,7 @@
rows,
subscribe,
selectedRowCount,
allVisibleColumns,
visibleColumns,
selectedCells,
rowLookupMap,
} = getContext("grid")
@ -40,8 +40,8 @@
if (newRows.length) {
const firstRow = newRows[0]
const lastRow = newRows[newRows.length - 1]
const firstCol = $allVisibleColumns[0]
const lastCol = $allVisibleColumns[$allVisibleColumns.length - 1]
const firstCol = $visibleColumns[0]
const lastCol = $visibleColumns[$visibleColumns.length - 1]
const startCellId = getCellID(firstRow._id, firstCol.name)
const endCellId = getCellID(lastRow._id, lastCol.name)
selectedCells.actions.selectRange(startCellId, endCellId)

View file

@ -19,7 +19,6 @@
selectedCells,
cellSelection,
columnLookupMap,
allVisibleColumns,
} = getContext("grid")
const ignoredOriginSelectors = [
@ -188,7 +187,7 @@
// Determine the new position for this cell
const { rowId, field } = parseCellID(sourceCellId)
const colIdx = $columnLookupMap[field]
const nextColumn = $allVisibleColumns[colIdx + delta]
const nextColumn = $visibleColumns[colIdx + delta]
if (!nextColumn) {
return
}

View file

@ -18,7 +18,7 @@
copyAllowed,
pasteAllowed,
selectedCellCount,
allVisibleColumns,
visibleColumns,
selectedCells,
} = getContext("grid")
@ -41,8 +41,8 @@
menu.actions.close()
const newRow = await rows.actions.duplicateRow($focusedRow)
if (newRow) {
const firstCol = $allVisibleColumns[0]
const lastCol = $allVisibleColumns[$allVisibleColumns.length - 1]
const firstCol = $visibleColumns[0]
const lastCol = $visibleColumns[$visibleColumns.length - 1]
const startCellId = getCellID(newRow._id, firstCol.name)
const endCellId = getCellID(newRow._id, lastCol.name)
selectedCells.actions.selectRange(startCellId, endCellId)

View file

@ -64,7 +64,7 @@ export const createActions = context => {
rows,
focusedCellId,
columnLookupMap,
allVisibleColumns,
visibleColumns,
} = context
// Copies the currently selected value (or values)
@ -162,8 +162,8 @@ export const createActions = context => {
// Get limits of how many rows and columns we're able to paste into
const $rows = get(rows)
const $allVisibleColumns = get(allVisibleColumns)
const colCount = $allVisibleColumns.length
const $visibleColumns = get(visibleColumns)
const colCount = $visibleColumns.length
const rowCount = $rows.length
const selectedRows = value.length
const selectedColumns = value[0].length
@ -172,7 +172,7 @@ export const createActions = context => {
// Get the target cell ID (bottom right of our pastable extent)
const targetRowId = $rows[rowIdx + rowExtent]._id
const targetColName = $allVisibleColumns[colIdx + colExtent].name
const targetColName = $visibleColumns[colIdx + colExtent].name
const targetCellId = getCellID(targetRowId, targetColName)
// Paste into target cell range

View file

@ -6,16 +6,15 @@ export const createStores = () => {
const enrichedColumns = derived(columns, $columns => {
let offset = GutterWidth
let visibleIdx = 0
return $columns.map((col, idx) => {
let idx = 0
return $columns.map(col => {
const enriched = {
...col,
__idx: idx, // Overall column index
__visibleIdx: visibleIdx, // Index within the visible columns
__left: offset, // Left offset relative to all visible columns
__idx: idx,
__left: offset,
}
if (col.visible) {
visibleIdx++
idx++
offset += col.width
}
return enriched

View file

@ -196,12 +196,15 @@ export const createActions = context => {
targetColumn,
insertAfter = false,
}) => {
const $columnLookupMap = get(columnLookupMap)
let sourceIdx = $columnLookupMap[sourceColumn].__idx
let targetIdx = $columnLookupMap[targetColumn].__idx
// Find the indices in the overall columns array
const $columns = get(columns)
let sourceIdx = $columns.findIndex(col => col.name === sourceColumn)
let targetIdx = $columns.findIndex(col => col.name === targetColumn)
if (insertAfter) {
targetIdx++
}
// Reorder columns
columns.update(state => {
const removed = state.splice(sourceIdx, 1)
if (--targetIdx < sourceIdx) {

View file

@ -54,7 +54,7 @@ export const deriveStores = context => {
selectedRows,
cellSelection,
columnLookupMap,
allVisibleColumns,
visibleColumns,
} = context
// Derive the current focused row ID
@ -107,7 +107,7 @@ export const deriveStores = context => {
return []
}
const $rows = get(rows)
const $allVisibleColumns = get(allVisibleColumns)
const $visibleColumns = get(visibleColumns)
// Get source and target row and column indices
const sourceInfo = parseCellID(sourceCellId)
@ -120,8 +120,8 @@ export const deriveStores = context => {
const upperRowIndex = Math.max(sourceRowIndex, targetRowIndex)
// Column indices
const sourceColIndex = $columnLookupMap[sourceInfo.field]
const targetColIndex = $columnLookupMap[targetInfo.field]
const sourceColIndex = $columnLookupMap[sourceInfo.field].__idx
const targetColIndex = $columnLookupMap[targetInfo.field].__idx
const lowerColIndex = Math.min(sourceColIndex, targetColIndex)
const upperColIndex = Math.max(sourceColIndex, targetColIndex)
@ -132,7 +132,7 @@ export const deriveStores = context => {
let rowCells = []
for (let colIdx = lowerColIndex; colIdx <= upperColIndex; colIdx++) {
rowId = $rows[rowIdx]._id
colName = $allVisibleColumns[colIdx].name
colName = $visibleColumns[colIdx].name
rowCells.push(getCellID(rowId, colName))
}
cells.push(rowCells)