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