Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 26f9c9ff

Přidáno uživatelem Václav Honzík před téměř 3 roky(ů)

toggles for specific map points

re #9741

Zobrazit rozdíly:

frontend/src/features/TrackingTool/Import/AddFromCoordinatesDialog.tsx
7 7
    Paper,
8 8
    Stack,
9 9
    TextField,
10
    Typography,
11 10
} from '@mui/material'
12 11
import { Fragment, FunctionComponent, useState } from 'react'
13 12
import ButtonOpenableDialog from '../../Reusables/ButtonOpenableDialog'
frontend/src/features/TrackingTool/Import/MapPointToggleables.tsx
1
import { Checkbox, FormControlLabel, Stack, Typography } from '@mui/material'
2
import { useEffect, useState } from 'react'
3
import { useDispatch, useSelector } from 'react-redux'
4
import { RootState } from '../../redux/store'
5
import { updatePrimaryPath } from '../trackingToolSlice'
6
import { MapPointType, PathVariant } from '../trackingToolUtils'
7

  
8
const MapPointToggleables = () => {
9
    const dispatch = useDispatch()
10
    const paths = useSelector(
11
        (state: RootState) => state.trackingTool.pathVariants
12
    )
13
    const [path, setPath] = useState<PathVariant>([])
14
    const primaryPathIdx = useSelector(
15
        (state: RootState) => state.trackingTool.primaryPathIdx
16
    )
17
    useEffect(() => {
18
        setPath(
19
            paths && paths.length > primaryPathIdx ? paths[primaryPathIdx] : []
20
        )
21
    }, [paths, primaryPathIdx])
22

  
23
    const [enableMap, setEnableMap] = useState({
24
        [MapPointType.LocalCatalog]: true,
25
        [MapPointType.FromCoordinates]: true,
26
        [MapPointType.GeoJson]: true,
27
        [MapPointType.ExternalCatalog]: true,
28
    })
29

  
30
    // Disables specific feature
31
    const toggleFeature = (feature: MapPointType) => {
32
        setEnableMap({ ...enableMap, [feature]: !enableMap[feature] })
33
        const newPath = path.map((point) => {
34
            if (point.type === feature) {
35
                return {
36
                    ...point,
37
                    hidden: enableMap[point.type],
38
                    addToPath: !enableMap[point.type] ? true : point.addToPath,
39
                }
40
            }
41

  
42
            return point
43
        })
44
        dispatch(updatePrimaryPath(newPath))
45
    }
46

  
47
    return (
48
        <Stack direction="column">
49
            <Stack direction="row" justifyItems="space-between">
50
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
51
                    From file
52
                </Typography>
53
                <FormControlLabel
54
                    control={
55
                        <Checkbox
56
                            checked={enableMap[MapPointType.GeoJson]}
57
                            onChange={() => toggleFeature(MapPointType.GeoJson)}
58
                        />
59
                    }
60
                    label="Show All"
61
                />
62
            </Stack>
63
            <Stack direction="row" justifyItems="space-between">
64
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
65
                    From local catalog
66
                </Typography>
67
                <FormControlLabel
68
                    control={
69
                        <Checkbox
70
                            checked={enableMap[MapPointType.LocalCatalog]}
71
                            onChange={() =>
72
                                toggleFeature(MapPointType.LocalCatalog)
73
                            }
74
                        />
75
                    }
76
                    label="Show All"
77
                />
78
            </Stack>
79
            <Stack direction="row" justifyItems="space-between">
80
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
81
                    From coordinates
82
                </Typography>
83
                <FormControlLabel
84
                    control={
85
                        <Checkbox
86
                            checked={enableMap[MapPointType.FromCoordinates]}
87
                            onChange={() =>
88
                                toggleFeature(MapPointType.FromCoordinates)
89
                            }
90
                        />
91
                    }
92
                    label="Show All"
93
                />
94
            </Stack>
95
            <Stack direction="row" justifyItems="space-between">
96
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
97
                    From external catalog
98
                </Typography>
99
                <FormControlLabel
100
                    control={
101
                        <Checkbox
102
                            checked={enableMap[MapPointType.ExternalCatalog]}
103
                            onChange={() =>
104
                                toggleFeature(MapPointType.ExternalCatalog)
105
                            }
106
                        />
107
                    }
108
                    label="Show All"
109
                />
110
            </Stack>
111
        </Stack>
112
    )
113
}
114

  
115
export default MapPointToggleables
frontend/src/features/TrackingTool/MapPointDraggableList/MapPointDraggableListItem.tsx
6 6
    Typography,
7 7
} from '@mui/material'
8 8
import { Draggable } from 'react-beautiful-dnd'
9
import { getMapPointSemanticColor as getMapPointSemanticColor, MapPoint, MapPointType, PathVariant } from '../trackingToolUtils'
9
import {
10
    getMapPointSemanticColor,
11
    MapPointType,
12
    PathVariant,
13
} from '../trackingToolUtils'
10 14
import { CatalogItemDto } from '../../../swagger/data-contracts'
11 15
import { useDispatch } from 'react-redux'
12 16
import { removeMapMarker, updateMapMarker } from '../trackingToolSlice'
......
101 105
                            <ListItemText
