Skip to content

Commit 24020a7

Browse files
committed
Refactor file navigation functionality into a unified GO_TO_FILE message and implement file path display and navigation actions within the StageFilesModal component
1 parent 26e687e commit 24020a7

8 files changed

Lines changed: 54 additions & 18 deletions

File tree

‎packages/ui/src/components/editor/panel/modals/StageFilesModal/StageFilesModal.module.scss‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
.files {
22
display: flex;
33
flex-direction: column;
4-
gap: var(--padding-4px);
4+
margin: 0 -12px;
55

66
&__item {
77
display: flex;
88
align-items: center;
99
gap: var(--padding-6px);
1010
cursor: pointer;
11+
padding: 0 12px;
12+
height: var(--list-item-height);
13+
14+
&:hover {
15+
background-color: var(--vscode-list-hoverBackground);
16+
17+
.files__item__actions {
18+
display: flex;
19+
}
20+
}
1121

1222
&__details {
23+
flex: 1;
1324
overflow: hidden;
1425
white-space: nowrap;
1526
text-overflow: ellipsis;
@@ -24,5 +35,9 @@
2435
font-size: var(--font-size-12px);
2536
color: var(--vscode-descriptionForeground);
2637
}
38+
39+
&__actions {
40+
display: none;
41+
}
2742
}
2843
}

‎packages/ui/src/components/editor/panel/modals/StageFilesModal/StageFilesModal.stories.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ export const Default = () => {
2525
set_visible(false)
2626
}
2727

28+
const handle_go_to_file = (file: string) => {
29+
alert(`Go to file: ${file}`)
30+
}
31+
2832
return visible ? (
2933
<StageFilesModal
3034
files={mock_files}
3135
on_stage={handle_stage}
3236
on_cancel={handle_cancel}
37+
on_go_to_file={handle_go_to_file}
3338
/>
3439
) : null
3540
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import styles from './StageFilesModal.module.scss'
33
import { Button } from '../../Button'
44
import { Modal } from '../Modal'
55
import { Checkbox } from '../../../common/Checkbox'
6+
import { IconButton } from '../../IconButton/IconButton'
67

78
type Props = {
89
files: string[]
910
on_stage: (files_to_stage: string[]) => void
1011
on_cancel: () => void
12+
on_go_to_file: (file: string) => void
1113
}
1214

1315
export const StageFilesModal: React.FC<Props> = (props) => {
@@ -74,6 +76,16 @@ export const StageFilesModal: React.FC<Props> = (props) => {
7476
<span className={styles.files__item__path}>{dir_path}</span>
7577
)}
7678
</div>
79+
<div className={styles.files__item__actions}>
80+
<IconButton
81+
codicon_icon="go-to-file"
82+
title="Go To File"
83+
on_click={(e) => {
84+
e.stopPropagation()
85+
props.on_go_to_file(file)
86+
}}
87+
/>
88+
</div>
7789
</label>
7890
)
7991
})}

packages/vscode/src/views/panel/backend/message-handlers/handle-go-to-file-in-review.ts renamed to packages/vscode/src/views/panel/backend/message-handlers/handle-go-to-file.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import * as vscode from 'vscode'
2-
import { PanelProvider } from '@/views/panel/backend/panel-provider'
3-
import { GoToFileInReviewMessage } from '@/views/panel/types/messages'
2+
import { GoToFileMessage } from '@/views/panel/types/messages'
43
import { Logger } from '@shared/utils/logger'
54
import { dictionary } from '@shared/constants/dictionary'
65

7-
export const handle_go_to_file_in_review = async (
8-
provider: PanelProvider,
9-
message: GoToFileInReviewMessage
6+
export const handle_go_to_file = async (
7+
message: GoToFileMessage
108
): Promise<void> => {
119
const { file_path, workspace_name } = message
1210
const workspace_folders = vscode.workspace.workspaceFolders
1311
if (!workspace_folders) {
1412
Logger.warn({
15-
function_name: 'handle_go_to_file_in_review',
13+
function_name: 'handle_go_to_file',
1614
message: 'No workspace folders open'
1715
})
1816
return
@@ -22,7 +20,7 @@ export const handle_go_to_file_in_review = async (
2220

2321
if (workspace_name) {
2422
target_workspace = workspace_folders.find(
25-
(folder) => folder.name === workspace_name
23+
(folder) => folder.name == workspace_name
2624
)
2725
} else if (workspace_folders.length === 1) {
2826
target_workspace = workspace_folders[0]
@@ -41,7 +39,7 @@ export const handle_go_to_file_in_review = async (
4139

4240
if (!target_workspace) {
4341
Logger.error({
44-
function_name: 'handle_go_to_file_in_review',
42+
function_name: 'handle_go_to_file',
4543
message: `Workspace not found for file: ${file_path}`,
4644
data: { file_path, workspace_name }
4745
})
@@ -58,7 +56,7 @@ export const handle_go_to_file_in_review = async (
5856
await vscode.window.showTextDocument(document, { preview: false })
5957
} catch (error) {
6058
Logger.error({
61-
function_name: 'handle_go_to_file_in_review',
59+
function_name: 'handle_go_to_file',
6260
message: `Could not open file: ${file_path}`,
6361
data: { error, file_uri: file_uri.toString() }
6462
})

‎packages/vscode/src/views/panel/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export * from './handle-reorder-api-tool-configurations'
3636
export * from './handle-get-donations-visibility'
3737
export * from './handle-save-donations-visibility'
3838
export * from './handle-focus-on-file-in-review'
39-
export * from './handle-go-to-file-in-review'
39+
export * from './handle-go-to-file'
4040
export * from './handle-toggle-file-in-review'
4141
export * from './handle-intelligent-update-file-in-review'
4242
export * from './handle-commit-changes/handle-commit-changes'

‎packages/vscode/src/views/panel/backend/panel-provider.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
handle_get_donations_visibility,
4646
handle_save_donations_visibility,
4747
handle_focus_on_file_in_review,
48-
handle_go_to_file_in_review,
48+
handle_go_to_file,
4949
handle_toggle_file_in_review,
5050
handle_intelligent_update_file_in_review,
5151
handle_commit_changes,
@@ -442,10 +442,10 @@ export class PanelProvider implements vscode.WebviewViewProvider {
442442
handle_get_donations_visibility(this)
443443
} else if (message.command == 'SAVE_DONATIONS_VISIBILITY') {
444444
await handle_save_donations_visibility(this, message)
445+
} else if (message.command == 'GO_TO_FILE') {
446+
handle_go_to_file(message)
445447
} else if (message.command == 'FOCUS_ON_FILE_IN_REVIEW') {
446448
handle_focus_on_file_in_review(this, message)
447-
} else if (message.command == 'GO_TO_FILE_IN_REVIEW') {
448-
handle_go_to_file_in_review(this, message)
449449
} else if (message.command == 'TOGGLE_FILE_IN_REVIEW') {
450450
await handle_toggle_file_in_review(this, message)
451451
} else if (message.command == 'INTELLIGENT_UPDATE_FILE_IN_REVIEW') {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export const Panel = () => {
281281
}}
282282
on_go_to_file={(file) => {
283283
post_message(vscode, {
284-
command: 'GO_TO_FILE_IN_REVIEW',
284+
command: 'GO_TO_FILE',
285285
file_path: file.file_path,
286286
workspace_name: file.workspace_name
287287
})
@@ -357,6 +357,12 @@ export const Panel = () => {
357357
set_files_to_stage(undefined)
358358
set_commit_button_enabling_trigger_count((k) => k + 1)
359359
}}
360+
on_go_to_file={(file) => {
361+
post_message(vscode, {
362+
command: 'GO_TO_FILE',
363+
file_path: file
364+
})
365+
}}
360366
/>
361367
</div>
362368
)}

‎packages/vscode/src/views/panel/types/messages.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ export interface FocusOnFileInReviewMessage extends BaseMessage {
252252
workspace_name?: string
253253
}
254254

255-
export interface GoToFileInReviewMessage extends BaseMessage {
256-
command: 'GO_TO_FILE_IN_REVIEW'
255+
export interface GoToFileMessage extends BaseMessage {
256+
command: 'GO_TO_FILE'
257257
file_path: string
258258
workspace_name?: string
259259
}
@@ -367,7 +367,7 @@ export type FrontendMessage =
367367
| EditsReviewMessage
368368
| ToggleFileInReviewMessage
369369
| FocusOnFileInReviewMessage
370-
| GoToFileInReviewMessage
370+
| GoToFileMessage
371371
| GetWorkspaceStateMessage
372372
| RequestGitStateMessage
373373
| IntelligentUpdateFileInReviewMessage

0 commit comments

Comments
 (0)