-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.tsx
158 lines (144 loc) · 3.98 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import React from "react";
import SearchBox from "./Components/SearchBox";
import QuerySummary from "./Components/QuerySummary";
import ResultList from "./Components/ResultList";
import Pager from "./Components/Pager";
import Facet from "./Components/Facet";
import ResultsPerPage from "./Components/ResultsPerPage";
import FacetBreadcrumbs from "./Components/FacetBreadcrumbs";
import {
loadSearchAnalyticsActions,
loadSearchActions,
buildQueryExpression,
TabOptions,
TabProps,
} from "@coveo/headless";
import headlessEngine from "./Engine";
import Sort from "./Components/Sort";
import { Box, Container, Grid, Typography } from "@mui/material";
import Tab from "./Components/Tab";
import Tabs from "@mui/material/Tabs";
export default class App extends React.Component {
constructor(props: any) {
super(props);
this.state = { currentTabIndex: 0 };
}
componentDidMount() {
const { logInterfaceLoad } = loadSearchAnalyticsActions(headlessEngine);
const { executeSearch } = loadSearchActions(headlessEngine);
headlessEngine.dispatch(executeSearch(logInterfaceLoad()));
}
handleTabChange = (e: any, tabIndex: number) => {
this.setState({
currentTabIndex: tabIndex,
});
};
render() {
return (
<Container maxWidth="xl">
<Box my={3}>
<Typography
align="center"
color="text.primary"
variant="h2"
component="h2"
gutterBottom
>
Coveo Headless + Material UI
</Typography>
</Box>
<Tabs onChange={this.handleTabChange}>
<Tab
initialState={anyProps.initialState!}
options={anyProps.options!}
/>
<Tab
initialState={intelProps.initialState!}
options={intelProps.options!}
/>
<Tab
initialState={amdProps.initialState!}
options={amdProps.options!}
/>
</Tabs>
<SearchBox />
<Box my={1}>
<FacetBreadcrumbs />
<Grid container>
<Grid item xs={4}>
<Facet title="Brand" field="ec_brand" />
<Facet title="Processor" field="eng_processor" />
<Facet title="Store name" field="store_name" />
</Grid>
<Grid item xs={8}>
<Grid container my={3} alignItems="center">
<Grid item xs={8}>
<QuerySummary />
</Grid>
<Grid item xs={4}>
<Sort />
</Grid>
</Grid>
<ResultList />
<Box my={4}>
<Grid container alignItems="center">
<Grid item xs={6}>
<Pager />
</Grid>
<Grid item xs={6}>
<ResultsPerPage />
</Grid>
</Grid>
</Box>
</Grid>
</Grid>
</Box>
</Container>
);
}
}
const filterIntelProcessor = buildQueryExpression()
.addStringField({
field: "eng_processor",
operator: "contains",
values: ["Intel"],
})
.toQuerySyntax();
const filterAmdProcessor = buildQueryExpression()
.addStringField({
field: "eng_processor",
operator: "contains",
values: ["AMD"],
})
.toQuerySyntax();
const noFilter = buildQueryExpression()
.addStringField({
field: "store_name",
operator: "contains",
values: ["Barca"],
})
.toQuerySyntax();
const intelOptions: TabOptions = {
id: "Intel",
expression: filterIntelProcessor,
};
const amdOptions: TabOptions = {
id: "AMD",
expression: filterAmdProcessor,
};
const anyOptions: TabOptions = {
id: "Any",
expression: noFilter,
};
const intelProps: TabProps = {
initialState: { isActive: false },
options: intelOptions,
};
const amdProps: TabProps = {
initialState: { isActive: false },
options: amdOptions,
};
const anyProps: TabProps = {
initialState: { isActive: true },
options: anyOptions,
};