Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): logic of hidden tabs and categories #130

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/client/src/composables/state-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,33 @@ export function useAllTabs() {
})
const categorizedTabs = computed(() => {
const { hiddenTabCategories, hiddenTabs, pinnedTabs } = devtoolsClientState.value.tabSettings
const pinnedHidden = hiddenTabCategories.includes('pinned')
// TODO: custom tabs
const tabs = allTabs.value.reduce<CategorizedTabs>((prev, [category, tabs]) => {
const data: [CategorizedCategory, CategorizedTab[]] = [{ hidden: false, name: category }, []]
let hiddenCount = 0
const categoryHidden = hiddenTabCategories.includes(category)
tabs.forEach((tab) => {
const hidden = hiddenTabs.includes(tab.name) || hiddenTabCategories.includes(category)
if (hidden)
hiddenCount += 1
const tabHidden = hiddenTabs.includes(tab.name)

if (pinnedTabs.includes(tab.name)) {
prev[0][1].push({
...tab,
hidden,
hidden: tabHidden || pinnedHidden,
})
}
else { data[1].push({ ...tab, hidden }) }
else {
const hidden = tabHidden || categoryHidden
data[1].push({ ...tab, hidden })
}
})
if (hiddenCount === tabs.length)
data[0].hidden = true
data[0].hidden = data[1].every(t => t.hidden)
prev.push(data)
return prev
}, [[{ name: 'pinned', hidden: false }, []]])

// set pinned category hidden value
tabs[0][0].hidden = tabs[0][1].every(t => t.hidden)

// sort pinned tabs by pinned order
tabs[0][1].sort((a, b) => pinnedTabs.indexOf(a.name) - pinnedTabs.indexOf(b.name))
return tabs
Expand Down