Skip to content

Commit 6fba6ca

Browse files
committed
Disable empty settings groups and navigation items instead of hiding them
- instead of hiding settings groups (e.g. model, defaults), make them dimmed and ignore pointer events ├── apps │ └── editor │ └── src │ └── views │ └── settings │ └── frontend │ └── Home │ ├── Home.tsx │ ├── hooks │ │ └── use-scroll-to.ts │ └── sections │ └── ApiSection.tsx └── packages └── ui └── src ├── components │ └── editor │ └── settings │ ├── Group │ │ ├── Group.module.scss │ │ └── Group.tsx │ └── NavigationItemGroup │ ├── NavigationItemGroup.module.scss │ └── NavigationItemGroup.tsx └── styles └── foundation └── _variables.scss
1 parent 9023843 commit 6fba6ca

7 files changed

Lines changed: 271 additions & 304 deletions

File tree

‎apps/editor/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ export const Home: React.FC<Props> = (props) => {
164164
handle_nav_click
165165
} = use_scroll_to({
166166
nav_items_config: NAV_ITEMS_CONFIG,
167-
providers_length: props.providers.length,
168-
api_configurations_length: props.api_configurations.length,
169167
scroll_to_section_on_load: props.scroll_to_section_on_load
170168
})
171169

@@ -204,21 +202,6 @@ export const Home: React.FC<Props> = (props) => {
204202
}[] = []
205203

206204
for (const item of NAV_ITEMS_CONFIG) {
207-
if (
208-
[
209-
'section:api:group:api-defaults',
210-
'section:api:group:system-instructions'
211-
].includes(item.id) &&
212-
props.api_configurations.length === 0
213-
) {
214-
continue
215-
}
216-
if (
217-
item.id === 'section:api:group:models' &&
218-
props.providers.length === 0
219-
) {
220-
continue
221-
}
222205
if (
223206
item.id.startsWith('section:') &&
224207
!item.id.includes(':group:')
@@ -241,17 +224,29 @@ export const Home: React.FC<Props> = (props) => {
241224
is_active={is_section_active}
242225
has_warning={get_has_warning(section.parent.id)}
243226
/>
244-
{section.groups.map((group, j) => (
245-
<UiNavigationItemGroup
246-
key={j}
247-
href={`#${group.id}`}
248-
label={t(group.label)}
249-
is_active={group.id === active_nav_item_id}
250-
has_warning={get_has_warning(group.id)}
251-
on_click={(e) => handle_nav_click(e, group.id)}
252-
is_last={j === section.groups.length - 1}
253-
/>
254-
))}
227+
{section.groups.map((group, j) => {
228+
const is_disabled =
229+
(group.id === 'section:api:group:models' &&
230+
props.providers.length === 0) ||
231+
([
232+
'section:api:group:api-defaults',
233+
'section:api:group:system-instructions'
234+
].includes(group.id) &&
235+
props.api_configurations.length === 0)
236+
237+
return (
238+
<UiNavigationItemGroup
239+
key={j}
240+
href={`#${group.id}`}
241+
label={t(group.label)}
242+
is_active={group.id === active_nav_item_id}
243+
has_warning={get_has_warning(group.id)}
244+
on_click={(e) => handle_nav_click(e, group.id)}
245+
is_last={j === section.groups.length - 1}
246+
is_disabled={is_disabled}
247+
/>
248+
)
249+
})}
255250
</UiNavigationSection>
256251
)
257252
})

‎apps/editor/src/views/settings/frontend/Home/hooks/use-scroll-to.ts‎

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@ import type { NavItem, NavConfigItem } from '../Home'
44

55
export const use_scroll_to = (params: {
66
nav_items_config: NavConfigItem[]
7-
providers_length: number
8-
api_configurations_length: number
97
scroll_to_section_on_load?: NavItem
108
}) => {
11-
const {
12-
nav_items_config,
13-
providers_length,
14-
api_configurations_length,
15-
scroll_to_section_on_load
16-
} = params
9+
const { nav_items_config, scroll_to_section_on_load } = params
1710

1811
const scroll_container_ref = useRef<HTMLDivElement>(null)
1912
const section_refs = useRef<Partial<Record<NavItem, HTMLDivElement | null>>>(
@@ -33,24 +26,8 @@ export const use_scroll_to = (params: {
3326
const [is_layout_ready, set_is_layout_ready] = useState(false)
3427

3528
const last_rendered_item_id = useMemo(() => {
36-
let last_id = nav_items_config[0].id
37-
for (const item of nav_items_config) {
38-
if (
39-
[
40-
'section:api:group:api-defaults',
41-
'section:api:group:system-instructions'
42-
].includes(item.id) &&
43-
api_configurations_length === 0
44-
) {
45-
continue
46-
}
47-
if (item.id === 'section:api:group:models' && providers_length === 0) {
48-
continue
49-
}
50-
last_id = item.id
51-
}
52-
return last_id
53-
}, [nav_items_config, providers_length, api_configurations_length])
29+
return nav_items_config[nav_items_config.length - 1].id
30+
}, [nav_items_config])
5431

5532
useEffect(() => {
5633
const scroll_container = scroll_container_ref.current
@@ -120,18 +97,6 @@ export const use_scroll_to = (params: {
12097
let new_active_id = nav_items_config[0].id
12198

12299
for (const item of nav_items_config) {
123-
if (
124-
[
125-
'section:api:group:api-defaults',
126-
'section:api:group:system-instructions'
127-
].includes(item.id) &&
128-
api_configurations_length === 0
129-
) {
130-
continue
131-
}
132-
if (item.id === 'section:api:group:models' && providers_length === 0) {
133-
continue
134-
}
135100
const el = section_refs.current[item.id]
136101
if (el) {
137102
const rect = el.getBoundingClientRect()
@@ -154,7 +119,7 @@ export const use_scroll_to = (params: {
154119
scroll_container.removeEventListener('scroll', handle_scroll)
155120
window.removeEventListener('resize', handle_scroll)
156121
}
157-
}, [providers_length, api_configurations_length, nav_items_config])
122+
}, [nav_items_config])
158123

159124
const handle_scroll_to_section = useCallback(
160125
(item_id: NavItem) => {

0 commit comments

Comments
 (0)