fix(web): keep grouped project renames (#7831)
This commit is contained in:
1 parent
5d76653960
commit
e67074f809
3 files changed
+49
-5
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { projectGroupTitleNeedsUpdate } from "./ProjectSettingsPanel.logic";
|
||||
|
||||
describe("projectGroupTitleNeedsUpdate", () => {
|
||||
it("updates divergent member titles even when the next title is the derived group label", () => {
|
||||
expect(
|
||||
projectGroupTitleNeedsUpdate(["local-title", "remote-title"], "Repository name", true),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("skips an untouched blur when the derived label differs from member titles", () => {
|
||||
expect(projectGroupTitleNeedsUpdate(["repo-slug", "repo-slug"], "Repository Name", false)).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("skips an update when every member already has the next title", () => {
|
||||
expect(projectGroupTitleNeedsUpdate(["Shared name", "Shared name"], "Shared name", true)).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
export function projectGroupTitleNeedsUpdate(
|
||||
memberTitles: ReadonlyArray<string>,
|
||||
nextTitle: string,
|
||||
wasEdited: boolean,
|
||||
): boolean {
|
||||
return wasEdited && memberTitles.some((title) => title !== nextTitle);
|
||||
}
|
||||
@@ -113,6 +113,7 @@ import {
|
||||
canPickExternalProjectFavicon,
|
||||
ProjectFaviconPickerDialog,
|
||||
} from "./ProjectFaviconPickerDialog";
|
||||
import { projectGroupTitleNeedsUpdate } from "./ProjectSettingsPanel.logic";
|
||||
|
||||
export const PROJECT_GROUPING_MODE_LABELS: Record<SidebarProjectGroupingMode, string> = {
|
||||
repository: "Group by repository",
|
||||
@@ -304,6 +305,7 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
|
||||
const removeKeybinding = useAtomCommand(serverEnvironment.removeKeybinding, {
|
||||
reportFailure: false,
|
||||
});
|
||||
const projectNameEditedRef = useRef(false);
|
||||
const { copyToClipboard: copyPathToClipboard } = useCopyToClipboard<{ path: string }>({
|
||||
onCopy: ({ path }) => {
|
||||
toastManager.add({ type: "success", title: "Path copied", description: path });
|
||||
@@ -392,17 +394,24 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
|
||||
);
|
||||
|
||||
const renameGroup = useCallback(
|
||||
async (nextTitle: string) => {
|
||||
async (nextTitle: string, wasEdited: boolean) => {
|
||||
const title = nextTitle.trim();
|
||||
if (!title) {
|
||||
toastManager.add({ type: "warning", title: "Project title cannot be empty" });
|
||||
return;
|
||||
}
|
||||
if (title === group.displayName) return;
|
||||
if (group.memberProjects.every((member) => member.title === title)) return;
|
||||
if (
|
||||
!projectGroupTitleNeedsUpdate(
|
||||
group.memberProjects.map((member) => member.title),
|
||||
title,
|
||||
wasEdited,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await updateAllMembers({ title }, "Failed to rename project");
|
||||
},
|
||||
[group.displayName, group.memberProjects, updateAllMembers],
|
||||
[group.memberProjects, updateAllMembers],
|
||||
);
|
||||
|
||||
// ----- default model -----
|
||||
@@ -767,8 +776,13 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
|
||||
className="w-full sm:w-64"
|
||||
aria-label="Project name"
|
||||
defaultValue={group.displayName}
|
||||
onChange={() => {
|
||||
projectNameEditedRef.current = true;
|
||||
}}
|
||||
onBlur={(event) => {
|
||||
void renameGroup(event.currentTarget.value);
|
||||
const wasEdited = projectNameEditedRef.current;
|
||||
projectNameEditedRef.current = false;
|
||||
void renameGroup(event.currentTarget.value, wasEdited);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") event.currentTarget.blur();
|
||||
|
||||
Reference in new issue
Block a user