Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

feat(nc-gui): allow deselecting records after select all

Ramesh Manee43acd99f25a
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts
index 0f56f4b069..9e5e57d9cd 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts
@@ -97,6 +97,7 @@ export function useCanvasRender({
upgradeModalInlineState,
rowMetaColumnWidth,
rowColouringBorderWidth,
+ isRecordSelected,
}: {
width: Ref<number>
height: Ref<number>
@@ -177,6 +178,7 @@ export function useCanvasRender({
}>
rowMetaColumnWidth: ComputedRef<number>
rowColouringBorderWidth: ComputedRef<number>
+ isRecordSelected: (row: Row) => boolean
}) {
const canvasRef = ref<HTMLCanvasElement>()
const colResizeHoveredColIds = ref(new Set())
@@ -194,9 +196,6 @@ export function useCanvasRender({
const isSelectedAllRecords = computed(() => vSelectedAllRecords.value && ncIsEmptyObject(vSelectedAllRecordsSkipPks.value))
- const isRecordSelectedInSelectedAllRecords = (rowIdx?: number) =>
- vSelectedAllRecords.value && (!ncIsNumber(rowIdx) || !!vSelectedAllRecordsSkipPks.value[rowIdx])
-
const drawShimmerEffect = (ctx: CanvasRenderingContext2D, x: number, y: number, width: number, rowIdx: number) => {
ctx.save()
@@ -886,17 +885,17 @@ export function useCanvasRender({
rowColor?: string,
) => {
const isHover = hoverRow.value?.rowIndex === row.rowMeta.rowIndex && comparePath(hoverRow.value?.path, row?.rowMeta?.path)
- const isChecked = row.rowMeta?.selected || isRecordSelectedInSelectedAllRecords(row.rowMeta?.rowIndex)
+ const isChecked = isRecordSelected(row)
const isRowCellSelected =
activeCell.value.row === row.rowMeta.rowIndex && comparePath(activeCell.value.path, row?.rowMeta?.path)
- const isDisabled = !row.rowMeta.selected && selectedRows.value.length >= MAX_SELECTED_ROWS
+ const isDisabled = !vSelectedAllRecords.value && !row.rowMeta.selected && selectedRows.value.length >= MAX_SELECTED_ROWS
if (rowColor) {
ctx.fillStyle = rowColor
} else {
ctx.fillStyle = isHover || isRowCellSelected ? '#F9F9FA' : '#ffffff'
- if (row.rowMeta.selected) ctx.fillStyle = '#F6F7FE'
+ if (isChecked) ctx.fillStyle = '#F6F7FE'
}
ctx.fillRect(xOffset, yOffset, width, rowHeight.value)
@@ -1274,8 +1273,10 @@ export function useCanvasRender({
const isRowCellSelected =
activeCell.value.row === rowIdx && comparePath(activeCell.value.path, row?.rowMeta?.path ?? group?.path)
+ const recordSelected = isRecordSelected(row)
+
const rowColor = row?.row
- ? row.rowMeta?.is_set_as_background && (isHovered || row.rowMeta.selected || isRowCellSelected)
+ ? row.rowMeta?.is_set_as_background && (isHovered || recordSelected || isRowCellSelected)
? row.rowMeta.rowHoverColor
: row.rowMeta.rowBgColor
: null
@@ -1320,7 +1321,7 @@ export function useCanvasRender({
isActiveCellInCurrentGroup
if (
- row.rowMeta.selected ||
+ recordSelected ||
(selection.value.isCellInRange({ row: rowIdx, col: absoluteColIdx }) && isActiveCellInCurrentGroup)
) {
ctx.fillStyle = rowColor ? '#3366ff0d' : '#F6F7FE'
@@ -1336,7 +1337,7 @@ export function useCanvasRender({
// Vertical cell lines
ctx.strokeStyle =
- isHovered || row.rowMeta.selected || isColumnInSelection || isRowCellSelected || columnState || prevColumnState
+ isHovered || recordSelected || isColumnInSelection || isRowCellSelected || columnState || prevColumnState
? themeV3Colors.gray['200']
: themeV3Colors.gray['100']
ctx.beginPath()
@@ -1391,7 +1392,7 @@ export function useCanvasRender({
path: groupPath,
skipRender: isCellEditEnabled,
isRowHovered: isHovered,
- isRowChecked: row.rowMeta.selected,
+ isRowChecked: recordSelected,
isCellInSelectionRange:
selection.value.isCellInRange({ row: rowIdx, col: absoluteColIdx }) && isActiveCellInCurrentGroup,
isRootCell: true,
@@ -1413,10 +1414,7 @@ export function useCanvasRender({
activeCell.value.column === colIdx &&
isActiveCellInCurrentGroup
- if (
- row.rowMeta.selected ||
- (selection.value.isCellInRange({ row: rowIdx, col: colIdx }) && isActiveCellInCurrentGroup)
- ) {
+ if (recordSelected || (selection.value.isCellInRange({ row: rowIdx, col: colIdx }) && isActiveCellInCurrentGroup)) {
ctx.fillStyle = rowColor ? '#3366ff0d' : '#F6F7FE'
ctx.fillRect(xOffset, yOffset, width, rowHeight.value)
} else {
@@ -1476,7 +1474,7 @@ export function useCanvasRender({
skipRender: isCellEditEnabled,
path: groupPath,
isRowHovered: isHovered,
- isRowChecked: row.rowMeta.selected,
+ isRowChecked: recordSelected,
isCellInSelectionRange: selection.value.isCellInRange({ row: rowIdx, col: colIdx }) && isActiveCellInCurrentGroup,
isRootCell: true,
})
@@ -1489,7 +1487,7 @@ export function useCanvasRender({
isActiveCellInCurrentGroup
ctx.strokeStyle =
- idx !== 0 && (isHovered || row.rowMeta.selected || isColumnInSelection || isRowCellSelected || rowColor)
+ idx !== 0 && (isHovered || recordSelected || isColumnInSelection || isRowCellSelected || rowColor)
? themeV3Colors.gray['200']
: themeV3Colors.gray['100']
ctx.lineWidth = 1
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
index eed748cbd2..1333f1c2d5 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
@@ -8,6 +8,7 @@ import {
isReadonlyVirtualColumn,
isSystemColumn,
isVirtualCol,
+ ncHasProperties,
} from 'nocodb-sdk'
import type { ButtonType, ColumnType, FormulaType, TableType, UserType, ViewType } from 'nocodb-sdk'
import type { WritableComputedRef } from '@vue/reactivity'
@@ -866,6 +867,7 @@ export function useCanvasTable({
upgradeModalInlineState,
rowMetaColumnWidth,
rowColouringBorderWidth,
+ isRecordSelected,
})
const { handleDragStart } = useRowReorder({
@@ -1318,6 +1320,20 @@ export function useCanvasTable({
makeEditable(row, clickedColumn)
}
+ function isRecordSelectedInSelectedAllRecords(rowIdx?: number) {
+ return vSelectedAllRecords.value && (!ncIsNumber(rowIdx) || !ncHasProperties(vSelectedAllRecordsSkipPks.value, rowIdx))
+ }
+
+ function isRecordSelected(row: Row) {
+ if (!row?.rowMeta) return false
+
+ if (vSelectedAllRecords.value) {
+ return isRecordSelectedInSelectedAllRecords(row.rowMeta.rowIndex)
+ }
+
+ return !!row.rowMeta.selected
+ }
+
function triggerRefreshCanvas() {
renderCanvas()
}
@@ -1394,6 +1410,8 @@ export function useCanvasTable({
findColumnAtPosition,
findClickedColumn,
findColumnPosition,
+ isRecordSelectedInSelectedAllRecords,
+ isRecordSelected,
// GroupBy Related
syncGroupCount,
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
index 19cfb94357..404767e4b7 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
@@ -9,6 +9,7 @@ import {
UITypes,
type ViewType,
isVirtualCol,
+ ncHasProperties,
readonlyMetaAllowedTypes,
} from 'nocodb-sdk'
import { flip, offset, shift, useFloating } from '@floating-ui/vue'
@@ -363,6 +364,7 @@ const {
isRowDraggingEnabled,
rowMetaColumnWidth,
rowColouringBorderWidth,
+ isRecordSelected,
} = useCanvasTable({
rowHeightEnum,
cachedRows,
@@ -790,12 +792,9 @@ function closeAddColumnDropdownMenu(scrollToLastCol = false, savedColumn?: Colum
function extractHoverMetaColRegions(row: Row, group?: CanvasGroup) {
const isAtMaxSelection = selectedRows.value.length >= MAX_SELECTED_ROWS
- const isCheckboxDisabled = (!row.rowMeta.selected && isAtMaxSelection && !vSelectedAllRecords.value) || readOnly.value
+ const isChecked = isRecordSelected(row)
- const isChecked =
- row.rowMeta?.selected ||
- (vSelectedAllRecords.value &&
- (!ncIsNumber(row.rowMeta?.rowIndex) || !!vSelectedAllRecordsSkipPks.value[row.rowMeta?.rowIndex]))
+ const isCheckboxDisabled = (!vSelectedAllRecords.value && !isChecked && isAtMaxSelection) || readOnly.value
const path = group ? generateGroupPath(group) : []
@@ -897,23 +896,21 @@ const handleRowMetaClick = ({
if (!clickedRegion) return
- console.log('checkbox ', isCheckboxDisabled)
-
if (onlyDrag && clickedRegion.action !== 'reorder' && clickedRegion.action !== 'select') return
switch (clickedRegion.action) {
case 'select':
- if (!isCheckboxDisabled && (row.rowMeta?.selected || (!isAtMaxSelection && vSelectedAllRecords.value))) {
+ if (!isCheckboxDisabled) {
resetActiveCell()
if (onlyDrag) {
row.rowMeta.selected = !row.rowMeta?.selected
- if (vSelectedAllRecords.value && row.rowMeta.rowIndex) {
- if (vSelectedAllRecordsSkipPks.value?.[row.rowMeta.rowIndex]) {
- delete vSelectedAllRecordsSkipPks.value[row.rowMeta.rowIndex]
+ if (vSelectedAllRecords.value && isValidValue(row.rowMeta.rowIndex)) {
+ if (ncHasProperties(vSelectedAllRecordsSkipPks.value, row.rowMeta.rowIndex!)) {
+ delete vSelectedAllRecordsSkipPks.value[row.rowMeta.rowIndex!]
} else {
- vSelectedAllRecordsSkipPks.value[row.rowMeta.rowIndex] = extractPkFromRow(row.row, meta.value?.columns ?? [])
+ vSelectedAllRecordsSkipPks.value[row.rowMeta.rowIndex!] = extractPkFromRow(row.row, meta.value?.columns ?? [])
}
}
@@ -2073,7 +2070,10 @@ const handleMouseMove = (e: MouseEvent) => {
const selectionStart = Math.min(selectedRowInfo.index, row.rowMeta.rowIndex)
- const selectionEnd = Math.min(selectionStart + MAX_SELECTED_ROWS, Math.max(selectedRowInfo.index, row.rowMeta.rowIndex))
+ const selectionEnd = Math.min(
+ selectionStart + (MAX_SELECTED_ROWS - 1),
+ Math.max(selectedRowInfo.index, row.rowMeta.rowIndex),
+ )
/**
* If selection is started and the selection is not changed, then don't do anything