@@ -23,12 +23,15 @@ import {
2323import {
2424 selectAircraftType ,
2525 // Selectors
26+ selectColorIndex ,
2627 selectLogType ,
2728 selectMessageFilters ,
29+ selectPersistentColorMap ,
2830 setCanSavePreset ,
2931 setColorIndex ,
3032 setCustomColors ,
3133 setMessageFilters ,
34+ setPersistentColorMapEntry ,
3235} from "../../redux/slices/logAnalyserSlice.js"
3336
3437// Utility function to convert a string to title case
@@ -42,8 +45,10 @@ export default function PresetAccordionItem({ category, deleteCustomPreset }) {
4245 // Redux
4346 const dispatch = useDispatch ( )
4447 const aircraftType = useSelector ( selectAircraftType )
48+ const colorIndex = useSelector ( selectColorIndex )
4549 const logType = useSelector ( selectLogType )
4650 const messageFilters = useSelector ( selectMessageFilters )
51+ const persistentColorMap = useSelector ( selectPersistentColorMap )
4752
4853 // Preset selection
4954 function selectPreset ( preset ) {
@@ -60,7 +65,11 @@ export default function PresetAccordionItem({ category, deleteCustomPreset }) {
6065 newFilters [ categoryName ] [ fieldName ] = false
6166 } )
6267 } )
63- let newColors = { }
68+ // Use preset's custom colors if available, otherwise initialize empty
69+ let newColors = preset . customColors
70+ ? structuredClone ( preset . customColors )
71+ : { }
72+ let nextColorIndex = colorIndex
6473
6574 // Turn on filters for the given preset
6675 Object . keys ( preset . filters ) . forEach ( ( requestedName ) => {
@@ -78,10 +87,26 @@ export default function PresetAccordionItem({ category, deleteCustomPreset }) {
7887 }
7988 newFilters [ actualMessageName ] [ field ] = true
8089
81- // Assign a color using the actual message name
82- if ( ! newColors [ `${ actualMessageName } /${ field } ` ] ) {
83- newColors [ `${ actualMessageName } /${ field } ` ] =
84- colorPalette [ Object . keys ( newColors ) . length % colorPalette . length ]
90+ // Assign a color
91+ const fieldKey = `${ actualMessageName } /${ field } `
92+ // First priority: use color from preset if it exists
93+ if ( ! newColors [ fieldKey ] ) {
94+ // Second priority: use color from persistent map if it exists
95+ if ( persistentColorMap [ fieldKey ] ) {
96+ newColors [ fieldKey ] = persistentColorMap [ fieldKey ]
97+ } else {
98+ // Fall back to palette color
99+ const assignedColor =
100+ colorPalette [ nextColorIndex % colorPalette . length ]
101+ newColors [ fieldKey ] = assignedColor
102+ nextColorIndex = ( nextColorIndex + 1 ) % colorPalette . length
103+ dispatch (
104+ setPersistentColorMapEntry ( {
105+ key : fieldKey ,
106+ color : assignedColor ,
107+ } ) ,
108+ )
109+ }
85110 }
86111 } )
87112 } else {
@@ -91,7 +116,7 @@ export default function PresetAccordionItem({ category, deleteCustomPreset }) {
91116 }
92117 } )
93118
94- dispatch ( setColorIndex ( Object . keys ( newColors ) . length % colorPalette . length ) ) // limited by palette length
119+ dispatch ( setColorIndex ( nextColorIndex ) ) // limited by palette length
95120 dispatch ( setCustomColors ( newColors ) )
96121 dispatch ( setMessageFilters ( newFilters ) )
97122 // Don't allow saving if we just selected an existing preset
0 commit comments