@@ -6,19 +6,38 @@ import Pager from "./Components/Pager";
6
6
import Facet from "./Components/Facet" ;
7
7
import ResultsPerPage from "./Components/ResultsPerPage" ;
8
8
import 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" ;
10
16
import headlessEngine from "./Engine" ;
11
17
import Sort from "./Components/Sort" ;
12
18
import { Box , Container , Grid , Typography } from "@mui/material" ;
19
+ import Tab from "./Components/Tab" ;
20
+ import Tabs from "@mui/material/Tabs" ;
13
21
14
22
export default class App extends React . Component {
23
+ constructor ( props : any ) {
24
+ super ( props ) ;
25
+ this . state = { currentTabIndex : 0 } ;
26
+ }
27
+
15
28
componentDidMount ( ) {
16
29
const { logInterfaceLoad } = loadSearchAnalyticsActions ( headlessEngine ) ;
17
30
const { executeSearch } = loadSearchActions ( headlessEngine ) ;
18
31
19
32
headlessEngine . dispatch ( executeSearch ( logInterfaceLoad ( ) ) ) ;
20
33
}
21
34
35
+ handleTabChange = ( e : any , tabIndex : number ) => {
36
+ this . setState ( {
37
+ currentTabIndex : tabIndex ,
38
+ } ) ;
39
+ } ;
40
+
22
41
render ( ) {
23
42
return (
24
43
< Container maxWidth = "xl" >
@@ -33,14 +52,26 @@ export default class App extends React.Component {
33
52
Coveo Headless + Material UI
34
53
</ Typography >
35
54
</ 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 >
37
69
< SearchBox />
38
70
< Box my = { 1 } >
39
71
< FacetBreadcrumbs />
40
72
< Grid container >
41
73
< Grid item xs = { 4 } >
42
74
< Facet title = "Brand" field = "ec_brand" />
43
- < Facet title = "Frequencies" field = "eng_frequencies" />
44
75
< Facet title = "Processor" field = "eng_processor" />
45
76
< Facet title = "Store name" field = "store_name" />
46
77
</ Grid >
@@ -71,3 +102,57 @@ export default class App extends React.Component {
71
102
) ;
72
103
}
73
104
}
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