1
|
import {
|
2
|
Checkbox,
|
3
|
Collapse,
|
4
|
FormControlLabel,
|
5
|
Stack,
|
6
|
Typography,
|
7
|
} from '@mui/material'
|
8
|
import { Fragment } from 'react'
|
9
|
import { useDispatch, useSelector } from 'react-redux'
|
10
|
import { RootState } from '../../redux/store'
|
11
|
import { updateToggleables } from '../trackingToolSlice'
|
12
|
import { MapPointType } from '../trackingToolUtils'
|
13
|
|
14
|
// Component which controls what type of map points are enabled and disabled
|
15
|
const MapPointToggleables = () => {
|
16
|
const dispatch = useDispatch()
|
17
|
const open = useSelector(
|
18
|
(state: RootState) => state.trackingTool.toggleablesOpen
|
19
|
)
|
20
|
const toggleables = useSelector(
|
21
|
(state: RootState) => state.trackingTool.toggleables
|
22
|
)
|
23
|
|
24
|
// Disables specific feature
|
25
|
const toggleFeature = (feature: MapPointType) => {
|
26
|
dispatch(
|
27
|
updateToggleables({
|
28
|
...toggleables,
|
29
|
[feature]: !toggleables[feature],
|
30
|
})
|
31
|
)
|
32
|
}
|
33
|
|
34
|
const renderToggle = (
|
35
|
text: string,
|
36
|
checked: boolean,
|
37
|
onChange: () => void
|
38
|
) => (
|
39
|
<Stack direction="row" justifyItems="space-between" alignItems="center">
|
40
|
<Typography align="left" variant="h6" fontSize={18} sx={{ mr: 1 }}>
|
41
|
{text}
|
42
|
</Typography>
|
43
|
<FormControlLabel
|
44
|
control={<Checkbox checked={checked} onChange={onChange} />}
|
45
|
label="Show All"
|
46
|
/>
|
47
|
</Stack>
|
48
|
)
|
49
|
|
50
|
const toggles = [
|
51
|
renderToggle(
|
52
|
'Processed Text',
|
53
|
toggleables[MapPointType.ProcessedText],
|
54
|
() => toggleFeature(MapPointType.ProcessedText)
|
55
|
),
|
56
|
renderToggle('From File', toggleables[MapPointType.FileImport], () =>
|
57
|
toggleFeature(MapPointType.FileImport)
|
58
|
),
|
59
|
renderToggle(
|
60
|
'From Local Catalog',
|
61
|
toggleables[MapPointType.LocalCatalog],
|
62
|
() => toggleFeature(MapPointType.LocalCatalog)
|
63
|
),
|
64
|
renderToggle(
|
65
|
'From Coordinates',
|
66
|
toggleables[MapPointType.FromCoordinates],
|
67
|
() => toggleFeature(MapPointType.FromCoordinates)
|
68
|
),
|
69
|
renderToggle(
|
70
|
'From External Catalog',
|
71
|
toggleables[MapPointType.ExternalCatalog],
|
72
|
() => toggleFeature(MapPointType.ExternalCatalog)
|
73
|
),
|
74
|
]
|
75
|
|
76
|
return (
|
77
|
<Fragment>
|
78
|
<Collapse in={open} timeout="auto" unmountOnExit>
|
79
|
<Stack direction="column">
|
80
|
{toggles}
|
81
|
</Stack>
|
82
|
</Collapse>
|
83
|
</Fragment>
|
84
|
)
|
85
|
}
|
86
|
|
87
|
export default MapPointToggleables
|