From e3ead466abdb03c5f1eb5d3979ad286d38ac95cb Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Thu, 7 Jan 2021 17:06:20 +0530 Subject: Hiding add computed attribute button for non admin users --- modern/src/EditCollectionView.js | 12 +++++++++--- modern/src/settings/ComputedAttributePage.js | 1 - modern/src/settings/ComputedAttributesPage.js | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'modern/src') diff --git a/modern/src/EditCollectionView.js b/modern/src/EditCollectionView.js index bec1056..f15d72c 100644 --- a/modern/src/EditCollectionView.js +++ b/modern/src/EditCollectionView.js @@ -5,6 +5,7 @@ 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 { useSelector } from 'react-redux'; import t from './common/localization'; import RemoveDialog from './RemoveDialog'; @@ -25,6 +26,7 @@ const EditCollectionView = ({ content, editPath, endpoint }) => { const [selectedAnchorEl, setSelectedAnchorEl] = useState(null); const [removeDialogShown, setRemoveDialogShown] = useState(false); const [updateTimestamp, setUpdateTimestamp] = useState(Date.now()); + const adminEnabled = useSelector(state => state.session.user && state.session.user.administrator); const menuShow = (anchorId, itemId) => { setSelectedAnchorEl(anchorId); @@ -60,9 +62,13 @@ const EditCollectionView = ({ content, editPath, endpoint }) => { return ( <> - - - + {adminEnabled && + ( + + + + ) + } {t('sharedEdit')} {t('sharedRemove')} diff --git a/modern/src/settings/ComputedAttributePage.js b/modern/src/settings/ComputedAttributePage.js index 7ff9511..73759fa 100644 --- a/modern/src/settings/ComputedAttributePage.js +++ b/modern/src/settings/ComputedAttributePage.js @@ -2,7 +2,6 @@ import React, { useState } from 'react'; import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, FormControl, InputLabel, MenuItem, Select, TextField } from "@material-ui/core"; import t from '../common/localization'; import EditItemView from '../EditItemView'; - import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import positionAttributes from '../attributes/positionAttributes'; diff --git a/modern/src/settings/ComputedAttributesPage.js b/modern/src/settings/ComputedAttributesPage.js index 53d1172..dde6b23 100644 --- a/modern/src/settings/ComputedAttributesPage.js +++ b/modern/src/settings/ComputedAttributesPage.js @@ -2,6 +2,7 @@ import React, { useState } from 'react'; import MainToolbar from '../MainToolbar'; import { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton } from '@material-ui/core'; import MoreVertIcon from '@material-ui/icons/MoreVert'; +import { useSelector } from 'react-redux'; import t from '../common/localization'; import { useEffectAsync } from '../reactHelper'; import EditCollectionView from '../EditCollectionView'; @@ -17,6 +18,7 @@ const ComputedAttributeView = ({ updateTimestamp, onMenuClick }) => { const classes = useStyles(); const [items, setItems] = useState([]); + const adminEnabled = useSelector(state => state.session.user && state.session.user.administrator); useEffectAsync(async () => { const response = await fetch('/api/attributes/computed'); @@ -30,7 +32,7 @@ const ComputedAttributeView = ({ updateTimestamp, onMenuClick }) => { - + {adminEnabled && ()} {t('sharedDescription')} {t('sharedAttribute')} {t('sharedExpression')} @@ -40,11 +42,15 @@ const ComputedAttributeView = ({ updateTimestamp, onMenuClick }) => { {items.map((item) => ( - - onMenuClick(event.currentTarget, item.id)}> - - - + {adminEnabled && + ( + + onMenuClick(event.currentTarget, item.id)}> + + + + ) + } {item.description} {item.attribute} {item.expression} -- cgit v1.2.3