Files
tatlock-ui/lib/shared/components/data_grid/data_grid_state.dart
T
Jeroen SchweitzerandClaude Opus 4.5 c494ace5d8
Build and Push / release (push) Successful in 3s
Build and Push / build (push) Successful in 3m5s
feat: add URL deep-linking for DataGrids
- Add PageUrlState utility for URL ↔ state serialization
- Add column `id` field for unique column identification in URLs
- Update idSelector to return String for URL compatibility
- All DataGrid pages now support URL params: search, sort, order, id
- Browser URL updates via replaceState (no GoRouter rebuilds)
- Add FilterPanelSemantics for filter panel semantic IDs
- Add TESTING.md documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 13:59:08 +01:00

63 lines
1.8 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
part 'data_grid_state.freezed.dart';
/// State for a DataGrid instance.
@freezed
sealed class DataGridState<T> with _$DataGridState<T> {
const factory DataGridState({
/// Current items being displayed.
@Default([]) List<T> items,
/// Total count of items (may differ from items.length for pagination).
@Default(0) int totalCount,
/// Whether data is currently loading.
@Default(false) bool isLoading,
/// Whether initial load is in progress.
@Default(true) bool isInitialLoad,
/// Error that occurred during loading.
Object? error,
/// Current search query.
@Default('') String searchQuery,
/// Index of the column currently sorted by.
int? sortColumnIndex,
/// Whether sort is descending.
@Default(false) bool sortDescending,
/// Currently selected item IDs (if selectable).
@Default({}) Set<String> selectedIds,
/// Current page (for paginated mode).
@Default(0) int currentPage,
/// Whether more items can be loaded (for infinite scroll).
@Default(false) bool hasMore,
}) = _DataGridState<T>;
}
/// Extension methods for DataGridState.
extension DataGridStateX<T> on DataGridState<T> {
/// Whether the grid has an error.
bool get hasError => error != null;
/// Whether the grid is empty (no items and not loading).
bool get isEmpty => items.isEmpty && !isLoading && !hasError;
/// Whether all visible items are selected.
bool get allSelected =>
items.isNotEmpty && selectedIds.length == items.length;
/// Whether some (but not all) items are selected.
bool get someSelected =>
selectedIds.isNotEmpty && selectedIds.length < items.length;
/// Number of selected items.
int get selectedCount => selectedIds.length;
}