Skip to content

Commit b78cfd6

Browse files
committed
Redesign prompt view layout to incorporate mode toggling in the header and token counts in the prompt field footer
- place 'tokens in context' count (e.g. 22K) in 'prompt field', next to edit format. Use '·' as separator when necessary. Remove 'context utilization' component. - when context is 0, don't show it - place token count on the right side of 'edit format', make it the same font-size - token count should have font size of edit format - [Commit] restore the mode toggler ui component - place 'mode toggler' to the left of prompt type in header - to mode toggler add support for alt+esc handling - mode toggler should use font family accent - use chatbots/api calls labels for mode toggler - wrap edit/ask in a div, set gap to 10px - align mode toggler labels to left - remove tabs component - on token count show tooltip "Tokens in context" - rename 'right edit format' to 'right details - use css instead of [Pasted text] - use css instead ofstyle={{ position: 'relative', display: 'flex', minWidth: 0 }} - extract footer to a render function - after recent edits, tabs are rendered incorrectly [Changes] - after recent edits, tabs are render incorrectly [Changes] - use bem for [Pasted text] ├── apps │ └── editor │ └── src │ ├── commands │ │ └── select-referencing-files-commands │ │ ├── index.ts │ │ ├── select-referencing-files-commands.ts │ │ └── utils │ │ ├── get-referencing-files-for-position.ts │ │ ├── get-referencing-files-for-uris.ts │ │ └── prompt-for-referencing-files.ts │ └── views │ └── prompt │ └── frontend │ ├── Main │ │ ├── Main.tsx │ │ └── MainView │ │ ├── MainView.module.scss │ │ ├── MainView.tsx │ │ ├── components │ │ │ └── Header │ │ │ ├── Header.module.scss │ │ │ ├── Header.tsx │ │ │ ├── hooks │ │ │ │ └── use-keyboard-shortcuts.ts │ │ │ └── index.ts │ │ ├── hooks │ │ │ ├── use-invocation-counts.ts │ │ │ ├── use-last-choice-tooltip.ts │ │ │ └── use-re-render-on-interval.ts │ │ ├── index.ts │ │ └── prompt-type-labels.ts │ └── i18n │ └── use-translation.tsx └── packages └── ui └── src └── components └── editor ├── common │ └── prompts │ ├── PromptField │ │ ├── PromptField.module.scss │ │ ├── PromptField.stories.tsx │ │ ├── PromptField.tsx │ │ ├── components │ │ │ ├── Tooltip.module.scss │ │ │ ├── Tooltip.tsx │ │ │ └── index.ts │ │ ├── hooks │ │ │ ├── use-drag-drop.ts │ │ │ ├── use-dropdown.ts │ │ │ ├── use-ghost-text.ts │ │ │ ├── use-handlers │ │ │ │ ├── handle-copy.ts │ │ │ │ ├── handle-cut.ts │ │ │ │ ├── handle-input-change.ts │ │ │ │ ├── handle-input-click.ts │ │ │ │ ├── handle-key-down.ts │ │ │ │ ├── handle-paste.ts │ │ │ │ ├── handle-submit.ts │ │ │ │ ├── index.ts │ │ │ │ ├── types.ts │ │ │ │ ├── use-handlers.ts │ │ │ │ └── utils.ts │ │ │ └── use-keyboard-shortcuts.ts │ │ └── index.ts │ ├── Template │ │ ├── Template.module.scss │ │ ├── Template.tsx │ │ └── index.ts │ └── shared │ └── symbols │ ├── caret.ts │ ├── get-highlighted-text.tsx │ ├── index.ts │ ├── position-mapping.ts │ ├── prompt-symbols.module.scss │ ├── reconstruct-raw-value.ts │ └── use-symbol-deletion.ts └── prompt ├── ModeToggler │ ├── ModeToggler.module.scss │ ├── ModeToggler.tsx │ └── index.ts └── PromptTypeButton ├── PromptTypeButton.module.scss ├── PromptTypeButton.stories.tsx ├── PromptTypeButton.tsx └── index.ts
1 parent 02cbb3c commit b78cfd6

14 files changed

Lines changed: 716 additions & 564 deletions

