Skip to content

Commit 9c153b1

Browse files
committed
Close the diff viewer for discarded changes
1 parent fd68e85 commit 9c153b1

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

apps/array/src/renderer/features/panels/store/panelLayoutStore.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
createDiffTabId,
1313
createFileTabId,
1414
generatePanelId,
15+
getDiffTabIdsForFile,
1516
getLeafPanel,
1617
getSplitConfig,
1718
selectNextTabAfterClose,
@@ -55,6 +56,7 @@ export interface PanelLayoutStore {
5556
closeOtherTabs: (taskId: string, panelId: string, tabId: string) => void;
5657
closeTabsToRight: (taskId: string, panelId: string, tabId: string) => void;
5758
closeTabsForFile: (taskId: string, filePath: string) => void;
59+
closeDiffTabsForFile: (taskId: string, filePath: string) => void;
5860
setActiveTab: (taskId: string, panelId: string, tabId: string) => void;
5961
setDraggingTab: (
6062
taskId: string,
@@ -428,12 +430,7 @@ export const usePanelLayoutStore = createWithEqualityFn<PanelLayoutStore>()(
428430

429431
const tabIds = [
430432
createFileTabId(filePath),
431-
createDiffTabId(filePath),
432-
createDiffTabId(filePath, "modified"),
433-
createDiffTabId(filePath, "deleted"),
434-
createDiffTabId(filePath, "added"),
435-
createDiffTabId(filePath, "untracked"),
436-
createDiffTabId(filePath, "renamed"),
433+
...getDiffTabIdsForFile(filePath),
437434
];
438435

439436
for (const tabId of tabIds) {
@@ -444,6 +441,20 @@ export const usePanelLayoutStore = createWithEqualityFn<PanelLayoutStore>()(
444441
}
445442
},
446443

444+
closeDiffTabsForFile: (taskId, filePath) => {
445+
const layout = get().taskLayouts[taskId];
446+
if (!layout) return;
447+
448+
const tabIds = getDiffTabIdsForFile(filePath);
449+
450+
for (const tabId of tabIds) {
451+
const tabLocation = findTabInTree(layout.panelTree, tabId);
452+
if (tabLocation) {
453+
get().closeTab(taskId, tabLocation.panelId, tabId);
454+
}
455+
}
456+
},
457+
447458
setActiveTab: (taskId, panelId, tabId) => {
448459
set((state) =>
449460
updateTaskLayout(state, taskId, (layout) => {

apps/array/src/renderer/features/panels/store/panelStoreHelpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ export function createDiffTabId(filePath: string, status?: string): string {
2929
return `diff-${filePath}`;
3030
}
3131

32+
export function getDiffTabIdsForFile(filePath: string): string[] {
33+
return [
34+
createDiffTabId(filePath),
35+
createDiffTabId(filePath, "modified"),
36+
createDiffTabId(filePath, "deleted"),
37+
createDiffTabId(filePath, "added"),
38+
createDiffTabId(filePath, "untracked"),
39+
createDiffTabId(filePath, "renamed"),
40+
];
41+
}
42+
3243
export function parseTabId(tabId: string): ParsedTabId & { status?: string } {
3344
if (tabId.startsWith("file-")) {
3445
return { type: "file", value: tabId.slice(5) };

apps/array/src/renderer/features/task-detail/components/ChangesPanel.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ function ChangedFileItem({
8888
isActive,
8989
}: ChangedFileItemProps) {
9090
const openDiff = usePanelLayoutStore((state) => state.openDiff);
91+
const closeDiffTabsForFile = usePanelLayoutStore(
92+
(state) => state.closeDiffTabsForFile,
93+
);
9194
const queryClient = useQueryClient();
9295
const fileName = file.path.split("/").pop() || file.path;
9396
const indicator = getStatusIndicator(file.status);
@@ -107,7 +110,7 @@ function ChangedFileItem({
107110
};
108111

109112
const handleDiscard = async (e: React.MouseEvent) => {
110-
e.stopPropagation();
113+
e.preventDefault();
111114

112115
const { message, action } = getDiscardInfo(file, fileName);
113116

@@ -128,7 +131,9 @@ function ChangedFileItem({
128131
file.path,
129132
file.status,
130133
);
131-
// Invalidate the changed files query to refresh the list
134+
135+
closeDiffTabsForFile(taskId, file.path);
136+
132137
queryClient.invalidateQueries({
133138
queryKey: ["changed-files-head", repoPath],
134139
});

0 commit comments

Comments
 (0)