aboutsummaryrefslogtreecommitdiff
path: root/modern/src/attributes/AddAttributeDialog.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-09-27 19:49:47 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-09-27 19:49:47 -0700
commit9bfda9e131ddda3076b4094a94795db41072a39c (patch)
treed6b4e12f2d62431cc0d320b5396e578944af78f4 /modern/src/attributes/AddAttributeDialog.js
parentbbc54a464a8a3cf41904c5335fb1845ff8af1887 (diff)
downloadtrackermap-web-9bfda9e131ddda3076b4094a94795db41072a39c.tar.gz
trackermap-web-9bfda9e131ddda3076b4094a94795db41072a39c.tar.bz2
trackermap-web-9bfda9e131ddda3076b4094a94795db41072a39c.zip
Implement attributes editing
Diffstat (limited to 'modern/src/attributes/AddAttributeDialog.js')
-rw-r--r--modern/src/attributes/AddAttributeDialog.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/modern/src/attributes/AddAttributeDialog.js b/modern/src/attributes/AddAttributeDialog.js
new file mode 100644
index 00000000..ee4c48c1
--- /dev/null
+++ b/modern/src/attributes/AddAttributeDialog.js
@@ -0,0 +1,83 @@
+import React, { useState } from 'react';
+import { Button, Dialog, DialogActions, DialogContent, FormControl, InputLabel, MenuItem, Select, TextField } from "@material-ui/core";
+
+import t from '../common/localization';
+import { Autocomplete, createFilterOptions } from '@material-ui/lab';
+
+const AddAttributeDialog = ({ open, onResult, definitions }) => {
+ const filter = createFilterOptions({
+ stringify: option => option.name,
+ });
+
+ const options = Object.entries(definitions).map(([key, value]) => ({
+ key,
+ name: value.name,
+ type: value.type,
+ }));
+
+ const [key, setKey] = useState();
+ const [type, setType] = useState('string');
+
+ return (
+ <Dialog open={open} fullWidth maxWidth="xs">
+ <DialogContent>
+ <Autocomplete
+ onChange={(_, option) => {
+ setKey(option && typeof option === 'object' ? option.key : option);
+ if (option && option.type) {
+ setType(option.type);
+ }
+ }}
+ filterOptions={(options, params) => {
+ const filtered = filter(options, params);
+ if (params.inputValue) {
+ filtered.push({
+ key: params.inputValue,
+ name: params.inputValue,
+ });
+ }
+ return filtered;
+ }}
+ options={options}
+ getOptionLabel={option => {
+ return option && typeof option === 'object' ? option.name : option;
+ }}
+ renderOption={option => option.name}
+ freeSolo
+ renderInput={(params) => (
+ <TextField {...params} label={t('sharedAttribute')} variant="filled" margin="normal" />
+ )}
+ />
+ <FormControl
+ variant="filled"
+ margin="normal"
+ fullWidth
+ disabled={key in definitions}>
+ <InputLabel>{t('sharedType')}</InputLabel>
+ <Select
+ value={type}
+ onChange={e => setType(e.target.value)}>
+ <MenuItem value={'string'}>{t('sharedTypeString')}</MenuItem>
+ <MenuItem value={'number'}>{t('sharedTypeNumber')}</MenuItem>
+ <MenuItem value={'boolean'}>{t('sharedTypeBoolean')}</MenuItem>
+ </Select>
+ </FormControl>
+ </DialogContent>
+ <DialogActions>
+ <Button
+ color="primary"
+ disabled={!key}
+ onClick={() => onResult({ key, type })}>
+ {t('sharedAdd')}
+ </Button>
+ <Button
+ autoFocus
+ onClick={() => onResult(null)}>
+ {t('sharedCancel')}
+ </Button>
+ </DialogActions>
+ </Dialog>
+ )
+}
+
+export default AddAttributeDialog;