@@ -9,11 +9,17 @@ import { useState } from 'react';
99import { Trans , useTranslation } from 'react-i18next' ;
1010import { useAppDispatch } from 'src/app/hooks' ;
1111import { theme as globalTheme } from 'src/app/theme' ;
12- import { Field } from '@zendeskgarden/react-forms' ;
13- import { updateFilters } from 'src/features/bugsPage/bugsPageSlice' ;
12+ import { Field , Toggle } from '@zendeskgarden/react-forms' ;
13+ import {
14+ getIsNaBugExcluded ,
15+ setIsNaBugExcluded ,
16+ updateFilters ,
17+ } from 'src/features/bugsPage/bugsPageSlice' ;
1418import { Divider } from 'src/common/components/divider' ;
1519import { CustomStatusFilterType } from 'src/features/bugsPage/customStatusFilter' ;
1620import { getCustomStatusInfo } from 'src/common/components/utils/getCustomStatusInfo' ;
21+ import { getExcludeNotABugInfo } from 'src/common/components/utils/getExcludeNotABugInfo' ;
22+ import { BugCustomStatus } from 'src/features/api' ;
1723import { ShowMore } from './ShowMore' ;
1824import { useFilterData } from './useFilterData' ;
1925import { LabelSpaceBetween , disabledStyle } from './LabelWithCounter' ;
@@ -31,9 +37,37 @@ export const CustomStatusField = ({
3137 const { t } = useTranslation ( ) ;
3238 const { available : unsorted , selected } = customStatuses ;
3339 const available = [ ...unsorted ] . sort ( ( a , b ) => a . id - b . id ) ;
40+ const currentIsNaBugExcluded = getIsNaBugExcluded ( ) ;
3441
3542 if ( ! counters ) return null ;
3643
44+ const customStatusNotABugInfo = getExcludeNotABugInfo ( t ) ;
45+
46+ const selectedWithNaB = currentIsNaBugExcluded
47+ ? [
48+ ...selected ,
49+ {
50+ id : customStatusNotABugInfo . actionIdentifier ,
51+ name : customStatusNotABugInfo . drawerTitle ,
52+ } ,
53+ ]
54+ : [ ...selected ] ;
55+
56+ const shallDisable = ( item : BugCustomStatus ) : boolean => {
57+ if ( item . id !== customStatusNotABugInfo . customStatusId )
58+ return ! counters [ item . id ] ;
59+ if ( currentIsNaBugExcluded ) return currentIsNaBugExcluded ;
60+ return ! counters [ item . id ] ;
61+ } ;
62+
63+ const filterNaBug = ( arr : BugCustomStatus [ ] ) =>
64+ arr . filter (
65+ ( item : BugCustomStatus ) =>
66+ item . id !== customStatusNotABugInfo . customStatusId
67+ ) ;
68+
69+ const shouldDisableToggle = ! counters [ customStatusNotABugInfo . customStatusId ] ;
70+
3771 return (
3872 < >
3973 < Accordion level = { 3 } defaultExpandedSections = { [ ] } >
@@ -51,14 +85,18 @@ export const CustomStatusField = ({
5185 textTransform : 'capitalize' ,
5286 } }
5387 >
54- { selected && selected . length
55- ? `${ selected
88+ { selectedWithNaB && selectedWithNaB . length
89+ ? `${ selectedWithNaB
5690 . slice ( 0 , maxItemsToShow )
57- . map ( ( item ) => item . name )
91+ . map ( ( item ) =>
92+ item . id === customStatusNotABugInfo . actionIdentifier
93+ ? customStatusNotABugInfo . drawerTitle
94+ : getCustomStatusInfo ( item ?. name as BugState , t ) . text
95+ )
5896 . join ( ', ' )
5997 . toLowerCase ( ) } ${
60- selected . length > maxItemsToShow
61- ? `+${ selected . length - maxItemsToShow } `
98+ selectedWithNaB . length > maxItemsToShow
99+ ? `+${ selectedWithNaB . length - maxItemsToShow } `
62100 : ''
63101 } `
64102 : t (
@@ -68,6 +106,33 @@ export const CustomStatusField = ({
68106 </ Accordion . Label >
69107 </ Accordion . Header >
70108 < Accordion . Panel >
109+ < Field style = { { marginBottom : globalTheme . space . md } } >
110+ < Toggle
111+ disabled = { shouldDisableToggle }
112+ checked = { currentIsNaBugExcluded }
113+ onChange = { ( event ) => {
114+ dispatch ( setIsNaBugExcluded ( event . target . checked ) ) ;
115+ dispatch (
116+ updateFilters ( {
117+ filters : { customStatuses : [ ...filterNaBug ( selected ) ] } ,
118+ } )
119+ ) ;
120+ } }
121+ >
122+ < LabelSpaceBetween
123+ isRegular
124+ style = { {
125+ color : globalTheme . palette . grey [ 700 ] ,
126+ ...( shouldDisableToggle && disabledStyle ) ,
127+ } }
128+ >
129+ { customStatusNotABugInfo . drawerTitle }
130+ < MD >
131+ { counters [ customStatusNotABugInfo . customStatusId ] || 0 }
132+ </ MD >
133+ </ LabelSpaceBetween >
134+ </ Toggle >
135+ </ Field >
71136 { available . length
72137 ? available
73138 . slice ( 0 , showMore ? undefined : maxItemsToShow )
@@ -76,7 +141,7 @@ export const CustomStatusField = ({
76141 < Checkbox
77142 value = { item . name }
78143 name = "filter-custom-status"
79- disabled = { ! counters [ item . id ] }
144+ disabled = { shallDisable ( item ) }
80145 checked = { selected . map ( ( i ) => i . id ) . includes ( item . id ) }
81146 onChange = { ( ) => {
82147 dispatch (
@@ -98,7 +163,7 @@ export const CustomStatusField = ({
98163 isRegular
99164 style = { {
100165 color : globalTheme . palette . grey [ 700 ] ,
101- ...( ! counters [ item . id ] && disabledStyle ) ,
166+ ...( shallDisable ( item ) && disabledStyle ) ,
102167 } }
103168 >
104169 { getCustomStatusInfo ( item ?. name as BugState , t ) . text }
0 commit comments