@@ -6,19 +6,38 @@ import Pager from "./Components/Pager";
66import Facet from "./Components/Facet" ;
77import ResultsPerPage from "./Components/ResultsPerPage" ;
88import FacetBreadcrumbs from "./Components/FacetBreadcrumbs" ;
9- import { loadSearchAnalyticsActions , loadSearchActions } from "@coveo/headless" ;
9+ import {
10+ loadSearchAnalyticsActions ,
11+ loadSearchActions ,
12+ buildQueryExpression ,
13+ TabOptions ,
14+ TabProps ,
15+ } from "@coveo/headless" ;
1016import headlessEngine from "./Engine" ;
1117import Sort from "./Components/Sort" ;
1218import { Box , Container , Grid , Typography } from "@mui/material" ;
19+ import Tab from "./Components/Tab" ;
20+ import Tabs from "@mui/material/Tabs" ;
1321
1422export default class App extends React . Component {
23+ constructor ( props : any ) {
24+ super ( props ) ;
25+ this . state = { currentTabIndex : 0 } ;
26+ }
27+
1528 componentDidMount ( ) {
1629 const { logInterfaceLoad } = loadSearchAnalyticsActions ( headlessEngine ) ;
1730 const { executeSearch } = loadSearchActions ( headlessEngine ) ;
1831
1932 headlessEngine . dispatch ( executeSearch ( logInterfaceLoad ( ) ) ) ;
2033 }
2134
35+ handleTabChange = ( e : any , tabIndex : number ) => {
36+ this . setState ( {
37+ currentTabIndex : tabIndex ,
38+ } ) ;
39+ } ;
40+
2241 render ( ) {
2342 return (
2443 < Container maxWidth = "xl" >
@@ -33,14 +52,26 @@ export default class App extends React.Component {
3352 Coveo Headless + Material UI
3453 </ Typography >
3554 </ Box >
36-
55+ < Tabs onChange = { this . handleTabChange } >
56+ < Tab
57+ initialState = { anyProps . initialState ! }
58+ options = { anyProps . options ! }
59+ />
60+ < Tab
61+ initialState = { intelProps . initialState ! }
62+ options = { intelProps . options ! }
63+ />
64+ < Tab
65+ initialState = { amdProps . initialState ! }
66+ options = { amdProps . options ! }
67+ />
68+ </ Tabs >
3769 < SearchBox />
3870 < Box my = { 1 } >
3971 < FacetBreadcrumbs />
4072 < Grid container >
4173 < Grid item xs = { 4 } >
4274 < Facet title = "Brand" field = "ec_brand" />
43- < Facet title = "Frequencies" field = "eng_frequencies" />
4475 < Facet title = "Processor" field = "eng_processor" />
4576 < Facet title = "Store name" field = "store_name" />
4677 </ Grid >
@@ -71,3 +102,57 @@ export default class App extends React.Component {
71102 ) ;
72103 }
73104}
105+
106+ const filterIntelProcessor = buildQueryExpression ( )
107+ . addStringField ( {
108+ field : "eng_processor" ,
109+ operator : "contains" ,
110+ values : [ "Intel" ] ,
111+ } )
112+ . toQuerySyntax ( ) ;
113+
114+ const filterAmdProcessor = buildQueryExpression ( )
115+ . addStringField ( {
116+ field : "eng_processor" ,
117+ operator : "contains" ,
118+ values : [ "AMD" ] ,
119+ } )
120+ . toQuerySyntax ( ) ;
121+
122+ const noFilter = buildQueryExpression ( )
123+ . addStringField ( {
124+ field : "store_name" ,
125+ operator : "contains" ,
126+ values : [ "Barca" ] ,
127+ } )
128+ . toQuerySyntax ( ) ;
129+
130+ const intelOptions : TabOptions = {
131+ id : "Intel" ,
132+ expression : filterIntelProcessor ,
133+ } ;
134+
135+ const amdOptions : TabOptions = {
136+ id : "AMD" ,
137+ expression : filterAmdProcessor ,
138+ } ;
139+
140+ const anyOptions : TabOptions = {
141+ id : "Any" ,
142+ expression : noFilter ,
143+ } ;
144+
145+ const intelProps : TabProps = {
146+ initialState : { isActive : false } ,
147+ options : intelOptions ,
148+ } ;
149+
150+ const amdProps : TabProps = {
151+ initialState : { isActive : false } ,
152+ options : amdOptions ,
153+ } ;
154+
155+ const anyProps : TabProps = {
156+ initialState : { isActive : true } ,
157+ options : anyOptions ,
158+ } ;
0 commit comments