@@ -4,9 +4,12 @@ import '@ts/ui/list/modules/m_selection';
44
55import messageLocalization from '@js/common/core/localization/message' ;
66import $ from '@js/core/renderer' ;
7+ import type { DeferredObj } from '@js/core/utils/deferred' ;
78import { extend } from '@js/core/utils/extend' ;
89import { each } from '@js/core/utils/iterator' ;
9- import { isDefined , isFunction } from '@js/core/utils/type' ;
10+ import { isDeferred , isDefined , isFunction } from '@js/core/utils/type' ;
11+ import type dxCheckBox from '@js/ui/check_box' ;
12+ import type dxList from '@js/ui/list' ;
1013import List from '@js/ui/list_light' ;
1114import Popup from '@js/ui/popup/ui.popup' ;
1215import TreeView from '@js/ui/tree_view' ;
@@ -28,20 +31,45 @@ function resetChildrenItemSelection(items) {
2831 }
2932}
3033
31- function getSelectAllCheckBox ( listComponent ) {
34+ function getSelectAllCheckBox ( listComponent ) : dxCheckBox {
3235 const selector = listComponent . NAME === 'dxTreeView' ? '.dx-treeview-select-all-item' : '.dx-list-select-all-checkbox' ;
3336
3437 return listComponent . $element ( ) . find ( selector ) . dxCheckBox ( 'instance' ) ;
3538}
3639
37- function updateListSelectAllState ( e , filterValues ) {
38- if ( e . component . option ( 'searchValue' ) ) {
40+ function updateListSelectAllState (
41+ // NOTE: In runtime dxList's "unselectAll" returns Deferred.
42+ // But in d.ts dxList has a void return type.
43+ listComponent : Omit < dxList , 'unselectAll' > & { unselectAll : ( ) => ( DeferredObj < void > | void ) } ,
44+ filterValues : any [ ] ,
45+ ) : void {
46+ if ( listComponent . option ( 'searchValue' ) ) {
3947 return ;
4048 }
41- const selectAllCheckBox = getSelectAllCheckBox ( e . component ) ;
4249
43- if ( selectAllCheckBox && filterValues && filterValues . length ) {
50+ const selectAllCheckBox = getSelectAllCheckBox ( listComponent ) ;
51+
52+ if ( selectAllCheckBox && filterValues ?. length ) {
4453 selectAllCheckBox . option ( 'value' , undefined ) ;
54+
55+ // NOTE: T1284200 fix
56+ // We manually set checkbox state (value) above
57+ // So, list do nothing because inner list component's "select all" state
58+ // doesn't react to our manual update.
59+ // Therefore -> we should handle first "select all" checkbox click manually.
60+ // And after it return original "onValueChanged" handler back.
61+ const originalValueChanged = selectAllCheckBox . option ( 'onValueChanged' ) ;
62+ selectAllCheckBox . option ( 'onValueChanged' , ( event ) => {
63+ selectAllCheckBox . option ( 'onValueChanged' , originalValueChanged ) ;
64+
65+ const deferred = listComponent . unselectAll ( ) ;
66+
67+ if ( isDeferred ( deferred ) ) {
68+ ( deferred as DeferredObj < void > ) . always ( ( ) => { originalValueChanged ?.( event ) ; } ) ;
69+ } else {
70+ originalValueChanged ?.( event ) ;
71+ }
72+ } ) ;
4573 }
4674}
4775
@@ -330,11 +358,12 @@ export class HeaderFilterView extends Modules.View {
330358 showSelectionControls : true ,
331359 selectionMode : needShowSelectAllCheckbox ? 'all' : 'multiple' ,
332360 onOptionChanged,
333- onSelectionChanged ( e ) {
334- const items = e . component . option ( 'items' ) ;
335- const selectedItems = e . component . option ( 'selectedItems' ) ;
361+ onSelectionChanged ( event ) {
362+ const { component : listComponent } = event ;
363+ const items = listComponent . option ( 'items' ) ;
364+ const selectedItems = listComponent . option ( 'selectedItems' ) ;
336365
337- if ( ! e . component . _selectedItemsUpdating && ! e . component . option ( 'searchValue' ) && ! options . isFilterBuilder ) {
366+ if ( ! listComponent . _selectedItemsUpdating && ! listComponent . option ( 'searchValue' ) && ! options . isFilterBuilder ) {
338367 const filterValues = options . filterValues || [ ] ;
339368 const isExclude = options . filterType === 'exclude' ;
340369 if ( selectedItems . length === 0 && items . length && ( filterValues . length <= 1 || isExclude && filterValues . length === items . length - 1 ) ) {
@@ -366,23 +395,24 @@ export class HeaderFilterView extends Modules.View {
366395 }
367396 } ) ;
368397
369- updateListSelectAllState ( e , options . filterValues ) ;
398+ updateListSelectAllState ( listComponent , options . filterValues ) ;
370399 } ,
371400 onContentReady ( e ) {
372- const { component } = e ;
373- const items = component . option ( 'items' ) ;
401+ const { component : listComponent } = e ;
402+ const items = listComponent . option ( 'items' ) ;
374403 const selectedItems : any = [ ] ;
375404
376405 each ( items , function ( ) {
377406 if ( this . selected ) {
378407 selectedItems . push ( this ) ;
379408 }
380409 } ) ;
381- component . _selectedItemsUpdating = true ;
382- component . option ( 'selectedItems' , selectedItems ) ;
383- component . _selectedItemsUpdating = false ;
384410
385- updateListSelectAllState ( e , options . filterValues ) ;
411+ listComponent . _selectedItemsUpdating = true ;
412+ listComponent . option ( 'selectedItems' , selectedItems ) ;
413+ listComponent . _selectedItemsUpdating = false ;
414+
415+ updateListSelectAllState ( listComponent , options . filterValues ) ;
386416 } ,
387417 } ) ,
388418 ) ;
0 commit comments