aboutsummaryrefslogtreecommitdiff
path: root/modern/src/settings/ComputedAttributePage.js
diff options
context:
space:
mode:
authorAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-01-05 17:23:32 +0530
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-01-05 17:23:32 +0530
commit3fb3b5334e11c1239b5126767c4160da79d1cfe9 (patch)
treeb68db81232ab2e74656fb18af9559ca8c2278b6e /modern/src/settings/ComputedAttributePage.js
parentbe88468a42eb4fd61c1bc5bdbf54be173825196d (diff)
downloadtrackermap-web-3fb3b5334e11c1239b5126767c4160da79d1cfe9.tar.gz
trackermap-web-3fb3b5334e11c1239b5126767c4160da79d1cfe9.tar.bz2
trackermap-web-3fb3b5334e11c1239b5126767c4160da79d1cfe9.zip
Computed Attributes
Diffstat (limited to 'modern/src/settings/ComputedAttributePage.js')
-rw-r--r--modern/src/settings/ComputedAttributePage.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/modern/src/settings/ComputedAttributePage.js b/modern/src/settings/ComputedAttributePage.js
new file mode 100644
index 00000000..f985152f
--- /dev/null
+++ b/modern/src/settings/ComputedAttributePage.js
@@ -0,0 +1,92 @@
+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';
+
+
+const useStyles = makeStyles(() => ({
+ details: {
+ flexDirection: 'column',
+ },
+}));
+
+const ComputedAttributePage =() => {
+
+ const classes = useStyles();
+ const [item, setItem] = useState();
+ const [key, setKey] = useState();
+
+ const options = Object.entries(positionAttributes).map(([key, value]) => ({
+ key,
+ name: value.name,
+ type: value.type,
+ }));
+
+ return (
+ <EditItemView endpoint="/attributes/computed" item={item} setItem={setItem}>
+ {item &&
+ <Accordion defaultExpanded>
+ <AccordionSummary expandIcon={<ExpandMoreIcon />}>
+ <Typography variant="subtitle1">
+ {t('sharedRequired')}
+ </Typography>
+ </AccordionSummary>
+ <AccordionDetails className={classes.details}>
+ <TextField
+ margin="normal"
+ value={item.description || ''}
+ onChange={event => setItem({...item, description: event.target.value})}
+ label={t('sharedDescription')}
+ variant="filled" />
+ <FormControl variant="filled" margin="normal" fullWidth>
+ <InputLabel>{t('sharedAttribute')}</InputLabel>
+ <Select
+ value={item.attribute || ''}
+ onChange={(e) => {
+ const newValue = e.target.value;
+ const positionAttribute = positionAttributes[newValue];
+ setKey(newValue);
+ if(positionAttribute && positionAttribute.type) {
+ setItem({...item, attribute: newValue, type: positionAttribute.type});
+ }else {
+ setItem({...item, attribute: newValue});
+ }
+ }}>
+ {options.map((option) => (
+ <MenuItem key={option.key} value={option.key}>{option.name}</MenuItem>
+ ))}
+ </Select>
+ </FormControl>
+ <TextField
+ margin="normal"
+ value={item.expression || ''}
+ onChange={event => setItem({...item, expression: event.target.value})}
+ label={t('sharedExpression')}
+ multiline
+ rows={4}
+ variant="filled" />
+ <FormControl
+ variant="filled"
+ margin="normal"
+ fullWidth
+ disabled={key in positionAttributes}>
+ <InputLabel>{t('sharedType')}</InputLabel>
+ <Select
+ value={item.type || ''}
+ onChange={event => setItem({...item, type: event.target.value})}>
+ <MenuItem value={'string'}>{t('sharedTypeString')}</MenuItem>
+ <MenuItem value={'number'}>{t('sharedTypeNumber')}</MenuItem>
+ <MenuItem value={'boolean'}>{t('sharedTypeBoolean')}</MenuItem>
+ </Select>
+ </FormControl>
+ </AccordionDetails>
+ </Accordion>
+ }
+ </EditItemView>
+ )
+}
+
+export default ComputedAttributePage;