Skip to content

Commit 0d57104

Browse files
committed
add a tab back if it is selected but has been closed
1 parent de20cd6 commit 0d57104

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/reactComponents/Tabs.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,42 @@ export function Component(props: TabsProps) {
7373
setActiveKey(key);
7474
}
7575
}
76+
const inTabs = (key: string): boolean => {
77+
props.tabList.forEach(tab => {
78+
if (tab.key === key) {
79+
return true;
80+
}
81+
});
82+
return false;
83+
}
84+
85+
const addTab = (key: string) => {
86+
const newTabs = [...props.tabList];
87+
if (props.project) {
88+
const module = commonStorage.findModuleInProject(props.project, key);
89+
if (module) {
90+
switch (module.moduleType) {
91+
case commonStorage.MODULE_TYPE_MECHANISM:
92+
newTabs.push({ key: key, title: module.className, type: TabType.MECHANISM });
93+
break;
94+
case commonStorage.MODULE_TYPE_OPMODE:
95+
newTabs.push({ key: key, title: module.className, type: TabType.OPMODE });
96+
break;
97+
default:
98+
console.log("Unknown module type", module.moduleType);
99+
break;
100+
}
101+
}
102+
props.setTabList(newTabs);
103+
}
104+
};
105+
76106
React.useEffect(() => {
107+
let found = false;
77108
if (activeKey != props.activeTab) {
109+
if (!inTabs(props.activeTab)) {
110+
addTab(props.activeTab);
111+
}
78112
onChange(props.activeTab);
79113
}
80114
}, [props.activeTab]);

0 commit comments

Comments
 (0)