| 230 | } |
| 231 | |
| 232 | const groupByVariableLabel = (variables) => { |
| 233 | const newVariables = [] |
| 234 | const seenVariables = new Set() |
| 235 | |
| 236 | variables.forEach((item) => { |
| 237 | const { id, name, type } = item |
| 238 | seenVariables.add(id) |
| 239 | |
| 240 | const param = { id, name, type } |
| 241 | |
| 242 | // If overrideConfigStatus is true, look for existing variable config |
| 243 | // Otherwise, create new default config |
| 244 | if (overrideConfigStatus) { |
| 245 | const existingVariable = variableOverrides?.find((existingParam) => existingParam.id === id) |
| 246 | if (existingVariable) { |
| 247 | if (!newVariables.some((variable) => variable.id === id)) { |
| 248 | newVariables.push({ ...existingVariable }) |
| 249 | } |
| 250 | } else { |
| 251 | if (!newVariables.some((variable) => variable.id === id)) { |
| 252 | newVariables.push({ ...param, enabled: false }) |
| 253 | } |
| 254 | } |
| 255 | } else { |
| 256 | // When no override config exists, create default values |
| 257 | if (!newVariables.some((variable) => variable.id === id)) { |
| 258 | newVariables.push({ ...param, enabled: false }) |
| 259 | } |
| 260 | } |
| 261 | }) |
| 262 | |
| 263 | // If overrideConfigStatus is true, clean up any variables that no longer exist |
| 264 | if (overrideConfigStatus && variableOverrides) { |
| 265 | variableOverrides.forEach((existingVariable) => { |
| 266 | if (!seenVariables.has(existingVariable.id)) { |
| 267 | const index = newVariables.findIndex((newVariable) => newVariable.id === existingVariable.id) |
| 268 | if (index !== -1) { |
| 269 | newVariables.splice(index, 1) |
| 270 | } |
| 271 | } |
| 272 | }) |
| 273 | } |
| 274 | |
| 275 | setVariableOverrides(newVariables) |
| 276 | } |
| 277 | |
| 278 | const handleAccordionChange = (nodeLabel) => (event, isExpanded) => { |
| 279 | const accordianNodes = { ...nodeConfigExpanded } |