@scm-manager/ui-api 2.29.1 → 2.29.2-20220018-094807
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/index.ts +1 -0
- package/src/namespaceSuggestions.ts +32 -0
- package/src/repositories.test.ts +3 -17
- package/src/repositories.ts +35 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scm-manager/ui-api",
|
|
3
|
-
"version": "2.29.
|
|
3
|
+
"version": "2.29.2-20220018-094807",
|
|
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.29.
|
|
28
|
+
"@scm-manager/ui-types": "^2.29.2-20220018-094807",
|
|
29
29
|
"fetch-mock-jest": "^1.5.1",
|
|
30
30
|
"gitdiff-parser": "^0.1.2",
|
|
31
31
|
"query-string": "6.14.1",
|
package/src/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ export * from "./users";
|
|
|
36
36
|
export * from "./suggestions";
|
|
37
37
|
export * from "./userSuggestions";
|
|
38
38
|
export * from "./groupSuggestions";
|
|
39
|
+
export * from "./namespaceSuggestions";
|
|
39
40
|
export * from "./repositories";
|
|
40
41
|
export * from "./namespaces";
|
|
41
42
|
export * from "./branches";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
import { Link } from "@scm-manager/ui-types";
|
|
25
|
+
import { useIndexLinks } from "./base";
|
|
26
|
+
import { useSuggestions } from "./suggestions";
|
|
27
|
+
|
|
28
|
+
export const useNamespaceSuggestions = () => {
|
|
29
|
+
const indexLinks = useIndexLinks();
|
|
30
|
+
const autocompleteLink = (indexLinks.autocomplete as Link[]).find((i) => i.name === "namespaces");
|
|
31
|
+
return useSuggestions(autocompleteLink?.href);
|
|
32
|
+
};
|
package/src/repositories.test.ts
CHANGED
|
@@ -89,11 +89,7 @@ describe("Test repository hooks", () => {
|
|
|
89
89
|
it("should return repositories", async () => {
|
|
90
90
|
const queryClient = createInfiniteCachingClient();
|
|
91
91
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
92
|
-
fetchMock.get("/api/v2/repos", repositoryCollection
|
|
93
|
-
query: {
|
|
94
|
-
sortBy: "namespaceAndName"
|
|
95
|
-
}
|
|
96
|
-
});
|
|
92
|
+
fetchMock.get("/api/v2/repos", repositoryCollection);
|
|
97
93
|
|
|
98
94
|
await expectCollection(queryClient);
|
|
99
95
|
});
|
|
@@ -103,7 +99,6 @@ describe("Test repository hooks", () => {
|
|
|
103
99
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
104
100
|
fetchMock.get("/api/v2/repos", repositoryCollection, {
|
|
105
101
|
query: {
|
|
106
|
-
sortBy: "namespaceAndName",
|
|
107
102
|
page: "42"
|
|
108
103
|
}
|
|
109
104
|
});
|
|
@@ -116,11 +111,7 @@ describe("Test repository hooks", () => {
|
|
|
116
111
|
it("should use repository from namespace", async () => {
|
|
117
112
|
const queryClient = createInfiniteCachingClient();
|
|
118
113
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
119
|
-
fetchMock.get("/api/v2/spaceships", repositoryCollection
|
|
120
|
-
query: {
|
|
121
|
-
sortBy: "namespaceAndName"
|
|
122
|
-
}
|
|
123
|
-
});
|
|
114
|
+
fetchMock.get("/api/v2/spaceships", repositoryCollection);
|
|
124
115
|
|
|
125
116
|
await expectCollection(queryClient, {
|
|
126
117
|
namespace: {
|
|
@@ -139,7 +130,6 @@ describe("Test repository hooks", () => {
|
|
|
139
130
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
140
131
|
fetchMock.get("/api/v2/repos", repositoryCollection, {
|
|
141
132
|
query: {
|
|
142
|
-
sortBy: "namespaceAndName",
|
|
143
133
|
q: "heart"
|
|
144
134
|
}
|
|
145
135
|
});
|
|
@@ -152,11 +142,7 @@ describe("Test repository hooks", () => {
|
|
|
152
142
|
it("should update repository cache", async () => {
|
|
153
143
|
const queryClient = createInfiniteCachingClient();
|
|
154
144
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
155
|
-
fetchMock.get("/api/v2/repos", repositoryCollection
|
|
156
|
-
query: {
|
|
157
|
-
sortBy: "namespaceAndName"
|
|
158
|
-
}
|
|
159
|
-
});
|
|
145
|
+
fetchMock.get("/api/v2/repos", repositoryCollection);
|
|
160
146
|
|
|
161
147
|
await expectCollection(queryClient);
|
|
162
148
|
|
package/src/repositories.ts
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
Repository,
|
|
31
31
|
RepositoryCollection,
|
|
32
32
|
RepositoryCreation,
|
|
33
|
-
RepositoryTypeCollection
|
|
33
|
+
RepositoryTypeCollection
|
|
34
34
|
} from "@scm-manager/ui-types";
|
|
35
35
|
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
36
36
|
import { apiClient } from "./apiclient";
|
|
@@ -55,9 +55,7 @@ export const useRepositories = (request?: UseRepositoriesRequest): ApiResult<Rep
|
|
|
55
55
|
const namespaceLink = (request?.namespace?._links.repositories as Link)?.href;
|
|
56
56
|
const link = namespaceLink || indexLink;
|
|
57
57
|
|
|
58
|
-
const queryParams: Record<string, string> = {
|
|
59
|
-
sortBy: "namespaceAndName",
|
|
60
|
-
};
|
|
58
|
+
const queryParams: Record<string, string> = {};
|
|
61
59
|
if (request?.search) {
|
|
62
60
|
queryParams.q = request.search;
|
|
63
61
|
}
|
|
@@ -66,7 +64,7 @@ export const useRepositories = (request?: UseRepositoriesRequest): ApiResult<Rep
|
|
|
66
64
|
}
|
|
67
65
|
return useQuery<RepositoryCollection, Error>(
|
|
68
66
|
["repositories", request?.namespace?.namespace, request?.search || "", request?.page || 0],
|
|
69
|
-
() => apiClient.get(`${link}?${createQueryString(queryParams)}`).then(
|
|
67
|
+
() => apiClient.get(`${link}?${createQueryString(queryParams)}`).then(response => response.json()),
|
|
70
68
|
{
|
|
71
69
|
enabled: !request?.disabled,
|
|
72
70
|
onSuccess: (repositories: RepositoryCollection) => {
|
|
@@ -74,7 +72,7 @@ export const useRepositories = (request?: UseRepositoriesRequest): ApiResult<Rep
|
|
|
74
72
|
repositories._embedded?.repositories.forEach((repository: Repository) => {
|
|
75
73
|
queryClient.setQueryData(["repository", repository.namespace, repository.name], repository);
|
|
76
74
|
});
|
|
77
|
-
}
|
|
75
|
+
}
|
|
78
76
|
}
|
|
79
77
|
);
|
|
80
78
|
};
|
|
@@ -92,14 +90,14 @@ const createRepository = (link: string) => {
|
|
|
92
90
|
}
|
|
93
91
|
return apiClient
|
|
94
92
|
.post(createLink, request.repository, "application/vnd.scmm-repository+json;v=2")
|
|
95
|
-
.then(
|
|
93
|
+
.then(response => {
|
|
96
94
|
const location = response.headers.get("Location");
|
|
97
95
|
if (!location) {
|
|
98
96
|
throw new Error("Server does not return required Location header");
|
|
99
97
|
}
|
|
100
98
|
return apiClient.get(location);
|
|
101
99
|
})
|
|
102
|
-
.then(
|
|
100
|
+
.then(response => response.json());
|
|
103
101
|
};
|
|
104
102
|
};
|
|
105
103
|
|
|
@@ -111,10 +109,10 @@ export const useCreateRepository = () => {
|
|
|
111
109
|
const { mutate, data, isLoading, error } = useMutation<Repository, Error, CreateRepositoryRequest>(
|
|
112
110
|
createRepository(link),
|
|
113
111
|
{
|
|
114
|
-
onSuccess:
|
|
112
|
+
onSuccess: repository => {
|
|
115
113
|
queryClient.setQueryData(["repository", repository.namespace, repository.name], repository);
|
|
116
114
|
return queryClient.invalidateQueries(["repositories"]);
|
|
117
|
-
}
|
|
115
|
+
}
|
|
118
116
|
}
|
|
119
117
|
);
|
|
120
118
|
return {
|
|
@@ -123,7 +121,7 @@ export const useCreateRepository = () => {
|
|
|
123
121
|
},
|
|
124
122
|
isLoading,
|
|
125
123
|
error,
|
|
126
|
-
repository: data
|
|
124
|
+
repository: data
|
|
127
125
|
};
|
|
128
126
|
};
|
|
129
127
|
|
|
@@ -133,7 +131,7 @@ export const useRepositoryTypes = () => useIndexJsonResource<RepositoryTypeColle
|
|
|
133
131
|
export const useRepository = (namespace: string, name: string): ApiResult<Repository> => {
|
|
134
132
|
const link = useRequiredIndexLink("repositories");
|
|
135
133
|
return useQuery<Repository, Error>(["repository", namespace, name], () =>
|
|
136
|
-
apiClient.get(concat(link, namespace, name)).then(
|
|
134
|
+
apiClient.get(concat(link, namespace, name)).then(response => response.json())
|
|
137
135
|
);
|
|
138
136
|
};
|
|
139
137
|
|
|
@@ -144,7 +142,7 @@ export type UseDeleteRepositoryOptions = {
|
|
|
144
142
|
export const useDeleteRepository = (options?: UseDeleteRepositoryOptions) => {
|
|
145
143
|
const queryClient = useQueryClient();
|
|
146
144
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
147
|
-
|
|
145
|
+
repository => {
|
|
148
146
|
const link = requiredLink(repository, "delete");
|
|
149
147
|
return apiClient.delete(link);
|
|
150
148
|
},
|
|
@@ -153,23 +151,23 @@ export const useDeleteRepository = (options?: UseDeleteRepositoryOptions) => {
|
|
|
153
151
|
if (options?.onSuccess) {
|
|
154
152
|
options.onSuccess(repository);
|
|
155
153
|
}
|
|
156
|
-
|
|
154
|
+
queryClient.removeQueries(repoQueryKey(repository));
|
|
157
155
|
await queryClient.invalidateQueries(["repositories"]);
|
|
158
|
-
}
|
|
156
|
+
}
|
|
159
157
|
}
|
|
160
158
|
);
|
|
161
159
|
return {
|
|
162
160
|
remove: (repository: Repository) => mutate(repository),
|
|
163
161
|
isLoading,
|
|
164
162
|
error,
|
|
165
|
-
isDeleted: !!data
|
|
163
|
+
isDeleted: !!data
|
|
166
164
|
};
|
|
167
165
|
};
|
|
168
166
|
|
|
169
167
|
export const useUpdateRepository = () => {
|
|
170
168
|
const queryClient = useQueryClient();
|
|
171
169
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
172
|
-
|
|
170
|
+
repository => {
|
|
173
171
|
const link = requiredLink(repository, "update");
|
|
174
172
|
return apiClient.put(link, repository, "application/vnd.scmm-repository+json;v=2");
|
|
175
173
|
},
|
|
@@ -177,21 +175,21 @@ export const useUpdateRepository = () => {
|
|
|
177
175
|
onSuccess: async (_, repository) => {
|
|
178
176
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
179
177
|
await queryClient.invalidateQueries(["repositories"]);
|
|
180
|
-
}
|
|
178
|
+
}
|
|
181
179
|
}
|
|
182
180
|
);
|
|
183
181
|
return {
|
|
184
182
|
update: (repository: Repository) => mutate(repository),
|
|
185
183
|
isLoading,
|
|
186
184
|
error,
|
|
187
|
-
isUpdated: !!data
|
|
185
|
+
isUpdated: !!data
|
|
188
186
|
};
|
|
189
187
|
};
|
|
190
188
|
|
|
191
189
|
export const useArchiveRepository = () => {
|
|
192
190
|
const queryClient = useQueryClient();
|
|
193
191
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
194
|
-
|
|
192
|
+
repository => {
|
|
195
193
|
const link = requiredLink(repository, "archive");
|
|
196
194
|
return apiClient.post(link);
|
|
197
195
|
},
|
|
@@ -199,21 +197,21 @@ export const useArchiveRepository = () => {
|
|
|
199
197
|
onSuccess: async (_, repository) => {
|
|
200
198
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
201
199
|
await queryClient.invalidateQueries(["repositories"]);
|
|
202
|
-
}
|
|
200
|
+
}
|
|
203
201
|
}
|
|
204
202
|
);
|
|
205
203
|
return {
|
|
206
204
|
archive: (repository: Repository) => mutate(repository),
|
|
207
205
|
isLoading,
|
|
208
206
|
error,
|
|
209
|
-
isArchived: !!data
|
|
207
|
+
isArchived: !!data
|
|
210
208
|
};
|
|
211
209
|
};
|
|
212
210
|
|
|
213
211
|
export const useUnarchiveRepository = () => {
|
|
214
212
|
const queryClient = useQueryClient();
|
|
215
213
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
216
|
-
|
|
214
|
+
repository => {
|
|
217
215
|
const link = requiredLink(repository, "unarchive");
|
|
218
216
|
return apiClient.post(link);
|
|
219
217
|
},
|
|
@@ -221,35 +219,35 @@ export const useUnarchiveRepository = () => {
|
|
|
221
219
|
onSuccess: async (_, repository) => {
|
|
222
220
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
223
221
|
await queryClient.invalidateQueries(["repositories"]);
|
|
224
|
-
}
|
|
222
|
+
}
|
|
225
223
|
}
|
|
226
224
|
);
|
|
227
225
|
return {
|
|
228
226
|
unarchive: (repository: Repository) => mutate(repository),
|
|
229
227
|
isLoading,
|
|
230
228
|
error,
|
|
231
|
-
isUnarchived: !!data
|
|
229
|
+
isUnarchived: !!data
|
|
232
230
|
};
|
|
233
231
|
};
|
|
234
232
|
|
|
235
233
|
export const useRunHealthCheck = () => {
|
|
236
234
|
const queryClient = useQueryClient();
|
|
237
235
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
238
|
-
|
|
236
|
+
repository => {
|
|
239
237
|
const link = requiredLink(repository, "runHealthCheck");
|
|
240
238
|
return apiClient.post(link);
|
|
241
239
|
},
|
|
242
240
|
{
|
|
243
241
|
onSuccess: async (_, repository) => {
|
|
244
242
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
245
|
-
}
|
|
243
|
+
}
|
|
246
244
|
}
|
|
247
245
|
);
|
|
248
246
|
return {
|
|
249
247
|
runHealthCheck: (repository: Repository) => mutate(repository),
|
|
250
248
|
isLoading,
|
|
251
249
|
error,
|
|
252
|
-
isRunning: !!data
|
|
250
|
+
isRunning: !!data
|
|
253
251
|
};
|
|
254
252
|
};
|
|
255
253
|
|
|
@@ -258,7 +256,7 @@ export const useExportInfo = (repository: Repository): ApiResultWithFetching<Exp
|
|
|
258
256
|
//TODO Refetch while exporting to update the page
|
|
259
257
|
const { isLoading, isFetching, error, data } = useQuery<ExportInfo, Error>(
|
|
260
258
|
["repository", repository.namespace, repository.name, "exportInfo"],
|
|
261
|
-
() => apiClient.get(link).then(
|
|
259
|
+
() => apiClient.get(link).then(response => response.json()),
|
|
262
260
|
{}
|
|
263
261
|
);
|
|
264
262
|
|
|
@@ -266,7 +264,7 @@ export const useExportInfo = (repository: Repository): ApiResultWithFetching<Exp
|
|
|
266
264
|
isLoading,
|
|
267
265
|
isFetching,
|
|
268
266
|
error: error instanceof NotFoundError ? null : error,
|
|
269
|
-
data
|
|
267
|
+
data
|
|
270
268
|
};
|
|
271
269
|
};
|
|
272
270
|
|
|
@@ -309,14 +307,14 @@ export const useExportRepository = () => {
|
|
|
309
307
|
const id = setInterval(() => {
|
|
310
308
|
apiClient
|
|
311
309
|
.get(infolink)
|
|
312
|
-
.then(
|
|
310
|
+
.then(r => r.json())
|
|
313
311
|
.then((info: ExportInfo) => {
|
|
314
312
|
if (info._links.download) {
|
|
315
313
|
clearInterval(id);
|
|
316
314
|
resolve(info);
|
|
317
315
|
}
|
|
318
316
|
})
|
|
319
|
-
.catch(
|
|
317
|
+
.catch(e => {
|
|
320
318
|
clearInterval(id);
|
|
321
319
|
reject(e);
|
|
322
320
|
});
|
|
@@ -329,21 +327,21 @@ export const useExportRepository = () => {
|
|
|
329
327
|
onSuccess: async (_, { repository }) => {
|
|
330
328
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
331
329
|
await queryClient.invalidateQueries(["repositories"]);
|
|
332
|
-
}
|
|
330
|
+
}
|
|
333
331
|
}
|
|
334
332
|
);
|
|
335
333
|
return {
|
|
336
334
|
exportRepository: (repository: Repository, options: ExportOptions) => mutate({ repository, options }),
|
|
337
335
|
isLoading,
|
|
338
336
|
error,
|
|
339
|
-
data
|
|
337
|
+
data
|
|
340
338
|
};
|
|
341
339
|
};
|
|
342
340
|
|
|
343
341
|
export const usePaths = (repository: Repository, revision: string): ApiResult<Paths> => {
|
|
344
342
|
const link = requiredLink(repository, "paths").replace("{revision}", revision);
|
|
345
343
|
return useQuery<Paths, Error>(repoQueryKey(repository, "paths", revision), () =>
|
|
346
|
-
apiClient.get(link).then(
|
|
344
|
+
apiClient.get(link).then(response => response.json())
|
|
347
345
|
);
|
|
348
346
|
};
|
|
349
347
|
|
|
@@ -364,7 +362,7 @@ export const useRenameRepository = (repository: Repository) => {
|
|
|
364
362
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, RenameRepositoryRequest>(
|
|
365
363
|
({ name, namespace }) => apiClient.post(url, { namespace, name }, "application/vnd.scmm-repository+json;v=2"),
|
|
366
364
|
{
|
|
367
|
-
onSuccess: () => queryClient.removeQueries(repoQueryKey(repository))
|
|
365
|
+
onSuccess: () => queryClient.removeQueries(repoQueryKey(repository))
|
|
368
366
|
}
|
|
369
367
|
);
|
|
370
368
|
|
|
@@ -372,6 +370,6 @@ export const useRenameRepository = (repository: Repository) => {
|
|
|
372
370
|
renameRepository: (namespace: string, name: string) => mutate({ namespace, name }),
|
|
373
371
|
isLoading,
|
|
374
372
|
error,
|
|
375
|
-
isRenamed: !!data
|
|
373
|
+
isRenamed: !!data
|
|
376
374
|
};
|
|
377
375
|
};
|