Skip to content

Commit 8c9cbc0

Browse files
authored
Merge pull request #6341 from ethereum/hide-tab
Support Hidden Tabs
2 parents 1f20a98 + f774787 commit 8c9cbc0

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

apps/remix-ide/src/app/panels/tab-proxy.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ export default class TabProxy extends Plugin {
186186
this.call('manager', 'deactivatePlugin', name)
187187
},
188188
icon,
189-
description
189+
description,
190+
show
190191
)
191192
show && this.switchTab(name)
192193
}
@@ -210,6 +211,10 @@ export default class TabProxy extends Plugin {
210211

211212
focus (name) {
212213
this.emit('switchApp', name)
214+
const tabIndex = this.loadedTabs.findIndex(tab => tab.name === name)
215+
if (tabIndex !== -1) {
216+
this.loadedTabs[tabIndex].show = true
217+
}
213218
this.tabsApi.activateTab(name)
214219
}
215220

@@ -259,7 +264,7 @@ export default class TabProxy extends Plugin {
259264
* @param {string} description
260265
* @returns
261266
*/
262-
addTab (name, title, switchTo, close, icon, description = '') {
267+
addTab (name, title, switchTo, close, icon, description = '', show = true) {
263268
if (this._handlers[name]) return this.renderComponent()
264269

265270
if ((name.endsWith('.vy') && icon === undefined) || title.includes('Vyper')) {
@@ -290,7 +295,8 @@ export default class TabProxy extends Plugin {
290295
title,
291296
icon,
292297
tooltip: name,
293-
iconClass: getPathIcon(name)
298+
iconClass: getPathIcon(name),
299+
show
294300
})
295301
formatPath.shift()
296302
if (formatPath.length > 0) {
@@ -307,7 +313,8 @@ export default class TabProxy extends Plugin {
307313
title: duplicateTabTitle,
308314
icon,
309315
tooltip: duplicateTabTooltip || duplicateTabTitle,
310-
iconClass: getPathIcon(duplicateTabName)
316+
iconClass: getPathIcon(duplicateTabName),
317+
show
311318
}
312319
}
313320
}
@@ -321,7 +328,8 @@ export default class TabProxy extends Plugin {
321328
title,
322329
icon,
323330
tooltip: description || title,
324-
iconClass: getPathIcon(name)
331+
iconClass: getPathIcon(name),
332+
show
325333
})
326334
}
327335

@@ -335,17 +343,29 @@ export default class TabProxy extends Plugin {
335343
if(!this.loadedTabs.find(tab => tab.name === name)) return // prevent removing tab that doesn't exist
336344
this.loadedTabs = this.loadedTabs.filter((tab, index) => {
337345
if (!previous && tab.name === name) {
338-
if(index - 1 >= 0 && this.loadedTabs[index - 1])
339-
previous = this.loadedTabs[index - 1]
340-
else if (index + 1 && this.loadedTabs[index + 1])
341-
previous = this.loadedTabs[index + 1]
346+
previous = this.getPreviousVisibleTab(index)
347+
if (!previous) previous = this.getNextVisibleTab(index)
342348
}
343349
return tab.name !== name
344350
})
345351
this.renderComponent()
346352
if (previous) this.switchTab(previous.name)
347353
}
348354

355+
getPreviousVisibleTab (index) {
356+
for (let i = index - 1; i >= 0; i--) {
357+
if (this.loadedTabs[i].show) return this.loadedTabs[i]
358+
}
359+
return null
360+
}
361+
362+
getNextVisibleTab (index) {
363+
for (let i = index + 1; i < this.loadedTabs.length; i++) {
364+
if (this.loadedTabs[i].show) return this.loadedTabs[i]
365+
}
366+
return null
367+
}
368+
349369
addHandler (type, fn) {
350370
this.handlers[type] = fn
351371
}

libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface Tab {
3434
name: string
3535
title: string
3636
tooltip: string
37+
show: boolean
3738
}
3839
export interface TabsUIApi {
3940
activateTab: (name: string) => void
@@ -95,7 +96,7 @@ export const TabsUI = (props: TabsUIProps) => {
9596
const [compileState, setCompileState] = useState<'idle' | 'compiling' | 'compiled'>('idle')
9697

9798
useEffect(() => {
98-
if (props.tabs[tabsState.selectedIndex]) {
99+
if (props.tabs[tabsState.selectedIndex] && props.tabs[tabsState.selectedIndex].show) {
99100
tabsRef.current[tabsState.selectedIndex].scrollIntoView({
100101
behavior: 'smooth',
101102
block: 'center'
@@ -614,14 +615,14 @@ export const TabsUI = (props: TabsUIProps) => {
614615
>
615616
<TabList className="d-flex flex-row align-items-center">
616617
{props.tabs.map((tab, i) => (
617-
<Tab className="" key={tab.name} data-id={tab.id}>
618+
<Tab className={tab.show ? '' : 'd-none'} key={tab.name} data-id={tab.id}>
618619
{renderTab(tab, i)}
619620
</Tab>
620621
))}
621622
<div style={{ minWidth: '4rem', height: '1rem' }} id="dummyElForLastXVisibility"></div>
622623
</TabList>
623624
{props.tabs.map((tab) => (
624-
<TabPanel key={tab.name}></TabPanel>
625+
<TabPanel className={tab.show ? '' : 'd-none'} key={tab.name}></TabPanel>
625626
))}
626627
</Tabs>
627628

0 commit comments

Comments
 (0)