From 0a89d1ecae4e70b7c694b85b1696bf0c24b5c8d1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 23 Oct 2022 08:25:18 -0700 Subject: Implement filter popover --- modern/src/main/DeviceList.js | 25 ++++++++++------------ modern/src/main/DeviceRow.js | 7 ------- modern/src/main/MainPage.js | 1 + modern/src/main/MainToolbar.js | 47 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 53 insertions(+), 27 deletions(-) (limited to 'modern/src') diff --git a/modern/src/main/DeviceList.js b/modern/src/main/DeviceList.js index 6672ac46..eb51232f 100644 --- a/modern/src/main/DeviceList.js +++ b/modern/src/main/DeviceList.js @@ -1,7 +1,6 @@ import React, { useEffect, useRef, useState } from 'react'; import { useDispatch } from 'react-redux'; import makeStyles from '@mui/styles/makeStyles'; -import { List } from '@mui/material'; import { FixedSizeList } from 'react-window'; import AutoSizer from 'react-virtualized-auto-sizer'; import { devicesActions } from '../store'; @@ -48,19 +47,17 @@ const DeviceList = ({ devices }) => { return ( {({ height, width }) => ( - - - {DeviceRow} - - + + {DeviceRow} + )} ); diff --git a/modern/src/main/DeviceRow.js b/modern/src/main/DeviceRow.js index 978813b4..11dbfdcb 100644 --- a/modern/src/main/DeviceRow.js +++ b/modern/src/main/DeviceRow.js @@ -28,12 +28,6 @@ const useStyles = makeStyles((theme) => ({ height: '25px', filter: 'brightness(0) invert(1)', }, - listItem: { - backgroundColor: 'white', - '&:hover': { - backgroundColor: 'white', - }, - }, batteryText: { fontSize: '0.75rem', fontWeight: 'normal', @@ -98,7 +92,6 @@ const DeviceRow = ({ data, index, style }) => {
dispatch(devicesActions.select(item.id))} disabled={!admin && item.disabled} > diff --git a/modern/src/main/MainPage.js b/modern/src/main/MainPage.js index a296d5f6..9a21d570 100644 --- a/modern/src/main/MainPage.js +++ b/modern/src/main/MainPage.js @@ -105,6 +105,7 @@ const MainPage = () => {
({ toolbar: { @@ -27,6 +28,7 @@ const useStyles = makeStyles((theme) => ({ })); const MainToolbar = ({ + filteredDevices, devicesOpen, setDevicesOpen, filter, @@ -37,6 +39,7 @@ const MainToolbar = ({ setFilterMap, }) => { const classes = useStyles(); + const theme = useTheme(); const navigate = useNavigate(); const t = useTranslation(); @@ -45,24 +48,28 @@ const MainToolbar = ({ const groups = useSelector((state) => state.groups.items); const devices = useSelector((state) => state.devices.items); - const filterRef = useRef(); + const toolbarRef = useRef(); + const inputRef = useRef(); const [filterAnchorEl, setFilterAnchorEl] = useState(null); + const [devicesAnchorEl, setDevicesAnchorEl] = useState(null); const deviceStatusCount = (status) => Object.values(devices).filter((d) => d.status === status).length; return ( - + setDevicesOpen(!devicesOpen)}> {devicesOpen ? : } setFilter({ ...filter, keyword: e.target.value })} + onFocus={() => setDevicesAnchorEl(toolbarRef.current)} + onBlur={() => setDevicesAnchorEl(null)} endAdornment={( - setFilterAnchorEl(filterRef.current)}> + setFilterAnchorEl(inputRef.current)}> @@ -72,6 +79,34 @@ const MainToolbar = ({ size="small" fullWidth /> + setDevicesAnchorEl(null)} + anchorOrigin={{ + vertical: 'bottom', + horizontal: Number(theme.spacing(2).slice(0, -2)), + }} + marginThreshold={0} + PaperProps={{ + style: { width: `calc(${toolbarRef.current?.clientWidth}px - ${theme.spacing(4)})` }, + }} + elevation={1} + disableAutoFocus + disableEnforceFocus + > + {filteredDevices.slice(0, 3).map((_, index) => ( + + ))} + {filteredDevices.length > 3 && ( + setDevicesOpen(true)}> + + + )} +