From 63efebbfcc981bb350ce3822e56a730490301571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Velarde?= Date: Fri, 18 Dec 2020 10:50:13 +0100 Subject: [PATCH] fix: store filters when using breadcrumbs to all stores --- .gitignore | 2 + CHANGELOG.md | 1 + .../components/views/stores/StoresDetail.js | 121 ++++++++++-------- 3 files changed, 68 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index eda9b8bf..49a35478 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. template-skeleton/README.md +/template-skeleton/yarn.lock /template-skeleton/template/package.json /template-skeleton/template/yarn.lock /template-skeleton/template/node_modules /template-skeleton/template/_templates template-sample-app/README.md +/template-sample-app/yarn.lock /template-sample-app/template/package.json /template-sample-app/template/yarn.lock /template-sample-app/template/node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md index d89ca88f..25ef78f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Not released - Fix use of layerAttributes in UserDatasets [#154](https://github.com/CartoDB/carto-react-template/pull/154) - Improve stores layout and loading [#155](https://github.com/CartoDB/carto-react-template/pull/155) +- Fix store filters when using breadcrumbs to all stores [#156](https://github.com/CartoDB/carto-react-template/pull/156) - Improve mobility UX [#157](https://github.com/CartoDB/carto-react-template/pull/157) - Improve layout for Google Maps basemaps [#157](https://github.com/CartoDB/carto-react-template/pull/157) diff --git a/template-sample-app/template/src/components/views/stores/StoresDetail.js b/template-sample-app/template/src/components/views/stores/StoresDetail.js index 28c1a7bc..ad5e116a 100644 --- a/template-sample-app/template/src/components/views/stores/StoresDetail.js +++ b/template-sample-app/template/src/components/views/stores/StoresDetail.js @@ -1,6 +1,6 @@ import React, { useState, useEffect, useMemo } from 'react'; import { useSelector, useDispatch } from 'react-redux'; -import { NavLink, useLocation, useParams } from 'react-router-dom'; +import { useLocation, useParams, useNavigate } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { @@ -14,7 +14,12 @@ import { import NavigateNextIcon from '@material-ui/icons/NavigateNext'; import { WrapperWidgetUI, FormulaWidgetUI, HistogramWidgetUI } from '@carto/react/ui'; -import { updateLayer, selectSourceById, setViewState } from '@carto/react/redux'; +import { + clearFilters, + updateLayer, + selectSourceById, + setViewState, +} from '@carto/react/redux'; import { getStore, getRevenuePerMonth } from 'models/StoreModel'; import { LAYER_ID, MONTHS_LABELS } from './constants'; @@ -22,6 +27,8 @@ import { Isochrone } from 'components/common/Isochrone'; import { currencyFormatter } from 'utils/formatter'; import { setBottomSheetOpen, setError } from 'config/appSlice'; +import { SOURCE_ID } from './constants'; + export default function StoresDetail() { const [storeDetail, setStoreDetail] = useState(null); const [revenuePerMonth, setRevenuePerMonth] = useState(null); @@ -29,7 +36,7 @@ export default function StoresDetail() { const { id } = useParams(); const source = useSelector((state) => selectSourceById(state, 'storesSource')); const location = useLocation(); - + const navigate = useNavigate(); const classes = useStyles(); const histogramData = (revenuePerMonth || []).map((month) => month.revenue); @@ -92,6 +99,11 @@ export default function StoresDetail() { }; }, [dispatch, source, id, location.state]); + const navigateToStores = () => { + dispatch(clearFilters(SOURCE_ID)); + navigate('/stores'); + }; + const onTotalRevenueWidgetError = (error) => { dispatch(setError(`Error obtaining total revenue: ${error.message}`)); }; @@ -102,65 +114,62 @@ export default function StoresDetail() { return ( <> - {(revenuePerMonth === null || storeDetail === null) - ? ( - - - - ) - : ( - -
- } - aria-label='breadcrumb' - gutterBottom - > - - All stores - - Store detail - - - {storeName(storeDetail)} - - -
- - - - - - - - - - - - - - -
- ) - } + {revenuePerMonth === null || storeDetail === null ? ( + + + + ) : ( + +
+ } + aria-label='breadcrumb' + gutterBottom + > + + All stores + + Store detail + + + {storeName(storeDetail)} + + +
+ + + + + + + + + + + + + + +
+ )} ); } const useStyles = makeStyles((theme) => ({ storeDetail: { - padding: theme.spacing(3.25, 3) + padding: theme.spacing(3.25, 3), }, title: { textTransform: 'capitalize',