Skip to content

Commit 16ea8c8

Browse files
committed
Fixup: Complete type guards and improve type safety in config-subtree component
Adds type guards for _source and _description properties to prevent runtime crashes when accessing metadata on non-leaf config nodes. Also removes unused parameters and adds explicit TypeScript type annotations for better type safety.
1 parent 715dd51 commit 16ea8c8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/apps/esm-implementer-tools-app/src/configuration/interactive-editor/config-subtree.component.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ export interface ConfigSubtreeProps {
1010
}
1111

1212
export function ConfigSubtree({ config, path = [] }: ConfigSubtreeProps) {
13-
function setActiveItemDescriptionOnMouseEnter(thisPath, key, value) {
13+
function setActiveItemDescriptionOnMouseEnter(thisPath: Array<string>, value: any) {
1414
if (!implementerToolsStore.getState().configPathBeingEdited) {
1515
const isLeaf = value && typeof value === 'object' && Object.hasOwn(value, '_value');
1616
implementerToolsStore.setState({
1717
activeItemDescription: {
1818
path: thisPath,
19-
source: value._source,
20-
description: value._description,
19+
source: isLeaf ? value._source : undefined,
20+
description: isLeaf ? value._description : undefined,
2121
value: isLeaf ? JSON.stringify(value._value) : undefined,
2222
},
2323
});
2424
}
2525
}
2626

27-
function removeActiveItemDescriptionOnMouseLeave(thisPath) {
27+
function removeActiveItemDescriptionOnMouseLeave(thisPath: Array<string>) {
2828
const state = implementerToolsStore.getState();
2929
if (isEqual(state.activeItemDescription?.path, thisPath) && !isEqual(state.configPathBeingEdited, thisPath)) {
3030
implementerToolsStore.setState({ activeItemDescription: undefined });
@@ -35,14 +35,14 @@ export function ConfigSubtree({ config, path = [] }: ConfigSubtreeProps) {
3535
<>
3636
{Object.entries(config)
3737
.filter(([key]) => !key.startsWith('_'))
38-
.map(([key, value], i) => {
38+
.map(([key, value]) => {
3939
const thisPath = path.concat([key]);
4040
const isLeaf = value && typeof value === 'object' && Object.hasOwn(value, '_value');
4141
return (
4242
<Subtree
4343
label={key}
4444
leaf={isLeaf}
45-
onMouseEnter={() => setActiveItemDescriptionOnMouseEnter(thisPath, key, value)}
45+
onMouseEnter={() => setActiveItemDescriptionOnMouseEnter(thisPath, value)}
4646
onMouseLeave={() => removeActiveItemDescriptionOnMouseLeave(thisPath)}
4747
key={`subtree-${thisPath.join('.')}`}
4848
>

0 commit comments

Comments
 (0)