@scm-manager/ui-api 2.27.3-20211117-144126 → 2.27.4
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 +3 -3
- package/src/branches.test.ts +20 -22
- package/src/branches.ts +13 -106
- package/src/changesets.test.ts +18 -19
- package/src/config.test.ts +0 -1
- package/src/contentType.ts +0 -6
- package/src/import.ts +9 -9
- package/src/index.ts +0 -2
- package/src/repositories.test.ts +57 -54
- package/src/urls.ts +2 -7
- package/src/loginInfo.ts +0 -43
- package/src/usePluginCenterAuthInfo.ts +0 -78
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scm-manager/ui-api",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.4",
|
|
4
4
|
"description": "React hook api for the SCM-Manager backend",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"react-test-renderer": "^17.0.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@scm-manager/ui-types": "^2.27.
|
|
28
|
+
"@scm-manager/ui-types": "^2.27.4",
|
|
29
29
|
"fetch-mock-jest": "^1.5.1",
|
|
30
30
|
"gitdiff-parser": "^0.1.2",
|
|
31
|
-
"query-string": "
|
|
31
|
+
"query-string": "5",
|
|
32
32
|
"react": "^17.0.1",
|
|
33
33
|
"react-query": "^3.25.1"
|
|
34
34
|
},
|
package/src/branches.test.ts
CHANGED
|
@@ -36,38 +36,36 @@ describe("Test branches hooks", () => {
|
|
|
36
36
|
type: "hg",
|
|
37
37
|
_links: {
|
|
38
38
|
branches: {
|
|
39
|
-
href: "/hog/branches"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
39
|
+
href: "/hog/branches",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const develop: Branch = {
|
|
45
45
|
name: "develop",
|
|
46
46
|
revision: "42",
|
|
47
|
-
lastCommitter: { name: "trillian" },
|
|
48
47
|
_links: {
|
|
49
48
|
delete: {
|
|
50
|
-
href: "/hog/branches/develop"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
49
|
+
href: "/hog/branches/develop",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
53
52
|
};
|
|
54
53
|
|
|
55
54
|
const feature: Branch = {
|
|
56
55
|
name: "feature/something-special",
|
|
57
56
|
revision: "42",
|
|
58
|
-
lastCommitter: { name: "trillian" },
|
|
59
57
|
_links: {
|
|
60
58
|
delete: {
|
|
61
|
-
href: "/hog/branches/feature%2Fsomething-special"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
59
|
+
href: "/hog/branches/feature%2Fsomething-special",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
64
62
|
};
|
|
65
63
|
|
|
66
64
|
const branches: BranchCollection = {
|
|
67
65
|
_embedded: {
|
|
68
|
-
branches: [develop]
|
|
66
|
+
branches: [develop],
|
|
69
67
|
},
|
|
70
|
-
_links: {}
|
|
68
|
+
_links: {},
|
|
71
69
|
};
|
|
72
70
|
|
|
73
71
|
const queryClient = createInfiniteCachingClient();
|
|
@@ -85,7 +83,7 @@ describe("Test branches hooks", () => {
|
|
|
85
83
|
fetchMock.getOnce("/api/v2/hog/branches", branches);
|
|
86
84
|
|
|
87
85
|
const { result, waitFor } = renderHook(() => useBranches(repository), {
|
|
88
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
86
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
89
87
|
});
|
|
90
88
|
await waitFor(() => {
|
|
91
89
|
return !!result.current.data;
|
|
@@ -106,7 +104,7 @@ describe("Test branches hooks", () => {
|
|
|
106
104
|
"repository",
|
|
107
105
|
"hitchhiker",
|
|
108
106
|
"heart-of-gold",
|
|
109
|
-
"branches"
|
|
107
|
+
"branches",
|
|
110
108
|
]);
|
|
111
109
|
expect(data).toEqual(branches);
|
|
112
110
|
});
|
|
@@ -117,7 +115,7 @@ describe("Test branches hooks", () => {
|
|
|
117
115
|
fetchMock.getOnce("/api/v2/hog/branches/" + encodeURIComponent(name), branch);
|
|
118
116
|
|
|
119
117
|
const { result, waitFor } = renderHook(() => useBranch(repository, name), {
|
|
120
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
118
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
121
119
|
});
|
|
122
120
|
|
|
123
121
|
expect(result.error).toBeUndefined();
|
|
@@ -145,14 +143,14 @@ describe("Test branches hooks", () => {
|
|
|
145
143
|
fetchMock.postOnce("/api/v2/hog/branches", {
|
|
146
144
|
status: 201,
|
|
147
145
|
headers: {
|
|
148
|
-
Location: "/hog/branches/develop"
|
|
149
|
-
}
|
|
146
|
+
Location: "/hog/branches/develop",
|
|
147
|
+
},
|
|
150
148
|
});
|
|
151
149
|
|
|
152
150
|
fetchMock.getOnce("/api/v2/hog/branches/develop", develop);
|
|
153
151
|
|
|
154
152
|
const { result, waitForNextUpdate } = renderHook(() => useCreateBranch(repository), {
|
|
155
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
153
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
156
154
|
});
|
|
157
155
|
|
|
158
156
|
await act(() => {
|
|
@@ -177,7 +175,7 @@ describe("Test branches hooks", () => {
|
|
|
177
175
|
"hitchhiker",
|
|
178
176
|
"heart-of-gold",
|
|
179
177
|
"branch",
|
|
180
|
-
"develop"
|
|
178
|
+
"develop",
|
|
181
179
|
]);
|
|
182
180
|
expect(branch).toEqual(develop);
|
|
183
181
|
});
|
|
@@ -194,11 +192,11 @@ describe("Test branches hooks", () => {
|
|
|
194
192
|
describe("useDeleteBranch tests", () => {
|
|
195
193
|
const deleteBranch = async () => {
|
|
196
194
|
fetchMock.deleteOnce("/api/v2/hog/branches/develop", {
|
|
197
|
-
status: 204
|
|
195
|
+
status: 204,
|
|
198
196
|
});
|
|
199
197
|
|
|
200
198
|
const { result, waitForNextUpdate } = renderHook(() => useDeleteBranch(repository), {
|
|
201
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
199
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
202
200
|
});
|
|
203
201
|
|
|
204
202
|
await act(() => {
|
package/src/branches.ts
CHANGED
|
@@ -21,35 +21,19 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import {
|
|
25
|
-
Branch,
|
|
26
|
-
BranchCollection,
|
|
27
|
-
BranchCreation,
|
|
28
|
-
BranchDetails,
|
|
29
|
-
BranchDetailsCollection,
|
|
30
|
-
Link,
|
|
31
|
-
NamespaceAndName,
|
|
32
|
-
Repository
|
|
33
|
-
} from "@scm-manager/ui-types";
|
|
24
|
+
import { Branch, BranchCollection, BranchCreation, Link, Repository } from "@scm-manager/ui-types";
|
|
34
25
|
import { requiredLink } from "./links";
|
|
35
|
-
import {
|
|
26
|
+
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
36
27
|
import { ApiResult, ApiResultWithFetching } from "./base";
|
|
37
28
|
import { branchQueryKey, repoQueryKey } from "./keys";
|
|
38
29
|
import { apiClient } from "./apiclient";
|
|
39
30
|
import { concat } from "./urls";
|
|
40
|
-
import { useEffect } from "react";
|
|
41
31
|
|
|
42
32
|
export const useBranches = (repository: Repository): ApiResult<BranchCollection> => {
|
|
43
|
-
const queryClient = useQueryClient();
|
|
44
33
|
const link = requiredLink(repository, "branches");
|
|
45
34
|
return useQuery<BranchCollection, Error>(
|
|
46
35
|
repoQueryKey(repository, "branches"),
|
|
47
|
-
() => apiClient.get(link).then(response => response.json())
|
|
48
|
-
{
|
|
49
|
-
onSuccess: () => {
|
|
50
|
-
return queryClient.invalidateQueries(branchQueryKey(repository, "details"));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
36
|
+
() => apiClient.get(link).then((response) => response.json())
|
|
53
37
|
// we do not populate the cache for a single branch,
|
|
54
38
|
// because we have no pagination for branches and if we have a lot of them
|
|
55
39
|
// the population slows us down
|
|
@@ -59,99 +43,22 @@ export const useBranches = (repository: Repository): ApiResult<BranchCollection>
|
|
|
59
43
|
export const useBranch = (repository: Repository, name: string): ApiResultWithFetching<Branch> => {
|
|
60
44
|
const link = requiredLink(repository, "branches");
|
|
61
45
|
return useQuery<Branch, Error>(branchQueryKey(repository, name), () =>
|
|
62
|
-
apiClient.get(concat(link, encodeURIComponent(name))).then(response => response.json())
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
function chunkBranches(branches: Branch[]) {
|
|
67
|
-
const chunks: Branch[][] = [];
|
|
68
|
-
const chunkSize = 5;
|
|
69
|
-
let chunkIndex = 0;
|
|
70
|
-
for (const branch of branches) {
|
|
71
|
-
if (!chunks[chunkIndex]) {
|
|
72
|
-
chunks[chunkIndex] = [];
|
|
73
|
-
}
|
|
74
|
-
chunks[chunkIndex].push(branch);
|
|
75
|
-
if (chunks[chunkIndex].length >= chunkSize) {
|
|
76
|
-
chunkIndex = chunkIndex + 1;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return chunks;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const branchDetailsQueryKey = (
|
|
83
|
-
repository: NamespaceAndName,
|
|
84
|
-
branch: string | undefined = undefined
|
|
85
|
-
) => {
|
|
86
|
-
let branchName;
|
|
87
|
-
if (!branch) {
|
|
88
|
-
branchName = "_";
|
|
89
|
-
} else {
|
|
90
|
-
branchName = branch;
|
|
91
|
-
}
|
|
92
|
-
return [...repoQueryKey(repository), "branch-details", branchName];
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const useBranchDetailsCollection = (repository: Repository, branches: Branch[]) => {
|
|
96
|
-
const link = requiredLink(repository, "branchDetailsCollection");
|
|
97
|
-
const chunks = chunkBranches(branches);
|
|
98
|
-
const queryClient = useQueryClient();
|
|
99
|
-
|
|
100
|
-
const { data, isLoading, error, fetchNextPage } = useInfiniteQuery<
|
|
101
|
-
BranchDetailsCollection,
|
|
102
|
-
Error,
|
|
103
|
-
BranchDetailsCollection
|
|
104
|
-
>(
|
|
105
|
-
branchDetailsQueryKey(repository),
|
|
106
|
-
({ pageParam = 0 }) => {
|
|
107
|
-
const encodedBranches = chunks[pageParam]?.map(b => encodeURIComponent(b.name)).join("&branches=");
|
|
108
|
-
return apiClient.get(concat(link, `?branches=${encodedBranches}`)).then(response => response.json());
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
getNextPageParam: (lastPage, allPages) => {
|
|
112
|
-
if (allPages.length >= chunks.length) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
return allPages.length;
|
|
116
|
-
},
|
|
117
|
-
onSuccess: newData => {
|
|
118
|
-
newData.pages
|
|
119
|
-
.flatMap(d => d._embedded?.branchDetails)
|
|
120
|
-
.filter(d => !!d)
|
|
121
|
-
.forEach(d => queryClient.setQueryData(branchDetailsQueryKey(repository, d!.branchName), () => d));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
46
|
+
apiClient.get(concat(link, encodeURIComponent(name))).then((response) => response.json())
|
|
124
47
|
);
|
|
125
|
-
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
fetchNextPage();
|
|
128
|
-
}, [data, fetchNextPage]);
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
data: data?.pages?.map(d => d._embedded?.branchDetails).flat(1),
|
|
132
|
-
isLoading,
|
|
133
|
-
error
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const useBranchDetails = (repository: Repository, branch: Branch) => {
|
|
138
|
-
const link = (branch._links.details as Link).href;
|
|
139
|
-
const queryKey = branchDetailsQueryKey(repository, branch.name);
|
|
140
|
-
return useQuery<BranchDetails, Error>(queryKey, () => apiClient.get(link).then(response => response.json()));
|
|
141
48
|
};
|
|
142
49
|
|
|
143
50
|
const createBranch = (link: string) => {
|
|
144
51
|
return (branch: BranchCreation) => {
|
|
145
52
|
return apiClient
|
|
146
53
|
.post(link, branch, "application/vnd.scmm-branchRequest+json;v=2")
|
|
147
|
-
.then(response => {
|
|
54
|
+
.then((response) => {
|
|
148
55
|
const location = response.headers.get("Location");
|
|
149
56
|
if (!location) {
|
|
150
57
|
throw new Error("Server does not return required Location header");
|
|
151
58
|
}
|
|
152
59
|
return apiClient.get(location);
|
|
153
60
|
})
|
|
154
|
-
.then(response => response.json());
|
|
61
|
+
.then((response) => response.json());
|
|
155
62
|
};
|
|
156
63
|
};
|
|
157
64
|
|
|
@@ -159,23 +66,23 @@ export const useCreateBranch = (repository: Repository) => {
|
|
|
159
66
|
const queryClient = useQueryClient();
|
|
160
67
|
const link = requiredLink(repository, "branches");
|
|
161
68
|
const { mutate, isLoading, error, data } = useMutation<Branch, Error, BranchCreation>(createBranch(link), {
|
|
162
|
-
onSuccess: async branch => {
|
|
69
|
+
onSuccess: async (branch) => {
|
|
163
70
|
queryClient.setQueryData(branchQueryKey(repository, branch), branch);
|
|
164
71
|
await queryClient.invalidateQueries(repoQueryKey(repository, "branches"));
|
|
165
|
-
}
|
|
72
|
+
},
|
|
166
73
|
});
|
|
167
74
|
return {
|
|
168
75
|
create: (branch: BranchCreation) => mutate(branch),
|
|
169
76
|
isLoading,
|
|
170
77
|
error,
|
|
171
|
-
branch: data
|
|
78
|
+
branch: data,
|
|
172
79
|
};
|
|
173
80
|
};
|
|
174
81
|
|
|
175
82
|
export const useDeleteBranch = (repository: Repository) => {
|
|
176
83
|
const queryClient = useQueryClient();
|
|
177
84
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Branch>(
|
|
178
|
-
branch => {
|
|
85
|
+
(branch) => {
|
|
179
86
|
const deleteUrl = (branch._links.delete as Link).href;
|
|
180
87
|
return apiClient.delete(deleteUrl);
|
|
181
88
|
},
|
|
@@ -183,14 +90,14 @@ export const useDeleteBranch = (repository: Repository) => {
|
|
|
183
90
|
onSuccess: async (_, branch) => {
|
|
184
91
|
queryClient.removeQueries(branchQueryKey(repository, branch));
|
|
185
92
|
await queryClient.invalidateQueries(repoQueryKey(repository, "branches"));
|
|
186
|
-
}
|
|
93
|
+
},
|
|
187
94
|
}
|
|
188
95
|
);
|
|
189
96
|
return {
|
|
190
97
|
remove: (branch: Branch) => mutate(branch),
|
|
191
98
|
isLoading,
|
|
192
99
|
error,
|
|
193
|
-
isDeleted: !!data
|
|
100
|
+
isDeleted: !!data,
|
|
194
101
|
};
|
|
195
102
|
};
|
|
196
103
|
|
|
@@ -199,6 +106,6 @@ type DefaultBranch = { defaultBranch: string };
|
|
|
199
106
|
export const useDefaultBranch = (repository: Repository): ApiResult<DefaultBranch> => {
|
|
200
107
|
const link = requiredLink(repository, "defaultBranch");
|
|
201
108
|
return useQuery<DefaultBranch, Error>(branchQueryKey(repository, "__default-branch"), () =>
|
|
202
|
-
apiClient.get(link).then(response => response.json())
|
|
109
|
+
apiClient.get(link).then((response) => response.json())
|
|
203
110
|
);
|
|
204
111
|
};
|
package/src/changesets.test.ts
CHANGED
|
@@ -35,20 +35,19 @@ describe("Test changeset hooks", () => {
|
|
|
35
35
|
type: "hg",
|
|
36
36
|
_links: {
|
|
37
37
|
changesets: {
|
|
38
|
-
href: "/r/c"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
38
|
+
href: "/r/c",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
const develop: Branch = {
|
|
44
44
|
name: "develop",
|
|
45
45
|
revision: "42",
|
|
46
|
-
lastCommitter: { name: "trillian" },
|
|
47
46
|
_links: {
|
|
48
47
|
history: {
|
|
49
|
-
href: "/r/b/c"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
48
|
+
href: "/r/b/c",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
52
51
|
};
|
|
53
52
|
|
|
54
53
|
const changeset: Changeset = {
|
|
@@ -56,19 +55,19 @@ describe("Test changeset hooks", () => {
|
|
|
56
55
|
description: "Awesome change",
|
|
57
56
|
date: new Date(),
|
|
58
57
|
author: {
|
|
59
|
-
name: "Arthur Dent"
|
|
58
|
+
name: "Arthur Dent",
|
|
60
59
|
},
|
|
61
60
|
_embedded: {},
|
|
62
|
-
_links: {}
|
|
61
|
+
_links: {},
|
|
63
62
|
};
|
|
64
63
|
|
|
65
64
|
const changesets: ChangesetCollection = {
|
|
66
65
|
page: 1,
|
|
67
66
|
pageTotal: 1,
|
|
68
67
|
_embedded: {
|
|
69
|
-
changesets: [changeset]
|
|
68
|
+
changesets: [changeset],
|
|
70
69
|
},
|
|
71
|
-
_links: {}
|
|
70
|
+
_links: {},
|
|
72
71
|
};
|
|
73
72
|
|
|
74
73
|
const expectChangesetCollection = (result?: ChangesetCollection) => {
|
|
@@ -86,7 +85,7 @@ describe("Test changeset hooks", () => {
|
|
|
86
85
|
const queryClient = createInfiniteCachingClient();
|
|
87
86
|
|
|
88
87
|
const { result, waitFor } = renderHook(() => useChangesets(repository), {
|
|
89
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
88
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
90
89
|
});
|
|
91
90
|
|
|
92
91
|
await waitFor(() => {
|
|
@@ -99,14 +98,14 @@ describe("Test changeset hooks", () => {
|
|
|
99
98
|
it("should return changesets for page", async () => {
|
|
100
99
|
fetchMock.getOnce("/api/v2/r/c", changesets, {
|
|
101
100
|
query: {
|
|
102
|
-
page: 42
|
|
103
|
-
}
|
|
101
|
+
page: 42,
|
|
102
|
+
},
|
|
104
103
|
});
|
|
105
104
|
|
|
106
105
|
const queryClient = createInfiniteCachingClient();
|
|
107
106
|
|
|
108
107
|
const { result, waitFor } = renderHook(() => useChangesets(repository, { page: 42 }), {
|
|
109
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
108
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
110
109
|
});
|
|
111
110
|
|
|
112
111
|
await waitFor(() => {
|
|
@@ -122,7 +121,7 @@ describe("Test changeset hooks", () => {
|
|
|
122
121
|
const queryClient = createInfiniteCachingClient();
|
|
123
122
|
|
|
124
123
|
const { result, waitFor } = renderHook(() => useChangesets(repository, { branch: develop }), {
|
|
125
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
124
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
126
125
|
});
|
|
127
126
|
|
|
128
127
|
await waitFor(() => {
|
|
@@ -138,7 +137,7 @@ describe("Test changeset hooks", () => {
|
|
|
138
137
|
const queryClient = createInfiniteCachingClient();
|
|
139
138
|
|
|
140
139
|
const { result, waitFor } = renderHook(() => useChangesets(repository), {
|
|
141
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
140
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
142
141
|
});
|
|
143
142
|
|
|
144
143
|
await waitFor(() => {
|
|
@@ -150,7 +149,7 @@ describe("Test changeset hooks", () => {
|
|
|
150
149
|
"hitchhiker",
|
|
151
150
|
"heart-of-gold",
|
|
152
151
|
"changeset",
|
|
153
|
-
"42"
|
|
152
|
+
"42",
|
|
154
153
|
]);
|
|
155
154
|
|
|
156
155
|
expect(changeset?.id).toBe("42");
|
|
@@ -164,7 +163,7 @@ describe("Test changeset hooks", () => {
|
|
|
164
163
|
const queryClient = createInfiniteCachingClient();
|
|
165
164
|
|
|
166
165
|
const { result, waitFor } = renderHook(() => useChangeset(repository, "42"), {
|
|
167
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
166
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
168
167
|
});
|
|
169
168
|
|
|
170
169
|
await waitFor(() => {
|
package/src/config.test.ts
CHANGED
package/src/contentType.ts
CHANGED
|
@@ -28,9 +28,6 @@ import { ApiResultWithFetching } from "./base";
|
|
|
28
28
|
export type ContentType = {
|
|
29
29
|
type: string;
|
|
30
30
|
language?: string;
|
|
31
|
-
aceMode?: string;
|
|
32
|
-
codemirrorMode?: string;
|
|
33
|
-
prismMode?: string;
|
|
34
31
|
};
|
|
35
32
|
|
|
36
33
|
function getContentType(url: string): Promise<ContentType> {
|
|
@@ -38,9 +35,6 @@ function getContentType(url: string): Promise<ContentType> {
|
|
|
38
35
|
return {
|
|
39
36
|
type: response.headers.get("Content-Type") || "application/octet-stream",
|
|
40
37
|
language: response.headers.get("X-Programming-Language") || undefined,
|
|
41
|
-
aceMode: response.headers.get("X-Syntax-Mode-Ace") || undefined,
|
|
42
|
-
codemirrorMode: response.headers.get("X-Syntax-Mode-Codemirror") || undefined,
|
|
43
|
-
prismMode: response.headers.get("X-Syntax-Mode-Prism") || undefined,
|
|
44
38
|
};
|
|
45
39
|
});
|
|
46
40
|
}
|
package/src/import.ts
CHANGED
|
@@ -30,12 +30,12 @@ import { requiredLink } from "./links";
|
|
|
30
30
|
|
|
31
31
|
export const useImportLog = (logId: string): ApiResult<string> => {
|
|
32
32
|
const link = useRequiredIndexLink("importLog").replace("{logId}", logId);
|
|
33
|
-
return useQuery<string, Error>(["importLog", logId], () => apiClient.get(link).then(response => response.text()));
|
|
33
|
+
return useQuery<string, Error>(["importLog", logId], () => apiClient.get(link).then((response) => response.text()));
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export const useImportRepositoryFromUrl = (repositoryType: RepositoryType) => {
|
|
37
37
|
const url = requiredLink(repositoryType, "import", "url");
|
|
38
|
-
const { isLoading, error, data, mutate } = useMutation<Repository, Error, RepositoryUrlImport>(repo =>
|
|
38
|
+
const { isLoading, error, data, mutate } = useMutation<Repository, Error, RepositoryUrlImport>((repo) =>
|
|
39
39
|
apiClient
|
|
40
40
|
.post(url, repo, "application/vnd.scmm-repository+json;v=2")
|
|
41
41
|
.then(fetchResourceFromLocationHeader)
|
|
@@ -46,14 +46,14 @@ export const useImportRepositoryFromUrl = (repositoryType: RepositoryType) => {
|
|
|
46
46
|
isLoading,
|
|
47
47
|
error,
|
|
48
48
|
importRepositoryFromUrl: (repository: RepositoryUrlImport) => mutate(repository),
|
|
49
|
-
importedRepository: data
|
|
49
|
+
importedRepository: data,
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const importRepository = (url: string, repository: RepositoryCreation, file: File, password?: string) => {
|
|
54
54
|
return apiClient
|
|
55
|
-
.postBinary(url, formData => {
|
|
56
|
-
formData.append("bundle", file, file
|
|
55
|
+
.postBinary(url, (formData) => {
|
|
56
|
+
formData.append("bundle", file, file?.name);
|
|
57
57
|
formData.append("repository", JSON.stringify({ ...repository, password }));
|
|
58
58
|
})
|
|
59
59
|
.then(fetchResourceFromLocationHeader)
|
|
@@ -82,9 +82,9 @@ export const useImportRepositoryFromBundle = (repositoryType: RepositoryType) =>
|
|
|
82
82
|
repository,
|
|
83
83
|
file,
|
|
84
84
|
compressed,
|
|
85
|
-
password
|
|
85
|
+
password,
|
|
86
86
|
}),
|
|
87
|
-
importedRepository: data
|
|
87
|
+
importedRepository: data,
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
90
|
|
|
@@ -107,8 +107,8 @@ export const useImportFullRepository = (repositoryType: RepositoryType) => {
|
|
|
107
107
|
mutate({
|
|
108
108
|
repository,
|
|
109
109
|
file,
|
|
110
|
-
password
|
|
110
|
+
password,
|
|
111
111
|
}),
|
|
112
|
-
importedRepository: data
|
|
112
|
+
importedRepository: data,
|
|
113
113
|
};
|
|
114
114
|
};
|
package/src/index.ts
CHANGED
|
@@ -58,8 +58,6 @@ export * from "./history";
|
|
|
58
58
|
export * from "./contentType";
|
|
59
59
|
export * from "./annotations";
|
|
60
60
|
export * from "./search";
|
|
61
|
-
export * from "./loginInfo";
|
|
62
|
-
export * from "./usePluginCenterAuthInfo";
|
|
63
61
|
|
|
64
62
|
export { default as ApiProvider } from "./ApiProvider";
|
|
65
63
|
export * from "./ApiProvider";
|
package/src/repositories.test.ts
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
useRepository,
|
|
38
38
|
useRepositoryTypes,
|
|
39
39
|
useUnarchiveRepository,
|
|
40
|
-
useUpdateRepository
|
|
40
|
+
useUpdateRepository,
|
|
41
41
|
} from "./repositories";
|
|
42
42
|
import { Repository } from "@scm-manager/ui-types";
|
|
43
43
|
import { QueryClient } from "react-query";
|
|
@@ -50,25 +50,25 @@ describe("Test repository hooks", () => {
|
|
|
50
50
|
type: "git",
|
|
51
51
|
_links: {
|
|
52
52
|
delete: {
|
|
53
|
-
href: "/r/spaceships/heartOfGold"
|
|
53
|
+
href: "/r/spaceships/heartOfGold",
|
|
54
54
|
},
|
|
55
55
|
update: {
|
|
56
|
-
href: "/r/spaceships/heartOfGold"
|
|
56
|
+
href: "/r/spaceships/heartOfGold",
|
|
57
57
|
},
|
|
58
58
|
archive: {
|
|
59
|
-
href: "/r/spaceships/heartOfGold/archive"
|
|
59
|
+
href: "/r/spaceships/heartOfGold/archive",
|
|
60
60
|
},
|
|
61
61
|
unarchive: {
|
|
62
|
-
href: "/r/spaceships/heartOfGold/unarchive"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
62
|
+
href: "/r/spaceships/heartOfGold/unarchive",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
const repositoryCollection = {
|
|
68
68
|
_embedded: {
|
|
69
|
-
repositories: [heartOfGold]
|
|
69
|
+
repositories: [heartOfGold],
|
|
70
70
|
},
|
|
71
|
-
_links: {}
|
|
71
|
+
_links: {},
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
afterEach(() => {
|
|
@@ -78,7 +78,7 @@ describe("Test repository hooks", () => {
|
|
|
78
78
|
describe("useRepositories tests", () => {
|
|
79
79
|
const expectCollection = async (queryClient: QueryClient, request?: UseRepositoriesRequest) => {
|
|
80
80
|
const { result, waitFor } = renderHook(() => useRepositories(request), {
|
|
81
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
81
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
82
82
|
});
|
|
83
83
|
await waitFor(() => {
|
|
84
84
|
return !!result.current.data;
|
|
@@ -91,8 +91,8 @@ describe("Test repository hooks", () => {
|
|
|
91
91
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
92
92
|
fetchMock.get("/api/v2/repos", repositoryCollection, {
|
|
93
93
|
query: {
|
|
94
|
-
sortBy: "namespaceAndName"
|
|
95
|
-
}
|
|
94
|
+
sortBy: "namespaceAndName",
|
|
95
|
+
},
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
await expectCollection(queryClient);
|
|
@@ -104,12 +104,12 @@ describe("Test repository hooks", () => {
|
|
|
104
104
|
fetchMock.get("/api/v2/repos", repositoryCollection, {
|
|
105
105
|
query: {
|
|
106
106
|
sortBy: "namespaceAndName",
|
|
107
|
-
page: "42"
|
|
108
|
-
}
|
|
107
|
+
page: "42",
|
|
108
|
+
},
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
await expectCollection(queryClient, {
|
|
112
|
-
page: 42
|
|
112
|
+
page: 42,
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
|
|
@@ -118,8 +118,8 @@ describe("Test repository hooks", () => {
|
|
|
118
118
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
119
119
|
fetchMock.get("/api/v2/spaceships", repositoryCollection, {
|
|
120
120
|
query: {
|
|
121
|
-
sortBy: "namespaceAndName"
|
|
122
|
-
}
|
|
121
|
+
sortBy: "namespaceAndName",
|
|
122
|
+
},
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
await expectCollection(queryClient, {
|
|
@@ -127,10 +127,10 @@ describe("Test repository hooks", () => {
|
|
|
127
127
|
namespace: "spaceships",
|
|
128
128
|
_links: {
|
|
129
129
|
repositories: {
|
|
130
|
-
href: "/spaceships"
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
130
|
+
href: "/spaceships",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
|
|
@@ -140,12 +140,12 @@ describe("Test repository hooks", () => {
|
|
|
140
140
|
fetchMock.get("/api/v2/repos", repositoryCollection, {
|
|
141
141
|
query: {
|
|
142
142
|
sortBy: "namespaceAndName",
|
|
143
|
-
q: "heart"
|
|
144
|
-
}
|
|
143
|
+
q: "heart",
|
|
144
|
+
},
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
await expectCollection(queryClient, {
|
|
148
|
-
search: "heart"
|
|
148
|
+
search: "heart",
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
151
|
|
|
@@ -154,8 +154,8 @@ describe("Test repository hooks", () => {
|
|
|
154
154
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
155
155
|
fetchMock.get("/api/v2/repos", repositoryCollection, {
|
|
156
156
|
query: {
|
|
157
|
-
sortBy: "namespaceAndName"
|
|
158
|
-
}
|
|
157
|
+
sortBy: "namespaceAndName",
|
|
158
|
+
},
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
await expectCollection(queryClient);
|
|
@@ -168,7 +168,7 @@ describe("Test repository hooks", () => {
|
|
|
168
168
|
const queryClient = createInfiniteCachingClient();
|
|
169
169
|
setIndexLink(queryClient, "repositories", "/repos");
|
|
170
170
|
const { result } = renderHook(() => useRepositories({ disabled: true }), {
|
|
171
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
171
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
expect(result.current.isLoading).toBe(false);
|
|
@@ -185,18 +185,19 @@ describe("Test repository hooks", () => {
|
|
|
185
185
|
fetchMock.postOnce("/api/v2/r", {
|
|
186
186
|
status: 201,
|
|
187
187
|
headers: {
|
|
188
|
-
Location: "/r/spaceships/heartOfGold"
|
|
189
|
-
}
|
|
188
|
+
Location: "/r/spaceships/heartOfGold",
|
|
189
|
+
},
|
|
190
190
|
});
|
|
191
191
|
|
|
192
192
|
fetchMock.getOnce("/api/v2/r/spaceships/heartOfGold", heartOfGold);
|
|
193
193
|
|
|
194
194
|
const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
|
|
195
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
195
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
const repository = {
|
|
199
|
-
...heartOfGold
|
|
199
|
+
...heartOfGold,
|
|
200
|
+
contextEntries: [],
|
|
200
201
|
};
|
|
201
202
|
|
|
202
203
|
await act(() => {
|
|
@@ -215,18 +216,19 @@ describe("Test repository hooks", () => {
|
|
|
215
216
|
fetchMock.postOnce("/api/v2/r?initialize=true", {
|
|
216
217
|
status: 201,
|
|
217
218
|
headers: {
|
|
218
|
-
Location: "/r/spaceships/heartOfGold"
|
|
219
|
-
}
|
|
219
|
+
Location: "/r/spaceships/heartOfGold",
|
|
220
|
+
},
|
|
220
221
|
});
|
|
221
222
|
|
|
222
223
|
fetchMock.getOnce("/api/v2/r/spaceships/heartOfGold", heartOfGold);
|
|
223
224
|
|
|
224
225
|
const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
|
|
225
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
226
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
226
227
|
});
|
|
227
228
|
|
|
228
229
|
const repository = {
|
|
229
|
-
...heartOfGold
|
|
230
|
+
...heartOfGold,
|
|
231
|
+
contextEntries: [],
|
|
230
232
|
};
|
|
231
233
|
|
|
232
234
|
await act(() => {
|
|
@@ -243,15 +245,16 @@ describe("Test repository hooks", () => {
|
|
|
243
245
|
setIndexLink(queryClient, "repositories", "/r");
|
|
244
246
|
|
|
245
247
|
fetchMock.postOnce("/api/v2/r", {
|
|
246
|
-
status: 201
|
|
248
|
+
status: 201,
|
|
247
249
|
});
|
|
248
250
|
|
|
249
251
|
const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
|
|
250
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
252
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
251
253
|
});
|
|
252
254
|
|
|
253
255
|
const repository = {
|
|
254
|
-
...heartOfGold
|
|
256
|
+
...heartOfGold,
|
|
257
|
+
contextEntries: [],
|
|
255
258
|
};
|
|
256
259
|
|
|
257
260
|
await act(() => {
|
|
@@ -271,7 +274,7 @@ describe("Test repository hooks", () => {
|
|
|
271
274
|
fetchMock.get("/api/v2/r/spaceships/heartOfGold", heartOfGold);
|
|
272
275
|
|
|
273
276
|
const { result, waitFor } = renderHook(() => useRepository("spaceships", "heartOfGold"), {
|
|
274
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
277
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
275
278
|
});
|
|
276
279
|
await waitFor(() => {
|
|
277
280
|
return !!result.current.data;
|
|
@@ -290,15 +293,15 @@ describe("Test repository hooks", () => {
|
|
|
290
293
|
{
|
|
291
294
|
name: "git",
|
|
292
295
|
displayName: "Git",
|
|
293
|
-
_links: {}
|
|
294
|
-
}
|
|
295
|
-
]
|
|
296
|
+
_links: {},
|
|
297
|
+
},
|
|
298
|
+
],
|
|
296
299
|
},
|
|
297
|
-
_links: {}
|
|
300
|
+
_links: {},
|
|
298
301
|
});
|
|
299
302
|
|
|
300
303
|
const { result, waitFor } = renderHook(() => useRepositoryTypes(), {
|
|
301
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
304
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
302
305
|
});
|
|
303
306
|
await waitFor(() => {
|
|
304
307
|
return !!result.current.data;
|
|
@@ -319,11 +322,11 @@ describe("Test repository hooks", () => {
|
|
|
319
322
|
|
|
320
323
|
const deleteRepository = async (options?: UseDeleteRepositoryOptions) => {
|
|
321
324
|
fetchMock.deleteOnce("/api/v2/r/spaceships/heartOfGold", {
|
|
322
|
-
status: 204
|
|
325
|
+
status: 204,
|
|
323
326
|
});
|
|
324
327
|
|
|
325
328
|
const { result, waitForNextUpdate } = renderHook(() => useDeleteRepository(options), {
|
|
326
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
329
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
327
330
|
});
|
|
328
331
|
|
|
329
332
|
await act(() => {
|
|
@@ -368,9 +371,9 @@ describe("Test repository hooks", () => {
|
|
|
368
371
|
it("should call onSuccess callback", async () => {
|
|
369
372
|
let repo;
|
|
370
373
|
await deleteRepository({
|
|
371
|
-
onSuccess: repository => {
|
|
374
|
+
onSuccess: (repository) => {
|
|
372
375
|
repo = repository;
|
|
373
|
-
}
|
|
376
|
+
},
|
|
374
377
|
});
|
|
375
378
|
expect(repo).toEqual(heartOfGold);
|
|
376
379
|
});
|
|
@@ -385,11 +388,11 @@ describe("Test repository hooks", () => {
|
|
|
385
388
|
|
|
386
389
|
const updateRepository = async () => {
|
|
387
390
|
fetchMock.putOnce("/api/v2/r/spaceships/heartOfGold", {
|
|
388
|
-
status: 204
|
|
391
|
+
status: 204,
|
|
389
392
|
});
|
|
390
393
|
|
|
391
394
|
const { result, waitForNextUpdate } = renderHook(() => useUpdateRepository(), {
|
|
392
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
395
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
393
396
|
});
|
|
394
397
|
|
|
395
398
|
await act(() => {
|
|
@@ -433,11 +436,11 @@ describe("Test repository hooks", () => {
|
|
|
433
436
|
|
|
434
437
|
const archiveRepository = async () => {
|
|
435
438
|
fetchMock.postOnce("/api/v2/r/spaceships/heartOfGold/archive", {
|
|
436
|
-
status: 204
|
|
439
|
+
status: 204,
|
|
437
440
|
});
|
|
438
441
|
|
|
439
442
|
const { result, waitForNextUpdate } = renderHook(() => useArchiveRepository(), {
|
|
440
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
443
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
441
444
|
});
|
|
442
445
|
|
|
443
446
|
await act(() => {
|
|
@@ -481,11 +484,11 @@ describe("Test repository hooks", () => {
|
|
|
481
484
|
|
|
482
485
|
const unarchiveRepository = async () => {
|
|
483
486
|
fetchMock.postOnce("/api/v2/r/spaceships/heartOfGold/unarchive", {
|
|
484
|
-
status: 204
|
|
487
|
+
status: 204,
|
|
485
488
|
});
|
|
486
489
|
|
|
487
490
|
const { result, waitForNextUpdate } = renderHook(() => useUnarchiveRepository(), {
|
|
488
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
491
|
+
wrapper: createWrapper(undefined, queryClient),
|
|
489
492
|
});
|
|
490
493
|
|
|
491
494
|
await act(() => {
|
package/src/urls.ts
CHANGED
|
@@ -84,13 +84,8 @@ function parsePageNumber(pageAsString: string) {
|
|
|
84
84
|
return page;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
export function getQueryStringFromLocation(location:
|
|
88
|
-
|
|
89
|
-
const query = queryString.parse(location.search).q;
|
|
90
|
-
if (query && !Array.isArray(query)) {
|
|
91
|
-
return query;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
87
|
+
export function getQueryStringFromLocation(location: any) {
|
|
88
|
+
return location.search ? queryString.parse(location.search).q : undefined;
|
|
94
89
|
}
|
|
95
90
|
|
|
96
91
|
export function stripEndingSlash(url: string) {
|
package/src/loginInfo.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
|
-
import { ApiResult, useIndexLink } from "./base";
|
|
25
|
-
import { useQuery } from "react-query";
|
|
26
|
-
import { LoginInfo } from "@scm-manager/ui-types";
|
|
27
|
-
|
|
28
|
-
export const useLoginInfo = (disabled = false): ApiResult<LoginInfo> => {
|
|
29
|
-
const loginInfoLink = useIndexLink("loginInfo");
|
|
30
|
-
const { error, isLoading, data } = useQuery<LoginInfo, Error>(
|
|
31
|
-
["loginInfo"],
|
|
32
|
-
() => fetch(loginInfoLink!).then(response => response.json()),
|
|
33
|
-
{
|
|
34
|
-
enabled: !disabled && !!loginInfoLink,
|
|
35
|
-
refetchOnWindowFocus: false
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
return {
|
|
39
|
-
data,
|
|
40
|
-
error,
|
|
41
|
-
isLoading
|
|
42
|
-
};
|
|
43
|
-
};
|
|
@@ -1,78 +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 { ApiResult, useIndexLink } from "./base";
|
|
26
|
-
import { Link, PluginCenterAuthenticationInfo } from "@scm-manager/ui-types";
|
|
27
|
-
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
import { useLocation } from "react-router-dom";
|
|
30
|
-
|
|
31
|
-
export const usePluginCenterAuthInfo = (): ApiResult<PluginCenterAuthenticationInfo> => {
|
|
32
|
-
const link = useIndexLink("pluginCenterAuth");
|
|
33
|
-
const location = useLocation();
|
|
34
|
-
return useQuery<PluginCenterAuthenticationInfo, Error>(
|
|
35
|
-
["pluginCenterAuth"],
|
|
36
|
-
() => {
|
|
37
|
-
if (!link) {
|
|
38
|
-
throw new Error("no such plugin center auth link");
|
|
39
|
-
}
|
|
40
|
-
return apiClient
|
|
41
|
-
.get(link)
|
|
42
|
-
.then(response => response.json())
|
|
43
|
-
.then((result: PluginCenterAuthenticationInfo) => {
|
|
44
|
-
if (result._links?.login) {
|
|
45
|
-
(result._links.login as Link).href += `?source=${location.pathname}`;
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
enabled: !!link
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const usePluginCenterLogout = (authenticationInfo: PluginCenterAuthenticationInfo) => {
|
|
57
|
-
const queryClient = useQueryClient();
|
|
58
|
-
const { mutate, isLoading, error } = useMutation<unknown, Error>(
|
|
59
|
-
() => {
|
|
60
|
-
if (!authenticationInfo._links.logout) {
|
|
61
|
-
throw new Error("authenticationInfo has no logout link");
|
|
62
|
-
}
|
|
63
|
-
const logout = authenticationInfo._links.logout as Link;
|
|
64
|
-
return apiClient.delete(logout.href);
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
onSuccess: () => queryClient.invalidateQueries("pluginCenterAuth")
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
logout: () => {
|
|
73
|
-
mutate();
|
|
74
|
-
},
|
|
75
|
-
isLoading,
|
|
76
|
-
error
|
|
77
|
-
};
|
|
78
|
-
};
|