File tree

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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'
43
import { PromptField as UiPromptField } from '@ui/components/editor/common/prompts/PromptField'
54
import { Separator as UiSeparator } from '@ui/components/editor/prompt/Separator'
65
import { WebConfiguration } from '@shared/types/web-configuration'
@@ -13,7 +12,6 @@ import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrolla
1312
import { BrowserExtensionMessage as UiBrowserExtensionMessage } from '@ui/components/editor/prompt/BrowserExtensionMessage'
1413
import { ApiConfiguration } from '@/views/prompt/types/messages'
1514
import { use_last_choice_tooltip } from './hooks/use-last-choice-tooltip'
16-
import { ContextUtilisation as UiContextUtilisation } from '@ui/components/editor/prompt/ContextUtilisation'
1715
import { Header } from './components/Header'
1816
import { use_invocation_counts } from './hooks/use-invocation-counts'
1917
import { SelectionState } from '@/views/prompt/types/messages'
@@ -262,6 +260,7 @@ export const MainView: React.FC<Props> = (props) => {
262260
<>
263261
<Header
264262
mode={props.mode}
263+
on_mode_change={props.on_mode_change}
265264
on_show_home={props.on_show_home}
266265
web_prompt_type={props.web_prompt_type}
267266
on_web_prompt_type_change={props.on_web_prompt_type_change}
@@ -353,6 +352,7 @@ export const MainView: React.FC<Props> = (props) => {
353352
on_tabs_reorder={props.on_tabs_reorder}
354353
warning={warning}
355354
voice_input_push_to_talk={props.voice_input_push_to_talk}
355+
token_count={props.token_count}
356356
translations={{
357357
invocation_count: t('prompt-field.invocation-count'),
358358
voice_input: t('prompt-field.voice-input'),
@@ -380,26 +380,9 @@ export const MainView: React.FC<Props> = (props) => {
380380
send: t('prompt-field.action.send')
381381
}}
382382
/>
383-
<UiContextUtilisation
384-
current_context_size={props.token_count}
385-
is_context_disabled={false}
386-
/>
387383
</div>
388384

389-
<UiSeparator height={6} />
390-
391-
<UiTabs
392-
tabs={[
393-
{ id: 'web', label: 'WEB' },
394-
{ id: 'api', label: 'API' }
395-
]}
396-
active_tab={props.mode == MODE.WEB ? 'web' : 'api'}
397-
on_tab_change={(id) =>
398-
props.on_mode_change(id == 'web' ? MODE.WEB : MODE.API)
399-
}
400-
/>
401-
402-
<UiSeparator height={6} />
385+
<UiSeparator height={10} />
403386

404387
{props.mode == MODE.WEB && (
405388
<UiConfigurations

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
display: flex;
1616
align-items: center;
1717
padding: 4px 0;
18+
gap: 6px;
19+
}
20+
21+
&__prompt-types {
22+
display: flex;
23+
align-items: center;
1824
gap: 2px;
1925
}
2026
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { use_compacting } from '@shared/hooks'
33
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
44
import { PromptTypeButton as UiPromptTypeButton } from '@ui/components/editor/prompt/PromptTypeButton'
55
import { IconButton as UiIconButton } from '@ui/components/editor/common/IconButton'
6+
import { ModeToggler as UiModeToggler } from '@ui/components/editor/prompt/ModeToggler'
67
import styles from './Header.module.scss'
78
import {
89
api_prompt_type_labels,
@@ -13,6 +14,7 @@ import { use_translation } from '@/views/prompt/frontend/i18n/use-translation'
1314

1415
type Props = {
1516
mode: Mode
17+
on_mode_change: (mode: Mode) => void
1618
on_show_home: () => void
1719
web_prompt_type: WebPromptType
1820
api_prompt_type: ApiPromptType
@@ -27,6 +29,7 @@ export const Header: React.FC<Props> = (props) => {
2729

2830
const { is_alt_pressed } = use_keyboard_shortcuts({
2931
mode: props.mode,
32+
on_mode_change: props.on_mode_change,
3033
on_web_prompt_type_change: props.on_web_prompt_type_change,
3134
on_api_prompt_type_change: props.on_api_prompt_type_change,
3235
on_show_home: props.on_show_home,
@@ -41,8 +44,18 @@ export const Header: React.FC<Props> = (props) => {
4144
on_click={props.on_show_home}
4245
title={`${t('header.return')} (Esc)`}
4346
/>
47+
<UiModeToggler
48+
mode={props.mode == MODE.WEB ? 'Chatbots' : 'API Calls'}
49+
alt_mode={props.mode == MODE.WEB ? 'API Calls' : 'Chatbots'}
50+
is_alt_pressed={is_alt_pressed}
51+
on_toggle={() =>
52+
props.on_mode_change(
53+
props.mode == MODE.WEB ? MODE.API : MODE.WEB
54+
)
55+
}
56+
/>
4457
{props.mode == MODE.WEB && (
45-
<>
58+
<div className={styles['header__prompt-types']}>
4659
<UiPromptTypeButton
4760
label={web_prompt_type_labels['edit-files']}
4861
icon="edit-sparkle"
@@ -71,7 +84,7 @@ export const Header: React.FC<Props> = (props) => {
7184
props.on_web_prompt_type_change('ask-about-files')
7285
}
7386
/>
74-
</>
87+
</div>
7588
)}
7689
{props.mode == MODE.API && (
7790
<UiPromptTypeButton

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
44

55
export const use_keyboard_shortcuts = (params: {
66
mode: Mode
7+
on_mode_change: (mode: Mode) => void
78
on_web_prompt_type_change: (prompt_type: WebPromptType) => void
89
on_api_prompt_type_change: (prompt_type: ApiPromptType) => void
910
on_show_home: () => void
@@ -113,6 +114,14 @@ export const use_keyboard_shortcuts = (params: {
113114
if (event.code == 'KeyA' && params.mode == MODE.WEB) {
114115
event.preventDefault()
115116
params.on_web_prompt_type_change('ask-about-files')
117+
return
118+
}
119+
120+
if (event.code == 'Escape') {
121+
event.preventDefault()
122+
params.on_mode_change(
123+
params.mode == MODE.WEB ? MODE.API : MODE.WEB
124+
)
116125
}
117126
}
118127

@@ -123,6 +132,7 @@ export const use_keyboard_shortcuts = (params: {
123132
}
124133
}, [
125134
params.mode,
135+
params.on_mode_change,
126136
params.on_web_prompt_type_change,
127137
params.on_api_prompt_type_change,
128138
params.is_disabled

‎packages/ui/src/components/editor/common/prompts/PromptField/PromptField.module.scss‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
.footer {
158158
display: flex;
159159
padding: 6px 10px 6px 6px;
160-
gap: 5px;
160+
gap: 2px;
161161
justify-content: space-between;
162162
position: relative;
163163
min-width: 0;
@@ -197,15 +197,42 @@
197197
pointer-events: none;
198198
min-width: 0;
199199

200-
&__edit-format {
200+
&__details {
201+
display: none;
201202
flex: 1;
202-
display: flex;
203203
align-items: center;
204204
justify-content: flex-end;
205205
min-width: 0;
206+
font-size: 11px;
207+
gap: 3px;
208+
pointer-events: all;
209+
210+
&--visible {
211+
display: flex;
212+
}
213+
214+
&__edit-format-wrapper {
215+
position: relative;
216+
display: flex;
217+
min-width: 0;
218+
}
219+
220+
&__token-count {
221+
font-size: inherit;
222+
color: var(--cwc-text-color-dimmed);
223+
white-space: nowrap;
224+
font-variant-numeric: tabular-nums;
225+
pointer-events: auto;
226+
}
227+
228+
&__separator {
229+
font-size: inherit;
230+
color: var(--cwc-text-color-dimmed);
231+
padding: 0 4px;
232+
}
206233

207234
&__button {
208-
font-size: 11px;
235+
font-size: inherit;
209236
pointer-events: all;
210237
color: var(--vscode-foreground);
211238
padding: 5px 2px;
@@ -347,6 +374,10 @@
347374
flex-wrap: wrap;
348375
user-select: none;
349376
margin: 2px 1px 0 -2px;
377+
position: relative;
378+
z-index: 2;
379+
margin: 7px 1px 0 5px;
380+
350381

351382
&__tab {
352383
height: 15px;

0 commit comments

Comments
 (0)