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
|
(tab) => tab.id === activeTabIdRef.current
|
||||||
)
|
)
|
||||||
const nextTab = cloneCurrentPageTab(currentTab, location)
|
const nextTab = cloneCurrentPageTab(currentTab, location)
|
||||||
setTabs((current) => {
|
setTabs((current) => [...current, nextTab])
|
||||||
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)
|
|
||||||
]
|
|
||||||
})
|
|
||||||
setActiveTabId(nextTab.id)
|
setActiveTabId(nextTab.id)
|
||||||
}, [location])
|
}, [location])
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user