дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-21 17:10:45 +02:00
Порівняти коміти
2
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
e999838f69 | ||
|
|
a93437df2e |
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { expect, stubDesktop, test } from "./fixtures";
|
||||
|
||||
test("Shelf keeps patch and file selection available in a narrow dock", async ({ workbench: page }) => {
|
||||
const name = "Reconcile payment and settlement totals before exporting ledger reports";
|
||||
const directory = "services/settlement/internal/payment-reconciliation/statement-generation";
|
||||
const filename = "invoiceSettlementRowAssembler.ts";
|
||||
const file = directory + "/" + filename;
|
||||
await page.setViewportSize({ width: 1440, height: 760 });
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(
|
||||
async ({ name, file }) => {
|
||||
const root = "/dev/acme-api";
|
||||
const h = window.__ipc.handlers;
|
||||
h.vcs_roots = () => [{ root, operation: null, head: "main", headCommit: "1111111" }];
|
||||
h.vcs_branch_info = () => ({
|
||||
head: "main",
|
||||
headCommit: "1111111",
|
||||
upstream: null,
|
||||
ahead: 0,
|
||||
behind: 0,
|
||||
operation: null,
|
||||
});
|
||||
h.vcs_status = () => [];
|
||||
h.vcs_shelves = () => [
|
||||
{
|
||||
id: "settlement",
|
||||
name,
|
||||
timeMs: null,
|
||||
branch: "main",
|
||||
files: [file, "README.md"].map((path) => ({ path, kind: "modified", oldPath: null })),
|
||||
},
|
||||
{
|
||||
id: "docs",
|
||||
name: "Update release notes",
|
||||
timeMs: null,
|
||||
branch: "main",
|
||||
files: [{ path: "CHANGELOG.md", kind: "modified", oldPath: null }],
|
||||
},
|
||||
];
|
||||
h.vcs_shelf_diff = () => [];
|
||||
const vcs = "/src/features/vcs/store.ts";
|
||||
const { useVcs } = await import(/* @vite-ignore */ vcs);
|
||||
useVcs.setState({ root, repo: root, roots: [root], available: true });
|
||||
const project = "/src/platform/project.ts";
|
||||
const { useProject } = await import(/* @vite-ignore */ project);
|
||||
const settings = useProject.getState().settings ?? {};
|
||||
useProject.setState({ settings: { ...settings, vcs: { ...settings.vcs, commit: { nonModal: true } } } });
|
||||
const context = "/src/platform/context.ts";
|
||||
(await import(/* @vite-ignore */ context)).setContext("vcsAvailable", true);
|
||||
const dock = "/src/workbench/toolwindows/store.ts";
|
||||
(await import(/* @vite-ignore */ dock)).setToolWindowSize("left", 228);
|
||||
const actions = "/src/platform/actions.ts";
|
||||
await (await import(/* @vite-ignore */ actions)).executeAction("vcs.showShelf");
|
||||
},
|
||||
{ name, file },
|
||||
);
|
||||
|
||||
const panel = page.locator("[data-shelf-panel]");
|
||||
const patches = panel.getByRole("tree", { name: "Shelved changes" });
|
||||
const patch = patches.getByRole("treeitem").filter({ hasText: name });
|
||||
await patch.click({ position: { x: 90, y: 12 } });
|
||||
if ((await patch.getAttribute("aria-expanded")) === "false") await page.keyboard.press("ArrowRight");
|
||||
const location = panel.getByText(directory, { exact: true });
|
||||
await expect.poll(() => location.evaluate((el) => el.clientWidth)).toBeGreaterThan(100);
|
||||
|
||||
const divider = panel.getByRole("separator", { name: "Resize shelf panes" });
|
||||
await expect(divider).toHaveAttribute("aria-orientation", "horizontal");
|
||||
const files = panel.getByRole("tree", { name: "Shelved files" });
|
||||
await expect(files.getByRole("treeitem")).toHaveCount(2);
|
||||
const pathBox = (await location.boundingBox())!;
|
||||
const filesBox = (await files.boundingBox())!;
|
||||
expect(pathBox.x).toBeLessThan(filesBox.x + filesBox.width - 50);
|
||||
const row = files.getByRole("treeitem").filter({ hasText: filename });
|
||||
await row.click({ position: { x: 90, y: 12 } });
|
||||
await expect(row).toHaveAttribute("aria-selected", "true");
|
||||
await panel.getByRole("button", { name: "Unshelve…", exact: true }).click();
|
||||
const dialog = page.getByRole("dialog", { name: "Unshelve Changes" });
|
||||
await expect(
|
||||
dialog.getByRole("tree", { name: "Files to unshelve" }).getByText(filename, { exact: true }),
|
||||
).toBeVisible();
|
||||
await expect(dialog.getByText("README.md", { exact: true })).toHaveCount(0);
|
||||
await dialog.getByRole("button", { name: "Cancel", exact: true }).click();
|
||||
|
||||
await page.evaluate(async () => {
|
||||
const dock = "/src/workbench/toolwindows/store.ts";
|
||||
(await import(/* @vite-ignore */ dock)).setToolWindowSize("left", 640);
|
||||
});
|
||||
await expect(divider).toHaveAttribute("aria-orientation", "vertical");
|
||||
await expect(row).toHaveAttribute("aria-selected", "true");
|
||||
await patches.getByRole("treeitem").filter({ hasText: "Update release notes" }).click();
|
||||
await expect(files.getByRole("treeitem")).toHaveCount(1);
|
||||
await expect(files.getByText("CHANGELOG.md", { exact: true })).toBeVisible();
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
.split {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.patchName {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: var(--fg-strong);
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.fileText {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.filesHeader {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: var(--h-compact-header);
|
||||
padding-inline: var(--space-2);
|
||||
border-bottom: 1px solid var(--border);
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
.detail {
|
||||
flex: none;
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
.date {
|
||||
composes: detail;
|
||||
flex: 0 10000 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
@@ -240,12 +240,10 @@ describe("shelf scope and diffs", () => {
|
||||
</>,
|
||||
);
|
||||
await waitFor(() => expect(screen.getByText("Work")).toBeTruthy());
|
||||
fireEvent.doubleClick(screen.getByText("Work"));
|
||||
// Expand explicitly through the accessible tree keyboard navigation.
|
||||
const tree = screen.getByRole("tree");
|
||||
fireEvent.keyDown(tree, { key: "ArrowRight" });
|
||||
fireEvent.mouseDown(screen.getByText("Work"), { button: 0 });
|
||||
expect(useCommit.getState().selectedShelf).toBe("work");
|
||||
const file = await screen.findByText("a.txt");
|
||||
fireEvent.click(file);
|
||||
fireEvent.mouseDown(file, { button: 0 });
|
||||
expect(useCommit.getState().selectedShelf).toBe("work\u0000a.txt");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Unshelve…" }));
|
||||
expect(mocks.execute).toHaveBeenCalledWith("vcs.unshelve", { id: "work", path: "a.txt" });
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* merge UI), rename and delete.
|
||||
*/
|
||||
import { writeClipboardText } from "@/platform/clipboard";
|
||||
import { useEffect, useMemo, useState, type MouseEvent } from "react";
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type MouseEvent } from "react";
|
||||
import { create } from "zustand";
|
||||
import type {
|
||||
ApplyOutcome,
|
||||
@@ -21,7 +21,21 @@ import { showCreatePatchForShelf } from "./patches";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { workflowSettings } from "@/platform/workflowSettings";
|
||||
import { Checkbox, Dialog, Icon, IconButton, Input, Select, Tree, fileIconName, showContextMenu, T } from "@/ui";
|
||||
import {
|
||||
Checkbox,
|
||||
Dialog,
|
||||
Icon,
|
||||
IconButton,
|
||||
Input,
|
||||
Select,
|
||||
SplitGroup,
|
||||
SplitHandle,
|
||||
SplitPanel,
|
||||
Tree,
|
||||
fileIconName,
|
||||
showContextMenu,
|
||||
T,
|
||||
} from "@/ui";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { groupOf } from "./changes";
|
||||
import { buildFileTree, dirKeys, type FileTreeNode } from "./fileTree";
|
||||
@@ -45,6 +59,7 @@ import { conflictedFiles, currentRepo, refreshNow, useVcs } from "./store";
|
||||
import { repositoryPath } from "./repositoryPaths";
|
||||
import styles from "./common.module.css";
|
||||
import viewStyles from "./CommitView.module.css";
|
||||
import shelfStyles from "./Shelf.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
|
||||
interface ShelfState {
|
||||
@@ -473,7 +488,6 @@ interface ShelfNode {
|
||||
key: string;
|
||||
entry: ShelvedChangeList;
|
||||
file?: ShelvedChangeList["files"][number];
|
||||
children?: ShelfNode[];
|
||||
}
|
||||
|
||||
export interface ShelfTarget {
|
||||
@@ -600,31 +614,130 @@ export function createShelfPatch(arg?: unknown) {
|
||||
if (target) showCreatePatchForShelf(target.entry, target.path);
|
||||
}
|
||||
|
||||
function ShelfTree({
|
||||
nodes,
|
||||
kind,
|
||||
selectedKey,
|
||||
empty,
|
||||
}: {
|
||||
nodes: ShelfNode[];
|
||||
kind: "changes" | "files";
|
||||
selectedKey: string | null;
|
||||
empty: string;
|
||||
}) {
|
||||
const selected = useMemo(() => new Set(selectedKey ? [selectedKey] : []), [selectedKey]);
|
||||
const filePane = kind === "files";
|
||||
return (
|
||||
<Tree<ShelfNode>
|
||||
roots={nodes}
|
||||
getKey={(n) => n.key}
|
||||
getLabel={(n) => (n.file ? baseName(n.file.path) : n.entry.name)}
|
||||
getChildren={() => undefined}
|
||||
isExpandable={() => false}
|
||||
selected={selected}
|
||||
onSelectionChange={(sel) => useCommit.setState({ selectedShelf: [...sel][0] ?? null })}
|
||||
horizontalScroll={filePane}
|
||||
rowHeight={filePane ? 40 : undefined}
|
||||
multiSelect={false}
|
||||
onActivate={(n) => {
|
||||
void executeAction(n.file ? "vcs.shelf.showDiff" : "vcs.unshelve", { id: n.entry.id, path: n.file?.path });
|
||||
}}
|
||||
onContextMenu={(node, _sel, e: MouseEvent) => {
|
||||
if (!node) return;
|
||||
e.preventDefault();
|
||||
useCommit.setState({ selectedShelf: node.key });
|
||||
const point = { x: e.clientX, y: e.clientY };
|
||||
const target = { id: node.entry.id, path: node.file?.path };
|
||||
void Promise.all(
|
||||
shelfDiffs(target, true).map(async (d) => {
|
||||
try {
|
||||
return !(await call(commands.fsProbe(d.path))).binary;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
).then((supported) => showContextMenu(point, shelfMenu(node, supported.some(Boolean))));
|
||||
}}
|
||||
aria-label={filePane ? "Shelved files" : "Shelved changes"}
|
||||
empty={<span className={viewStyles.empty}>{tx(empty)}</span>}
|
||||
renderNode={(n) => {
|
||||
const file = n.file;
|
||||
if (file) {
|
||||
const directory = dirName(file.path);
|
||||
return (
|
||||
<>
|
||||
<Icon name={fileIconName(baseName(file.path), file.path)} size={16} className={viewStyles.icon} />
|
||||
<span className={shelfStyles.fileText} title={file.path}>
|
||||
<span style={{ color: KIND_COLOR[file.kind === "untracked" ? "added" : file.kind] }}>
|
||||
{baseName(file.path)}
|
||||
</span>
|
||||
{directory && <span className={shelfStyles.detail}>{directory}</span>}
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
const time = n.entry.timeMs ? formatTime(n.entry.timeMs) : null;
|
||||
return (
|
||||
<>
|
||||
<Icon name="shelve" size={16} className={viewStyles.icon} />
|
||||
<span className={shelfStyles.patchName} title={n.entry.name}>
|
||||
{n.entry.name}
|
||||
</span>
|
||||
<span className={shelfStyles.detail}>{fileCount(n.entry.files.length)}</span>
|
||||
{time && (
|
||||
<span className={shelfStyles.date} title={time}>
|
||||
{time}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** The Shelf tab of the Commit tool window. */
|
||||
export function ShelfPanel() {
|
||||
const shelves = useShelf((s) => s.shelves);
|
||||
const loaded = useShelf((s) => s.loaded);
|
||||
const root = useVcs((s) => s.root);
|
||||
useShelf((s) => s.diffs);
|
||||
const selectedShelf = useCommit((s) => s.selectedShelf);
|
||||
const selected = useMemo(() => new Set(selectedShelf ? [selectedShelf] : []), [selectedShelf]);
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const [stacked, setStacked] = useState(true);
|
||||
useLayoutEffect(() => {
|
||||
const panel = panelRef.current;
|
||||
if (!panel) return;
|
||||
const measure = () => setStacked(panel.clientWidth < 560);
|
||||
measure();
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(panel);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
void loadShelves().catch(() => undefined);
|
||||
return () => setContext("shelfFocus", false);
|
||||
}, [root]);
|
||||
const roots = useMemo<ShelfNode[]>(
|
||||
() =>
|
||||
shelves.map((entry) => ({
|
||||
key: entry.id,
|
||||
entry,
|
||||
children: entry.files.map((file) => ({ key: `${entry.id}\u0000${file.path}`, entry, file })),
|
||||
})),
|
||||
[shelves],
|
||||
const selectedId = selectedShelf?.split("\u0000", 1)[0];
|
||||
const entry = shelves.find((s) => s.id === selectedId);
|
||||
const patches = useMemo<ShelfNode[]>(() => shelves.map((s) => ({ key: s.id, entry: s })), [shelves]);
|
||||
const files = useMemo<ShelfNode[]>(
|
||||
() => entry?.files.map((file) => ({ key: `${entry.id}\u0000${file.path}`, entry, file })) ?? [],
|
||||
[entry],
|
||||
);
|
||||
const current = selectedShelf ? shelfTarget(selectedShelf) : null;
|
||||
const patchTree = (
|
||||
<ShelfTree
|
||||
nodes={patches}
|
||||
kind="changes"
|
||||
selectedKey={entry?.id ?? null}
|
||||
empty={loaded ? "No shelved changes" : "Loading…"}
|
||||
/>
|
||||
);
|
||||
const current = shelfTarget([...selected][0]);
|
||||
return (
|
||||
<div
|
||||
className={viewStyles.changes}
|
||||
ref={panelRef}
|
||||
data-shelf-panel
|
||||
onFocusCapture={() => setContext("shelfFocus", true)}
|
||||
onBlurCapture={(e) => {
|
||||
@@ -652,64 +765,32 @@ export function ShelfPanel() {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className={viewStyles.treeWrap}>
|
||||
<Tree<ShelfNode>
|
||||
roots={roots}
|
||||
getKey={(n) => n.key}
|
||||
getLabel={(n) => (n.file ? baseName(n.file.path) : n.entry.name)}
|
||||
getChildren={(n) => n.children}
|
||||
isExpandable={(n) => !n.file}
|
||||
selected={selected}
|
||||
onSelectionChange={(sel) => {
|
||||
const key = [...sel][0];
|
||||
useCommit.setState({ selectedShelf: key ?? null });
|
||||
}}
|
||||
multiSelect={false}
|
||||
onActivate={(n) => {
|
||||
void executeAction(n.file ? "vcs.shelf.showDiff" : "vcs.unshelve", { id: n.entry.id, path: n.file?.path });
|
||||
}}
|
||||
onContextMenu={(node, _sel, e: MouseEvent) => {
|
||||
if (!node) return;
|
||||
e.preventDefault();
|
||||
const point = { x: e.clientX, y: e.clientY };
|
||||
const target = { id: node.entry.id, path: node.file?.path };
|
||||
void Promise.all(
|
||||
shelfDiffs(target, true).map(async (d) => {
|
||||
try {
|
||||
return !(await call(commands.fsProbe(d.path))).binary;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
).then((supported) => showContextMenu(point, shelfMenu(node, supported.some(Boolean))));
|
||||
}}
|
||||
aria-label="Shelved changes"
|
||||
empty={<span className={viewStyles.empty}>{loaded ? tx("No shelved changes") : tx("Loading…")}</span>}
|
||||
renderNode={(n) =>
|
||||
n.file ? (
|
||||
<>
|
||||
<Icon name={fileIconName(baseName(n.file.path), n.file.path)} size={16} className={viewStyles.icon} />
|
||||
<span
|
||||
className={viewStyles.label}
|
||||
style={{ color: KIND_COLOR[n.file.kind === "untracked" ? "added" : n.file.kind] }}
|
||||
>
|
||||
{baseName(n.file.path)}
|
||||
</span>
|
||||
<span className={viewStyles.detail}>{dirName(n.file.path)}</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon name="shelve" size={16} className={viewStyles.icon} />
|
||||
<span className={viewStyles.label}>{n.entry.name}</span>
|
||||
<span className={viewStyles.detail}>
|
||||
{fileCount(n.entry.files.length)}
|
||||
{n.entry.timeMs ? ` · ${formatTime(n.entry.timeMs)}` : ""}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{patches.length ? (
|
||||
<SplitGroup
|
||||
id="shelf-panes"
|
||||
className={shelfStyles.split}
|
||||
orientation={stacked ? "vertical" : "horizontal"}
|
||||
storageKey={`openidea.vcs.shelf.layout.${stacked ? "stacked" : "sideBySide"}`}
|
||||
>
|
||||
<SplitPanel id="shelf-changes" defaultSize="50%" minSize="25%">
|
||||
{patchTree}
|
||||
</SplitPanel>
|
||||
<SplitHandle aria-label={tx("Resize shelf panes")} />
|
||||
<SplitPanel id="shelf-files" defaultSize="50%" minSize="25%">
|
||||
<div className={shelfStyles.filesHeader}>
|
||||
<T>Shelved files</T>
|
||||
</div>
|
||||
<ShelfTree
|
||||
nodes={files}
|
||||
kind="files"
|
||||
selectedKey={current?.path ? selectedShelf : null}
|
||||
empty={entry ? "No files" : "Select a shelf to view its files"}
|
||||
/>
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
) : (
|
||||
<div className={viewStyles.treeWrap}>{patchTree}</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2697,6 +2697,10 @@
|
||||
"Resize rebase panes": "Resize rebase panes",
|
||||
"New message for {id}": "New message for {id}",
|
||||
"Resize right merge pane": "Resize right merge pane",
|
||||
"Resize shelf panes": "Resize shelf panes",
|
||||
"Shelved files": "Shelved files",
|
||||
"Select a shelf to view its files": "Select a shelf to view its files",
|
||||
"No files": "No files",
|
||||
"Database and schema": "Database and schema",
|
||||
"Loading…": "Loading…",
|
||||
"<schema>": "<schema>",
|
||||
|
||||
@@ -2755,6 +2755,9 @@
|
||||
"Shelve Changes": "搁置更改",
|
||||
"Shelve Changes…": "搁置更改…",
|
||||
"Shelved changes": "已搁置的更改",
|
||||
"Shelved files": "已搁置的文件",
|
||||
"Select a shelf to view its files": "选择一条搁置记录以查看文件",
|
||||
"No files": "没有文件",
|
||||
"Show": "显示",
|
||||
"Show \"Today\", \"Yesterday\" and \"N min ago\" for recent dates": "对最近的日期显示“今天”、“昨天”和“N 分钟前”",
|
||||
"Show All": "全部显示",
|
||||
@@ -9066,6 +9069,7 @@
|
||||
"Resize left merge pane": "调整左侧合并窗格宽度",
|
||||
"Resize rebase panes": "调整变基计划和详细信息窗格大小",
|
||||
"Resize right merge pane": "调整右侧合并窗格宽度",
|
||||
"Resize shelf panes": "调整搁置记录和文件窗格大小",
|
||||
"Database and schema": "数据库和 schema",
|
||||
"Shelve Silently": "静默搁置",
|
||||
"Unshelve Silently": "静默取消搁置"
|
||||
|
||||
Reference in new issue
Заблокувати користувача