aboutsummaryrefslogtreecommitdiff
path: root/modern/src/settings/ComputedAttributesPage.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-01-08 09:21:04 -0800
committerGitHub <noreply@github.com>2021-01-08 09:21:04 -0800
commit2201f5417f41204453e3cd53da003296925282aa (patch)
tree5f9a8ffedc10160ce3aecc7f4f1cb50074a4497f /modern/src/settings/ComputedAttributesPage.js
parentbe88468a42eb4fd61c1bc5bdbf54be173825196d (diff)
parentf48e7801d86ca3d8b831358013823dd62d33c7ee (diff)
downloadtrackermap-web-2201f5417f41204453e3cd53da003296925282aa.tar.gz
trackermap-web-2201f5417f41204453e3cd53da003296925282aa.tar.bz2
trackermap-web-2201f5417f41204453e3cd53da003296925282aa.zip
Merge pull request #806 from mail2bishnoi/computed_attributes
Computed Attributes
Diffstat (limited to 'modern/src/settings/ComputedAttributesPage.js')
-rw-r--r--modern/src/settings/ComputedAttributesPage.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/modern/src/settings/ComputedAttributesPage.js b/modern/src/settings/ComputedAttributesPage.js
new file mode 100644
index 00000000..1a6feab5
--- /dev/null
+++ b/modern/src/settings/ComputedAttributesPage.js
@@ -0,0 +1,73 @@
+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';
+
+const useStyles = makeStyles(theme => ({
+ columnAction: {
+ width: theme.spacing(1),
+ padding: theme.spacing(0, 1),
+ },
+}));
+
+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');
+ if (response.ok) {
+ setItems(await response.json());
+ }
+ }, [updateTimestamp]);
+
+ return (
+ <TableContainer>
+ <Table>
+ <TableHead>
+ <TableRow>
+ {adminEnabled && <TableCell className={classes.columnAction} />}
+ <TableCell>{t('sharedDescription')}</TableCell>
+ <TableCell>{t('sharedAttribute')}</TableCell>
+ <TableCell>{t('sharedExpression')}</TableCell>
+ <TableCell>{t('sharedType')}</TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {items.map((item) => (
+ <TableRow key={item.id}>
+ {adminEnabled &&
+ <TableCell className={classes.columnAction} padding="none">
+ <IconButton onClick={(event) => onMenuClick(event.currentTarget, item.id)}>
+ <MoreVertIcon />
+ </IconButton>
+ </TableCell>
+ }
+ <TableCell>{item.description}</TableCell>
+ <TableCell>{item.attribute}</TableCell>
+ <TableCell>{item.expression}</TableCell>
+ <TableCell>{item.type}</TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </TableContainer>
+ );
+}
+
+const ComputedAttributesPage = () => {
+ return (
+ <>
+ <MainToolbar />
+ <EditCollectionView content={ComputedAttributeView} editPath="/settings/attribute" endpoint="attributes/computed" />
+ </>
+ );
+}
+
+export default ComputedAttributesPage;