Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit 12ec7f2

Browse files
Googlernshahan
Googler
authored andcommitted
Disabling select all, re-submitting with changes to product group
Cloned from CL 181372356 by 'g4 patch'. Original change by ejia@ejia:Tardigrade:664:citc on 2018/01/09 14:14:06. Add option to disable select all in the table selection model PiperOrigin-RevId: 181792178
1 parent 552dd00 commit 12ec7f2

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

lib/model/selection/table_selection_model.dart

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import 'selection_model.dart';
1111

1212
typedef bool IsIndeterminate(var entity);
1313

14+
/// Count getter to return when there is no valid count
15+
final CountGetter _noCountGetter = () => -1;
16+
1417
/// Selection model interface that is meant to be used with the table view
1518
/// component.
1619
abstract class BaseTableSelectionModel<T> implements SelectionModel<T> {
@@ -88,6 +91,13 @@ abstract class TableSelectionModel<T> extends BaseTableSelectionModel<T>
8891
@override
8992
SelectableGetter<T> getSelectable;
9093

94+
/// Whether or not the concept of "all entities" is applicable to this model
95+
/// or not.
96+
///
97+
/// Useful for cases such as an unknown number of entities in the model
98+
/// due to expansion.
99+
bool supportsSelectAll;
100+
91101
/// If the table supports selection over multiple pages.
92102
bool supportsMultiplePageSelection;
93103

@@ -118,7 +128,7 @@ class _SingleTableSelectionModelImpl<T> extends Observable<ChangeRecord>
118128

119129
bool deselectOnRemove;
120130

121-
CountGetter _totalEntitiesCount = () => -1;
131+
CountGetter _totalEntitiesCount = _noCountGetter;
122132

123133
@override
124134
CountGetter get totalEntitiesCount => _totalEntitiesCount;
@@ -137,7 +147,7 @@ class _SingleTableSelectionModelImpl<T> extends Observable<ChangeRecord>
137147
_totalEntitiesCountController.stream;
138148

139149
@override
140-
CountGetter entitiesOnPageCount = () => -1;
150+
CountGetter entitiesOnPageCount = _noCountGetter;
141151

142152
@override
143153
IsIndeterminate isIndeterminate;
@@ -220,10 +230,11 @@ class _TableSelectionModelImpl<T> extends Observable<ChangeRecord>
220230

221231
bool _allSelected = false;
222232

223-
CountGetter _totalEntitiesCount = () => -1;
233+
CountGetter _totalEntitiesCount = _noCountGetter;
224234

225235
@override
226-
CountGetter get totalEntitiesCount => _totalEntitiesCount;
236+
CountGetter get totalEntitiesCount =>
237+
supportsSelectAll ? _totalEntitiesCount : _noCountGetter;
227238

228239
@override
229240
set totalEntitiesCount(CountGetter value) {
@@ -239,14 +250,17 @@ class _TableSelectionModelImpl<T> extends Observable<ChangeRecord>
239250
_totalEntitiesCountController.stream;
240251

241252
@override
242-
CountGetter entitiesOnPageCount = () => -1;
253+
CountGetter entitiesOnPageCount = _noCountGetter;
243254

244255
@override
245256
bool supportsMultiplePageSelection = true;
246257

247258
@override
248259
SelectableGetter<T> getSelectable;
249260

261+
@override
262+
bool supportsSelectAll = true;
263+
250264
/// Returns number of items selected in the model.
251265
int get _selectedCount => _backingModel.selectedValues.length;
252266

@@ -261,13 +275,14 @@ class _TableSelectionModelImpl<T> extends Observable<ChangeRecord>
261275
// allOnPageSelected and allAcrossPagesSelected, but it turns out to be
262276
// ambiguous and does more bad than good.
263277
bool get allAcrossPagesSelected =>
264-
_allSelected ||
265-
(_selectedCount > 0 && totalEntitiesCount() == _selectedCount);
278+
supportsSelectAll &&
279+
(_allSelected ||
280+
(_selectedCount > 0 && totalEntitiesCount() == _selectedCount));
266281

267282
@override
268283
void selectAllAcrossPages() {
269284
if (_allSelected) return;
270-
assert(supportsMultiplePageSelection);
285+
assert(supportsSelectAll && supportsMultiplePageSelection);
271286
bool wasEmpty = isEmpty;
272287
_allSelected = true;
273288
if (wasEmpty) {
@@ -347,7 +362,9 @@ class _TableSelectionModelImpl<T> extends Observable<ChangeRecord>
347362

348363
@override
349364
bool get isPageSelected =>
350-
selectedCount > 0 && selectedCount == entitiesOnPageCount();
365+
supportsSelectAll &&
366+
selectedCount > 0 &&
367+
selectedCount == entitiesOnPageCount();
351368

352369
@override
353370
void onRemove(T entity) {

0 commit comments

Comments
 (0)