@scm-manager/ui-api 2.30.2-20220115-125803 → 2.30.2-20220117-100916
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/sources.test.ts +7 -7
- package/src/sources.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scm-manager/ui-api",
|
|
3
|
-
"version": "2.30.2-
|
|
3
|
+
"version": "2.30.2-20220117-100916",
|
|
4
4
|
"description": "React hook api for the SCM-Manager backend",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"react-test-renderer": "^17.0.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@scm-manager/ui-types": "^2.30.2-
|
|
28
|
+
"@scm-manager/ui-types": "^2.30.2-20220117-100916",
|
|
29
29
|
"fetch-mock-jest": "^1.5.1",
|
|
30
30
|
"gitdiff-parser": "^0.1.2",
|
|
31
31
|
"query-string": "6.14.1",
|
package/src/sources.test.ts
CHANGED
|
@@ -126,7 +126,7 @@ describe("Test sources hooks", () => {
|
|
|
126
126
|
describe("useSources tests", () => {
|
|
127
127
|
it("should return root directory", async () => {
|
|
128
128
|
const queryClient = createInfiniteCachingClient();
|
|
129
|
-
fetchMock.getOnce("/api/v2/src", rootDirectory);
|
|
129
|
+
fetchMock.getOnce("/api/v2/src?collapse=true", rootDirectory);
|
|
130
130
|
const { result, waitFor } = renderHook(() => useSources(puzzle42), {
|
|
131
131
|
wrapper: createWrapper(undefined, queryClient),
|
|
132
132
|
});
|
|
@@ -136,7 +136,7 @@ describe("Test sources hooks", () => {
|
|
|
136
136
|
|
|
137
137
|
it("should return file from url with revision and path", async () => {
|
|
138
138
|
const queryClient = createInfiniteCachingClient();
|
|
139
|
-
fetchMock.getOnce("/api/v2/src/abc/README.md", readmeMd);
|
|
139
|
+
fetchMock.getOnce("/api/v2/src/abc/README.md?collapse=true", readmeMd);
|
|
140
140
|
const { result, waitFor } = renderHook(() => useSources(puzzle42, { revision: "abc", path: "README.md" }), {
|
|
141
141
|
wrapper: createWrapper(undefined, queryClient),
|
|
142
142
|
});
|
|
@@ -146,7 +146,7 @@ describe("Test sources hooks", () => {
|
|
|
146
146
|
|
|
147
147
|
it("should fetch next page", async () => {
|
|
148
148
|
const queryClient = createInfiniteCachingClient();
|
|
149
|
-
fetchMock.getOnce("/api/v2/src", mainDirectoryTruncated);
|
|
149
|
+
fetchMock.getOnce("/api/v2/src?collapse=true", mainDirectoryTruncated);
|
|
150
150
|
fetchMock.getOnce("/api/v2/src/2", mainDirectory);
|
|
151
151
|
const { result, waitFor, waitForNextUpdate } = renderHook(() => useSources(puzzle42), {
|
|
152
152
|
wrapper: createWrapper(undefined, queryClient),
|
|
@@ -168,7 +168,7 @@ describe("Test sources hooks", () => {
|
|
|
168
168
|
it("should refetch if partial files exists", async () => {
|
|
169
169
|
const queryClient = createInfiniteCachingClient();
|
|
170
170
|
fetchMock.get(
|
|
171
|
-
"/api/v2/src",
|
|
171
|
+
"/api/v2/src?collapse=true",
|
|
172
172
|
{
|
|
173
173
|
...mainDirectory,
|
|
174
174
|
_embedded: {
|
|
@@ -180,7 +180,7 @@ describe("Test sources hooks", () => {
|
|
|
180
180
|
}
|
|
181
181
|
);
|
|
182
182
|
fetchMock.get(
|
|
183
|
-
"/api/v2/src",
|
|
183
|
+
"/api/v2/src?collapse=true",
|
|
184
184
|
{
|
|
185
185
|
...mainDirectory,
|
|
186
186
|
_embedded: {
|
|
@@ -206,9 +206,9 @@ describe("Test sources hooks", () => {
|
|
|
206
206
|
|
|
207
207
|
it("should not refetch if computation is aborted", async () => {
|
|
208
208
|
const queryClient = createInfiniteCachingClient();
|
|
209
|
-
fetchMock.getOnce("/api/v2/src/abc/main/special.md", sepecialMdComputationAborted, { repeat: 1 });
|
|
209
|
+
fetchMock.getOnce("/api/v2/src/abc/main/special.md?collapse=true", sepecialMdComputationAborted, { repeat: 1 });
|
|
210
210
|
// should never be called
|
|
211
|
-
fetchMock.getOnce("/api/v2/src/abc/main/special.md", sepecialMd, {
|
|
211
|
+
fetchMock.getOnce("/api/v2/src/abc/main/special.md?collapse=true", sepecialMd, {
|
|
212
212
|
repeat: 1,
|
|
213
213
|
overwriteRoutes: false,
|
|
214
214
|
});
|
package/src/sources.ts
CHANGED
|
@@ -28,17 +28,20 @@ import * as urls from "./urls";
|
|
|
28
28
|
import { useInfiniteQuery } from "react-query";
|
|
29
29
|
import { repoQueryKey } from "./keys";
|
|
30
30
|
import { useEffect } from "react";
|
|
31
|
+
import { createQueryString } from "./utils";
|
|
31
32
|
|
|
32
33
|
export type UseSourcesOptions = {
|
|
33
34
|
revision?: string;
|
|
34
35
|
path?: string;
|
|
35
36
|
refetchPartialInterval?: number;
|
|
36
37
|
enabled?: boolean;
|
|
38
|
+
collapse?: boolean;
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
const UseSourcesDefaultOptions: UseSourcesOptions = {
|
|
40
42
|
enabled: true,
|
|
41
43
|
refetchPartialInterval: 3000,
|
|
44
|
+
collapse: true
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
export const useSources = (repository: Repository, opts: UseSourcesOptions = UseSourcesDefaultOptions) => {
|
|
@@ -48,7 +51,7 @@ export const useSources = (repository: Repository, opts: UseSourcesOptions = Use
|
|
|
48
51
|
};
|
|
49
52
|
const link = createSourcesLink(repository, options);
|
|
50
53
|
const { isLoading, error, data, isFetchingNextPage, fetchNextPage, refetch } = useInfiniteQuery<File, Error, File>(
|
|
51
|
-
repoQueryKey(repository, "sources", options.revision || "", options.path || ""),
|
|
54
|
+
repoQueryKey(repository, "sources", options.revision || "", options.path || "", options.collapse ? "collapse" : ""),
|
|
52
55
|
({ pageParam }) => {
|
|
53
56
|
return apiClient.get(pageParam || link).then((response) => response.json());
|
|
54
57
|
},
|
|
@@ -93,6 +96,9 @@ const createSourcesLink = (repository: Repository, options: UseSourcesOptions) =
|
|
|
93
96
|
link = urls.concat(link, options.path);
|
|
94
97
|
}
|
|
95
98
|
}
|
|
99
|
+
if (options.collapse) {
|
|
100
|
+
return `${link}?${createQueryString({ collapse: "true" })}`;
|
|
101
|
+
}
|
|
96
102
|
return link;
|
|
97
103
|
};
|
|
98
104
|
|