Skip to content

Commit 04580ac

Browse files
authored
[SettingUI] Group setting menu items (#3510)
1 parent cd35f1d commit 04580ac

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

src/components/dialog/content/SettingDialogContent.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@
1010
/>
1111
<Listbox
1212
v-model="activeCategory"
13-
:options="allCategories"
13+
:options="groupedMenuTreeNodes"
1414
option-label="translatedLabel"
15+
option-group-label="label"
16+
option-group-children="children"
1517
scroll-height="100%"
1618
:option-disabled="
1719
(option: SettingTreeNode) =>
1820
!queryIsEmpty && !searchResultsCategories.has(option.label ?? '')
1921
"
2022
class="border-none w-full"
21-
/>
23+
>
24+
<template #optiongroup>
25+
<Divider class="my-0" />
26+
</template>
27+
</Listbox>
2228
</ScrollPanel>
2329
<Divider layout="vertical" class="mx-1 2xl:mx-4 hidden md:flex" />
2430
<Divider layout="horizontal" class="flex md:hidden" />
@@ -103,8 +109,12 @@ const ServerConfigPanel = defineAsyncComponent(
103109
() => import('./setting/ServerConfigPanel.vue')
104110
)
105111
106-
const { activeCategory, defaultCategory, allCategories, settingCategories } =
107-
useSettingUI(defaultPanel)
112+
const {
113+
activeCategory,
114+
defaultCategory,
115+
settingCategories,
116+
groupedMenuTreeNodes
117+
} = useSettingUI(defaultPanel)
108118
109119
const {
110120
searchQuery,
@@ -183,14 +193,8 @@ watch(activeCategory, (_, oldValue) => {
183193
}
184194
}
185195
186-
/* Show a separator line above the Keybinding tab */
187-
/* This indicates the start of custom setting panels */
188-
.settings-sidebar :deep(.p-listbox-option[aria-label='Keybinding']) {
189-
position: relative;
190-
}
191-
192-
.settings-sidebar :deep(.p-listbox-option[aria-label='Keybinding'])::before {
193-
@apply content-[''] top-0 left-0 absolute w-full;
194-
border-top: 1px solid var(--p-divider-border-color);
196+
/* Hide the first group separator */
197+
.settings-sidebar :deep(.p-listbox-option-group:nth-child(1)) {
198+
display: none;
195199
}
196200
</style>

src/composables/setting/useSettingUI.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,42 @@ export function useSettingUI(
8282
: settingCategories.value[0]
8383
})
8484

85-
/**
86-
* Translated all categories with labels
87-
*/
88-
const translatedCategories = computed<SettingTreeNode[]>(() => {
89-
return [
90-
...settingCategories.value,
91-
keybindingPanelNode,
92-
extensionPanelNode,
93-
...serverConfigPanelNodeList.value,
94-
aboutPanelNode
95-
].map((node) => ({
96-
...node,
97-
translatedLabel: t(
98-
`settingsCategories.${normalizeI18nKey(node.label)}`,
99-
node.label
100-
)
101-
}))
85+
const translateCategory = (node: SettingTreeNode) => ({
86+
...node,
87+
translatedLabel: t(
88+
`settingsCategories.${normalizeI18nKey(node.label)}`,
89+
node.label
90+
)
10291
})
10392

93+
const groupedMenuTreeNodes = computed<SettingTreeNode[]>(() => [
94+
// Normal settings stored in the settingStore
95+
{
96+
key: 'settings',
97+
label: 'Application Settings',
98+
children: settingCategories.value.map(translateCategory)
99+
},
100+
// Special settings such as about, keybinding, extension, server-config
101+
{
102+
key: 'specialSettings',
103+
label: 'Special Settings',
104+
children: [
105+
keybindingPanelNode,
106+
extensionPanelNode,
107+
aboutPanelNode,
108+
...serverConfigPanelNodeList.value
109+
].map(translateCategory)
110+
}
111+
])
112+
104113
onMounted(() => {
105114
activeCategory.value = defaultCategory.value
106115
})
107116

108117
return {
109118
activeCategory,
110119
defaultCategory,
111-
allCategories: translatedCategories,
120+
groupedMenuTreeNodes,
112121
settingCategories
113122
}
114123
}

0 commit comments

Comments
 (0)