Skip to content

Commit

Permalink
Displaying MAPs is working
Browse files Browse the repository at this point in the history
  • Loading branch information
iyourshaw committed Feb 13, 2025
1 parent 236ec57 commit 0a2d30a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
34 changes: 33 additions & 1 deletion webapp/src/features/intersections/decoder/pcap-decoder-slice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
selectSourceDataType,
setDecoderModeEnabled,
setMapProps,
handleNewMapMessageData
} from '../map/map-slice'

const initialState = {
Expand All @@ -32,7 +33,8 @@ const initialState = {
srmCount: 0,
unknownCount: 0
},
uniqueMaps: [] as ProcessedMap[]
uniqueMaps: [] as ProcessedMap[],
selectedMap: {} as ProcessedMap,
}


Expand Down Expand Up @@ -120,6 +122,25 @@ export const pcapDecoderModeToggled = createAsyncThunk(
}
)

export const updateMap = createAsyncThunk(
'pcapDecoder/updateMap',
async(_, { getState, dispatch }) => {
console.log("updateMap")

const selectedMap = selectSelectedMap(getState() as RootState)
const initialSourceDataType = selectInitialSourceDataType(getState() as RootState)
const intersectionId = selectedMap?.properties?.intersectionId
const roadRegulatorId = selectedMap?.properties?.region
const loadOnNull = selectLoadOnNull(getState() as RootState)
dispatch(handleNewMapMessageData({
mapData: selectedMap,
connectingLanes: selectedMap.connectingLanesFeatureCollection,
mapSignalGroups: {} as SignalStateFeatureCollection,
mapTime: Date.now()
}))
}
)

export const pcapDecoderSlice = createSlice({
name: 'pcapDecoder',
initialState: {
Expand All @@ -130,6 +151,15 @@ export const pcapDecoderSlice = createSlice({
setPcapDecoderDialogOpen: (state, action: PayloadAction<boolean>) => {
console.log("setPcapDecoderDialogOpen: " + action.payload)
state.value.dialogOpen = action.payload
},
onMapSelected: (state, action: PayloadAction<any>) => {
const intersectionId = action.payload
console.log("onMapSelected " + intersectionId)
state.value.selectedMap = state.value.uniqueMaps.find(function(aMap) {
return aMap.properties.intersectionId == intersectionId
})
console.log("selectedMap: ")
console.log(state.value.selectedMap)
}
},
extraReducers: (builder) => {
Expand Down Expand Up @@ -176,6 +206,7 @@ export const pcapDecoderSlice = createSlice({

export const {
setPcapDecoderDialogOpen,
onMapSelected,
} = pcapDecoderSlice.actions


Expand All @@ -184,5 +215,6 @@ export const selectPcapDataStats = (state: RootState) => state.pcapDecoder.value
export const selectDecodedJsonData = (state: RootState) => state.pcapDecoder.value.decodedJsonData
export const selectDialogOpen = (state: RootState) => state.pcapDecoder.value.dialogOpen
export const selectUniqueMaps = (state: RootState) => state.pcapDecoder.value.uniqueMaps
export const selectSelectedMap = (state: RootState) => state.pcapDecoder.value.selectedMap

export default pcapDecoderSlice.reducer
10 changes: 7 additions & 3 deletions webapp/src/features/intersections/decoder/pcap-tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import {
selectPcapDataStats,
selectDecodedJsonData,
selectUniqueMaps,
onMapSelected
} from './pcap-decoder-slice'
import { ThunkDispatch, AnyAction } from '@reduxjs/toolkit'
import { RootState } from '../../../store'

export const PcapTables = () => {
const dispatch: ThunkDispatch<RootState, void, AnyAction> = useDispatch()



const pcapData = useSelector(selectPcapData)
const pcapDataStats = useSelector(selectPcapDataStats)
const decodedJsonData = useSelector(selectDecodedJsonData)
Expand Down Expand Up @@ -80,8 +83,9 @@ export const PcapTables = () => {
element.click()
}

const handleCheckboxChange = (intersectionId) => {
console.log("Checkbox changed for intersection " + intersectionId);
const showMapButtonClick = (intersectionId) => {
console.log("Show map button click for intersection " + intersectionId);
dispatch(onMapSelected(intersectionId))
}


Expand Down Expand Up @@ -168,7 +172,7 @@ export const PcapTables = () => {
<TableCell>
<Button size="small"
variant="contained"
onClick={() => handleCheckboxChange(mapMsg?.properties?.intersectionId)}
onClick={() => showMapButtonClick(mapMsg?.properties?.intersectionId)}
>Show</Button>
</TableCell>
<TableCell>{mapMsg?.properties?.intersectionId}</TableCell>
Expand Down
12 changes: 10 additions & 2 deletions webapp/src/features/intersections/decoder/pcap-upload-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import { PcapTables } from './pcap-tables'
import {
setPcapDecoderDialogOpen,
selectDialogOpen,
updateMap,
selectSelectedMap,
} from './pcap-decoder-slice'
import { useDispatch, useSelector } from 'react-redux'
import { AnyAction, ThunkDispatch } from '@reduxjs/toolkit'
import { RootState } from '../../../store'
import { selectDecoderModeEnabled } from '../map/map-slice'
import {
selectDecoderModeEnabled,
} from '../map/map-slice'

const PcapUploadDialog = () => {
console.log("PcapUploadDialog")
const dispatch: ThunkDispatch<RootState, void, AnyAction> = useDispatch()

const open = useSelector(selectDialogOpen)
const decoderModeEnabled = useSelector(selectDecoderModeEnabled)
const selectedMap = useSelector(selectSelectedMap)

const handleClose = () => {
dispatch(setPcapDecoderDialogOpen(false))
Expand All @@ -34,7 +39,10 @@ const PcapUploadDialog = () => {
}
}, [decoderModeEnabled])


useEffect(() => {
console.log("useEffect.selectedMap")
dispatch(updateMap())
}, [selectedMap])

return (
<>
Expand Down

0 comments on commit 0a2d30a

Please sign in to comment.