Skip to content

Commit 42dbc6e

Browse files
committed
Replace header mode toggler with tab-based mode switching in main view
- place 'tabs' above configurations: 'Chatbots' 'API Calls' and make them change the active mode - from header,remove displaying / changing mode ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── frontend │ ├── Home │ │ └── Home.tsx │ └── Main │ └── MainView │ ├── MainView.tsx │ └── components │ └── Header │ ├── Header.module.scss │ ├── Header.tsx │ ├── hooks │ │ └── use-keyboard-shortcuts.ts │ └── index.ts └── packages └── ui └── src └── components └── editor └── prompt ├── Configurations │ ├── Configurations.module.scss │ ├── Configurations.stories.tsx │ ├── Configurations.tsx │ └── index.ts └── Tabs ├── Tabs.module.scss ├── Tabs.tsx └── index.ts
1 parent a2efd3c commit 42dbc6e

7 files changed

Lines changed: 79 additions & 284 deletions

File tree

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styles from './MainView.module.scss'
22
import { Configurations as UiConfigurations } from '@ui/components/editor/prompt/Configurations'
3+
import { Tabs as UiTabs } from '@ui/components/editor/prompt/Tabs'
34
import { PromptField as UiPromptField } from '@ui/components/editor/common/prompts/PromptField'
45
import { Separator as UiSeparator } from '@ui/components/editor/prompt/Separator'
56
import { WebConfiguration } from '@shared/types/web-configuration'
@@ -262,7 +263,6 @@ export const MainView: React.FC<Props> = (props) => {
262263
<>
263264
<Header
264265
mode={props.mode}
265-
on_mode_change={props.on_mode_change}
266266
on_show_home={props.on_show_home}
267267
web_prompt_type={props.web_prompt_type}
268268
on_web_prompt_type_change={props.on_web_prompt_type_change}
@@ -390,77 +390,84 @@ export const MainView: React.FC<Props> = (props) => {
390390
/>
391391
</div>
392392

393+
<UiSeparator height={6} />
394+
395+
<UiTabs
396+
tabs={[
397+
{ id: 'chatbots', label: t('home.mode.chatbots') },
398+
{ id: 'api-calls', label: t('home.mode.api-calls') }
399+
]}
400+
active_tab={props.mode == MODE.WEB ? 'chatbots' : 'api-calls'}
401+
on_tab_change={(id) =>
402+
props.on_mode_change(id == 'chatbots' ? MODE.WEB : MODE.API)
403+
}
404+
/>
405+
393406
{props.mode == MODE.WEB && (
394-
<>
395-
<UiSeparator height={6} />
396-
<UiConfigurations
397-
configurations={web_configurations}
398-
disable_invocation={!!warning || !props.is_connected}
399-
on_create={(params) => {
400-
props.on_create_web_configuration(params)
401-
}}
402-
on_configuration_click={(id) => {
403-
props.initialize_chats({
404-
web_configuration_name: id,
405-
show_quick_pick: false,
406-
invocation_count: current_invocation_count
407-
})
408-
}}
409-
on_edit={(id) => props.on_web_configuration_edit(id)}
410-
on_reorder={(reordered) => {
411-
const new_web_configurations = reordered.map((c) => {
412-
return props.web_configurations.find(
413-
(p, i) => (p.name ?? `unnamed-${i}`) == c.id
414-
)!
415-
})
416-
props.on_web_configurations_reorder(new_web_configurations)
417-
}}
418-
on_delete={(id) => {
419-
props.on_delete_web_configuration(id)
420-
}}
421-
on_toggle_pinned={(id) => {
422-
props.on_toggle_web_configuration_pinned(id)
423-
}}
424-
selected_configuration_id={props.selected_web_configuration_name}
425-
translations={{
426-
empty: t('configurations.empty'),
427-
add_new: t('action.add-new'),
428-
pin: t('action.pin'),
429-
unpin: t('action.unpin'),
430-
insert: t('action.insert-configuration'),
431-
edit: t('action.edit'),
432-
delete: t('action.delete')
433-
}}
434-
/>
435-
</>
407+
<UiConfigurations
408+
configurations={web_configurations}
409+
disable_invocation={!!warning || !props.is_connected}
410+
on_create={(params) => {
411+
props.on_create_web_configuration(params)
412+
}}
413+
on_configuration_click={(id) => {
414+
props.initialize_chats({
415+
web_configuration_name: id,
416+
show_quick_pick: false,
417+
invocation_count: current_invocation_count
418+
})
419+
}}
420+
on_edit={(id) => props.on_web_configuration_edit(id)}
421+
on_reorder={(reordered) => {
422+
const new_web_configurations = reordered.map((c) => {
423+
return props.web_configurations.find(
424+
(p, i) => (p.name ?? `unnamed-${i}`) == c.id
425+
)!
426+
})
427+
props.on_web_configurations_reorder(new_web_configurations)
428+
}}
429+
on_delete={(id) => {
430+
props.on_delete_web_configuration(id)
431+
}}
432+
on_toggle_pinned={(id) => {
433+
props.on_toggle_web_configuration_pinned(id)
434+
}}
435+
selected_configuration_id={props.selected_web_configuration_name}
436+
translations={{
437+
empty: t('configurations.empty'),
438+
add_new: t('action.add-new'),
439+
pin: t('action.pin'),
440+
unpin: t('action.unpin'),
441+
insert: t('action.insert-configuration'),
442+
edit: t('action.edit'),
443+
delete: t('action.delete')
444+
}}
445+
/>
436446
)}
437447

438448
{props.mode == MODE.API && (
439-
<>
440-
<UiSeparator height={6} />
441-
<UiConfigurations
442-
configurations={api_configurations_ui}
443-
disable_invocation={!!warning}
444-
on_configuration_click={props.on_api_configuration_click}
445-
on_reorder={(reordered) =>
446-
props.on_api_configurations_reorder(reordered)
447-
}
448-
on_toggle_pinned={props.on_toggle_pinned_api_configuration}
449-
on_edit={props.on_edit_api_configuration}
450-
on_delete={props.on_delete_api_configuration}
451-
selected_configuration_id={props.selected_api_configuration_id}
452-
on_create={props.on_create_api_configuration}
453-
translations={{
454-
empty: t('configurations.empty'),
455-
add_new: t('action.add-new'),
456-
pin: t('action.pin'),
457-
unpin: t('action.unpin'),
458-
insert: t('action.insert-configuration'),
459-
edit: t('action.edit'),
460-
delete: t('action.delete')
461-
}}
462-
/>
463-
</>
449+
<UiConfigurations
450+
configurations={api_configurations_ui}
451+
disable_invocation={!!warning}
452+
on_configuration_click={props.on_api_configuration_click}
453+
on_reorder={(reordered) =>
454+
props.on_api_configurations_reorder(reordered)
455+
}
456+
on_toggle_pinned={props.on_toggle_pinned_api_configuration}
457+
on_edit={props.on_edit_api_configuration}
458+
on_delete={props.on_delete_api_configuration}
459+
selected_configuration_id={props.selected_api_configuration_id}
460+
on_create={props.on_create_api_configuration}
461+
translations={{
462+
empty: t('configurations.empty'),
463+
add_new: t('action.add-new'),
464+
pin: t('action.pin'),
465+
unpin: t('action.unpin'),
466+
insert: t('action.insert-configuration'),
467+
edit: t('action.edit'),
468+
delete: t('action.delete')
469+
}}
470+
/>
464471
)}
465472
{props.bottom_spacer_height !== undefined &&
466473
props.bottom_spacer_height > 0 && (

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/Header.module.scss‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,4 @@
1717
padding: 4px 0;
1818
gap: 2px;
1919
}
20-
21-
&__right {
22-
display: flex;
23-
align-items: center;
24-
}
2520
}

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/Header.tsx‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { useCallback } from 'react'
21
import { MODE, Mode } from '@/views/prompt/types/main-view-mode'
3-
import { use_compacting, use_is_mac } from '@shared/hooks'
2+
import { use_compacting } from '@shared/hooks'
43
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
54
import { PromptTypeButton as UiPromptTypeButton } from '@ui/components/editor/prompt/PromptTypeButton'
6-
import { ModeToggler } from '@ui/components/editor/prompt/ModeToggler'
75
import { IconButton as UiIconButton } from '@ui/components/editor/common/IconButton'
86
import styles from './Header.module.scss'
97
import {
@@ -15,7 +13,6 @@ import { use_translation } from '@/views/prompt/frontend/i18n/use-translation'
1513

1614
type Props = {
1715
mode: Mode
18-
on_mode_change: (value: Mode) => void
1916
on_show_home: () => void
2017
web_prompt_type: WebPromptType
2118
api_prompt_type: ApiPromptType
@@ -26,20 +23,10 @@ type Props = {
2623

2724
export const Header: React.FC<Props> = (props) => {
2825
const { t } = use_translation()
29-
const is_mac = use_is_mac()
3026
const { container_ref, compact_step } = use_compacting()
3127

32-
const handle_heading_click = useCallback(() => {
33-
if (props.mode == MODE.WEB) {
34-
props.on_mode_change(MODE.API)
35-
} else {
36-
props.on_mode_change(MODE.WEB)
37-
}
38-
}, [props.mode, props.on_mode_change])
39-
4028
const { is_alt_pressed } = use_keyboard_shortcuts({
4129
mode: props.mode,
42-
handle_heading_click,
4330
on_web_prompt_type_change: props.on_web_prompt_type_change,
4431
on_api_prompt_type_change: props.on_api_prompt_type_change,
4532
on_show_home: props.on_show_home,
@@ -97,16 +84,6 @@ export const Header: React.FC<Props> = (props) => {
9784
/>
9885
)}
9986
</div>
100-
101-
<div className={styles.header__right}>
102-
<ModeToggler
103-
mode={props.mode == MODE.WEB ? 'Chatbots' : 'API calls'}
104-
alt_mode={props.mode == MODE.WEB ? 'API calls' : 'Chatbots'}
105-
title={`${t('header.change-mode')} (${is_mac ? '⌥Esc' : 'Alt+Esc'})`}
106-
is_alt_pressed={is_alt_pressed}
107-
on_toggle={handle_heading_click}
108-
/>
109-
</div>
11087
</div>
11188
)
11289
}

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/hooks/use-keyboard-shortcuts.ts‎

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,25 @@
11
import { useEffect, useState, useRef } from 'react'
2-
import { use_is_mac } from '@shared/hooks'
32
import { MODE, Mode } from '@/views/prompt/types/main-view-mode'
43
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
54

65
export const use_keyboard_shortcuts = (params: {
76
mode: Mode
8-
handle_heading_click: () => void
97
on_web_prompt_type_change: (prompt_type: WebPromptType) => void
108
on_api_prompt_type_change: (prompt_type: ApiPromptType) => void
119
on_show_home: () => void
1210
is_disabled: boolean
1311
}) => {
14-
const is_mac = use_is_mac()
1512
const [is_alt_pressed, set_is_alt_pressed] = useState(false)
1613
const alt_interrupted_ref = useRef(false)
1714
const is_alt_pressed_raw_ref = useRef(false)
18-
const pending_mode_ref = useRef<Mode | null>(null)
1915

2016
const update_alt_pressed = (val: boolean) => {
2117
is_alt_pressed_raw_ref.current = val
22-
if (pending_mode_ref.current) {
23-
if (val) set_is_alt_pressed(true)
24-
} else {
25-
set_is_alt_pressed(val)
26-
}
18+
set_is_alt_pressed(val)
2719
}
2820

29-
useEffect(() => {
30-
if (pending_mode_ref.current === params.mode) {
31-
pending_mode_ref.current = null
32-
set_is_alt_pressed(is_alt_pressed_raw_ref.current)
33-
}
34-
}, [params.mode])
35-
3621
useEffect(() => {
3722
const handle_key_down = (event: KeyboardEvent) => {
38-
let next_mode: Mode | undefined
39-
40-
if (
41-
event.key == 'Escape' &&
42-
event.altKey &&
43-
!event.metaKey &&
44-
!event.ctrlKey &&
45-
!event.shiftKey
46-
) {
47-
next_mode = params.mode === MODE.WEB ? MODE.API : MODE.WEB
48-
}
49-
5023
if (
5124
event.key == 'Alt' &&
5225
!event.shiftKey &&
@@ -61,12 +34,7 @@ export const use_keyboard_shortcuts = (params: {
6134
alt_interrupted_ref.current = true
6235
}
6336

64-
if (next_mode && params.mode !== next_mode) {
65-
pending_mode_ref.current = next_mode
66-
update_alt_pressed(false)
67-
} else {
68-
update_alt_pressed(false)
69-
}
37+
update_alt_pressed(false)
7038
}
7139

7240
if (params.is_disabled) return
@@ -79,9 +47,6 @@ export const use_keyboard_shortcuts = (params: {
7947
!event.shiftKey
8048
) {
8149
params.on_show_home()
82-
} else if (next_mode) {
83-
event.preventDefault()
84-
params.handle_heading_click()
8550
}
8651
}
8752

@@ -124,13 +89,7 @@ export const use_keyboard_shortcuts = (params: {
12489
window.removeEventListener('blur', handle_blur)
12590
window.removeEventListener('mouseup', handle_mouse_up)
12691
}
127-
}, [
128-
params.is_disabled,
129-
params.on_show_home,
130-
is_mac,
131-
params.handle_heading_click,
132-
params.mode
133-
])
92+
}, [params.is_disabled, params.on_show_home])
13493

13594
useEffect(() => {
13695
const handle_key_down = (event: KeyboardEvent) => {

0 commit comments

Comments
 (0)