feat(database): add mouse click-and-drag multi-row selection in grid …#8773
Open
PaiavullaNikhil wants to merge 2 commits into
Open
feat(database): add mouse click-and-drag multi-row selection in grid …#8773PaiavullaNikhil wants to merge 2 commits into
PaiavullaNikhil wants to merge 2 commits into
Conversation
Contributor
Reviewer's GuideImplements a reusable grid row selection controller to support mouse click-and-drag multi-row selection, keyboard-based bulk operations (delete, clear, select all), and integrates visual and contextual behavior changes across grid rows and row actions. Sequence diagram for keyboard bulk delete using grid selection controllersequenceDiagram
actor User
participant GridShortcuts
participant GridSelectionController
participant GridBloc
participant RowBackendService
participant Dialogs as showConfirmDeletionDialog
User->>GridShortcuts: press Delete/Backspace
GridShortcuts->>GridSelectionController: selectedRowIds
GridShortcuts->>GridSelectionController: hasSelection
alt [hasSelection]
GridShortcuts->>GridBloc: viewId
GridShortcuts->>Dialogs: showConfirmDeletionDialog(onConfirm)
User->>Dialogs: confirm
Dialogs->>RowBackendService: deleteRows(viewId, selectedIds)
Dialogs->>GridSelectionController: clearSelection()
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 3 issues, and left some high level feedback:
- The drag selection logic in
_GridRowsStatehardcodesrowHeight(32/36) and does its own y→row index math; consider reusing the same sizing source used by the row layout (or a shared constant/helper) so selection stays accurate if row height or layout changes. GridSelectionController.selectRowandselectRangeboth implement range-selection behavior in slightly different ways and onlyselectRowupdates_lastSelectedRowId; consider centralizing the range-selection logic and keeping_lastSelectedRowIdconsistent so shift-click, drag, and subsequent range selections behave predictably.- In
_RowLeadingStatetheRowActionMenuwraps the existingGridSelectionControlleragain withChangeNotifierProvider.value; since the controller is already available higher up, you can remove this extra provider and just rely on the inherited one to simplify the tree and avoid redundant wiring.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The drag selection logic in `_GridRowsState` hardcodes `rowHeight` (32/36) and does its own y→row index math; consider reusing the same sizing source used by the row layout (or a shared constant/helper) so selection stays accurate if row height or layout changes.
- `GridSelectionController.selectRow` and `selectRange` both implement range-selection behavior in slightly different ways and only `selectRow` updates `_lastSelectedRowId`; consider centralizing the range-selection logic and keeping `_lastSelectedRowId` consistent so shift-click, drag, and subsequent range selections behave predictably.
- In `_RowLeadingState` the `RowActionMenu` wraps the existing `GridSelectionController` again with `ChangeNotifierProvider.value`; since the controller is already available higher up, you can remove this extra provider and just rely on the inherited one to simplify the tree and avoid redundant wiring.
## Individual Comments
### Comment 1
<location path="frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart" line_range="506-507" />
<code_context>
+
+ final selection = context.read<GridSelectionController>();
+ final rowInfos = selection.getRowInfos();
+ final clampedIndex = currentRowIndex.clamp(0, rowInfos.length - 1);
+ selection.selectRange(_dragStartRowIndex!, clampedIndex);
+ }
+ },
</code_context>
<issue_to_address>
**issue (bug_risk):** Fix type mismatch from `clamp` returning `num` when passing indices to `selectRange`.
`clamp` returns `num` while `selectRange` requires `int` indices, so this won’t compile without a cast. Use something like `final clampedIndex = currentRowIndex.clamp(0, rowInfos.length - 1).toInt();` and ensure `rowInfos` is non-empty before computing the clamped index (per previous comment).
</issue_to_address>
### Comment 2
<location path="frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart" line_range="470-471" />
<code_context>
}
+ final horizontalPadding = context.read<DatabasePluginWidgetBuilderSize>().horizontalPadding;
+ final compactMode = context.read<GridBloc>().databaseController.compactModeNotifier.value;
+ final rowHeight = compactMode ? 32.0 : 36.0;
+
+ child = Listener(
</code_context>
<issue_to_address>
**suggestion:** Avoid hardcoding row height values and instead derive them from the row layout source of truth.
Using literal `32.0`/`36.0` here couples selection behavior to magic numbers that may drift from the actual row height if padding, font size, or themes change. Prefer reusing a shared row-height constant or size helper (as with other layout helpers in this module) so hit testing and visuals remain aligned.
Suggested implementation:
```
final size = context.read<DatabasePluginWidgetBuilderSize>();
final horizontalPadding = size.horizontalPadding;
final rowHeight = size.rowHeight;
```
If `DatabasePluginWidgetBuilderSize` does not yet expose a `rowHeight` (or equivalent) property, you will need to:
1. Add a `rowHeight` (or appropriately named) getter/field to `DatabasePluginWidgetBuilderSize`, derived from the same source of truth as the actual grid row widgets (likely taking compact/regular mode into account there).
2. Ensure all row renderers use this same `rowHeight` value so selection hit testing and visual row size stay in sync.
</issue_to_address>
### Comment 3
<location path="frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/selection_controller.dart" line_range="8-11" />
<code_context>
+ GridSelectionController({required this.getRowInfos});
+
+ final List<RowInfo> Function() getRowInfos;
+ final Set<String> _selectedRowIds = {};
+ String? _lastSelectedRowId;
+
+ Set<String> get selectedRowIds => _selectedRowIds;
+ bool get hasSelection => _selectedRowIds.isNotEmpty;
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Expose `selectedRowIds` as an unmodifiable view to protect internal state.
Because this getter exposes the backing `Set`, callers can mutate selection state without going through the controller, bypassing `notifyListeners()` and violating invariants. Consider returning an `UnmodifiableSetView` or a defensive copy instead so the controller remains the single source of truth for selection changes.
Suggested implementation:
```
import 'dart:collection';
import 'package:flutter/widgets.dart';
import 'package:appflowy/plugins/database/application/row/row_cache.dart';
```
```
final Set<String> _selectedRowIds = {};
String? _lastSelectedRowId;
UnmodifiableSetView<String> get selectedRowIds =>
UnmodifiableSetView(_selectedRowIds);
bool get hasSelection => _selectedRowIds.isNotEmpty;
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…clamp type, protect selection state
Author
feat(database): add mouse click-and-drag multi-row selection and keyboard shortcuts in grid viewDescriptionThis PR introduces mouse click-and-drag multi-row selection, standard keyboard shortcuts for row deletion/clearing/selection, and a centralized Key Changes1. 🎛️ Centralized Selection State (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…view (#8771)
Feature Preview
PR Checklist
Summary by Sourcery
Add row multi-selection support to the database grid and integrate it with keyboard shortcuts and row actions.
New Features: