Skip to content

Commit 15d4ef3

Browse files
committed
Refactor the ResponsePreview component to remove the redundant "Open Changes" button and initialize the selected file index correctly
1 parent 1fb388a commit 15d4ef3

3 files changed

Lines changed: 14 additions & 19 deletions

File tree

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ type Props = {
2525
}
2626

2727
export const ResponsePreview: FC<Props> = (props) => {
28-
const [last_clicked_file_index, set_last_clicked_file_index] = useState(0)
28+
const [last_clicked_file_index, set_last_clicked_file_index] = useState(
29+
props.items.findIndex((i) => i.type == 'file')
30+
)
2931
const [expanded_text_items, set_expanded_text_items] = useState<Set<number>>(
3032
new Set()
3133
)
@@ -201,18 +203,6 @@ export const ResponsePreview: FC<Props> = (props) => {
201203
}}
202204
/>
203205
)}
204-
<IconButton
205-
codicon_icon="diff-single"
206-
title="Open Changes"
207-
on_click={(e) => {
208-
e.stopPropagation()
209-
set_last_clicked_file_index(index)
210-
props.on_focus_file({
211-
file_path: file.file_path,
212-
workspace_name: file.workspace_name
213-
})
214-
}}
215-
/>
216206
<IconButton
217207
codicon_icon="go-to-file"
218208
title="Go To File"

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
padding: 2px 4px;
2323
border-radius: 3px;
2424
}
25+
26+
pre {
27+
display: flex;
28+
overflow: auto;
29+
}
2530
}
2631

2732
.hidden {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export const TextItem: FC<Props> = ({ content, is_expanded, on_toggle }) => {
2323
<ReactMarkdown disallowedElements={['hr']}>{content}</ReactMarkdown>
2424
</div>
2525
) : (
26-
<div ref={ref} className={styles.hidden}>
26+
<div
27+
ref={ref}
28+
className={styles.hidden}
29+
onClick={() => ref.current && on_toggle(ref.current)}
30+
>
2731
<div className={styles.line} />
28-
<IconButton
29-
codicon_icon="list-flat"
30-
on_click={() => ref.current && on_toggle(ref.current)}
31-
title="Show text"
32-
/>
32+
<IconButton codicon_icon="list-selection" title="Show text" />
3333
<div className={styles.line} />
3434
</div>
3535
)}

0 commit comments

Comments
 (0)