mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-04 20:45:52 +01:00
Add option to hide whitepace changes in diffs
Co-authored-by: Florian Scholdei<florian.scholdei@cloudogu.com> Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com> Reviewed-by: Florian Scholdei <florian.scholdei@cloudogu.com>
This commit is contained in:
@@ -221,11 +221,11 @@ describe("Test diff", () => {
|
||||
});
|
||||
|
||||
it("should append query parameters to url which has already query params", async () => {
|
||||
fetchMock.getOnce("/api/v2/diff?format=GIT&limit=25", {
|
||||
fetchMock.getOnce("/api/v2/diff?format=GIT&limit=25&ignoreWhitespace=NONE", {
|
||||
body: simpleDiff,
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useDiff("/diff?format=GIT", { limit: 25 }), {
|
||||
const { result, waitFor } = renderHook(() => useDiff("/diff?format=GIT", { limit: 25, ignoreWhitespace: "NONE" }), {
|
||||
wrapper: createWrapper(),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
|
||||
@@ -31,6 +31,7 @@ import { Diff, Link } from "@scm-manager/ui-types";
|
||||
type UseDiffOptions = {
|
||||
limit?: number;
|
||||
refetchOnWindowFocus?: boolean;
|
||||
ignoreWhitespace?: string;
|
||||
};
|
||||
|
||||
const defaultOptions: UseDiffOptions = {
|
||||
@@ -41,10 +42,10 @@ export const useDiff = (link: string, options: UseDiffOptions = defaultOptions)
|
||||
let initialLink = link;
|
||||
if (options.limit) {
|
||||
const separator = initialLink.includes("?") ? "&" : "?";
|
||||
initialLink = `${initialLink}${separator}limit=${options.limit}`;
|
||||
initialLink = `${initialLink}${separator}limit=${options.limit}&ignoreWhitespace=${options.ignoreWhitespace}`;
|
||||
}
|
||||
const { isLoading, error, data, isFetchingNextPage, fetchNextPage } = useInfiniteQuery<Diff, Error, Diff>(
|
||||
["link", link],
|
||||
["link", link, options.ignoreWhitespace],
|
||||
({ pageParam }) => {
|
||||
return apiClient.get(pageParam || initialLink).then((response) => {
|
||||
const contentType = response.headers.get("Content-Type");
|
||||
|
||||
Reference in New Issue
Block a user