Skip to content

Commit baec098

Browse files
committed
Add consistent Escape key handling to modals
1 parent 5c78b14 commit baec098

8 files changed

Lines changed: 319 additions & 257 deletions

File tree

‎packages/ui/src/components/editor/panel/modals/ApiManagerModal/ApiManagerModal.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ export const ApiManagerModal: React.FC<Props> = (props) => {
6969
}, [props.progress_items])
7070

7171
return (
72-
<div className={styles.overlay}>
72+
<div
73+
className={styles.overlay}
74+
onKeyDown={(e) => {
75+
if (e.key == 'Escape') {
76+
e.stopPropagation()
77+
}
78+
}}
79+
>
7380
<div className={styles.container}>
7481
<div
7582
className={cn(styles.title, {

‎packages/ui/src/components/editor/panel/modals/AutoClosingModal/AutoClosingModal.tsx‎

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,34 @@ export const AutoClosingModal: React.FC<Props> = (props) => {
2525
}, [])
2626

2727
return (
28-
<Modal
29-
title={props.title}
30-
icon={props.icon}
31-
content_slot={
32-
<div className={styles.progress}>
33-
<div
34-
className={styles.progress__fill}
35-
style={{
36-
width: is_filling ? '100%' : '0%',
37-
transition: `width ${props.duration}ms linear`
38-
}}
39-
/>
40-
</div>
41-
}
42-
on_background_click={props.on_close}
43-
footer_slot={
44-
<Button on_click={props.on_close} is_focused={true}>
45-
Close
46-
</Button>
47-
}
48-
/>
28+
<div
29+
onKeyDown={(e) => {
30+
if (e.key == 'Escape') {
31+
e.stopPropagation()
32+
}
33+
}}
34+
>
35+
<Modal
36+
title={props.title}
37+
icon={props.icon}
38+
content_slot={
39+
<div className={styles.progress}>
40+
<div
41+
className={styles.progress__fill}
42+
style={{
43+
width: is_filling ? '100%' : '0%',
44+
transition: `width ${props.duration}ms linear`
45+
}}
46+
/>
47+
</div>
48+
}
49+
on_background_click={props.on_close}
50+
footer_slot={
51+
<Button on_click={props.on_close} is_focused={true}>
52+
Close
53+
</Button>
54+
}
55+
/>
56+
</div>
4957
)
5058
}

‎packages/ui/src/components/editor/panel/modals/CommitMessageModal/CommitMessageModal.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ export const CommitMessageModal: React.FC<Props> = (props) => {
2626
})
2727

2828
return (
29-
<div onMouseDown={commit_timer_hook.stop_timer}>
29+
<div
30+
onMouseDown={commit_timer_hook.stop_timer}
31+
onKeyDown={(e) => {
32+
if (e.key == 'Escape') {
33+
e.stopPropagation()
34+
props.on_cancel()
35+
}
36+
}}
37+
>
3038
<Modal
3139
title="Commit changes"
3240
content_slot={

‎packages/ui/src/components/editor/panel/modals/EditCheckpointDescriptionModal/EditCheckpointDescriptionModal.tsx‎

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,38 @@ export const EditCheckpointDescriptionModal: React.FC<Props> = (props) => {
1313
const [description, set_description] = useState(props.description)
1414

1515
return (
16-
<Modal
17-
title="Edit Description"
18-
content_slot={
19-
<Textarea
20-
value={description}
21-
on_change={set_description}
22-
min_rows={2}
23-
autofocus
24-
on_key_down={(e) => {
25-
if (e.key == 'Enter' && (e.metaKey || e.ctrlKey)) {
26-
e.preventDefault()
27-
props.on_save(description)
28-
}
29-
}}
30-
/>
31-
}
32-
footer_slot={
33-
<>
34-
<Button on_click={props.on_cancel} is_secondary={true}>
35-
Cancel
36-
</Button>
37-
<Button on_click={() => props.on_save(description)}>Save</Button>
38-
</>
39-
}
40-
/>
16+
<div
17+
onKeyDown={(e) => {
18+
if (e.key == 'Escape') {
19+
e.stopPropagation()
20+
}
21+
}}
22+
>
23+
<Modal
24+
title="Edit Description"
25+
content_slot={
26+
<Textarea
27+
value={description}
28+
on_change={set_description}
29+
min_rows={2}
30+
autofocus
31+
on_key_down={(e) => {
32+
if (e.key == 'Enter' && (e.metaKey || e.ctrlKey)) {
33+
e.preventDefault()
34+
props.on_save(description)
35+
}
36+
}}
37+
/>
38+
}
39+
footer_slot={
40+
<>
41+
<Button on_click={props.on_cancel} is_secondary={true}>
42+
Cancel
43+
</Button>
44+
<Button on_click={() => props.on_save(description)}>Save</Button>
45+
</>
46+
}
47+
/>
48+
</div>
4149
)
4250
}

‎packages/ui/src/components/editor/panel/modals/ProgressModal/ProgressModal.tsx‎

Lines changed: 104 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -83,110 +83,118 @@ export const ProgressModal: React.FC<Props> = (props) => {
8383
}, [props.show_elapsed_time, props.delay_visibility])
8484

8585
return is_visible ? (
86-
<Modal
87-
title={props.title}
88-
content_max_height={props.files ? 'calc(100vh - 150px)' : undefined}
89-
content_slot={
90-
<>
91-
{props.show_elapsed_time !== false && (
92-
<div className={styles['elapsed-time']}>
93-
{elapsed_time.toFixed(1)}s
94-
</div>
95-
)}
86+
<div
87+
onKeyDown={(e) => {
88+
if (e.key == 'Escape') {
89+
e.stopPropagation()
90+
}
91+
}}
92+
>
93+
<Modal
94+
title={props.title}
95+
content_max_height={props.files ? 'calc(100vh - 150px)' : undefined}
96+
content_slot={
97+
<>
98+
{props.show_elapsed_time !== false && (
99+
<div className={styles['elapsed-time']}>
100+
{elapsed_time.toFixed(1)}s
101+
</div>
102+
)}
96103

97-
{props.files ? (
98-
<div className={styles.content}>
99-
{props.files.map((file) => {
100-
const last_slash_index = file.file_path.lastIndexOf('/')
101-
const file_name =
102-
last_slash_index == -1
103-
? file.file_path
104-
: file.file_path.substring(last_slash_index + 1)
105-
const directory_path =
106-
last_slash_index == -1
107-
? ''
108-
: file.file_path.substring(0, last_slash_index)
104+
{props.files ? (
105+
<div className={styles.content}>
106+
{props.files.map((file) => {
107+
const last_slash_index = file.file_path.lastIndexOf('/')
108+
const file_name =
109+
last_slash_index == -1
110+
? file.file_path
111+
: file.file_path.substring(last_slash_index + 1)
112+
const directory_path =
113+
last_slash_index == -1
114+
? ''
115+
: file.file_path.substring(0, last_slash_index)
109116

110-
return (
111-
<div key={file.file_path} className={styles['file-item']}>
112-
<div className={styles['file-item__header']}>
113-
<div className={styles['file-item__name']}>
114-
<span>{file_name}</span>
115-
<span>{directory_path}</span>
117+
return (
118+
<div key={file.file_path} className={styles['file-item']}>
119+
<div className={styles['file-item__header']}>
120+
<div className={styles['file-item__name']}>
121+
<span>{file_name}</span>
122+
<span>{directory_path}</span>
123+
</div>
124+
<div
125+
className={cn(
126+
styles['file-item__status'],
127+
styles[`file-item__status--${file.status}`]
128+
)}
129+
>
130+
{get_status_text(file.status)}
131+
</div>
116132
</div>
117-
<div
118-
className={cn(
119-
styles['file-item__status'],
120-
styles[`file-item__status--${file.status}`]
133+
<div className={styles.progress}>
134+
{file.status == 'thinking' ||
135+
file.status == 'retrying' ||
136+
(file.status == 'receiving' &&
137+
file.progress === undefined) ? (
138+
<div
139+
className={styles['progress__fill--indeterminate']}
140+
/>
141+
) : (
142+
<div
143+
className={cn(styles.progress__fill, {
144+
[styles['progress__fill--done']]:
145+
file.status == 'done'
146+
})}
147+
style={{
148+
width: `${
149+
file.status == 'done'
150+
? 100
151+
: file.status == 'receiving' &&
152+
file.progress !== undefined
153+
? file.progress
154+
: 0
155+
}%`
156+
}}
157+
/>
121158
)}
122-
>
123-
{get_status_text(file.status)}
124159
</div>
160+
{file.status == 'receiving' &&
161+
file.tokens_per_second !== undefined && (
162+
<div className={styles['file-item__details']}>
163+
~{format_tokens_per_second(file.tokens_per_second)}{' '}
164+
tokens/s
165+
</div>
166+
)}
125167
</div>
126-
<div className={styles.progress}>
127-
{file.status == 'thinking' ||
128-
file.status == 'retrying' ||
129-
(file.status == 'receiving' &&
130-
file.progress === undefined) ? (
131-
<div
132-
className={styles['progress__fill--indeterminate']}
133-
/>
134-
) : (
135-
<div
136-
className={cn(styles.progress__fill, {
137-
[styles['progress__fill--done']]:
138-
file.status == 'done'
139-
})}
140-
style={{
141-
width: `${
142-
file.status == 'done'
143-
? 100
144-
: file.status == 'receiving' &&
145-
file.progress !== undefined
146-
? file.progress
147-
: 0
148-
}%`
149-
}}
150-
/>
151-
)}
152-
</div>
153-
{file.status == 'receiving' &&
154-
file.tokens_per_second !== undefined && (
155-
<div className={styles['file-item__details']}>
156-
~{format_tokens_per_second(file.tokens_per_second)}{' '}
157-
tokens/s
158-
</div>
159-
)}
168+
)
169+
})}
170+
</div>
171+
) : (
172+
<div className={styles.content}>
173+
{props.tokens_per_second !== undefined && (
174+
<div className={styles['tokens-per-second']}>
175+
{format_tokens_per_second(props.tokens_per_second)} tokens/s
160176
</div>
161-
)
162-
})}
163-
</div>
164-
) : (
165-
<div className={styles.content}>
166-
{props.tokens_per_second !== undefined && (
167-
<div className={styles['tokens-per-second']}>
168-
{format_tokens_per_second(props.tokens_per_second)} tokens/s
169-
</div>
170-
)}
171-
<div className={styles.progress}>
172-
{props.progress !== undefined ? (
173-
<div
174-
className={styles.progress__fill}
175-
style={{ width: `${props.progress}%` }}
176-
/>
177-
) : (
178-
<div className={styles['progress__fill--indeterminate']} />
179177
)}
178+
<div className={styles.progress}>
179+
{props.progress !== undefined ? (
180+
<div
181+
className={styles.progress__fill}
182+
style={{ width: `${props.progress}%` }}
183+
/>
184+
) : (
185+
<div className={styles['progress__fill--indeterminate']} />
186+
)}
187+
</div>
180188
</div>
181-
</div>
182-
)}
183-
</>
184-
}
185-
footer_slot={
186-
props.on_cancel ? (
187-
<Button on_click={props.on_cancel}>Cancel</Button>
188-
) : undefined
189-
}
190-
/>
189+
)}
190+
</>
191+
}
192+
footer_slot={
193+
props.on_cancel ? (
194+
<Button on_click={props.on_cancel}>Cancel</Button>
195+
) : undefined
196+
}
197+
/>
198+
</div>
191199
) : null
192200
}

0 commit comments

Comments
 (0)