102 106
                                primary={
103 107
                                    <Typography
104
                                        style={{ color: getMapPointSemanticColor(item) }}
108
                                        style={{
109
                                            color: getMapPointSemanticColor(
110
                                                item
111
                                            ),
112
                                        }}
105 113
                                    >
106 114
                                        {item.catalogItem.name ??
107 115
                                            'Unknown name'}
frontend/src/features/TrackingTool/TrackingTool.tsx
27 27
import RightClickPopupMenu from './Import/ImportContextMenu'
28 28
import { buildTheme, getPalette } from '../Theme/ThemeWrapper'
29 29
import AttachFileIcon from '@mui/icons-material/AttachFile'
30
import MapPointToggleables from './Import/MapPointToggleables'
30 31

  
31 32
const mapTheme = buildTheme('light')
32 33

  
......
121 122
                    </Stack>
122 123

  
123 124
                    {pathDto && (
125
                        <Fragment>
126
                            <MapPointToggleables />
124 127
                        <Stack alignItems="flex-end">
125 128
                            <Button
126 129
                                startIcon={<ClearIcon />}
......
131 134
                                Clear Map
132 135
                            </Button>
133 136
                        </Stack>
137
                        </Fragment>
134 138
                    )}
135 139
                </Grid>
136 140

  
frontend/src/features/TrackingTool/trackingToolSlice.ts
3 3
import mapConfig from "../../config/mapConfig"
4 4
import { PathDto } from "../../swagger/data-contracts"
5 5
import buildPathVariants from "./Map/pathUtils"
6
import  { isMapPointDisplayable, MapPoint, PathVariant } from "./trackingToolUtils"
6
import { isMapPointDisplayable, MapPoint, PathVariant } from "./trackingToolUtils"
7 7
import { sendTextForProcessing } from "./trackingToolThunks"
8 8
import storage from "redux-persist/lib/storage"
9 9
import TrackingToolState from './trackingToolState'
......
61 61
            ...state,
62 62
            currentPage: action.payload,
63 63
        }),
64
        updatePrimaryPath: (state: TrackingToolState, action: { payload: PathVariant }) => {
65
            const { primaryPathIdx } = state
66
            const path = action.payload
67
            const paths = [...state.pathVariants ?? []]
68

  
69
            if (paths.length <= primaryPathIdx) {
70
                return { ...state }
71
            }
72

  
73
            return {
74
                ...state,
75
                pathVariants: [
76
                    ...paths.slice(0, primaryPathIdx),
77
                    path,
78
                    ...paths.slice(primaryPathIdx + 1),
79
                ],
80
            }
81
        },
64 82
        // Updates map marker while ignoring its idx property
65 83
        updateMapMarkerWithId: (state: TrackingToolState, action: { payload: { id: string, item: MapPoint } }) => {
66 84
            const { item } = action.payload
67
            const idx = state.primaryPathIdx
68
            if (!state.pathVariants || state.pathVariants.length <= idx) {
85
            const { primaryPathIdx } = state
86
            if (!state.pathVariants || state.pathVariants.length <= primaryPathIdx) {
69 87
                return state
70 88
            }
71 89

  
72
            const mapMarkerIdx = state.pathVariants[idx].findIndex((item) => item.id === action.payload.id)
90
            const mapMarkerIdx = state.pathVariants[primaryPathIdx].findIndex((item) => item.id === action.payload.id)
73 91
            if (mapMarkerIdx === -1) {
74 92
                return state
75 93
            }
76 94

  
77
            const newPathVariant = [...state.pathVariants[idx]]
95
            const newPathVariant = [...state.pathVariants[primaryPathIdx]]
78 96
            newPathVariant[mapMarkerIdx] = item
79 97
            return {
80 98
                ...state,
81
                pathVariants: [...state.pathVariants.slice(0, idx), newPathVariant, ...state.pathVariants.slice(idx + 1)],
99
                pathVariants: [...state.pathVariants.slice(0, primaryPathIdx), newPathVariant, ...state.pathVariants.slice(primaryPathIdx + 1)],
82 100
            }
83 101
        },
84 102
        // Updates map marker based on its idx property
85 103
        updateMapMarker: (state: TrackingToolState, action: { payload: MapPoint }) => {
86 104
            const item = action.payload
87
            const idx = state.primaryPathIdx
88
            if (!state.pathVariants || state.pathVariants.length <= idx) {
105
            const { primaryPathIdx } = state
106
            if (!state.pathVariants || state.pathVariants.length <= primaryPathIdx) {
89 107
                return state
90 108
            }
91 109

  
92 110
            return {
93 111
                ...state,
94 112
                pathVariants: state.pathVariants.map((pathVariant, i) => {
95
                    if (i !== idx) {
113
                    if (i !== primaryPathIdx) {
96 114
                        return [...pathVariant]
97 115
                    }
98 116

  
......
256 274
    moveMarkerToDestination,
257 275
    updateMapMarkerWithId,
258 276
    removeMapMarker,
277
    updatePrimaryPath
259 278
} = trackingToolSlice.actions
260 279
const trackingToolReducer = trackingToolSlice.reducer
261 280
export default trackingToolReducer
frontend/src/features/TrackingTool/trackingToolUtils.ts
65 65
    [MapPointType.FromCoordinates]: createMapMarkerSvg('#21972D'),
66 66
}
67 67

  
68
const iconAnchor = [32, 32] as PointExpression
69
const iconSize = [42, 42] as PointExpression
68
const iconAnchor = [25, 25] as PointExpression
69
const iconSize = [40, 40] as PointExpression
70 70

  
71 71
const mapMarkers = {
72 72
    [MapPointType.LocalCatalog]: L.icon({

Také k dispozici: Unified diff