mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Fix create branches
This commit is contained in:
@@ -7,3 +7,8 @@ export type Branch = {
|
||||
defaultBranch?: boolean,
|
||||
_links: Links
|
||||
}
|
||||
|
||||
export type BranchRequest = {
|
||||
name: string,
|
||||
parent: string
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export type { Group, Member } from "./Group";
|
||||
export type { Repository, RepositoryCollection, RepositoryGroup } from "./Repositories";
|
||||
export type { RepositoryType, RepositoryTypeCollection } from "./RepositoryTypes";
|
||||
|
||||
export type { Branch } from "./Branches";
|
||||
export type { Branch, BranchRequest } from "./Branches";
|
||||
|
||||
export type { Changeset } from "./Changesets";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import type { Repository, Branch } from "@scm-manager/ui-types";
|
||||
import type { Repository, Branch, BranchRequest } from "@scm-manager/ui-types";
|
||||
import {
|
||||
Select,
|
||||
InputField,
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { orderBranches } from "../util/orderBranches";
|
||||
|
||||
type Props = {
|
||||
submitForm: Branch => void,
|
||||
submitForm: BranchRequest => void,
|
||||
repository: Repository,
|
||||
branches: Branch[],
|
||||
loading?: boolean,
|
||||
@@ -51,7 +51,10 @@ class BranchForm extends React.Component<Props, State> {
|
||||
submit = (event: Event) => {
|
||||
event.preventDefault();
|
||||
if (this.isValid()) {
|
||||
this.props.submitForm(this.state.branch);
|
||||
this.props.submitForm({
|
||||
name: this.state.name,
|
||||
parent: this.state.source
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ import {
|
||||
} from "@scm-manager/ui-components";
|
||||
import { translate } from "react-i18next";
|
||||
import BranchForm from "../components/BranchForm";
|
||||
import type { Repository, Branch } from "@scm-manager/ui-types";
|
||||
import type { Repository, Branch, BranchRequest } from "@scm-manager/ui-types";
|
||||
import {
|
||||
fetchBranches,
|
||||
getBranches,
|
||||
getBrancheCreateLink,
|
||||
createBranch,
|
||||
createBranchReset,
|
||||
isCreateBranchPending,
|
||||
@@ -28,10 +29,16 @@ type Props = {
|
||||
error?: Error,
|
||||
repository: Repository,
|
||||
branches: Branch[],
|
||||
createBranchesLink: string,
|
||||
|
||||
// dispatcher functions
|
||||
fetchBranches: Repository => void,
|
||||
createBranch: (branch: Branch, callback?: () => void) => void,
|
||||
createBranch: (
|
||||
createLink: string,
|
||||
repository: Repository,
|
||||
branch: BranchRequest,
|
||||
callback?: (Branch) => void
|
||||
) => void,
|
||||
resetForm: () => void,
|
||||
|
||||
// context objects
|
||||
@@ -48,12 +55,21 @@ class CreateBranch extends React.Component<Props> {
|
||||
}
|
||||
|
||||
branchCreated = (branch: Branch) => {
|
||||
const { history } = this.props;
|
||||
history.push("/branch/" + encodeURIComponent(branch.name) + "/info");
|
||||
const { history, repository } = this.props;
|
||||
history.push(
|
||||
`/repo/${repository.namespace}/${
|
||||
repository.name
|
||||
}/branch/${encodeURIComponent(branch.name)}/info`
|
||||
);
|
||||
};
|
||||
|
||||
createBranch = (branch: Branch) => {
|
||||
this.props.createBranch(branch, () => this.branchCreated(branch));
|
||||
createBranch = (branch: BranchRequest) => {
|
||||
this.props.createBranch(
|
||||
this.props.createBranchesLink,
|
||||
this.props.repository,
|
||||
branch,
|
||||
newBranch => this.branchCreated(newBranch)
|
||||
);
|
||||
};
|
||||
|
||||
transmittedName = (url: string) => {
|
||||
@@ -76,7 +92,7 @@ class CreateBranch extends React.Component<Props> {
|
||||
<>
|
||||
<Subtitle subtitle={t("branches.create.title")} />
|
||||
<BranchForm
|
||||
submitForm={branch => this.createBranch(branch)}
|
||||
submitForm={branchRequest => this.createBranch(branchRequest)}
|
||||
loading={loading}
|
||||
repository={repository}
|
||||
branches={branches}
|
||||
@@ -93,11 +109,12 @@ const mapDispatchToProps = dispatch => {
|
||||
dispatch(fetchBranches(repository));
|
||||
},
|
||||
createBranch: (
|
||||
createLink: string,
|
||||
repository: Repository,
|
||||
branch: Branch,
|
||||
callback?: () => void
|
||||
branchRequest: BranchRequest,
|
||||
callback?: (newBranch: Branch) => void
|
||||
) => {
|
||||
dispatch(createBranch("INSERTLINK", repository, branch, callback)); //TODO
|
||||
dispatch(createBranch(createLink, repository, branchRequest, callback));
|
||||
},
|
||||
resetForm: () => {
|
||||
dispatch(createBranchReset());
|
||||
@@ -111,11 +128,13 @@ const mapStateToProps = (state, ownProps) => {
|
||||
const error =
|
||||
getFetchBranchesFailure(state, repository) || getCreateBranchFailure(state);
|
||||
const branches = getBranches(state, repository);
|
||||
const createBranchesLink = getBrancheCreateLink(state, repository);
|
||||
return {
|
||||
repository,
|
||||
loading,
|
||||
error,
|
||||
branches
|
||||
branches,
|
||||
createBranchesLink
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,12 @@ import {
|
||||
SUCCESS_SUFFIX
|
||||
} from "../../../modules/types";
|
||||
import { apiClient } from "@scm-manager/ui-components";
|
||||
import type { Action, Branch, Repository } from "@scm-manager/ui-types";
|
||||
import type {
|
||||
Action,
|
||||
Branch,
|
||||
BranchRequest,
|
||||
Repository
|
||||
} from "@scm-manager/ui-types";
|
||||
import { isPending } from "../../../modules/pending";
|
||||
import { getFailure } from "../../../modules/failure";
|
||||
|
||||
@@ -25,7 +30,8 @@ export const CREATE_BRANCH_SUCCESS = `${CREATE_BRANCH}_${PENDING_SUFFIX}`;
|
||||
export const CREATE_BRANCH_FAILURE = `${CREATE_BRANCH}_${PENDING_SUFFIX}`;
|
||||
export const CREATE_BRANCH_RESET = `${CREATE_BRANCH}_${PENDING_SUFFIX}`;
|
||||
|
||||
const CONTENT_TYPE_BRANCH = "application/vnd.scmm-branch+json;v=2";
|
||||
const CONTENT_TYPE_BRANCH_REQUEST =
|
||||
"application/vnd.scmm-branchRequest+json;v=2";
|
||||
|
||||
// Fetching branches
|
||||
|
||||
@@ -79,13 +85,13 @@ export function fetchBranch(repository: Repository, name: string) {
|
||||
export function createBranch(
|
||||
link: string,
|
||||
repository: Repository,
|
||||
branch: Branch,
|
||||
branchRequest: BranchRequest,
|
||||
callback?: (branch: Branch) => void
|
||||
) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(createBranchPending(repository, branch.name));
|
||||
dispatch(createBranchPending(repository, branchRequest.name));
|
||||
return apiClient
|
||||
.post(link, branch, CONTENT_TYPE_BRANCH)
|
||||
.post(link, branchRequest, CONTENT_TYPE_BRANCH_REQUEST)
|
||||
.then(response => response.headers.get("Location"))
|
||||
.then(location => apiClient.get(location))
|
||||
.then(response => response.json())
|
||||
@@ -110,6 +116,13 @@ export function getBranches(state: Object, repository: Repository) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getBrancheCreateLink(state: Object, repository: Repository) {
|
||||
const repoState = getRepoState(state, repository);
|
||||
if (repoState && repoState.list) {
|
||||
return repoState.list._links.create.href;
|
||||
}
|
||||
}
|
||||
|
||||
function getRepoState(state: Object, repository: Repository) {
|
||||
const key = createKey(repository);
|
||||
const repoState = state.branches[key];
|
||||
|
||||
Reference in New Issue
Block a user