Refactor tab management in NavigationTabsContext
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
- Simplified the logic for adding new tabs by directly appending the next tab to the current tabs array, improving code readability and maintainability. - Removed unnecessary calculations for determining the insertion index, streamlining the tab addition process.
This commit is contained in:
parent
d16aa373be
commit
2f9f42c9e2
@ -112,17 +112,7 @@ export const NavigationTabsProvider = ({ children }) => {
|
||||
(tab) => tab.id === activeTabIdRef.current
|
||||
)
|
||||
const nextTab = cloneCurrentPageTab(currentTab, location)
|
||||
setTabs((current) => {
|
||||
const activeIndex = current.findIndex(
|
||||
(tab) => tab.id === activeTabIdRef.current
|
||||
)
|
||||
const insertAt = activeIndex === -1 ? current.length : activeIndex + 1
|
||||
return [
|
||||
...current.slice(0, insertAt),
|
||||
nextTab,
|
||||
...current.slice(insertAt)
|
||||
]
|
||||
})
|
||||
setTabs((current) => [...current, nextTab])
|
||||
setActiveTabId(nextTab.id)
|
||||
}, [location])
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user