mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Fix diff for mercurial and subversion (#1588)
The useDiff hook appends the query param for the limit always with a question mark, even if the link has already query parameters. Now we check if the url has an question mark and then we use an ampersand instead if the question mark to append the limit.
This commit is contained in:
@@ -222,4 +222,16 @@ describe("Test diff", () => {
|
||||
|
||||
expect(result.current.data).toEqual({ ...partialDiff2, files: [partialDiff1.files[0], partialDiff2.files[0]] });
|
||||
});
|
||||
|
||||
it("should append query parameters to url which has already query params", async () => {
|
||||
fetchMock.getOnce("/api/v2/diff?format=GIT&limit=25", {
|
||||
body: simpleDiff,
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" }
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useDiff("/diff?format=GIT", { limit: 25 }), {
|
||||
wrapper: createWrapper()
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(simpleDiff);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,7 +35,8 @@ type UseDiffOptions = {
|
||||
export const useDiff = (link: string, options: UseDiffOptions = {}) => {
|
||||
let initialLink = link;
|
||||
if (options.limit) {
|
||||
initialLink = `${initialLink}?limit=${options.limit}`;
|
||||
const separator = initialLink.includes("?") ? "&" : "?";
|
||||
initialLink = `${initialLink}${separator}limit=${options.limit}`;
|
||||
}
|
||||
const { isLoading, error, data, isFetchingNextPage, fetchNextPage } = useInfiniteQuery<Diff, Error, Diff>(
|
||||
["link", link],
|
||||
@@ -48,9 +49,9 @@ export const useDiff = (link: string, options: UseDiffOptions = {}) => {
|
||||
return response
|
||||
.text()
|
||||
.then(parser.parse)
|
||||
.then(data => {
|
||||
.then(parsedGit => {
|
||||
return {
|
||||
files: data,
|
||||
files: parsedGit,
|
||||
partial: false,
|
||||
_links: {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user