@scm-manager/ui-api 2.36.1 → 2.36.2-20220522-120507
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/build/index.d.ts +735 -0
- package/build/index.js +3200 -0
- package/build/index.mjs +3031 -0
- package/package.json +15 -10
- package/LICENSE.txt +0 -21
- package/src/ApiProvider.test.tsx +0 -60
- package/src/ApiProvider.tsx +0 -80
- package/src/LegacyContext.test.tsx +0 -52
- package/src/LegacyContext.tsx +0 -75
- package/src/admin.test.ts +0 -55
- package/src/admin.ts +0 -42
- package/src/alerts.ts +0 -107
- package/src/annotations.ts +0 -45
- package/src/apiKeys.ts +0 -82
- package/src/apiclient.test.ts +0 -126
- package/src/apiclient.ts +0 -336
- package/src/base.test.ts +0 -238
- package/src/base.ts +0 -120
- package/src/branches.test.ts +0 -234
- package/src/branches.ts +0 -201
- package/src/changesets.test.ts +0 -178
- package/src/changesets.ts +0 -82
- package/src/compare.ts +0 -90
- package/src/config.test.ts +0 -118
- package/src/config.ts +0 -60
- package/src/configLink.test.ts +0 -169
- package/src/configLink.ts +0 -89
- package/src/contentType.ts +0 -58
- package/src/diff.test.ts +0 -234
- package/src/diff.ts +0 -93
- package/src/errors.test.ts +0 -59
- package/src/errors.ts +0 -133
- package/src/fileContent.ts +0 -33
- package/src/groupSuggestions.ts +0 -32
- package/src/groups.test.ts +0 -241
- package/src/groups.ts +0 -141
- package/src/help/search/modal.de.ts +0 -33
- package/src/help/search/modal.en.ts +0 -33
- package/src/help/search/syntax.de.ts +0 -148
- package/src/help/search/syntax.en.ts +0 -145
- package/src/history.ts +0 -62
- package/src/import.ts +0 -114
- package/src/index.ts +0 -72
- package/src/keys.ts +0 -48
- package/src/links.test.ts +0 -99
- package/src/links.ts +0 -54
- package/src/login.test.ts +0 -240
- package/src/login.ts +0 -128
- package/src/loginInfo.ts +0 -43
- package/src/namespaceSuggestions.ts +0 -32
- package/src/namespaces.test.ts +0 -95
- package/src/namespaces.ts +0 -43
- package/src/notifications.ts +0 -183
- package/src/permissions.test.ts +0 -345
- package/src/permissions.ts +0 -202
- package/src/plugins.test.ts +0 -336
- package/src/plugins.ts +0 -259
- package/src/publicKeys.ts +0 -83
- package/src/repositories.test.ts +0 -508
- package/src/repositories.ts +0 -375
- package/src/repository-roles.test.ts +0 -229
- package/src/repository-roles.ts +0 -142
- package/src/reset.ts +0 -36
- package/src/search.ts +0 -153
- package/src/sources.test.ts +0 -233
- package/src/sources.ts +0 -136
- package/src/suggestions.ts +0 -47
- package/src/tags.test.ts +0 -272
- package/src/tags.ts +0 -118
- package/src/tests/createInfiniteCachingClient.ts +0 -37
- package/src/tests/createWrapper.tsx +0 -37
- package/src/tests/indexLinks.ts +0 -43
- package/src/urls.test.ts +0 -104
- package/src/urls.ts +0 -118
- package/src/usePluginCenterAuthInfo.ts +0 -91
- package/src/userSuggestions.ts +0 -32
- package/src/users.test.ts +0 -310
- package/src/users.ts +0 -240
- package/src/utils.ts +0 -29
package/src/suggestions.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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 { AutocompleteObject, SelectValue } from "@scm-manager/ui-types";
|
|
25
|
-
import { apiClient } from "./apiclient";
|
|
26
|
-
|
|
27
|
-
export const useSuggestions: (link?: string) => (query: string) => Promise<SelectValue[]> = (link) => {
|
|
28
|
-
if (!link) {
|
|
29
|
-
return () => Promise.resolve([]);
|
|
30
|
-
}
|
|
31
|
-
const url = link + "?q=";
|
|
32
|
-
return (inputValue) => {
|
|
33
|
-
// Prevent violate input condition of api call because parameter length is too short
|
|
34
|
-
if (inputValue.length < 2) {
|
|
35
|
-
return Promise.resolve([]);
|
|
36
|
-
}
|
|
37
|
-
return apiClient
|
|
38
|
-
.get(url + inputValue)
|
|
39
|
-
.then((response) => response.json())
|
|
40
|
-
.then((json: AutocompleteObject[]) =>
|
|
41
|
-
json.map((element) => ({
|
|
42
|
-
value: element,
|
|
43
|
-
label: element.displayName ? `${element.displayName} (${element.id})` : element.id,
|
|
44
|
-
}))
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
};
|
package/src/tags.test.ts
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
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 { Changeset, Repository, Tag, TagCollection } from "@scm-manager/ui-types";
|
|
25
|
-
import fetchMock from "fetch-mock-jest";
|
|
26
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
27
|
-
import createWrapper from "./tests/createWrapper";
|
|
28
|
-
import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
|
|
29
|
-
import { useCreateTag, useDeleteTag, useTag, useTags } from "./tags";
|
|
30
|
-
import { act } from "react-test-renderer";
|
|
31
|
-
|
|
32
|
-
describe("Test Tag hooks", () => {
|
|
33
|
-
const repository: Repository = {
|
|
34
|
-
namespace: "hitchhiker",
|
|
35
|
-
name: "heart-of-gold",
|
|
36
|
-
type: "git",
|
|
37
|
-
_links: {
|
|
38
|
-
tags: {
|
|
39
|
-
href: "/hog/tags",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const changeset: Changeset = {
|
|
45
|
-
id: "42",
|
|
46
|
-
description: "Awesome change",
|
|
47
|
-
date: new Date(),
|
|
48
|
-
author: {
|
|
49
|
-
name: "Arthur Dent",
|
|
50
|
-
},
|
|
51
|
-
_embedded: {},
|
|
52
|
-
_links: {
|
|
53
|
-
tag: {
|
|
54
|
-
href: "/hog/tag",
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const tagOneDotZero = {
|
|
60
|
-
name: "1.0",
|
|
61
|
-
revision: "42",
|
|
62
|
-
signatures: [],
|
|
63
|
-
_links: {
|
|
64
|
-
delete: {
|
|
65
|
-
href: "/hog/tags/1.0",
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const tags: TagCollection = {
|
|
71
|
-
_embedded: {
|
|
72
|
-
tags: [tagOneDotZero],
|
|
73
|
-
},
|
|
74
|
-
_links: {},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const queryClient = createInfiniteCachingClient();
|
|
78
|
-
|
|
79
|
-
beforeEach(() => queryClient.clear());
|
|
80
|
-
|
|
81
|
-
afterEach(() => {
|
|
82
|
-
fetchMock.reset();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe("useTags tests", () => {
|
|
86
|
-
const fetchTags = async () => {
|
|
87
|
-
fetchMock.getOnce("/api/v2/hog/tags", tags);
|
|
88
|
-
|
|
89
|
-
const { result, waitFor } = renderHook(() => useTags(repository), {
|
|
90
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
91
|
-
});
|
|
92
|
-
await waitFor(() => {
|
|
93
|
-
return !!result.current.data;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return result.current;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
it("should return tags", async () => {
|
|
100
|
-
const { data } = await fetchTags();
|
|
101
|
-
expect(data).toEqual(tags);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("should cache tag collection", async () => {
|
|
105
|
-
await fetchTags();
|
|
106
|
-
|
|
107
|
-
const cachedTags = queryClient.getQueryData(["repository", "hitchhiker", "heart-of-gold", "tags"]);
|
|
108
|
-
expect(cachedTags).toEqual(tags);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe("useTag tests", () => {
|
|
113
|
-
const fetchTag = async () => {
|
|
114
|
-
fetchMock.getOnce("/api/v2/hog/tags/1.0", tagOneDotZero);
|
|
115
|
-
|
|
116
|
-
const { result, waitFor } = renderHook(() => useTag(repository, "1.0"), {
|
|
117
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
118
|
-
});
|
|
119
|
-
await waitFor(() => {
|
|
120
|
-
return !!result.current.data;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return result.current;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
it("should return tag", async () => {
|
|
127
|
-
const { data } = await fetchTag();
|
|
128
|
-
expect(data).toEqual(tagOneDotZero);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("should cache tag", async () => {
|
|
132
|
-
await fetchTag();
|
|
133
|
-
|
|
134
|
-
const cachedTag = queryClient.getQueryData(["repository", "hitchhiker", "heart-of-gold", "tag", "1.0"]);
|
|
135
|
-
expect(cachedTag).toEqual(tagOneDotZero);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe("useCreateTags tests", () => {
|
|
140
|
-
const createTag = async () => {
|
|
141
|
-
fetchMock.postOnce("/api/v2/hog/tag", {
|
|
142
|
-
status: 201,
|
|
143
|
-
headers: {
|
|
144
|
-
Location: "/hog/tags/1.0",
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
fetchMock.getOnce("/api/v2/hog/tags/1.0", tagOneDotZero);
|
|
149
|
-
|
|
150
|
-
const { result, waitForNextUpdate } = renderHook(() => useCreateTag(repository, changeset), {
|
|
151
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
await act(() => {
|
|
155
|
-
const { create } = result.current;
|
|
156
|
-
create("1.0");
|
|
157
|
-
return waitForNextUpdate();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return result.current;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
|
|
164
|
-
queryClient.setQueryData(queryKey, data);
|
|
165
|
-
await createTag();
|
|
166
|
-
|
|
167
|
-
const queryState = queryClient.getQueryState(queryKey);
|
|
168
|
-
expect(queryState!.isInvalidated).toBe(true);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
it("should create tag", async () => {
|
|
172
|
-
const { tag } = await createTag();
|
|
173
|
-
|
|
174
|
-
expect(tag).toEqual(tagOneDotZero);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should cache tag", async () => {
|
|
178
|
-
await createTag();
|
|
179
|
-
|
|
180
|
-
const cachedTag = queryClient.getQueryData<Tag>(["repository", "hitchhiker", "heart-of-gold", "tag", "1.0"]);
|
|
181
|
-
expect(cachedTag).toEqual(tagOneDotZero);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it("should invalidate tag collection cache", async () => {
|
|
185
|
-
await shouldInvalidateQuery(["repository", "hitchhiker", "heart-of-gold", "tags"], tags);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("should invalidate changeset cache", async () => {
|
|
189
|
-
await shouldInvalidateQuery(["repository", "hitchhiker", "heart-of-gold", "changeset", "42"], changeset);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("should invalidate changeset collection cache", async () => {
|
|
193
|
-
await shouldInvalidateQuery(["repository", "hitchhiker", "heart-of-gold", "changesets"], [changeset]);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("should fail without location header", async () => {
|
|
197
|
-
fetchMock.postOnce("/api/v2/hog/tag", {
|
|
198
|
-
status: 201,
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
const { result, waitForNextUpdate } = renderHook(() => useCreateTag(repository, changeset), {
|
|
202
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
await act(() => {
|
|
206
|
-
const { create } = result.current;
|
|
207
|
-
create("awesome-42");
|
|
208
|
-
return waitForNextUpdate();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
expect(result.current.error).toBeDefined();
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
describe("useDeleteTags tests", () => {
|
|
216
|
-
const deleteTag = async () => {
|
|
217
|
-
fetchMock.deleteOnce("/api/v2/hog/tags/1.0", {
|
|
218
|
-
status: 204,
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const { result, waitForNextUpdate } = renderHook(() => useDeleteTag(repository), {
|
|
222
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
await act(() => {
|
|
226
|
-
const { remove } = result.current;
|
|
227
|
-
remove(tagOneDotZero);
|
|
228
|
-
return waitForNextUpdate();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
return result.current;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
|
|
235
|
-
queryClient.setQueryData(queryKey, data);
|
|
236
|
-
await deleteTag();
|
|
237
|
-
|
|
238
|
-
const queryState = queryClient.getQueryState(queryKey);
|
|
239
|
-
expect(queryState!.isInvalidated).toBe(true);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
const shouldRemoveQuery = async (queryKey: string[], data: unknown) => {
|
|
243
|
-
queryClient.setQueryData(queryKey, data);
|
|
244
|
-
await deleteTag();
|
|
245
|
-
|
|
246
|
-
const queryState = queryClient.getQueryState(queryKey);
|
|
247
|
-
expect(queryState).toBeUndefined();
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
it("should delete tag", async () => {
|
|
251
|
-
const { isDeleted } = await deleteTag();
|
|
252
|
-
|
|
253
|
-
expect(isDeleted).toBe(true);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("should delete tag cache", async () => {
|
|
257
|
-
await shouldRemoveQuery(["repository", "hitchhiker", "heart-of-gold", "tag", "1.0"], tagOneDotZero);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it("should invalidate tag collection cache", async () => {
|
|
261
|
-
await shouldInvalidateQuery(["repository", "hitchhiker", "heart-of-gold", "tags"], tags);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it("should invalidate changeset cache", async () => {
|
|
265
|
-
await shouldInvalidateQuery(["repository", "hitchhiker", "heart-of-gold", "changeset", "42"], changeset);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("should invalidate changeset collection cache", async () => {
|
|
269
|
-
await shouldInvalidateQuery(["repository", "hitchhiker", "heart-of-gold", "changesets"], [changeset]);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
});
|
package/src/tags.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
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 { Changeset, Link, NamespaceAndName, Repository, Tag, TagCollection } from "@scm-manager/ui-types";
|
|
25
|
-
import { requiredLink } from "./links";
|
|
26
|
-
import { QueryClient, useMutation, useQuery, useQueryClient } from "react-query";
|
|
27
|
-
import { ApiResult } from "./base";
|
|
28
|
-
import { repoQueryKey } from "./keys";
|
|
29
|
-
import { apiClient } from "./apiclient";
|
|
30
|
-
import { concat } from "./urls";
|
|
31
|
-
|
|
32
|
-
const tagQueryKey = (repository: NamespaceAndName, tag: string) => {
|
|
33
|
-
return repoQueryKey(repository, "tag", tag);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const useTags = (repository: Repository): ApiResult<TagCollection> => {
|
|
37
|
-
const link = requiredLink(repository, "tags");
|
|
38
|
-
return useQuery<TagCollection, Error>(
|
|
39
|
-
repoQueryKey(repository, "tags"),
|
|
40
|
-
() => apiClient.get(link).then((response) => response.json())
|
|
41
|
-
// we do not populate the cache for a single tag,
|
|
42
|
-
// because we have no pagination for tags and if we have a lot of them
|
|
43
|
-
// the population slows us down
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const useTag = (repository: Repository, name: string): ApiResult<Tag> => {
|
|
48
|
-
const link = requiredLink(repository, "tags");
|
|
49
|
-
return useQuery<Tag, Error>(tagQueryKey(repository, name), () =>
|
|
50
|
-
apiClient.get(concat(link, name)).then((response) => response.json())
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const invalidateCacheForTag = (queryClient: QueryClient, repository: NamespaceAndName, tag: Tag) => {
|
|
55
|
-
return Promise.all([
|
|
56
|
-
queryClient.invalidateQueries(repoQueryKey(repository, "tags")),
|
|
57
|
-
queryClient.invalidateQueries(repoQueryKey(repository, "changesets")),
|
|
58
|
-
queryClient.invalidateQueries(repoQueryKey(repository, "changeset", tag.revision)),
|
|
59
|
-
]);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const createTag = (changeset: Changeset, link: string) => {
|
|
63
|
-
return (name: string) => {
|
|
64
|
-
return apiClient
|
|
65
|
-
.post(link, {
|
|
66
|
-
name,
|
|
67
|
-
revision: changeset.id,
|
|
68
|
-
})
|
|
69
|
-
.then((response) => {
|
|
70
|
-
const location = response.headers.get("Location");
|
|
71
|
-
if (!location) {
|
|
72
|
-
throw new Error("Server does not return required Location header");
|
|
73
|
-
}
|
|
74
|
-
return apiClient.get(location);
|
|
75
|
-
})
|
|
76
|
-
.then((response) => response.json());
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const useCreateTag = (repository: Repository, changeset: Changeset) => {
|
|
81
|
-
const queryClient = useQueryClient();
|
|
82
|
-
const link = requiredLink(changeset, "tag");
|
|
83
|
-
const { isLoading, error, mutate, data } = useMutation<Tag, Error, string>(createTag(changeset, link), {
|
|
84
|
-
onSuccess: async (tag) => {
|
|
85
|
-
queryClient.setQueryData(tagQueryKey(repository, tag.name), tag);
|
|
86
|
-
await queryClient.invalidateQueries(tagQueryKey(repository, tag.name));
|
|
87
|
-
await invalidateCacheForTag(queryClient, repository, tag);
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
isLoading,
|
|
92
|
-
error,
|
|
93
|
-
create: (name: string) => mutate(name),
|
|
94
|
-
tag: data,
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export const useDeleteTag = (repository: Repository) => {
|
|
99
|
-
const queryClient = useQueryClient();
|
|
100
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Tag>(
|
|
101
|
-
(tag) => {
|
|
102
|
-
const deleteUrl = (tag._links.delete as Link).href;
|
|
103
|
-
return apiClient.delete(deleteUrl);
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
onSuccess: async (_, tag) => {
|
|
107
|
-
queryClient.removeQueries(tagQueryKey(repository, tag.name));
|
|
108
|
-
await invalidateCacheForTag(queryClient, repository, tag);
|
|
109
|
-
},
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
return {
|
|
113
|
-
remove: (tag: Tag) => mutate(tag),
|
|
114
|
-
isLoading,
|
|
115
|
-
error,
|
|
116
|
-
isDeleted: !!data,
|
|
117
|
-
};
|
|
118
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
|
|
25
|
-
import { QueryClient } from "react-query";
|
|
26
|
-
|
|
27
|
-
const createInfiniteCachingClient = () => {
|
|
28
|
-
return new QueryClient({
|
|
29
|
-
defaultOptions: {
|
|
30
|
-
queries: {
|
|
31
|
-
staleTime: Infinity,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default createInfiniteCachingClient;
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
|
|
25
|
-
import React, { FC } from "react";
|
|
26
|
-
import { LegacyContext, LegacyContextProvider } from "../LegacyContext";
|
|
27
|
-
import { QueryClient, QueryClientProvider } from "react-query";
|
|
28
|
-
|
|
29
|
-
const createWrapper = (context?: LegacyContext, queryClient?: QueryClient): FC => {
|
|
30
|
-
return ({ children }) => (
|
|
31
|
-
<QueryClientProvider client={queryClient ? queryClient : new QueryClient()}>
|
|
32
|
-
<LegacyContextProvider {...context}>{children}</LegacyContextProvider>
|
|
33
|
-
</QueryClientProvider>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default createWrapper;
|
package/src/tests/indexLinks.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
|
|
25
|
-
import { QueryClient } from "react-query";
|
|
26
|
-
|
|
27
|
-
export const setIndexLink = (queryClient: QueryClient, name: string, href: string) => {
|
|
28
|
-
queryClient.setQueryData("index", {
|
|
29
|
-
version: "x.y.z",
|
|
30
|
-
_links: {
|
|
31
|
-
[name]: {
|
|
32
|
-
href: href,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const setEmptyIndex = (queryClient: QueryClient) => {
|
|
39
|
-
queryClient.setQueryData("index", {
|
|
40
|
-
version: "x.y.z",
|
|
41
|
-
_links: {},
|
|
42
|
-
});
|
|
43
|
-
};
|
package/src/urls.test.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
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
|
-
|
|
25
|
-
import { concat, getNamespaceAndPageFromMatch, getQueryStringFromLocation, withEndingSlash } from "./urls";
|
|
26
|
-
|
|
27
|
-
describe("tests for withEndingSlash", () => {
|
|
28
|
-
it("should append missing slash", () => {
|
|
29
|
-
expect(withEndingSlash("abc")).toBe("abc/");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should not append a second slash", () => {
|
|
33
|
-
expect(withEndingSlash("abc/")).toBe("abc/");
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("concat tests", () => {
|
|
38
|
-
it("should concat the parts to a single url", () => {
|
|
39
|
-
expect(concat("a")).toBe("a");
|
|
40
|
-
expect(concat("a", "b")).toBe("a/b");
|
|
41
|
-
expect(concat("a", "b", "c")).toBe("a/b/c");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("tests for getNamespaceAndPageFromMatch", () => {
|
|
46
|
-
function createMatch(namespace?: string, page?: string) {
|
|
47
|
-
return {
|
|
48
|
-
params: { namespace, page },
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
it("should return no namespace and page 1 for neither namespace nor page", () => {
|
|
53
|
-
const match = createMatch();
|
|
54
|
-
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: undefined, page: 1 });
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should return no namespace and page 1 for 0 as only parameter", () => {
|
|
58
|
-
const match = createMatch("0");
|
|
59
|
-
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: undefined, page: 1 });
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should return no namespace and given number as page, when only a number is given", () => {
|
|
63
|
-
const match = createMatch("42");
|
|
64
|
-
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: undefined, page: 42 });
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should return big number as namespace and page 1, when only a big number is given", () => {
|
|
68
|
-
const match = createMatch("1337");
|
|
69
|
-
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: "1337", page: 1 });
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should namespace and page 1, when only a string is given", () => {
|
|
73
|
-
const match = createMatch("something");
|
|
74
|
-
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: "something", page: 1 });
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should namespace and given page, when namespace and page are given", () => {
|
|
78
|
-
const match = createMatch("something", "42");
|
|
79
|
-
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: "something", page: 42 });
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("tests for getQueryStringFromLocation", () => {
|
|
84
|
-
function createLocation(search: string) {
|
|
85
|
-
return {
|
|
86
|
-
search,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
it("should return the query string", () => {
|
|
91
|
-
const location = createLocation("?q=abc");
|
|
92
|
-
expect(getQueryStringFromLocation(location)).toBe("abc");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should return query string from multiple parameters", () => {
|
|
96
|
-
const location = createLocation("?x=a&y=b&q=abc&z=c");
|
|
97
|
-
expect(getQueryStringFromLocation(location)).toBe("abc");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should return undefined if q is not available", () => {
|
|
101
|
-
const location = createLocation("?x=a&y=b&z=c");
|
|
102
|
-
expect(getQueryStringFromLocation(location)).toBeUndefined();
|
|
103
|
-
});
|
|
104
|
-
});
|