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:
Viktor Egorov
2024-05-14 11:33:48 +02:00
parent e5e2fd151c
commit c8ef99cf07
37 changed files with 688 additions and 498 deletions

View File

@@ -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);

View File

@@ -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");