Skip to content

Commit 61e9b84

Browse files
Fixed warnings for the products page
1 parent 3856722 commit 61e9b84

17 files changed

+239
-98
lines changed

client/src/components/routes/navbar/searchBar.js

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,57 @@ export default function SearchBar(props) {
99
const classes = useNavBarStyles();
1010

1111
const handleClose = () => {
12-
props.handleClose();
12+
if (props.handleClose) {
13+
props.handleClose();
14+
}
1315
}
1416

1517
return (
16-
<Autocomplete
17-
value={value}
18-
autoHighlight
19-
onChange={(event, newValue) => {
20-
if (typeof newValue === 'string') {
21-
setValue({
22-
title: newValue,
23-
});
24-
} else if (newValue && newValue.inputValue) {
25-
// Create a new value from the user input
26-
setValue({
27-
title: newValue.inputValue,
28-
});
29-
} else {
30-
setValue(newValue);
31-
}
32-
}}
33-
selectOnFocus
34-
clearOnBlur
35-
handleHomeEndKeys
36-
closeIcon={<CloseIcon/>}
37-
id="free-solo-with-text-demo"
38-
options={top100Films}
39-
getOptionLabel={(option) => {
40-
// Value selected with enter, right from the input
41-
if (typeof option === 'string') {
42-
return option;
43-
}
44-
// Add "xxx" option created dynamically
45-
if (option.inputValue) {
46-
return option.inputValue;
47-
}
48-
// Regular option
49-
return option.title;
50-
}}
51-
renderOption={(option) => option.title}
52-
freeSolo
53-
fullWidth
54-
onClose={handleClose}
55-
size={props.size}
56-
classes={{root: classes.autoCompleteSearchBarRoot}}
57-
renderInput={(params) => (
58-
<TextField {...params} label="Search for products, brands and more" variant="outlined"/>
59-
)}
60-
/>
18+
<Autocomplete
19+
value={value}
20+
autoHighlight
21+
onChange={(event, newValue) => {
22+
if (typeof newValue === 'string') {
23+
setValue({
24+
title: newValue,
25+
});
26+
} else if (newValue && newValue.inputValue) {
27+
// Create a new value from the user input
28+
setValue({
29+
title: newValue.inputValue,
30+
});
31+
} else {
32+
setValue(newValue);
33+
}
34+
}}
35+
selectOnFocus
36+
clearOnBlur
37+
handleHomeEndKeys
38+
closeIcon={<CloseIcon/>}
39+
id="free-solo-with-text-demo"
40+
options={top100Films}
41+
getOptionLabel={(option) => {
42+
// Value selected with enter, right from the input
43+
if (typeof option === 'string') {
44+
return option;
45+
}
46+
// Add "xxx" option created dynamically
47+
if (option.inputValue) {
48+
return option.inputValue;
49+
}
50+
// Regular option
51+
return option.title;
52+
}}
53+
renderOption={(option) => option.title}
54+
freeSolo
55+
fullWidth
56+
onClose={handleClose}
57+
size={props.size}
58+
classes={{root: classes.autoCompleteSearchBarRoot}}
59+
renderInput={(params) => (
60+
<TextField {...params} label="Search for products, brands and more" variant="outlined"/>
61+
)}
62+
/>
6163
);
6264
}
6365

client/src/components/routes/product/filterChips.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import {useDispatch, useSelector} from "react-redux";
33
import Chip from "@material-ui/core/Chip";
44
import Box from '@material-ui/core/Box';
55
import log from "loglevel";
6-
import {
7-
ADD_SELECTED_CATEGORY
8-
9-
} from "../../../actions/types";
6+
import {ADD_SELECTED_CATEGORY} from "../../../actions/types";
107

