refactor UI

This commit is contained in:
Eduard Heimbuch
2020-11-30 16:20:39 +01:00
parent 5468fddf90
commit af9f6ab629
19 changed files with 503 additions and 403 deletions

View File

@@ -59,8 +59,6 @@ import reducer, {
getPermissionsLink,
getRepository,
getRepositoryCollection,
IMPORT_REPO_PENDING,
IMPORT_REPO_SUCCESS,
isAbleToCreateRepos,
isCreateRepoPending,
isDeleteRepoPending,
@@ -71,10 +69,9 @@ import reducer, {
MODIFY_REPO_FAILURE,
MODIFY_REPO_PENDING,
MODIFY_REPO_SUCCESS,
modifyRepo,
importRepoFromUrl
modifyRepo
} from "./repos";
import { Repository, RepositoryCollection, Link } from "@scm-manager/ui-types";
import { Link, Repository, RepositoryCollection } from "@scm-manager/ui-types";
const hitchhikerPuzzle42: Repository = {
contact: "fourtytwo@hitchhiker.com",
@@ -414,70 +411,6 @@ describe("repos fetch", () => {
});
});
it("should successfully import repo hitchhiker/restatend", () => {
const importUrl = REPOS_URL + "/import/git/url";
const importRequest = {
...hitchhikerRestatend,
url: "https://scm-manager.org/scm/repo/secret/puzzle42",
username: "trillian",
password: "secret"
};
fetchMock.postOnce(importUrl, {
status: 201,
headers: {
location: "repositories/hitchhiker/restatend"
}
});
fetchMock.getOnce(REPOS_URL + "/hitchhiker/restatend", hitchhikerRestatend);
const expectedActions = [
{
type: IMPORT_REPO_PENDING
},
{
type: IMPORT_REPO_SUCCESS
}
];
const store = mockStore({});
return store.dispatch(importRepoFromUrl(URL, importRequest)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it("should successfully import repo hitchhiker/restatend and call the callback", () => {
const importUrl = REPOS_URL + "/import/git/url";
const importRequest = {
...hitchhikerRestatend,
url: "https://scm-manager.org/scm/repo/secret/puzzle42",
username: "trillian",
password: "secret"
};
fetchMock.postOnce(importUrl, {
status: 201,
headers: {
location: "repositories/hitchhiker/restatend"
}
});
fetchMock.getOnce(REPOS_URL + "/hitchhiker/restatend", hitchhikerRestatend);
let callMe = "not yet";
const callback = (r: any) => {
expect(r).toEqual(hitchhikerRestatend);
callMe = "yeah";
};
const store = mockStore({});
return store.dispatch(importRepoFromUrl(URL, importRequest, callback)).then(() => {
expect(callMe).toBe("yeah");
});
});
it("should successfully create repo slarti/fjords", () => {
fetchMock.postOnce(REPOS_URL, {
status: 201,

View File

@@ -26,13 +26,12 @@ import { apiClient } from "@scm-manager/ui-components";
import * as types from "../../modules/types";
import {
Action,
Link,
Namespace,
NamespaceCollection,
Repository,
RepositoryCollection,
RepositoryCreation,
RepositoryImport,
Link
RepositoryCreation
} from "@scm-manager/ui-types";
import { isPending } from "../../modules/pending";
import { getFailure } from "../../modules/failure";
@@ -241,58 +240,6 @@ export function fetchRepoFailure(namespace: string, name: string, error: Error):
};
}
// import repo
export function importRepoFromUrl(link: string, repository: RepositoryImport, callback?: (repo: Repository) => void) {
const baseLink = link.endsWith("/") ? link : link + "/";
const importLink = baseLink + `import/${repository.type}/url`;
return function(dispatch: any) {
dispatch(importRepoPending());
return apiClient
.post(importLink, repository, CONTENT_TYPE)
.then(response => {
const location = response.headers.get("Location");
dispatch(importRepoSuccess());
// @ts-ignore Location is always set if the repository import was successful
return apiClient.get(location);
})
.then(response => response.json())
.then(response => {
if (callback) {
callback(response);
}
})
.catch(err => {
dispatch(importRepoFailure(err));
});
};
}
export function importRepoPending(): Action {
return {
type: IMPORT_REPO_PENDING
};
}
export function importRepoSuccess(): Action {
return {
type: IMPORT_REPO_SUCCESS
};
}
export function importRepoFailure(err: Error): Action {
return {
type: IMPORT_REPO_FAILURE,
payload: err
};
}
export function importRepoReset(): Action {
return {
type: IMPORT_REPO_RESET
};
}
// create repo
export function createRepo(