Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 80e18558

Přidáno uživatelem Václav Honzík před asi 2 roky(ů)

import dialogs more fleshed out

re #9741

Zobrazit rozdíly:

frontend/src/features/TrackingTool/Import/AddFromCoordinatesDialog.tsx
1
import { DialogContent, DialogTitle, Grid, TextField } from '@mui/material'
2
import { FunctionComponent, useState } from 'react'
1
import {
2
    Button,
3
    DialogContent,
4
    DialogTitle,
5
    Grid,
6
    IconButton,
7
    Paper,
8
    Stack,
9
    TextField,
10
    Typography,
11
} from '@mui/material'
12
import { Fragment, FunctionComponent, useState } from 'react'
3 13
import ButtonOpenableDialog from '../../Reusables/ButtonOpenableDialog'
4 14
import * as yup from 'yup'
5 15
import { useDispatch } from 'react-redux'
......
8 18
import generateUuid from '../../../utils/id/uuidGenerator'
9 19
import { useFormik } from 'formik'
10 20
import ContextMenuDialogProps from './contextMenuDialogProps'
21
import ThemeWrapper from '../../Theme/ThemeWrapper'
22
import CloseIcon from '@mui/icons-material/Close'
11 23

  
12 24
interface AddCatalogItemFromCoords {
13 25
    latitude: number
......
52 64
        },
53 65
    })
54 66

  
67
    const onClose = () => {
68
        formik.resetForm()
69
        closeContextMenu()
70
        setOpen(false)
71
    }
72

  
55 73
    return (
56 74
        <ButtonOpenableDialog
57 75
            buttonText="Create Location"
58 76
            buttonColor="primary"
59 77
            buttonVariant="text"
60
            onCloseCallback={closeContextMenu}
78
            onCloseCallback={onClose}
61 79
            maxWidth="xs"
62 80
            open={open}
63 81
            setOpen={setOpen}
64 82
            size="small"
65 83
        >
66
            <DialogTitle>Add New Location From Coordinates</DialogTitle>
67
            <DialogContent>
68
                <form onSubmit={formik.handleSubmit}>
69
                    <Grid container spacing={1} sx={{ mt: 1, mb: 1 }}>
70
                        <Grid item xs={12} md={6}>
71
                            <TextField
72
                                fullWidth
73
                                label="Latitude"
74
                                name="latitude"
75
                                type="number"
76
                                variant="outlined"
77
                                value={formik.values.latitude}
78
                                onChange={formik.handleChange}
79
                                error={
80
                                    Boolean(formik.errors.latitude) &&
81
                                    formik.touched.latitude
82
                                }
83
                                helperText={
84
                                    formik.errors.latitude &&
85
                                    formik.touched.latitude
86
                                }
87
                            />
88
                        </Grid>
89
                        <Grid item xs={12} md={6}>
90
                            <TextField
91
                                fullWidth
92
                                label="Longitude"
93
                                name="longitude"
94
                                type="number"
95
                                variant="outlined"
96
                                value={formik.values.longitude}
97
                                onChange={formik.handleChange}
98
                                error={
99
                                    Boolean(formik.errors.longitude) &&
100
                                    formik.touched.longitude
101
                                }
102
                                helperText={
103
                                    formik.errors.longitude &&
104
                                    formik.touched.longitude
105
                                }
106
                            />
107
                        </Grid>
108
                    </Grid>
109
                    <TextField
110
                        fullWidth
111
                        label="Name"
112
                        name="name"
113
                        variant="outlined"
114
                        value={formik.values.name}
115
                        onChange={formik.handleChange}
116
                        error={
117
                            Boolean(formik.errors.name) && formik.touched.name
118
                        }
119
                        helperText={formik.errors.name && formik.touched.name}
120
                    />
121
                </form>
122
            </DialogContent>
84
            <ThemeWrapper>
85
                <Paper>
86
                    <DialogTitle>
87
                        <Stack
88
                            direction="row"
89
                            justifyContent="space-between"
90
                            alignItems="center"
91
                            spacing={1}
92
                        >
93
                            <Fragment>
94
                                Add New Location From Coordinates
95
                            </Fragment>
96
                            <IconButton onClick={onClose}>
97
                                <CloseIcon />
98
                            </IconButton>
99
                        </Stack>
100
                    </DialogTitle>
101
                    <DialogContent>
102
                        <form onSubmit={formik.handleSubmit}>
103
                            <Grid
104
                                container
105
                                sx={{ mt: 1 }}
106
                                // spacing={1}
107
                                justifyContent="space-around"
108
                                alignItems="center"
109
                            >
110
                                <Grid item xs={6} md={9}>
111
                                    <TextField
112
                                        fullWidth
113
                                        label="Name"
114
                                        size="small"
115
                                        name="name"
116
                                        variant="outlined"
117
                                        value={formik.values.name}
118
                                        onChange={formik.handleChange}
119
                                        error={
120
                                            Boolean(formik.errors.name) &&
121
                                            formik.touched.name
122
                                        }
123
                                        helperText={
124
                                            formik.errors.name &&
125
                                            formik.touched.name
126
                                        }
127
                                    />
128
                                </Grid>
129
                                <Grid
130
                                    item
131
                                    container
132
                                    xs={6}
133
                                    md={3}
134
                                    justifyContent="flex-end"
135
                                >
136
                                    <Button variant="contained" type="submit" color="primary">
137
                                        Import
138
                                    </Button>
139
                                </Grid>
140
                            </Grid>
141
                            <Grid container spacing={1} sx={{ mt: 1, mb: 1 }}>
142
                                <Grid item xs={12} md={6}>
143
                                    <TextField
144
                                        fullWidth
145
                                        label="Latitude"
146
                                        name="latitude"
147
                                        type="number"
148
                                        size="small"
149
                                        variant="outlined"
150
                                        value={formik.values.latitude}
151
                                        onChange={formik.handleChange}
152
                                        error={
153
                                            Boolean(formik.errors.latitude) &&
154
                                            formik.touched.latitude
155
                                        }
156
                                        helperText={
157
                                            formik.errors.latitude &&
158
                                            formik.touched.latitude
159
                                        }
160
                                    />
161
                                </Grid>
162
                                <Grid item xs={12} md={6}>
163
                                    <TextField
164
                                        fullWidth
165
                                        label="Longitude"
166
                                        name="longitude"
167
                                        type="number"
168
                                        variant="outlined"
169
                                        size="small"
170
                                        value={formik.values.longitude}
171
                                        onChange={formik.handleChange}
172
                                        error={
173
                                            Boolean(formik.errors.longitude) &&
174
                                            formik.touched.longitude
175
                                        }
176
                                        helperText={
177
                                            formik.errors.longitude &&
178
                                            formik.touched.longitude
179
                                        }
180
                                    />
181
                                </Grid>
182
                            </Grid>
183
                        </form>
184
                    </DialogContent>
185
                </Paper>
186
            </ThemeWrapper>
123 187
        </ButtonOpenableDialog>
124 188
    )
125 189
}
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