Skip to content

Commit d90096a

Browse files
committed
fix(3d): apply converter settings to renderer config
Prevent later camera or panel saves from resetting nested converter edits. Provide a settings updater that applies edits through renderer.updateConfig and immediately saves the resulting config to keep both copies in sync. Detect topic changes across both the scene and converter handlers so direct field edits are saved immediately, keeping displayed values in sync with the renderer config.
1 parent 528a474 commit d90096a

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

‎packages/suite-base/src/panels/ThreeDeeRender/ThreeDeeRender.tsx‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
Topic,
2727
} from "@lichtblick/suite";
2828
import { AppSetting } from "@lichtblick/suite-base/AppSetting";
29+
import { TopicSettingsUpdater } from "@lichtblick/suite-base/components/PanelExtensionAdapter/types";
2930
import { useAnalytics } from "@lichtblick/suite-base/context/AnalyticsContext";
3031
import { DEFAULT_SCENE_EXTENSION_CONFIG } from "@lichtblick/suite-base/panels/ThreeDeeRender/SceneExtensionConfig";
3132
import {
@@ -132,6 +133,7 @@ export function ThreeDeeRender(props: Readonly<ThreeDeeRenderProps>): React.JSX.
132133
};
133134
});
134135
const configRef = useLatest(config);
136+
const lastSavedConfig = useRef<Immutable<RendererConfig>>();
135137
const { cameraState } = config;
136138
const backgroundColor = config.scene.backgroundColor;
137139

@@ -358,13 +360,35 @@ export function ThreeDeeRender(props: Readonly<ThreeDeeRenderProps>): React.JSX.
358360

359361
// Rebuild the settings sidebar tree as needed
360362
useEffect(() => {
361-
context.updatePanelSettingsEditor({
362-
actionHandler,
363-
enableFilter: true,
364-
focusedPath: focusedSettingsPath,
365-
nodes: settingsTree ?? {},
366-
});
367-
}, [actionHandler, context, focusedSettingsPath, settingsTree]);
363+
let topicsBeforeAction = renderer?.config.topics;
364+
365+
// Detect direct field edits even when the scene handler applies them first.
366+
const handleSettingsAction = (action: SettingsTreeAction) => {
367+
topicsBeforeAction = renderer?.config.topics;
368+
actionHandler(action);
369+
};
370+
371+
// Save immediately so stale editor values cannot overwrite the latest edits.
372+
const applyConverterSettings: TopicSettingsUpdater = (updateSettings) => {
373+
if (renderer) {
374+
renderer.updateConfig(updateSettings);
375+
if (renderer.config.topics !== topicsBeforeAction) {
376+
saveState(renderer.config);
377+
lastSavedConfig.current = renderer.config;
378+
}
379+
}
380+
};
381+
382+
context.updatePanelSettingsEditor(
383+
{
384+
actionHandler: handleSettingsAction,
385+
enableFilter: true,
386+
focusedPath: focusedSettingsPath,
387+
nodes: settingsTree ?? {},
388+
},
389+
applyConverterSettings,
390+
);
391+
}, [actionHandler, context, focusedSettingsPath, settingsTree, renderer, saveState]);
368392

369393
// Update the renderer's reference to `config` when it changes. Note that this does *not*
370394
// automatically update the settings tree.
@@ -412,7 +436,11 @@ export function ThreeDeeRender(props: Readonly<ThreeDeeRenderProps>): React.JSX.
412436
// Save panel settings whenever they change
413437
const throttledSave = useDebouncedCallback(
414438
(newConfig: Immutable<RendererConfig>) => {
415-
saveState(newConfig);
439+
// Immediate converter saves already persist this config.
440+
if (newConfig !== lastSavedConfig.current) {
441+
saveState(newConfig);
442+
lastSavedConfig.current = newConfig;
443+
}
416444
},
417445
100,
418446
{ leading: false, trailing: true, maxWait: 1000 },

0 commit comments

Comments
 (0)