Projekt

Obecné

Profil

Stáhnout (8.89 KB) Statistiky
| Větev: | Tag: | Revize:
1 48690561 Vaclav Honzik
import { Button, Grid, Stack, Typography } from '@mui/material'
2 c0b4ee98 Vaclav Honzik
import { Fragment, useEffect, useState } from 'react'
3 a7ae217f Vaclav Honzik
import PlaintextUpload from './Upload/PlaintextUpload'
4
import FileUpload from './Upload/FileUpload'
5
import { useDispatch, useSelector } from 'react-redux'
6
import { RootState } from '../redux/store'
7 582489ce Vaclav Honzik
import {
8
    clear as clearTrackingTool,
9
    consumeErr as consumeError,
10
    toggleToggleables,
11
} from './trackingToolSlice'
12 a7ae217f Vaclav Honzik
import { showNotification } from '../Notification/notificationSlice'
13
import ClearIcon from '@mui/icons-material/Clear'
14 582489ce Vaclav Honzik
import ExternalPathExportButton from './ExternalPath/ExternalPathExportButton'
15 48690561 Vaclav Honzik
import ProcessedTextDisplay from './Controls/ProcessedTextDisplay'
16
import MapPointToggleables from './Controls/MapPointToggleables'
17 582489ce Vaclav Honzik
import ExternalPathImportDialog from './ExternalPath/ExternalPathImportDialog'
18 48690561 Vaclav Honzik
import Map from './Map/Map'
19 6e163dd9 Vaclav Honzik
import ReorderableMapPointList from './Controls/ReorderableMapPointList'
20 582489ce Vaclav Honzik
import FilterListIcon from '@mui/icons-material/FilterList'
21
import FilterListOffIcon from '@mui/icons-material/FilterListOff'
22 c0b4ee98 Vaclav Honzik
import SaveDisplayedPath from './Controls/SaveDisplayedPath'
23 80d68e29 Vaclav Honzik
import { useNavigate } from 'react-router-dom'
24 c0b4ee98 Vaclav Honzik
import ConfirmationDialog from '../Reusables/ConfirmationDialog'
25 61199638 Vaclav Honzik
import ManageFilePaths from './Controls/ManageFilePaths'
26 788ce11e Vaclav Honzik
27
// Page with tracking tool
28
const TrackingTool = () => {
29 11fca75a Vaclav Honzik
    const pathDto = useSelector(
30 48690561 Vaclav Honzik
        // Path response from the API
31 11fca75a Vaclav Honzik
        (state: RootState) => state.trackingTool.pathDto
32
    )
33 48690561 Vaclav Honzik
34
    // Use path as flag for undefined or present
35
    const path = useSelector(
36
        (state: RootState) => state.trackingTool.displayedPath
37 11fca75a Vaclav Honzik
    )
38
39 582489ce Vaclav Honzik
    const toggleablesOpen = useSelector(
40
        (state: RootState) => state.trackingTool.toggleablesOpen
41
    )
42
43 c0b4ee98 Vaclav Honzik
    const userLoggedIn = useSelector(
44
        (state: RootState) => state.user.isLoggedIn
45
    )
46 558a15d4 Vaclav Honzik
    const trackingToolPermission = useSelector((state: RootState) => state.user.roles.includes('READ'))
47 80d68e29 Vaclav Honzik
    const navigate = useNavigate()
48
    useEffect(() => {
49 558a15d4 Vaclav Honzik
        if (!userLoggedIn || !trackingToolPermission) {
50 80d68e29 Vaclav Honzik
            navigate('/')
51
        }
52 558a15d4 Vaclav Honzik
    }, [userLoggedIn, navigate, trackingToolPermission])
53 80d68e29 Vaclav Honzik
54 11fca75a Vaclav Honzik
    // Consume any error
55 48690561 Vaclav Honzik
    const dispatch = useDispatch()
56 11fca75a Vaclav Honzik
    const err = useSelector((state: RootState) => state.trackingTool.lastError)
57
    useEffect(() => {
58
        if (!err) {
59
            return
60
        }
61
        const error = `${err}`
62
        dispatch(consumeError())
63
        dispatch(
64
            showNotification({
65
                message: error,
66 a7ae217f Vaclav Honzik
                severity: 'error',
67 11fca75a Vaclav Honzik
            })
68
        )
69
    }, [err, dispatch])
70 dd270a41 Vaclav Honzik
71 c0b4ee98 Vaclav Honzik
    const [showClearPathDialog, setShowClearPathDialog] = useState(false)
72
73 11fca75a Vaclav Honzik
    return (
74
        <Fragment>
75
            <Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
76
                Tracking Tool
77 788ce11e Vaclav Honzik
            </Typography>
78
79 11fca75a Vaclav Honzik
            <Grid container>
80 582489ce Vaclav Honzik
                <Grid item xs={12} alignItems="center">
81 11fca75a Vaclav Honzik
                    {pathDto && pathDto?.foundCatalogItems?.length === 0 && (
82
                        <Typography
83
                            variant="body1"
84
                            sx={{ mb: 2 }}
85
                            fontWeight="500"
86
                            align="center"
87
                            color="error.main"
88
                        >
89 582489ce Vaclav Honzik
                            Looks like no path / catalog items match the
90
                            uploaded text.
91 11fca75a Vaclav Honzik
                        </Typography>
92
                    )}
93 582489ce Vaclav Honzik
94
                    {!pathDto && (
95
                        <Fragment>
96
                            <Stack
97
                                direction="row"
98
                                alignItems="center"
99
                                spacing={1}
100
                                sx={{ my: 1 }}
101
                            >
102
                                <Typography variant="h6" fontWeight="500">
103 a7ae217f Vaclav Honzik
                                    Upload:
104
                                </Typography>
105 582489ce Vaclav Honzik
                                <Fragment>
106
                                    <PlaintextUpload />
107
                                    <FileUpload />
108
                                </Fragment>
109
                            </Stack>
110
                        </Fragment>
111
                    )}
112
                    {path && (
113
                        <Grid
114
                            container
115
                            direction="row"
116
                            sx={{ my: 1 }}
117
                            spacing={1}
118
                            // justifyContent="space-between"
119
                        >
120
                            <Grid
121
                                container
122
                                item
123 cba453f2 Vaclav Honzik
                                xs={12}
124 582489ce Vaclav Honzik
                                md={6}
125
                                direction="row"
126
                                spacing={1}
127
                            >
128
                                <Grid item>
129
                                    <Button
130
                                        startIcon={
131
                                            toggleablesOpen ? (
132
                                                <FilterListOffIcon />
133
                                            ) : (
134
                                                <FilterListIcon />
135
                                            )
136
                                        }
137
                                        variant="contained"
138
                                        color="primary"
139
                                        onClick={() => {
140
                                            dispatch(toggleToggleables())
141
                                        }}
142
                                    >
143
                                        Filter
144
                                    </Button>
145
                                </Grid>
146
                                <Grid item>
147
                                    <Button
148
                                        startIcon={<ClearIcon />}
149
                                        variant="contained"
150
                                        onClick={() => {
151 c0b4ee98 Vaclav Honzik
                                            setShowClearPathDialog(true)
152 582489ce Vaclav Honzik
                                        }}
153
                                    >
154
                                        Clear Map
155
                                    </Button>
156 c0b4ee98 Vaclav Honzik
                                    <ConfirmationDialog
157
                                        open={showClearPathDialog}
158
                                        setOpen={setShowClearPathDialog}
159 61199638 Vaclav Honzik
                                        onConfirmCallback={() => {
160
                                            dispatch(clearTrackingTool())
161
                                        }}
162 c0b4ee98 Vaclav Honzik
                                        title="Clear Map"
163
                                        secondaryText="Are you sure you want to clear the map? All data will be discarded."
164
                                        maxWidth="xs"
165
                                    />
166 582489ce Vaclav Honzik
                                </Grid>
167
                            </Grid>
168
                            <Grid
169
                                item
170
                                container
171
                                md={6}
172 cba453f2 Vaclav Honzik
                                xs={12}
173 582489ce Vaclav Honzik
                                direction="row"
174
                                spacing={1}
175 cba453f2 Vaclav Honzik
                                justifyContent="flex-end"
176 582489ce Vaclav Honzik
                            >
177 61199638 Vaclav Honzik
                                <Grid item>
178
                                    <ManageFilePaths />
179
                                </Grid>
180 582489ce Vaclav Honzik
                                <Grid item>
181
                                    <ExternalPathImportDialog />
182
                                </Grid>
183
                                <Grid item>
184
                                    <ExternalPathExportButton />
185
                                </Grid>
186 c0b4ee98 Vaclav Honzik
                                <Grid item>
187
                                    <SaveDisplayedPath />
188
                                </Grid>
189 582489ce Vaclav Honzik
                            </Grid>
190
                        </Grid>
191
                    )}
192 11fca75a Vaclav Honzik
193
                    {pathDto && (
194 26f9c9ff Vaclav Honzik
                        <Fragment>
195
                            <MapPointToggleables />
196
                        </Fragment>
197 11fca75a Vaclav Honzik
                    )}
198
                </Grid>
199 dda6e56e Vaclav Honzik
200 11fca75a Vaclav Honzik
                <Grid
201
                    item
202
                    xs={12}
203
                    md={12}
204
                    style={{
205 a7ae217f Vaclav Honzik
                        minHeight: '60vh',
206
                        maxHeight: '100vh',
207
                        width: '100%',
208 11fca75a Vaclav Honzik
                    }}
209
                >
210 48690561 Vaclav Honzik
                    <Map />
211 812b9f90 Vaclav Honzik
                </Grid>
212
                <Grid container sx={{ mt: 1, mb: 20 }} spacing={1}>
213 e3fecb14 Vaclav Honzik
                    <Grid item xs={12} md={6} lg={8}>
214 812b9f90 Vaclav Honzik
                        <ProcessedTextDisplay />
215
                    </Grid>
216 e3fecb14 Vaclav Honzik
                    <Grid item xs={12} md={6} lg={4}>
217
                        <ReorderableMapPointList />
218
                    </Grid>
219 11fca75a Vaclav Honzik
                </Grid>
220
            </Grid>
221
        </Fragment>
222
    )
223 788ce11e Vaclav Honzik
}
224
225
export default TrackingTool