@@ -35,21 +35,26 @@ export class FilterTools extends React.Component<
3535 this . createFilterBox = this . createFilterBox . bind ( this ) ;
3636 this . renderFilterOption = this . renderFilterOption . bind ( this ) ;
3737 this . renderTags = this . renderTags . bind ( this ) ;
38- this . renderTag = this . renderTag . bind ( this ) ;
38+ this . renderAppliedTag = this . renderAppliedTag . bind ( this ) ;
39+ this . renderUnappliedTag = this . renderUnappliedTag . bind ( this ) ;
3940 this . handleClick = this . handleClick . bind ( this ) ;
4041 this . filterSnippets = this . filterSnippets . bind ( this ) ;
4142 }
4243
4344 componentDidMount ( ) {
44- this . setState ( { show : false , selectedTags : [ ] , searchValue : '' } ) ;
45+ this . setState ( {
46+ show : false ,
47+ selectedTags : [ ] ,
48+ searchValue : ''
49+ } ) ;
4550 }
4651
4752 componentDidUpdate ( prevProps : IFilterSnippetProps ) {
4853 if ( prevProps !== this . props ) {
4954 this . setState ( state => ( {
50- selectedTags : state . selectedTags . filter ( tag =>
51- this . props . tags . includes ( tag )
52- )
55+ selectedTags : state . selectedTags
56+ . filter ( tag => this . props . tags . includes ( tag ) )
57+ . sort ( )
5358 } ) ) ;
5459 }
5560 }
@@ -66,14 +71,39 @@ export class FilterTools extends React.Component<
6671 renderTags ( ) : JSX . Element {
6772 return (
6873 < div className = { FILTER_TAGS } >
69- { this . props . tags . map ( ( tag : string , index : number ) =>
70- this . renderTag ( tag , index . toString ( ) )
71- ) }
74+ { this . props . tags . sort ( ) . map ( ( tag : string , index : number ) => {
75+ if ( this . state . selectedTags . includes ( tag ) ) {
76+ return this . renderAppliedTag ( tag , index . toString ( ) ) ;
77+ } else {
78+ return this . renderUnappliedTag ( tag , index . toString ( ) ) ;
79+ }
80+ } ) }
81+ </ div >
82+ ) ;
83+ }
84+
85+ renderAppliedTag ( tag : string , index : string ) : JSX . Element {
86+ return (
87+ < div
88+ className = { `${ FILTER_TAG } tag applied-tag` }
89+ id = { 'filter' + '-' + tag + '-' + index }
90+ key = { 'filter' + '-' + tag + '-' + index }
91+ >
92+ < button onClick = { this . handleClick } > { tag } </ button >
93+ < checkIcon . react
94+ className = { FILTER_CHECK }
95+ tag = "span"
96+ elementPosition = "center"
97+ height = "18px"
98+ width = "18px"
99+ marginLeft = "5px"
100+ marginRight = "-3px"
101+ />
72102 </ div >
73103 ) ;
74104 }
75105
76- renderTag ( tag : string , index : string ) : JSX . Element {
106+ renderUnappliedTag ( tag : string , index : string ) : JSX . Element {
77107 return (
78108 < div
79109 className = { `${ FILTER_TAG } tag unapplied-tag` }
@@ -93,7 +123,6 @@ export class FilterTools extends React.Component<
93123 this . setState (
94124 state => ( {
95125 selectedTags : this . handleClickHelper (
96- target ,
97126 parent ,
98127 state . selectedTags ,
99128 clickedTag
@@ -104,47 +133,21 @@ export class FilterTools extends React.Component<
104133 }
105134
106135 handleClickHelper (
107- target : HTMLElement ,
108136 parent : HTMLElement ,
109137 currentTags : string [ ] ,
110138 clickedTag : string
111139 ) : string [ ] {
112140 if ( parent . classList . contains ( 'unapplied-tag' ) ) {
113141 parent . classList . replace ( 'unapplied-tag' , 'applied-tag' ) ;
114- const iconContainer = checkIcon . element ( {
115- className : FILTER_CHECK ,
116- tag : 'span' ,
117- elementPosition : 'center' ,
118- height : '18px' ,
119- width : '18px' ,
120- marginLeft : '5px' ,
121- marginRight : '-3px'
122- } ) ;
123- const color = getComputedStyle ( document . documentElement ) . getPropertyValue (
124- '--jp-ui-font-color1'
125- ) ;
126- target . style . color = color ;
127- if ( parent . children . length === 1 ) {
128- parent . appendChild ( iconContainer ) ;
129- }
130142
131143 currentTags . splice ( - 1 , 0 , clickedTag ) ;
132144 } else if ( parent . classList . contains ( 'applied-tag' ) ) {
133145 parent . classList . replace ( 'applied-tag' , 'unapplied-tag' ) ;
134- const color = getComputedStyle ( document . documentElement ) . getPropertyValue (
135- '--jp-ui-font-color2'
136- ) ;
137- target . style . color = color ;
138-
139- if ( parent . children . length !== 1 ) {
140- // remove check icon
141- parent . removeChild ( parent . children . item ( 1 ) ) ;
142- }
143146
144147 const idx = currentTags . indexOf ( clickedTag ) ;
145148 currentTags . splice ( idx , 1 ) ;
146149 }
147- return currentTags ;
150+ return currentTags . sort ( ) ;
148151 }
149152
150153 handleSearch = ( event : React . ChangeEvent < HTMLInputElement > ) : void => {
0 commit comments