From dd18f6264b1a5eb006b4b57951176f7da9cf4fe1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 22 May 2022 15:55:45 -0700 Subject: Reorganize collections --- modern/src/main/DevicesList.js | 11 +-- modern/src/main/StatusCard.js | 25 ++++-- modern/src/other/GeofencesList.js | 17 +---- modern/src/settings/CalendarsPage.js | 60 +++++++-------- modern/src/settings/CommandsPage.js | 68 ++++++++--------- modern/src/settings/ComputedAttributesPage.js | 76 +++++++++--------- modern/src/settings/DriversPage.js | 64 ++++++++-------- modern/src/settings/GroupsPage.js | 60 +++++++-------- modern/src/settings/MaintenancesPage.js | 73 +++++++++--------- modern/src/settings/NotificationsPage.js | 72 +++++++++-------- modern/src/settings/UsersPage.js | 72 +++++++++-------- .../src/settings/components/CollectionActions.js | 48 ++++++++++++ modern/src/settings/components/CollectionFab.js | 35 +++++++++ .../src/settings/components/EditCollectionView.js | 89 ---------------------- 14 files changed, 365 insertions(+), 405 deletions(-) create mode 100644 modern/src/settings/components/CollectionActions.js create mode 100644 modern/src/settings/components/CollectionFab.js delete mode 100644 modern/src/settings/components/EditCollectionView.js diff --git a/modern/src/main/DevicesList.js b/modern/src/main/DevicesList.js index 6ff08c6a..b80eaf8b 100644 --- a/modern/src/main/DevicesList.js +++ b/modern/src/main/DevicesList.js @@ -21,7 +21,6 @@ import FlashOffIcon from '@material-ui/icons/FlashOff'; import ErrorIcon from '@material-ui/icons/Error'; import { devicesActions } from '../store'; -import EditCollectionView from '../settings/components/EditCollectionView'; import { useEffectAsync } from '../reactHelper'; import { formatAlarm, formatBoolean, formatPercentage, formatStatus, getStatusColor, @@ -139,7 +138,7 @@ const DeviceRow = ({ data, index, style }) => { ); }; -const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { +const DevicesList = ({ filter }) => { const classes = useStyles(); const dispatch = useDispatch(); const listInnerEl = useRef(null); @@ -167,7 +166,7 @@ const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, []); return ( @@ -177,7 +176,7 @@ const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { width={width} height={height} itemCount={filteredItems.length} - itemData={{ items: filteredItems, onMenuClick }} + itemData={{ items: filteredItems }} itemSize={72} overscanCount={10} innerRef={listInnerEl} @@ -190,8 +189,4 @@ const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { ); }; -const DevicesList = ({ filter }) => ( - -); - export default DevicesList; diff --git a/modern/src/main/StatusCard.js b/modern/src/main/StatusCard.js index b470890e..d23bc8c3 100644 --- a/modern/src/main/StatusCard.js +++ b/modern/src/main/StatusCard.js @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { useSelector } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { makeStyles, Card, CardContent, Typography, CardActions, CardHeader, IconButton, Avatar, Table, TableBody, TableRow, TableCell, TableContainer, @@ -19,6 +19,8 @@ import dimensions from '../common/theme/dimensions'; import { useDeviceReadonly, useReadonly } from '../common/util/permissions'; import usePersistedState from '../common/util/usePersistedState'; import usePositionAttributes from '../common/attributes/usePositionAttributes'; +import { devicesActions } from '../store'; +import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ card: { @@ -64,6 +66,7 @@ const StatusRow = ({ name, content }) => { const StatusCard = ({ deviceId, onClose }) => { const classes = useStyles(); const history = useHistory(); + const dispatch = useDispatch(); const t = useTranslation(); const readonly = useReadonly(); @@ -75,7 +78,19 @@ const StatusCard = ({ deviceId, onClose }) => { const positionAttributes = usePositionAttributes(t); const [positionItems] = usePersistedState('positionItems', ['speed', 'address', 'totalDistance', 'course']); - const [removeDialogShown, setRemoveDialogShown] = useState(false); + const [removing, setRemoving] = useState(false); + + const handleRemove = useCatch(async (removed) => { + if (removed) { + const response = await fetch('/api/devices'); + if (response.ok) { + dispatch(devicesActions.refresh(await response.json())); + } else { + throw Error(await response.text()); + } + } + setRemoving(false); + }); return ( <> @@ -131,17 +146,17 @@ const StatusCard = ({ deviceId, onClose }) => { history.push(`/settings/device/${deviceId}`)} disabled={deviceReadonly}> - setRemoveDialogShown(true)} disabled={deviceReadonly} className={classes.negative}> + setRemoving(true)} disabled={deviceReadonly} className={classes.negative}> )} setRemoveDialogShown(false)} + onResult={(removed) => handleRemove(removed)} /> ); diff --git a/modern/src/other/GeofencesList.js b/modern/src/other/GeofencesList.js index d0d0853f..202ae3b1 100644 --- a/modern/src/other/GeofencesList.js +++ b/modern/src/other/GeofencesList.js @@ -2,15 +2,12 @@ import React, { Fragment } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { makeStyles } from '@material-ui/core/styles'; import Divider from '@material-ui/core/Divider'; -import IconButton from '@material-ui/core/IconButton'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; -import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import ListItemText from '@material-ui/core/ListItemText'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { devicesActions } from '../store'; -import EditCollectionView from '../settings/components/EditCollectionView'; +import CollectionActions from '../settings/components/CollectionActions'; const useStyles = makeStyles(() => ({ list: { @@ -24,7 +21,7 @@ const useStyles = makeStyles(() => ({ }, })); -const GeofenceView = ({ onMenuClick }) => { +const GeofencesList = () => { const classes = useStyles(); const dispatch = useDispatch(); @@ -36,11 +33,7 @@ const GeofenceView = ({ onMenuClick }) => { dispatch(devicesActions.select(item.id))}> - - onMenuClick(event.currentTarget, item.id)}> - - - + {index < list.length - 1 ? : null} @@ -49,8 +42,4 @@ const GeofenceView = ({ onMenuClick }) => { ); }; -const GeofencesList = () => ( - -); - export default GeofencesList; diff --git a/modern/src/settings/CalendarsPage.js b/modern/src/settings/CalendarsPage.js index 06697647..a5072277 100644 --- a/modern/src/settings/CalendarsPage.js +++ b/modern/src/settings/CalendarsPage.js @@ -1,13 +1,13 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -16,10 +16,11 @@ const useStyles = makeStyles((theme) => ({ }, })); -const CalendarsView = ({ updateTimestamp, onMenuClick }) => { +const CalendarsPage = () => { const classes = useStyles(); const t = useTranslation(); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); useEffectAsync(async () => { @@ -29,38 +30,33 @@ const CalendarsView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); return ( - - - - - - {t('sharedName')} - - - - {items.map((item) => ( - - - onMenuClick(event.currentTarget, item.id)}> - - - - {item.name} + } breadcrumbs={['settingsTitle', 'sharedCalendars']}> + +
+ + + + {t('sharedName')} - ))} - -
-
+ + + {items.map((item) => ( + + + + + {item.name} + + ))} + + + + + ); }; -const CalendarsPage = () => ( - } breadcrumbs={['settingsTitle', 'sharedCalendars']}> - - -); - export default CalendarsPage; diff --git a/modern/src/settings/CommandsPage.js b/modern/src/settings/CommandsPage.js index 1b09a8bd..64a29bf6 100644 --- a/modern/src/settings/CommandsPage.js +++ b/modern/src/settings/CommandsPage.js @@ -1,15 +1,15 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; import { useTranslation } from '../common/components/LocalizationProvider'; import { formatBoolean } from '../common/util/formatter'; import { prefixString } from '../common/util/stringUtils'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -18,10 +18,11 @@ const useStyles = makeStyles((theme) => ({ }, })); -const CommandsView = ({ updateTimestamp, onMenuClick }) => { +const CommandsPage = () => { const classes = useStyles(); const t = useTranslation(); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); useEffectAsync(async () => { @@ -31,42 +32,37 @@ const CommandsView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); return ( - - - - - - {t('sharedDescription')} - {t('sharedType')} - {t('commandSendSms')} - - - - {items.map((item) => ( - - - onMenuClick(event.currentTarget, item.id)}> - - - - {item.description} - {t(prefixString('command', item.type))} - {formatBoolean(item.textChannel, t)} + } breadcrumbs={['settingsTitle', 'sharedSavedCommands']}> + +
+ + + + {t('sharedDescription')} + {t('sharedType')} + {t('commandSendSms')} - ))} - -
-
+ + + {items.map((item) => ( + + + + + {item.description} + {t(prefixString('command', item.type))} + {formatBoolean(item.textChannel, t)} + + ))} + + + + + ); }; -const CommandsPage = () => ( - } breadcrumbs={['settingsTitle', 'sharedSavedCommands']}> - - -); - export default CommandsPage; diff --git a/modern/src/settings/ComputedAttributesPage.js b/modern/src/settings/ComputedAttributesPage.js index 86704c3b..0b029308 100644 --- a/modern/src/settings/ComputedAttributesPage.js +++ b/modern/src/settings/ComputedAttributesPage.js @@ -1,14 +1,14 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; import { useTranslation } from '../common/components/LocalizationProvider'; import { useAdministrator } from '../common/util/permissions'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -17,10 +17,11 @@ const useStyles = makeStyles((theme) => ({ }, })); -const ComputedAttributeView = ({ updateTimestamp, onMenuClick }) => { +const ComputedAttributesPage = () => { const classes = useStyles(); const t = useTranslation(); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); const administrator = useAdministrator(); @@ -31,46 +32,41 @@ const ComputedAttributeView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); return ( - - - - - {administrator && } - {t('sharedDescription')} - {t('sharedAttribute')} - {t('sharedExpression')} - {t('sharedType')} - - - - {items.map((item) => ( - - {administrator && ( - - onMenuClick(event.currentTarget, item.id)}> - - - - )} - {item.description} - {item.attribute} - {item.expression} - {item.type} + } breadcrumbs={['settingsTitle', 'sharedComputedAttributes']}> + +
+ + + {administrator && } + {t('sharedDescription')} + {t('sharedAttribute')} + {t('sharedExpression')} + {t('sharedType')} - ))} - -
-
+ + + {items.map((item) => ( + + {administrator && ( + + + + )} + {item.description} + {item.attribute} + {item.expression} + {item.type} + + ))} + + + + + ); }; -const ComputedAttributesPage = () => ( - } breadcrumbs={['settingsTitle', 'sharedComputedAttributes']}> - - -); - export default ComputedAttributesPage; diff --git a/modern/src/settings/DriversPage.js b/modern/src/settings/DriversPage.js index 26601777..b5c30a17 100644 --- a/modern/src/settings/DriversPage.js +++ b/modern/src/settings/DriversPage.js @@ -1,13 +1,13 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -16,10 +16,11 @@ const useStyles = makeStyles((theme) => ({ }, })); -const DriversView = ({ updateTimestamp, onMenuClick }) => { +const DriversPage = () => { const classes = useStyles(); const t = useTranslation(); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); useEffectAsync(async () => { @@ -29,40 +30,35 @@ const DriversView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); return ( - - - - - - {t('sharedName')} - {t('deviceIdentifier')} - - - - {items.map((item) => ( - - - onMenuClick(event.currentTarget, item.id)}> - - - - {item.name} - {item.uniqueId} + } breadcrumbs={['settingsTitle', 'sharedDrivers']}> + +
+ + + + {t('sharedName')} + {t('deviceIdentifier')} - ))} - -
-
+ + + {items.map((item) => ( + + + + + {item.name} + {item.uniqueId} + + ))} + + + + + ); }; -const DriversPage = () => ( - } breadcrumbs={['settingsTitle', 'sharedDrivers']}> - - -); - export default DriversPage; diff --git a/modern/src/settings/GroupsPage.js b/modern/src/settings/GroupsPage.js index 257d0bca..ae17bd78 100644 --- a/modern/src/settings/GroupsPage.js +++ b/modern/src/settings/GroupsPage.js @@ -1,13 +1,13 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -16,10 +16,11 @@ const useStyles = makeStyles((theme) => ({ }, })); -const GroupsView = ({ updateTimestamp, onMenuClick }) => { +const GroupsPage = () => { const classes = useStyles(); const t = useTranslation(); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); useEffectAsync(async () => { @@ -29,38 +30,33 @@ const GroupsView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); return ( - - - - - - {t('sharedName')} - - - - {items.map((item) => ( - - - onMenuClick(event.currentTarget, item.id)}> - - - - {item.name} + } breadcrumbs={['settingsTitle', 'settingsGroups']}> + +
+ + + + {t('sharedName')} - ))} - -
-
+ + + {items.map((item) => ( + + + + + {item.name} + + ))} + + + + + ); }; -const GroupsPage = () => ( - } breadcrumbs={['settingsTitle', 'settingsGroups']}> - - -); - export default GroupsPage; diff --git a/modern/src/settings/MaintenancesPage.js b/modern/src/settings/MaintenancesPage.js index ea00e7e1..43a37b60 100644 --- a/modern/src/settings/MaintenancesPage.js +++ b/modern/src/settings/MaintenancesPage.js @@ -1,17 +1,16 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; - import usePositionAttributes from '../common/attributes/usePositionAttributes'; import { formatDistance, formatSpeed } from '../common/util/formatter'; import { useAttributePreference } from '../common/util/preferences'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -20,12 +19,13 @@ const useStyles = makeStyles((theme) => ({ }, })); -const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { +const MaintenacesPage = () => { const classes = useStyles(); const t = useTranslation(); const positionAttributes = usePositionAttributes(t); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); const speedUnit = useAttributePreference('speedUnit'); const distanceUnit = useAttributePreference('distanceUnit'); @@ -37,7 +37,7 @@ const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); const convertAttribute = (key, value) => { const attribute = positionAttributes[key]; @@ -56,41 +56,36 @@ const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { }; return ( - - - - - - {t('sharedName')} - {t('sharedType')} - {t('maintenanceStart')} - {t('maintenancePeriod')} - - - - {items.map((item) => ( - - - onMenuClick(event.currentTarget, item.id)}> - - - - {item.name} - {item.type} - {convertAttribute(item.type, item.start)} - {convertAttribute(item.type, item.period)} + } breadcrumbs={['settingsTitle', 'sharedMaintenance']}> + +
+ + + + {t('sharedName')} + {t('sharedType')} + {t('maintenanceStart')} + {t('maintenancePeriod')} - ))} - -
-
+ + + {items.map((item) => ( + + + + + {item.name} + {item.type} + {convertAttribute(item.type, item.start)} + {convertAttribute(item.type, item.period)} + + ))} + + + + + ); }; -const MaintenacesPage = () => ( - } breadcrumbs={['settingsTitle', 'sharedMaintenance']}> - - -); - export default MaintenacesPage; diff --git a/modern/src/settings/NotificationsPage.js b/modern/src/settings/NotificationsPage.js index de3e762f..ec0df1cb 100644 --- a/modern/src/settings/NotificationsPage.js +++ b/modern/src/settings/NotificationsPage.js @@ -1,15 +1,15 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; import { prefixString } from '../common/util/stringUtils'; import { formatBoolean } from '../common/util/formatter'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -18,10 +18,11 @@ const useStyles = makeStyles((theme) => ({ }, })); -const NotificationsView = ({ updateTimestamp, onMenuClick }) => { +const NotificationsPage = () => { const classes = useStyles(); const t = useTranslation(); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); useEffectAsync(async () => { @@ -31,7 +32,7 @@ const NotificationsView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); const formatList = (prefix, value) => { if (value) { @@ -45,41 +46,36 @@ const NotificationsView = ({ updateTimestamp, onMenuClick }) => { }; return ( - - - - - - {t('notificationType')} - {t('notificationAlways')} - {t('sharedAlarms')} - {t('notificationNotificators')} - - - - {items.map((item) => ( - - - onMenuClick(event.currentTarget, item.id)}> - - - - {t(prefixString('event', item.type))} - {formatBoolean(item.always, t)} - {formatList('alarm', item.attributes.alarms)} - {formatList('notificator', item.notificators)} + } breadcrumbs={['settingsTitle', 'sharedNotifications']}> + +
+ + + + {t('notificationType')} + {t('notificationAlways')} + {t('sharedAlarms')} + {t('notificationNotificators')} - ))} - -
-
+ + + {items.map((item) => ( + + + + + {t(prefixString('event', item.type))} + {formatBoolean(item.always, t)} + {formatList('alarm', item.attributes.alarms)} + {formatList('notificator', item.notificators)} + + ))} + + + + + ); }; -const NotificationsPage = () => ( - } breadcrumbs={['settingsTitle', 'sharedNotifications']}> - - -); - export default NotificationsPage; diff --git a/modern/src/settings/UsersPage.js b/modern/src/settings/UsersPage.js index 235ae4c7..059b6bcc 100644 --- a/modern/src/settings/UsersPage.js +++ b/modern/src/settings/UsersPage.js @@ -1,14 +1,14 @@ import React, { useState } from 'react'; import { - TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, + TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; -import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; -import EditCollectionView from './components/EditCollectionView'; import { formatBoolean } from '../common/util/formatter'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -17,10 +17,11 @@ const useStyles = makeStyles((theme) => ({ }, })); -const UsersView = ({ updateTimestamp, onMenuClick }) => { +const UsersPage = () => { const classes = useStyles(); const t = useTranslation(); + const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); useEffectAsync(async () => { @@ -30,44 +31,39 @@ const UsersView = ({ updateTimestamp, onMenuClick }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, [timestamp]); return ( - - - - - - {t('sharedName')} - {t('userEmail')} - {t('userAdmin')} - {t('sharedDisabled')} - - - - {items.map((item) => ( - - - onMenuClick(event.currentTarget, item.id)}> - - - - {item.name} - {item.email} - {formatBoolean(item.administrator, t)} - {formatBoolean(item.disabled, t)} + } breadcrumbs={['settingsTitle', 'settingsUsers']}> + +
+ + + + {t('sharedName')} + {t('userEmail')} + {t('userAdmin')} + {t('sharedDisabled')} - ))} - -
-
+ + + {items.map((item) => ( + + + + + {item.name} + {item.email} + {formatBoolean(item.administrator, t)} + {formatBoolean(item.disabled, t)} + + ))} + + + + + ); }; -const UsersPage = () => ( - } breadcrumbs={['settingsTitle', 'settingsUsers']}> - - -); - export default UsersPage; diff --git a/modern/src/settings/components/CollectionActions.js b/modern/src/settings/components/CollectionActions.js new file mode 100644 index 00000000..6bf9ddb1 --- /dev/null +++ b/modern/src/settings/components/CollectionActions.js @@ -0,0 +1,48 @@ +import React, { useState } from 'react'; +import { IconButton, Menu, MenuItem } from '@material-ui/core'; +import MoreVertIcon from '@material-ui/icons/MoreVert'; +import { useHistory } from 'react-router-dom'; +import RemoveDialog from '../../common/components/RemoveDialog'; +import { useTranslation } from '../../common/components/LocalizationProvider'; + +const CollectionActions = ({ + itemId, editPath, endpoint, setTimestamp, +}) => { + const history = useHistory(); + const t = useTranslation(); + + const [menuAnchorEl, setMenuAnchorEl] = useState(null); + const [removing, setRemoving] = useState(false); + + const handleEdit = () => { + history.push(`${editPath}/${itemId}`); + setMenuAnchorEl(null); + }; + + const handleRemove = () => { + setRemoving(true); + setMenuAnchorEl(null); + }; + + const handleRemoveResult = (removed) => { + setRemoving(false); + if (removed && setTimestamp) { + setTimestamp(Date.now()); + } + }; + + return ( + <> + setMenuAnchorEl(event.currentTarget)}> + + + setMenuAnchorEl(null)}> + {t('sharedEdit')} + {t('sharedRemove')} + + + + ); +}; + +export default CollectionActions; diff --git a/modern/src/settings/components/CollectionFab.js b/modern/src/settings/components/CollectionFab.js new file mode 100644 index 00000000..f52bed38 --- /dev/null +++ b/modern/src/settings/components/CollectionFab.js @@ -0,0 +1,35 @@ +import React from 'react'; +import { Fab, makeStyles } from '@material-ui/core'; +import AddIcon from '@material-ui/icons/Add'; +import { useHistory } from 'react-router-dom'; +import { useReadonly } from '../../common/util/permissions'; +import dimensions from '../../common/theme/dimensions'; + +const useStyles = makeStyles((theme) => ({ + fab: { + position: 'fixed', + bottom: theme.spacing(2), + right: theme.spacing(2), + [theme.breakpoints.down('sm')]: { + bottom: dimensions.bottomBarHeight + theme.spacing(2), + }, + }, +})); + +const CollectionFab = ({ editPath, disabled }) => { + const classes = useStyles(); + const history = useHistory(); + + const readonly = useReadonly(); + + if (!readonly && !disabled) { + return ( + history.push(editPath)}> + + + ); + } + return ''; +}; + +export default CollectionFab; diff --git a/modern/src/settings/components/EditCollectionView.js b/modern/src/settings/components/EditCollectionView.js deleted file mode 100644 index b0bf3ea0..00000000 --- a/modern/src/settings/components/EditCollectionView.js +++ /dev/null @@ -1,89 +0,0 @@ -import React, { useState } from 'react'; -import { makeStyles } from '@material-ui/core/styles'; -import { useHistory } from 'react-router-dom'; -import Menu from '@material-ui/core/Menu'; -import MenuItem from '@material-ui/core/MenuItem'; -import Fab from '@material-ui/core/Fab'; -import AddIcon from '@material-ui/icons/Add'; - -import RemoveDialog from '../../common/components/RemoveDialog'; -import { useTranslation } from '../../common/components/LocalizationProvider'; -import dimensions from '../../common/theme/dimensions'; -import { useReadonly } from '../../common/util/permissions'; - -const useStyles = makeStyles((theme) => ({ - fab: { - position: 'fixed', - bottom: theme.spacing(2), - right: theme.spacing(2), - [theme.breakpoints.down('sm')]: { - bottom: dimensions.bottomBarHeight + theme.spacing(2), - }, - }, -})); - -const EditCollectionView = ({ - content, editPath, endpoint, disableAdd, filter, -}) => { - const classes = useStyles(); - const history = useHistory(); - const t = useTranslation(); - - const readonly = useReadonly(); - - const [selectedId, setSelectedId] = useState(null); - const [selectedAnchorEl, setSelectedAnchorEl] = useState(null); - const [removeDialogShown, setRemoveDialogShown] = useState(false); - const [updateTimestamp, setUpdateTimestamp] = useState(Date.now()); - - const menuShow = (anchorId, itemId) => { - setSelectedAnchorEl(anchorId); - setSelectedId(itemId); - }; - - const menuHide = () => { - setSelectedAnchorEl(null); - }; - - const handleAdd = () => { - history.push(editPath); - menuHide(); - }; - - const handleEdit = () => { - history.push(`${editPath}/${selectedId}`); - menuHide(); - }; - - const handleRemove = () => { - setRemoveDialogShown(true); - menuHide(); - }; - - const handleRemoveResult = (removed) => { - setRemoveDialogShown(false); - if (removed) { - setUpdateTimestamp(Date.now()); - } - }; - - const Content = content; - - return ( - <> - - {!readonly && !disableAdd && ( - - - - )} - - {t('sharedEdit')} - {t('sharedRemove')} - - - - ); -}; - -export default EditCollectionView; -- cgit v1.2.3