Skip to content

Commit ddccd42

Browse files
committed
Extract the approval and discard footer from ResponsePreview into the parent Page component
1 parent 3bec449 commit ddccd42

7 files changed

Lines changed: 61 additions & 56 deletions

File tree

‎packages/ui/src/components/editor/panel/Page/Page.module.scss‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@
3232
}
3333
}
3434
}
35+
36+
.footer {
37+
display: flex;
38+
gap: var(--padding-8px);
39+
padding: var(--padding-12px);
40+
border-top: 1px solid var(--vscode-sideBarSectionHeader-border);
41+
42+
> button {
43+
flex: 1;
44+
}
45+
}

‎packages/ui/src/components/editor/panel/Page/Page.stories.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const Primary = () => (
99
title="Lorem ipsum"
1010
on_back_click={() => {}}
1111
header_slot={'header slot'}
12+
footer_slot={'footer slot'}
1213
>
1314
<div style={{ padding: 'var(--padding-12px)' }}>
1415
<p>

‎packages/ui/src/components/editor/panel/Page/Page.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Props = {
77
on_back_click?: () => void
88
on_close_click?: () => void
99
header_slot?: React.ReactNode
10+
footer_slot?: React.ReactNode
1011
children: React.ReactNode
1112
}
1213

@@ -38,6 +39,9 @@ export const Page: React.FC<Props> = (props) => {
3839
</div>
3940
</div>
4041
<Scrollable>{props.children}</Scrollable>
42+
{props.footer_slot && (
43+
<div className={styles.footer}>{props.footer_slot}</div>
44+
)}
4145
</div>
4246
)
4347
}

‎packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.module.scss‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
display: block;
4949

5050
&__text {
51+
font-size: var(--font-size-12px);
5152
margin: var(--padding-6px) var(--padding-12px);
5253
}
5354

@@ -134,16 +135,3 @@
134135
}
135136
}
136137
}
137-
138-
.footer {
139-
position: sticky;
140-
bottom: 0;
141-
background: var(--vscode-sideBar-background);
142-
display: flex;
143-
gap: var(--padding-8px);
144-
padding: var(--padding-12px);
145-
146-
> button {
147-
flex: 1;
148-
}
149-
}

‎packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.stories.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ const InteractiveResponsePreview = (props: any) => {
9292
{...props}
9393
items={items}
9494
on_toggle_file={handle_toggle_file}
95-
on_discard={log_action('on_undo')}
96-
on_approve={log_action('on_keep')}
9795
on_focus_file={log_action('on_focus_file')}
9896
on_go_to_file={log_action('on_go_to_file')}
9997
on_intelligent_update={log_action('on_intelligent_update')}

‎packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.tsx‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { FC, useState } from 'react'
22
import { FileInPreview, ItemInPreview } from '@shared/types/file-in-preview'
33
import cn from 'classnames'
44
import styles from './ResponsePreview.module.scss'
5-
import { Button } from '../Button'
65
import { Checkbox } from '../../common/Checkbox'
76
import { IconButton } from '../IconButton/IconButton'
87

98
type Props = {
109
items: ItemInPreview[]
1110
has_multiple_workspaces: boolean
12-
on_discard: () => void
13-
on_approve: (files: FileInPreview[]) => void
1411
on_focus_file: (file: { file_path: string; workspace_name?: string }) => void
1512
on_go_to_file: (file: { file_path: string; workspace_name?: string }) => void
1613
on_intelligent_update: (file: {
@@ -28,13 +25,6 @@ type Props = {
2825
export const ResponsePreview: FC<Props> = (props) => {
2926
const [last_clicked_file_index, set_last_clicked_file_index] = useState(0)
3027

31-
const handle_approve = () => {
32-
const accepted_files = props.items.filter(
33-
(f) => 'file_path' in f && f.is_checked
34-
) as FileInPreview[]
35-
props.on_approve(accepted_files)
36-
}
37-
3828
const files_in_preview = props.items.filter(
3929
(i) => 'file_path' in i
4030
) as FileInPreview[]
@@ -195,20 +185,6 @@ export const ResponsePreview: FC<Props> = (props) => {
195185
}
196186
})}
197187
</div>
198-
<div className={styles.footer}>
199-
<Button on_click={props.on_discard} is_secondary>
200-
Discard
201-
</Button>
202-
<Button
203-
on_click={handle_approve}
204-
disabled={
205-
files_in_preview.filter((f) => 'file_path' in f && f.is_checked)
206-
.length == 0
207-
}
208-
>
209-
Approve
210-
</Button>
211-
</div>
212188
</div>
213189
)
214190
}

‎packages/vscode/src/views/panel/frontend/Panel.tsx‎

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { ChatInitializedModal as UiChatInitializedModal } from '@ui/components/e
1313
import { CommitMessageModal as UiCommitMessageModal } from '@ui/components/editor/panel/modals/CommitMessageModal'
1414
import { StageFilesModal as UiStageFilesModal } from '@ui/components/editor/panel/modals/StageFilesModal'
1515
import { use_panel } from './hooks/use-panel'
16+
import { Button } from '@ui/components/editor/panel/Button'
17+
import { FileInPreview } from '@shared/types/file-in-preview'
1618
import { LayoutContext } from './contexts/LayoutContext'
1719
import { Layout } from './components/Layout/Layout'
1820

@@ -296,28 +298,53 @@ export const Panel = () => {
296298
on_back_click={() => {
297299
post_message(vscode, { command: 'EDITS_REVIEW', files: [] })
298300
}}
301+
footer_slot={
302+
<>
303+
<Button
304+
on_click={() => {
305+
set_response_history((prev) =>
306+
prev.filter(
307+
(i) =>
308+
i.created_at != selected_history_item_created_at
309+
)
310+
)
311+
set_selected_history_item_created_at(undefined)
312+
post_message(vscode, {
313+
command: 'EDITS_REVIEW',
314+
files: []
315+
})
316+
}}
317+
is_secondary
318+
>
319+
Discard
320+
</Button>
321+
<Button
322+
on_click={() => {
323+
const accepted_files = items_to_review.filter(
324+
(f) => 'file_path' in f && f.is_checked
325+
) as FileInPreview[]
326+
set_response_history([])
327+
set_selected_history_item_created_at(undefined)
328+
post_message(vscode, {
329+
command: 'EDITS_REVIEW',
330+
files: accepted_files
331+
})
332+
}}
333+
disabled={
334+
items_to_review.filter(
335+
(f) => 'file_path' in f && f.is_checked
336+
).length == 0
337+
}
338+
>
339+
Approve
340+
</Button>
341+
</>
342+
}
299343
>
300344
<UiResponsePreview
301345
items={items_to_review}
302346
raw_instructions={raw_instructions}
303347
has_multiple_workspaces={workspace_folder_count > 1}
304-
on_discard={() => {
305-
set_response_history((prev) =>
306-
prev.filter(
307-
(i) => i.created_at != selected_history_item_created_at
308-
)
309-
)
310-
set_selected_history_item_created_at(undefined)
311-
post_message(vscode, { command: 'EDITS_REVIEW', files: [] })
312-
}}
313-
on_approve={(accepted_files) => {
314-
set_response_history([])
315-
set_selected_history_item_created_at(undefined)
316-
post_message(vscode, {
317-
command: 'EDITS_REVIEW',
318-
files: accepted_files
319-
})
320-
}}
321348
on_focus_file={(file) => {
322349
post_message(vscode, {
323350
command: 'FOCUS_ON_FILE_IN_PREVIEW',

0 commit comments

Comments
 (0)