From 913c8e5f69107f2f725b1a9cdb591e5801c0a4ec Mon Sep 17 00:00:00 2001 From: aliu65803 Date: Fri, 13 Nov 2026 13:27:47 -0600 Subject: [PATCH 1/3] Create a new graph when duplicating instead of renaming the original Duplicate now uses the create path (force_rename=false), so saving an unchanged definition returns the backend's already-exists error. Co-Authored-By: Claude Opus 5.5 --- ui/src/pages/Graphs/NewGraph/NewGraph.tsx | 12 +++--------- .../pages/Graphs/__tests__/DuplicateGraph.test.tsx | 11 ++++++++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ui/src/pages/Graphs/NewGraph/NewGraph.tsx b/ui/src/pages/Graphs/NewGraph/NewGraph.tsx index 11e5e8ac9..0dbb71595 100644 --- a/ui/src/pages/Graphs/NewGraph/NewGraph.tsx +++ b/ui/src/pages/Graphs/NewGraph/NewGraph.tsx @@ -155,11 +155,6 @@ const NewGraph: React.FC = () => { */ const editGraph = useCallback(async () => { const gfc: GraphFlowInfo = { ...graphFlowInfo }; - if (gfc.flow_type === FlowType.DUPLICATE) { - //Update the name if flow is Duplicate - gfc.name = name; - setGraphFlowInfo(gfc); - } setLoading(true); try { const { graphId } = await createGraph( @@ -181,7 +176,6 @@ const NewGraph: React.FC = () => { } }, [ graphFlowInfo, - name, createGraph, groups, handleError, @@ -304,10 +298,10 @@ const NewGraph: React.FC = () => { return; } if (isObjectNotEmpty(graphFlowInfo) && groups) { - if (graphFlowInfo.flow_type === FlowType.CREATE) { - onCreateGraph(); - } else { + if (graphFlowInfo.flow_type === FlowType.EDIT) { validateAndEditGraph(); + } else { + onCreateGraph(); } } }, [graphFlowInfo, groups, name, onCreateGraph, validateAndEditGraph]); diff --git a/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx b/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx index ad8dbbfc0..4a8defa28 100644 --- a/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx +++ b/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx @@ -101,6 +101,7 @@ describe("DuplicateGraphPage", () => { validateWithFailure?: boolean; validateWithInvalid?: boolean; validateWithInvalidSuccess?: boolean; + createWithFailure?: boolean; validName?: string; } ) => { @@ -112,8 +113,10 @@ describe("DuplicateGraphPage", () => { await executeGraphCreationFlow(args, clickSubmitButton, { validateWithFailure: options.validateWithFailure, validateWithInvalid: options.validateWithInvalid, + validateWithInvalidSuccess: options.validateWithInvalidSuccess, + createWithFailure: options.createWithFailure, validName: "ltv_graph_copy", - forceRename: true + forceRename: false }); }; @@ -193,6 +196,12 @@ describe("DuplicateGraphPage", () => { validateWithInvalidSuccess: true } ); + await duplicateGraphApiCallTest( + mockNewDeuplicateGraphResponse as GraphDefinition, + { + createWithFailure: true + } + ); await duplicateGraphApiCallTest( mockNewDeuplicateGraphResponse as GraphDefinition, {} From 138eb01dfb3673f89a284bc907ee3166e226dd3e Mon Sep 17 00:00:00 2001 From: aliu65803 Date: Fri, 13 Nov 2026 19:40:29 -0600 Subject: [PATCH 2/3] Test unchanged graph duplicates and drop a redundant copy in editGraph Co-Authored-By: Claude Opus 5.5 --- ui/src/pages/Graphs/NewGraph/NewGraph.tsx | 5 +- .../Graphs/__tests__/DuplicateGraph.test.tsx | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/ui/src/pages/Graphs/NewGraph/NewGraph.tsx b/ui/src/pages/Graphs/NewGraph/NewGraph.tsx index 0dbb71595..664368d66 100644 --- a/ui/src/pages/Graphs/NewGraph/NewGraph.tsx +++ b/ui/src/pages/Graphs/NewGraph/NewGraph.tsx @@ -154,11 +154,10 @@ const NewGraph: React.FC = () => { * Function that makes an API call for Edit graph */ const editGraph = useCallback(async () => { - const gfc: GraphFlowInfo = { ...graphFlowInfo }; setLoading(true); try { const { graphId } = await createGraph( - gfc, + graphFlowInfo, groups, handleError, true @@ -167,7 +166,7 @@ const NewGraph: React.FC = () => { setLoading(false); if (isValid(graphId)) { - navigate(projectPaths.Graphs + gfc.name); + navigate(projectPaths.Graphs + graphFlowInfo.name); } } } catch (error) { diff --git a/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx b/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx index 4a8defa28..c9da7d981 100644 --- a/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx +++ b/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx @@ -145,6 +145,52 @@ describe("DuplicateGraphPage", () => { }); //Previous page }); + it("Should send an unchanged duplicate through create without renaming, show the server error, and stay on the page", async () => { + const graphInfo = duplicateGraphInfo(); + const original = expectedGraphDetailResponse().graph; + mockLocationStateValue({ + flow_type: FlowType.DUPLICATE, + name: graphInfo?.name, + jsGraph: graphInfo + }); + await renderDuplicateGraphPage(); + await pageLoadTest(); + await waitFor(() => { + expect(screen.getByPlaceholderText("name")).toHaveValue( + "ltv_graph_copy" + ); + }); + + await findAndClickButtonByRole("Next"); + await executeGraphCreationFlow( + { + col_groups: original?.col_groups?.map(({ columns }) => ({ + columns + })), + tables: original?.tables + } as GraphDefinition, + async () => { + await userEvent.click(screen.getByText("Save")); + }, + { + createWithInvalid: true, + validName: "ltv_graph_copy", + forceRename: false + } + ); + + expect(mockAxiosInstance.post).not.toHaveBeenCalledWith( + "v1/graphs/", + expect.anything(), + expect.objectContaining({ + params: expect.objectContaining({ force_rename: true }) + }) + ); + expect(mockUseNavigate).not.toHaveBeenCalledWith( + `${getProjectPath("project-tests").Graphs}ltv_graph_copy` + ); + }); + it("Should successfully duplicate the graph and handle validation errors (failure, invalid data)", async () => { const graphInfo = duplicateGraphInfo(); mockLocationStateValue({ From 5ccc5cfc4e99e5505055a7455f7eff0622b78c16 Mon Sep 17 00:00:00 2001 From: aliu65803 Date: Fri, 13 Nov 2026 20:13:29 -0600 Subject: [PATCH 3/3] Clarify the unchanged duplicate test and isolate sequential duplicate steps Co-Authored-By: Claude Opus 5.5 --- ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx b/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx index c9da7d981..3d9e06899 100644 --- a/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx +++ b/ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx @@ -109,6 +109,8 @@ describe("DuplicateGraphPage", () => { const saveGraph = screen.getByText("Save"); await userEvent.click(saveGraph); }; + vi.mocked(mockAxiosInstance.post).mockClear(); + mockUseNavigate.mockClear(); await executeGraphCreationFlow(args, clickSubmitButton, { validateWithFailure: options.validateWithFailure, @@ -145,7 +147,7 @@ describe("DuplicateGraphPage", () => { }); //Previous page }); - it("Should send an unchanged duplicate through create without renaming, show the server error, and stay on the page", async () => { + it("Should send an unchanged duplicate through create without force_rename and stay on the page when creation fails", async () => { const graphInfo = duplicateGraphInfo(); const original = expectedGraphDetailResponse().graph; mockLocationStateValue({