Skip to content

Commit 2ba72b4

Browse files
committed
fix: derive AWT action at render time without mutating shared groups array
1 parent f60f146 commit 2ba72b4

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/welcome/assets/components/NavigationPanel.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import * as _ from "lodash";
54
import { useState, useRef } from "react";
65
import { reportTabSwitch, WEBVIEW_ID } from "../utils";
76
import { encodeCommandUriWithTelemetry } from "../../../utils/webview";
@@ -48,15 +47,20 @@ export default function NavigationPanel({ isAwtDisabled }: NavigationPanelProps)
4847
const [activeTab, setActiveTab] = useState(groups[0].name);
4948
const prevTabRef = useRef(groups[0].name);
5049

51-
const studentSection = _.find(groups, { name: "Student" });
52-
if (studentSection) {
53-
for (const action of studentSection.actions) {
54-
if (action.command === "java.toggleAwtDevelopment") {
55-
action.name = `${isAwtDisabled ? "Enable" : "Disable"} AWT Development`;
56-
action.args = [isAwtDisabled];
57-
}
58-
}
59-
}
50+
const resolvedGroups = groups.map(group => {
51+
if (group.name !== "Student") return group;
52+
return {
53+
...group,
54+
actions: group.actions.map(action => {
55+
if (action.command !== "java.toggleAwtDevelopment") return action;
56+
return {
57+
...action,
58+
name: `${isAwtDisabled ? "Enable" : "Disable"} AWT Development`,
59+
args: [isAwtDisabled],
60+
};
61+
}),
62+
};
63+
});
6064

6165
const onSwitchTab = (newTab: string) => {
6266
reportTabSwitch(prevTabRef.current, newTab);
@@ -67,7 +71,7 @@ export default function NavigationPanel({ isAwtDisabled }: NavigationPanelProps)
6771
return (
6872
<div id="navigationPanel">
6973
<ul className="nav-tabs" role="tablist">
70-
{groups.map(group => (
74+
{resolvedGroups.map(group => (
7175
<li key={group.name} className="navigation-tab">
7276
<button
7377
role="tab"
@@ -82,7 +86,7 @@ export default function NavigationPanel({ isAwtDisabled }: NavigationPanelProps)
8286
</li>
8387
))}
8488
</ul>
85-
{groups.map(group => (
89+
{resolvedGroups.map(group => (
8690
activeTab === group.name && (
8791
<div key={group.name} className="navigation-tabcontent" role="tabpanel">
8892
<div className="list-group">

0 commit comments

Comments
 (0)