118
const FilterChips = () => {
129
const selectedGenders = useSelector(state => state.selectedFilterAttributesReducer.genders)
@@ -15,12 +12,20 @@ const FilterChips = () => {
1512
const selectedPriceRanges = useSelector(state => state.selectedFilterAttributesReducer.prices)
1613
const dispatch = useDispatch()
1714

15+
// check if any filter is selected or not
1816
if ((selectedGenders.length + selectedApparels.length
1917
+ selectedBrands.length + selectedPriceRanges.length) === 0) {
2018
log.debug(`[FilterChips] Filter are empty`)
2119
return null
2220
}
2321

22+
/**
23+
* construct the chip from selected filter option and assign Id.
24+
*
25+
* @param selectedAttrList
26+
* @param categoryId
27+
* @returns {[]}
28+
*/
2429
const addChips = (selectedAttrList, categoryId) => {
2530
let chipBoxList = []
2631
log.debug(`[FilterChips] addBoxTagToList boxDataList = ${JSON.stringify(selectedAttrList)}`)
@@ -39,6 +44,10 @@ const FilterChips = () => {
3944
return chipBoxList
4045
}
4146

47+
/**
48+
* Prepare chip list and render it.
49+
* @returns {null|[]}
50+
*/
4251
const renderChipBoxes = () => {
4352
log.debug(`[FilterChips] renderChipBoxes is invoked`)
4453

@@ -65,6 +74,13 @@ const FilterChips = () => {
6574
return null
6675
}
6776

77+
/**
78+
* Dispatch the chip from selected option list
79+
*
80+
* @param id
81+
* @param selectedAttrList
82+
* @param attributeName
83+
*/
6884
const findValueAndDispatch = (id, selectedAttrList, attributeName) => {
6985
log.debug(`[FilterChips] findValueAndDispatch id = ${id}`+
7086
`, attributeName = ${attributeName}, selectedAttrList = ${JSON.stringify(selectedAttrList)}`)
@@ -86,6 +102,11 @@ const FilterChips = () => {
86102
}
87103
}
88104

105+
/**
106+
* Delete the chip
107+
* @param id
108+
* @returns {function(...[*]=)}
109+
*/
89110
const handleDelete = id => () => {
90111
log.info(`[FilterChips] handleDelete for chip for id = ${id}`)
91112
const splitId = id.split("-")

client/src/components/routes/product/filterPagination.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect} from 'react';
1+
import React from 'react';
22
import Grid from "@material-ui/core/Grid";
33
import log from 'loglevel';
44
import {useDispatch, useSelector} from "react-redux";
@@ -23,11 +23,13 @@ export default function FilterPagination() {
2323
})
2424
}
2525

26+
// if we got data from the server side
2627
if(!filterProductsReducer || filterProductsReducer.hasOwnProperty("data") === false ||
2728
filterProductsReducer.data.hasOwnProperty("totalCount") === false) {
2829
log.info(`[FilterPagination] totalProducts = ${totalProducts}`)
2930
return null
3031
} else {
32+
// set the total products used to calculate how many pages require
3133
totalProducts = filterProductsReducer.data.totalCount
3234
}
3335

client/src/components/routes/product/filterProductDisplay.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const FilterProductDisplay = props => {
2424
log.info(`[FilterProductDisplay] Component did mount`)
2525

2626
try {
27+
// if query is present then call the products API
2728
if (queryStatus) {
2829
log.info(`[FilterProductDisplay] Getting products from API.....`)
2930
props.getDataViaAPI(LOAD_FILTER_PRODUCTS, PRODUCT_BY_CATEGORY_DATA_API + queryStatus)
@@ -32,12 +33,15 @@ const FilterProductDisplay = props => {
3233
log.error(`[FilterProductDisplay] Bad URL found in history.location.search`)
3334
}
3435

36+
// scroll up after call the API
3537
window.scrollTo(0, 0)
3638

3739
// eslint-disable-next-line
3840
}, [queryStatus]);
3941

4042

43+
// initial state is loading and this will change
44+
// when we retrieve data
4145
if (filterProductsReducer.isLoading) {
4246
log.info(`[FilterProductDisplay] filterProducts is null`)
4347
return (
@@ -47,6 +51,8 @@ const FilterProductDisplay = props => {
4751
)
4852
} else {
4953
if (filterProductsReducer.hasOwnProperty("data")) {
54+
// if does not got anything from the server but we didn't got any
55+
// error then we didn't find any matches
5056
if (Object.entries(filterProductsReducer.data).length === 0) {
5157

5258
log.info(`[Home]: homeAPIData.data length =` +
@@ -58,9 +64,13 @@ const FilterProductDisplay = props => {
5864
</Box>
5965
)
6066
}
67+
68+
// set the products here
6169
filterProducts = filterProductsReducer.data.products
6270

6371
} else {
72+
73+
// if there is any error then status code will be set in action creator.
6474
if (filterProductsReducer.hasOwnProperty('statusCode')) {
6575
log.info(`[Home]: homeAPIData.statusCode = ${filterProductsReducer.statusCode}`)
6676
return <HTTPError statusCode={filterProductsReducer.statusCode}/>

client/src/components/routes/product/filterSideNavbar/apparelCheckBox.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ export default function ApparelCheckBox() {
1515
const selectedApparels = useSelector(state => state.selectedFilterAttributesReducer.apparels)
1616
const [searchApparelList, setSearchApparelList] = useState(null)
1717

18+
// return if doesn't got anything from the server
1819
if (!apparelList) {
1920
log.debug(`[ApparelCheckBox] apparelList is null`)
2021
return null
2122
}
2223

24+
/**
25+
* return the normal list or list based on search keyword
26+
* @returns {any}
27+
*/
2328
const getActiveApparelList = () => {
2429
return searchApparelList ? searchApparelList : apparelList
2530
}
@@ -49,8 +54,7 @@ export default function ApparelCheckBox() {
4954
<CheckboxSearchBar title={TITLE}
5055
placeholderText="Search for Apparels"
5156
checkboxList={apparelList}
52-
searchListHandler={handleSearchListChange}
53-
/>
57+
searchListHandler={handleSearchListChange}/>
5458
<CheckboxList attrList={getActiveApparelList()}
5559
title={TITLE}
5660
maxItems={6}

client/src/components/routes/product/filterSideNavbar/brandCheckBox.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ export default function BrandCheckBox() {
1515
const selectedBrands = useSelector(state => state.selectedFilterAttributesReducer.brands)
1616
const [searchBrandList, setSearchBrandList] = useState(null)
1717

18+
// return if doesn't got anything from the server
1819
if (!brandList) {
1920
log.debug(`[BrandCheckBox] brandList is null`)
2021
return null
2122
}
2223

24+
/**
25+
* return the normal list or list based on search keyword
26+
* @returns {any}
27+
*/
2328
const getActiveBrandList = () => {
2429
return searchBrandList ? searchBrandList : brandList
2530
}
@@ -49,8 +54,7 @@ export default function BrandCheckBox() {
4954
<CheckboxSearchBar title={TITLE}
5055
placeholderText="Search for Brands"
5156
checkboxList={brandList}
52-
searchListHandler={handleSearchListChange}
53-
/>
57+
searchListHandler={handleSearchListChange}/>
5458
<CheckboxList attrList={getActiveBrandList()}
5559
title="Brand"
5660
maxItems={6}

client/src/components/routes/product/filterSideNavbar/checkboxMoreButton.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,29 @@ import CloseIcon from "@material-ui/icons/Close";
77
import IconButton from "@material-ui/core/IconButton";
88
import SortedCheckboxList from "../../../ui/sortedCheckboxList";
99

10+
const paperStyles = {
11+
backgroundColor: "inherit",
12+
width: "200vh",
13+
height: "70vh"
14+
}
15+
16+
const gridStyles = {
17+
height: '70vh',
18+
zIndex: 1300,
19+
overflow: "auto",
20+
left: 0,
21+
width: "inherit",
22+
position: "fixed",
23+
top: 150,
24+
backgroundColor: "white",
25+
border: "1px solid #eaeaec",
26+
boxShadow: "0 1px 8px rgba(0,0,0,.1)"
27+
}
28+
1029
export default function CheckboxMoreButton(props) {
1130
const [moreButtonState, setMoreButtonState] = useState({active: false, topPosition: 0})
1231

32+
// No need to render this component if the list is not present
1333
if (!props.checkboxList) {
1434
log.debug(`[CheckboxMoreButton] apparelList is null`)
1535
return null
@@ -31,12 +51,8 @@ export default function CheckboxMoreButton(props) {
3151
const renderMoreButtonList = () => {
3252
return (
3353
<Paper elevation={3} variant="outlined" square
34-
style={{backgroundColor: "inherit", width: "200vh", height: "70vh"}}>
35-
<Grid item container xs={props.size} direction="row" style={{
36-
height: '70vh', zIndex: 1300, overflow: "auto", left: 0, width: "inherit",
37-
position: "fixed", top: 150, backgroundColor: "white", border: "1px solid #eaeaec",
38-
boxShadow: "0 1px 8px rgba(0,0,0,.1)"
39-
}}>
54+
style={paperStyles}>
55+
<Grid item container xs={props.size} direction="row" style={gridStyles}>
4056
<Grid item sm={11}>
4157
<SortedCheckboxList attrList={props.checkboxList}
4258
title={props.title}
@@ -48,8 +64,7 @@ export default function CheckboxMoreButton(props) {
4864
<IconButton size="medium"
4965
color="primary"
5066
onClick={handleMoreListCloseButton}
51-
style={{position: "fixed"}}
52-
>
67+
style={{position: "fixed"}}>
5368
<CloseIcon/>
5469
</IconButton>
5570
</Grid>
@@ -58,6 +73,10 @@ export default function CheckboxMoreButton(props) {
5873
)
5974
}
6075

76+
/**
77+
* render more button if items are more then six
78+
* @returns {null|*}
79+
*/
6180
const renderMoreButton = () => {
6281
if (props.checkboxList.length > 6) {
6382
return (

client/src/components/routes/product/filterSideNavbar/clearAllButton.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ function ClearAllButton() {
88
const dispatch = useDispatch()
99
const selectedFilterAttribute = useSelector(state => state.selectedFilterAttributesReducer)
1010

11+
// check if any filter is selected or not
1112
if((selectedFilterAttribute.genders.length + selectedFilterAttribute.apparels.length
1213
+ selectedFilterAttribute.brands.length + selectedFilterAttribute.prices.length) === 0) {
1314
log.info(`[ClearAllButton] selected attribute are null`)
1415
return null
1516
}
1617

18+
/**
19+
* remove all selected filters
20+
*/
1721
const handleClearAllClick = () => {
1822
log.info(`[ClearAllButton] handleClearAllClick(value)`)
1923
dispatch({type: REMOVE_SELECTED_CATEGORY, payload: history.location.search.slice(3)})

0 commit comments

Comments
 (0)