Revize 80e18558
Přidáno uživatelem Václav Honzík před asi 2 roky(ů)
frontend/src/features/TrackingTool/Import/ImportLocationDialog.tsx | ||
---|---|---|
4 | 4 |
DialogTitle, |
5 | 5 |
FormControl, |
6 | 6 |
Grid, |
7 |
IconButton, |
|
7 | 8 |
InputLabel, |
8 | 9 |
MenuItem, |
10 |
Paper, |
|
9 | 11 |
Select, |
12 |
Stack, |
|
13 |
TextField, |
|
10 | 14 |
} from '@mui/material' |
11 |
import { FunctionComponent, useState } from 'react' |
|
15 |
import { Fragment, FunctionComponent, useState } from 'react'
|
|
12 | 16 |
import ButtonOpenableDialog from '../../Reusables/ButtonOpenableDialog' |
13 | 17 |
import ContextMenuDialogProps from './contextMenuDialogProps' |
18 |
import * as yup from 'yup' |
|
19 |
import { useFormik } from 'formik' |
|
20 |
import ThemeWrapper from '../../Theme/ThemeWrapper' |
|
21 |
import CloseIcon from '@mui/icons-material/Close' |
|
14 | 22 |
|
15 | 23 |
const importTypes = { |
16 | 24 |
localCatalog: 'Local Catalog', |
17 | 25 |
websiteCatalogs: 'Website Catalogs', |
18 | 26 |
} |
19 | 27 |
|
28 |
|
|
29 |
const externalCatalogs = { |
|
30 |
'PLEIADES': 'Pleiades', |
|
31 |
'GEONAMES': 'Geonames', |
|
32 |
'CIGS': 'CIGS', |
|
33 |
'ANE': 'ANE' |
|
34 |
} |
|
35 |
|
|
36 |
interface ImportData { |
|
37 |
name: string // used always |
|
38 |
externalCatalogType?: string // only used for website catalogs variant |
|
39 |
} |
|
40 |
|
|
20 | 41 |
const ImportLocationDialog: FunctionComponent<ContextMenuDialogProps> = ({ |
21 | 42 |
latLng, |
22 | 43 |
closeContextMenu, |
23 | 44 |
}) => { |
24 | 45 |
const [open, setOpen] = useState(false) |
25 | 46 |
const [importType, setImportType] = useState('localCatalog') |
26 |
const [submitFunction, setSubmitFunction] = useState<() => void>(() => {}) |
|
47 |
|
|
48 |
const formik = useFormik({ |
|
49 |
initialValues: { |
|
50 |
name: '', |
|
51 |
} as ImportData, |
|
52 |
validationSchema: yup.object().shape({ |
|
53 |
name: yup.string().required('Name is required'), |
|
54 |
}), |
|
55 |
onSubmit: async (values: ImportData) => { |
|
56 |
if (importType === 'localCatalog') { |
|
57 |
values.externalCatalogType = undefined |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
}, |
|
62 |
}) |
|
63 |
|
|
64 |
const NameTextField = () => ( |
|
65 |
<TextField |
|
66 |
sx={{ mt: 1 }} |
|
67 |
fullWidth |
|
68 |
label="Name" |
|
69 |
name="name" |
|
70 |
size="small" |
|
71 |
value={formik.values.name} |
|
72 |
onChange={formik.handleChange} |
|
73 |
variant="outlined" |
|
74 |
error={Boolean(formik.errors.name) && formik.touched.name} |
|
75 |
helperText={formik.errors.name && formik.touched.name} |
|
76 |
/> |
|
77 |
) |
|
78 |
|
|
79 |
const onClose = () => { |
|
80 |
formik.resetForm() |
|
81 |
setImportType('localCatalog') |
|
82 |
setOpen(false) |
|
83 |
closeContextMenu() |
|
84 |
} |
|
27 | 85 |
|
28 | 86 |
return ( |
29 | 87 |
<ButtonOpenableDialog |
30 | 88 |
buttonText="Import Location" |
31 | 89 |
buttonColor="primary" |
32 | 90 |
buttonVariant="text" |
33 |
onCloseCallback={closeContextMenu}
|
|
91 |
onCloseCallback={onClose}
|
|
34 | 92 |
maxWidth="xs" |
35 | 93 |
open={open} |
36 | 94 |
setOpen={setOpen} |
37 | 95 |
size="small" |
38 | 96 |
onOpenCallback={() => {}} |
39 | 97 |
> |
40 |
<DialogTitle>Import Locations</DialogTitle> |
|
41 |
<DialogContent> |
|
42 |
<Grid container sx={{mt: 0}} spacing={1}> |
|
43 |
<Grid item xs={6} md={9}> |
|
44 |
<FormControl fullWidth> |
|
45 |
<InputLabel id="importType">Import</InputLabel> |
|
46 |
<Select |
|
47 |
labelId="importType" |
|
48 |
id="importTypeSelect" |
|
49 |
value={importType} |
|
50 |
label="Import" |
|
51 |
size="small" |
|
52 |
onChange={(e) => setImportType(e.target.value)} |
|
53 |
> |
|
54 |
{Object.keys(importTypes).map((key) => ( |
|
55 |
<MenuItem key={key} value={key}> |
|
56 |
{ |
|
57 |
//@ts-ignore |
|
58 |
importTypes[key] |
|
98 |
<ThemeWrapper> |
|
99 |
<Paper> |
|
100 |
<DialogTitle> |
|
101 |
<Stack |
|
102 |
direction="row" |
|
103 |
justifyContent="space-between" |
|
104 |
alignItems="center" |
|
105 |
spacing={1} |
|
106 |
> |
|
107 |
<Fragment> |
|
108 |
Import Locations |
|
109 |
</Fragment> |
|
110 |
<IconButton onClick={onClose}> |
|
111 |
<CloseIcon /> |
|
112 |
</IconButton> |
|
113 |
</Stack> |
|
114 |
</DialogTitle> |
|
115 |
<DialogContent> |
|
116 |
<Grid |
|
117 |
container |
|
118 |
sx={{ mt: 1 }} |
|
119 |
// spacing={1} |
|
120 |
justifyContent="space-around" |
|
121 |
alignItems="center" |
|
122 |
> |
|
123 |
<Grid item xs={6} md={9}> |
|
124 |
<FormControl fullWidth> |
|
125 |
<InputLabel id="importType"> |
|
126 |
Import |
|
127 |
</InputLabel> |
|
128 |
<Select |
|
129 |
labelId="importType" |
|
130 |
id="importTypeSelect" |
|
131 |
value={importType} |
|
132 |
label="Import" |
|
133 |
size="small" |
|
134 |
onChange={(e) => |
|
135 |
setImportType(e.target.value) |
|
59 | 136 |
} |
60 |
</MenuItem> |
|
61 |
))} |
|
62 |
</Select> |
|
63 |
</FormControl> |
|
64 |
</Grid> |
|
65 |
<Grid item xs={6} md={3} alignContent="flex-end" justifyContent="flex-end"> |
|
66 |
<Button variant="contained" color="primary" onClick={submitFunction}>Import</Button> |
|
67 |
</Grid> |
|
68 |
</Grid> |
|
69 |
</DialogContent> |
|
137 |
> |
|
138 |
{Object.keys(importTypes).map((key) => ( |
|
139 |
<MenuItem key={key} value={key}> |
|
140 |
{ |
|
141 |
//@ts-ignore |
|
142 |
importTypes[key] |
|
143 |
} |
|
144 |
</MenuItem> |
|
145 |
))} |
|
146 |
</Select> |
|
147 |
</FormControl> |
|
148 |
</Grid> |
|
149 |
<Grid |
|
150 |
item |
|
151 |
container |
|
152 |
xs={6} |
|
153 |
md={3} |
|
154 |
justifyContent="flex-end" |
|
155 |
> |
|
156 |
<Button variant="contained" type="submit" color="primary"> |
|
157 |
Import |
|
158 |
</Button> |
|
159 |
</Grid> |
|
160 |
{importType === 'localCatalog' ? ( |
|
161 |
<NameTextField /> |
|
162 |
) : ( |
|
163 |
<Fragment> |
|
164 |
<FormControl |
|
165 |
fullWidth |
|
166 |
variant="outlined" |
|
167 |
sx={{ mt: 1 }} |
|
168 |
> |
|
169 |
<InputLabel id="externalCatalogType"> |
|
170 |
Catalog Type |
|
171 |
</InputLabel> |
|
172 |
<Select |
|
173 |
labelId="externalCatalogType" |
|
174 |
name="externalCatalogType" |
|
175 |
value={ |
|
176 |
formik.values |
|
177 |
.externalCatalogType || "PLEIADES" |
|
178 |
} |
|
179 |
onChange={formik.handleChange} |
|
180 |
label="Catalog Type" |
|
181 |
size="small" |
|
182 |
> |
|
183 |
{Object.entries(externalCatalogs).map( |
|
184 |
([key, value], idx) => ( |
|
185 |
<MenuItem |
|
186 |
key={key} |
|
187 |
value={key} |
|
188 |
> |
|
189 |
{value} |
|
190 |
</MenuItem> |
|
191 |
) |
|
192 |
)} |
|
193 |
</Select> |
|
194 |
</FormControl> |
|
195 |
<NameTextField /> |
|
196 |
</Fragment> |
|
197 |
)} |
|
198 |
</Grid> |
|
199 |
</DialogContent> |
|
200 |
</Paper> |
|
201 |
</ThemeWrapper> |
|
70 | 202 |
</ButtonOpenableDialog> |
71 | 203 |
) |
72 | 204 |
} |
Také k dispozici: Unified diff
import dialogs more fleshed out
re #9741