@@ -7,8 +7,9 @@ import React from 'react';
77//import { filter } from '@lumino/algorithm';
88
99interface IFilterSnippetProps {
10- languages : string [ ] ;
11- allTags : string [ ] [ ] ; // change to [[snip], [lang]]
10+ tagDictionary : Map < string , string [ ] > ;
11+ languageTags : string [ ] ; // just lang tags
12+ snippetTags : string [ ] ; // just snippet tags
1213 onFilter : (
1314 searchValue : string ,
1415 filterTags : string [ ] ,
@@ -61,13 +62,10 @@ export class FilterTools extends React.Component<
6162 componentDidUpdate ( prevProps : IFilterSnippetProps ) : void {
6263 if ( prevProps !== this . props ) {
6364 // get all the tags together in one list
64- const flattenTags = this . props . allTags . reduce (
65- ( accumulator , value ) => accumulator . concat ( value ) ,
66- [ ]
67- ) ;
65+ const concatTags = this . props . snippetTags . concat ( this . props . languageTags ) ;
6866 this . setState ( ( state ) => ( {
6967 selectedTags : state . selectedTags
70- . filter ( ( tag ) => flattenTags . includes ( tag ) )
68+ . filter ( ( tag ) => concatTags . includes ( tag ) )
7169 . sort ( ) ,
7270 } ) ) ;
7371 }
@@ -82,17 +80,15 @@ export class FilterTools extends React.Component<
8280 filterOption . classList . toggle ( 'idle' ) ;
8381 }
8482
85- renderTags ( tags : string [ ] [ ] , type : string ) : JSX . Element {
86- // get all the tags together in one list
87- const flattenTags = tags . reduce (
88- ( accumulator , value ) => accumulator . concat ( value ) ,
89- [ ]
83+ renderTags ( tags : string [ ] , type : string ) : JSX . Element {
84+ const selectedLanguageTags = this . state . selectedTags . filter ( ( tag ) =>
85+ this . props . languageTags . includes ( tag )
9086 ) ;
9187 return (
9288 < div className = { FILTER_TAGS } >
93- { flattenTags . sort ( ) . map ( ( tag : string , index : number ) => {
89+ { tags . sort ( ) . map ( ( tag : string , index : number ) => {
9490 // language tags
95- if ( type === 'language' && this . props . languages . includes ( tag ) ) {
91+ if ( type === 'language' && this . props . languageTags . includes ( tag ) ) {
9692 if ( this . state . selectedTags . includes ( tag ) ) {
9793 return this . renderAppliedTag ( tag , index . toString ( ) ) ;
9894 } else {
@@ -101,12 +97,25 @@ export class FilterTools extends React.Component<
10197 } else if (
10298 // snippet tags
10399 type === 'snippet' &&
104- ! this . props . languages . includes ( tag )
100+ ! this . props . languageTags . includes ( tag )
105101 ) {
106- if ( this . state . selectedTags . includes ( tag ) ) {
107- return this . renderAppliedTag ( tag , index . toString ( ) ) ;
102+ if ( selectedLanguageTags . length !== 0 ) {
103+ const langsMatch = this . props . tagDictionary
104+ . get ( tag )
105+ . some ( ( r ) => selectedLanguageTags . includes ( r ) ) ;
106+ if ( langsMatch ) {
107+ if ( this . state . selectedTags . includes ( tag ) ) {
108+ return this . renderAppliedTag ( tag , index . toString ( ) ) ;
109+ } else {
110+ return this . renderUnappliedTag ( tag , index . toString ( ) ) ;
111+ }
112+ }
108113 } else {
109- return this . renderUnappliedTag ( tag , index . toString ( ) ) ;
114+ if ( this . state . selectedTags . includes ( tag ) ) {
115+ return this . renderAppliedTag ( tag , index . toString ( ) ) ;
116+ } else {
117+ return this . renderUnappliedTag ( tag , index . toString ( ) ) ;
118+ }
110119 }
111120 }
112121 } ) }
@@ -189,23 +198,25 @@ export class FilterTools extends React.Component<
189198 this . state . searchValue ,
190199 this . state . selectedTags ,
191200 this . state . selectedTags . filter ( ( tag ) =>
192- this . props . languages . includes ( tag )
201+ this . props . languageTags . includes ( tag )
193202 )
194203 ) ;
195204 }
196205
197206 renderFilterOption ( ) : JSX . Element {
198207 //TODO: make lang tags/cell tags a dropdown
208+ // get all the tags together in one list
209+ const concatTags = this . props . snippetTags . concat ( this . props . languageTags ) ;
199210 return (
200211 < div className = { `${ FILTER_OPTION } idle` } >
201212 < div className = { FILTER_TITLE } >
202213 < span > language tags</ span >
203214 </ div >
204- { this . renderTags ( this . props . allTags , 'language' ) }
215+ { this . renderTags ( concatTags , 'language' ) }
205216 < div className = { FILTER_TITLE } >
206217 < span > snippet tags</ span >
207218 </ div >
208- { this . renderTags ( this . props . allTags , 'snippet' ) }
219+ { this . renderTags ( concatTags , 'snippet' ) }
209220 </ div >
210221 ) ;
211222 }
0 commit comments