Skip to content

Commit 89ad4f7

Browse files
committed
Refactor the response preview mechanism to support displaying both file changes and arbitrary text items
1 parent 29b8058 commit 89ad4f7

13 files changed

Lines changed: 313 additions & 437 deletions

File tree

‎packages/shared/src/types/file-in-preview.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ export type FileInPreview = {
1111
diff_fallback_method?: 'recount' | 'search_and_replace'
1212
content?: string
1313
}
14+
15+
export type TextContentInPreview = {
16+
type: 'text'
17+
content: string
18+
}
19+
20+
export type ItemInPreview = FileInPreview | TextContentInPreview

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
}
4444
}
4545

46+
.textItem {
47+
padding: var(--padding-5px) var(--padding-12px);
48+
margin: 0 var(--padding-12px) var(--padding-8px) var(--padding-12px);
49+
color: var(--vscode-descriptionForeground);
50+
white-space: pre-wrap;
51+
word-wrap: break-word;
52+
border: 1px solid var(--vscode-sideBarSectionHeader-border);
53+
border-radius: var(--border-radius-5px);
54+
}
55+
4656
.list {
4757
padding: 0 var(--spacing-s);
4858
}

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from 'react'
22
import { ResponsePreview } from './ResponsePreview'
3+
import { ItemInPreview } from '@shared/types/file-in-preview'
34

45
export default {
56
component: ResponsePreview
@@ -59,8 +60,10 @@ const log_action =
5960
}
6061

6162
const InteractiveResponsePreview = (props: any) => {
62-
const [files, set_files] = useState(
63-
props.files.map((f: any) => ({ ...f, is_checked: true }))
63+
const [items, set_items] = useState(
64+
props.items.map((f: any) =>
65+
'file_path' in f ? { ...f, is_checked: true } : f
66+
)
6467
)
6568

6669
const handle_toggle_file = ({
@@ -72,9 +75,11 @@ const InteractiveResponsePreview = (props: any) => {
7275
workspace_name?: string
7376
is_checked: boolean
7477
}) => {
75-
set_files(
76-
files.map((f: any) =>
77-
f.file_path === file_path && f.workspace_name === workspace_name
78+
set_items(
79+
items.map((f: any) =>
80+
'file_path' in f &&
81+
f.file_path === file_path &&
82+
f.workspace_name === workspace_name
7883
? { ...f, is_checked }
7984
: f
8085
)
@@ -85,7 +90,7 @@ const InteractiveResponsePreview = (props: any) => {
8590
return (
8691
<ResponsePreview
8792
{...props}
88-
files={files}
93+
items={items}
8994
on_toggle_file={handle_toggle_file}
9095
on_discard={log_action('on_undo')}
9196
on_approve={log_action('on_keep')}
@@ -96,21 +101,21 @@ const InteractiveResponsePreview = (props: any) => {
96101
)
97102
}
98103

99-
export const Default = () => <InteractiveResponsePreview files={base_files} />
104+
export const Default = () => <InteractiveResponsePreview items={base_files} />
100105

101106
export const WithSingleFile = () => (
102-
<InteractiveResponsePreview files={[base_files[0]]} />
107+
<InteractiveResponsePreview items={[base_files[0]]} />
103108
)
104109

105110
export const WithFallbacks = () => (
106111
<InteractiveResponsePreview
107-
files={[...base_files, ...files_using_fallbacks]}
112+
items={[...base_files, ...files_using_fallbacks]}
108113
/>
109114
)
110115

111116
export const WithMultipleWorkspaces = () => (
112117
<InteractiveResponsePreview
113-
files={[
118+
items={[
114119
{
115120
...base_files[0],
116121
workspace_name: 'project-a'
@@ -127,3 +132,17 @@ export const WithMultipleWorkspaces = () => (
127132
has_multiple_workspaces={true}
128133
/>
129134
)
135+
136+
export const WithText = () => (
137+
<InteractiveResponsePreview
138+
items={[
139+
{ type: 'text', content: 'This is a text item.' },
140+
...base_files,
141+
{
142+
type: 'text',
143+
content: 'Another text item explaining something.'
144+
},
145+
...files_using_fallbacks
146+
]}
147+
/>
148+
)

0 commit comments

Comments
 (0)