moved edit and delete funcs

This commit is contained in:
Florian Scholdei
2019-02-06 11:44:03 +01:00
parent 2a830e4bc4
commit 1c03c91e21
9 changed files with 84 additions and 77 deletions

View File

@@ -5,18 +5,27 @@ import type { Group } from "@scm-manager/ui-types";
import {
Subtitle,
DeleteButton,
confirmAlert
confirmAlert,
ErrorNotification
} from "@scm-manager/ui-components";
import { getDeleteGroupFailure, isDeleteGroupPending } from "../modules/groups";
import {
deleteGroup,
getDeleteGroupFailure,
isDeleteGroupPending,
} from "../modules/groups";
import { connect } from "react-redux";
import { ErrorNotification } from "@scm-manager/ui-components";
import {withRouter} from "react-router-dom";
import type {History} from "history";
type Props = {
loading: boolean,
error: Error,
group: Group,
confirmDialog?: boolean,
deleteGroup: (group: Group) => void,
deleteGroup: (group: Group, callback?: () => void) => void,
// context props
history: History,
t: string => string
};
@@ -26,7 +35,11 @@ export class DeleteGroup extends React.Component<Props> {
};
deleteGroup = () => {
this.props.deleteGroup(this.props.group);
this.props.deleteGroup(this.props.group, this.groupDeleted);
};
groupDeleted = () => {
this.props.history.push("/groups");
};
confirmDelete = () => {
@@ -86,4 +99,12 @@ const mapStateToProps = (state, ownProps) => {
};
};
export default connect(mapStateToProps)(translate("groups")(DeleteGroup));
const mapDispatchToProps = dispatch => {
return {
deleteGroup: (group: Group, callback?: () => void) => {
dispatch(deleteGroup(group, callback));
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(translate("groups")(DeleteGroup)));

View File

@@ -4,7 +4,6 @@ import { connect } from "react-redux";
import GroupForm from "../components/GroupForm";
import {
modifyGroup,
deleteGroup,
getModifyGroupFailure,
isModifyGroupPending,
modifyGroupReset
@@ -14,14 +13,13 @@ import { withRouter } from "react-router-dom";
import type { Group } from "@scm-manager/ui-types";
import { ErrorNotification } from "@scm-manager/ui-components";
import { getUserAutoCompleteLink } from "../../modules/indexResource";
import DeleteGroup from "../components/DeleteGroup";
import DeleteGroup from "./DeleteGroup";
type Props = {
group: Group,
fetchGroup: (name: string) => void,
modifyGroup: (group: Group, callback?: () => void) => void,
modifyGroupReset: Group => void,
deleteGroup: (group: Group, callback?: () => void) => void,
autocompleteLink: string,
history: History,
loading?: boolean,
@@ -42,14 +40,6 @@ class EditGroup extends React.Component<Props> {
this.props.modifyGroup(group, this.groupModified(group));
};
deleteGroup = (group: Group) => {
this.props.deleteGroup(group, this.groupDeleted);
};
groupDeleted = () => {
this.props.history.push("/groups");
};
loadUserAutocompletion = (inputValue: string) => {
const url = this.props.autocompleteLink + "?q=";
return fetch(url + inputValue)
@@ -78,7 +68,7 @@ class EditGroup extends React.Component<Props> {
loadUserSuggestions={this.loadUserAutocompletion}
/>
<hr />
<DeleteGroup group={group} deleteGroup={this.deleteGroup} />
<DeleteGroup group={group} />
</div>
);
}
@@ -102,9 +92,6 @@ const mapDispatchToProps = dispatch => {
},
modifyGroupReset: (group: Group) => {
dispatch(modifyGroupReset(group));
},
deleteGroup: (group: Group, callback?: () => void) => {
dispatch(deleteGroup(group, callback));
}
};
};

View File

@@ -8,19 +8,24 @@ import {
confirmAlert,
ErrorNotification
} from "@scm-manager/ui-components";
import { getDeleteRepoFailure, isDeleteRepoPending } from "../modules/repos";
import {
deleteRepo,
getDeleteRepoFailure,
isDeleteRepoPending,
} from "../modules/repos";
import { connect } from "react-redux";
import {withRouter} from "react-router-dom";
import type {History} from "history";
type Props = {
loading: boolean,
error: Error,
repository: Repository,
confirmDialog?: boolean,
// dispatcher functions
delete: Repository => void,
deleteRepo: (Repository, () => void) => void,
// context props
history: History,
t: string => string
};
@@ -29,8 +34,12 @@ class DeleteRepo extends React.Component<Props> {
confirmDialog: true
};
deleted = () => {
this.props.history.push("/repos");
};
deleteRepo = () => {
this.props.delete(this.props.repository);
this.props.deleteRepo(this.props.repository, this.deleted);
};
confirmDelete = () => {
@@ -91,4 +100,15 @@ const mapStateToProps = (state, ownProps) => {
};
};
export default connect(mapStateToProps)(translate("repos")(DeleteRepo));
const mapDispatchToProps = dispatch => {
return {
deleteRepo: (repo: Repository, callback: () => void) => {
dispatch(deleteRepo(repo, callback));
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withRouter(translate("repos")(DeleteRepo)));

View File

@@ -32,7 +32,7 @@ describe("DeleteRepo", () => {
};
const navLink = mount(
<DeleteRepo repository={repository} delete={() => {}} store={store} />
<DeleteRepo repository={repository} store={store} />
);
expect(navLink.text()).toBeNull();
});
@@ -47,7 +47,7 @@ describe("DeleteRepo", () => {
};
const navLink = mount(
<DeleteRepo repository={repository} delete={() => {}} store={store} />,
<DeleteRepo repository={repository} store={store} />,
options.get()
);
expect(navLink.text()).not.toBe("");
@@ -63,7 +63,7 @@ describe("DeleteRepo", () => {
};
const navLink = mount(
<DeleteRepo repository={repository} delete={() => {}} store={store} />,
<DeleteRepo repository={repository} store={store} />,
options.get()
);
navLink.find("button").simulate("click");
@@ -80,16 +80,10 @@ describe("DeleteRepo", () => {
}
};
let calledUrl = null;
function capture(repository) {
calledUrl = repository._links.delete.href;
}
const navLink = mount(
<DeleteRepo
repository={repository}
confirmDialog={false}
delete={capture}
store={store}
/>,
options.get()

View File

@@ -3,11 +3,10 @@ import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import RepositoryForm from "../components/form";
import DeleteRepo from "../components/DeleteRepo";
import DeleteRepo from "./DeleteRepo";
import type { Repository } from "@scm-manager/ui-types";
import {
modifyRepo,
deleteRepo,
isModifyRepoPending,
getModifyRepoFailure,
modifyRepoReset
@@ -22,7 +21,6 @@ type Props = {
modifyRepo: (Repository, () => void) => void,
modifyRepoReset: Repository => void,
deleteRepo: (Repository, () => void) => void,
// context props
repository: Repository,
@@ -41,14 +39,6 @@ class EditRepo extends React.Component<Props> {
history.push(`/repo/${repository.namespace}/${repository.name}`);
};
deleted = () => {
this.props.history.push("/repos");
};
delete = (repository: Repository) => {
this.props.deleteRepo(repository, this.deleted);
};
stripEndingSlash = (url: string) => {
if (url.endsWith("/")) {
return url.substring(0, url.length - 2);
@@ -86,7 +76,7 @@ class EditRepo extends React.Component<Props> {
props={extensionProps}
renderAll={true}
/>
<DeleteRepo repository={repository} delete={this.delete} />
<DeleteRepo repository={repository} />
</div>
);
}
@@ -109,9 +99,6 @@ const mapDispatchToProps = dispatch => {
},
modifyRepoReset: (repo: Repository) => {
dispatch(modifyRepoReset(repo));
},
deleteRepo: (repo: Repository, callback: () => void) => {
dispatch(deleteRepo(repo, callback));
}
};
};

View File

@@ -5,22 +5,23 @@ import type { User } from "@scm-manager/ui-types";
import {
Subtitle,
DeleteButton,
confirmAlert
confirmAlert,
ErrorNotification
} from "@scm-manager/ui-components";
import { getDeleteUserFailure, isDeleteUserPending } from "../modules/users";
import {deleteUser, getDeleteUserFailure, isDeleteUserPending} from "../modules/users";
import { connect } from "react-redux";
import { ErrorNotification } from "@scm-manager/ui-components";
import {withRouter} from "react-router-dom";
import type {History} from "history";
type Props = {
loading: boolean,
error: Error,
user: User,
confirmDialog?: boolean,
deleteUser: (user: User, callback?: () => void) => void,
// dispatcher functions
deleteUser: (user: User) => void,
// context objects
// context props
history: History,
t: string => string
};
@@ -29,8 +30,12 @@ class DeleteUser extends React.Component<Props> {
confirmDialog: true
};
userDeleted = () => {
this.props.history.push("/users");
};
deleteUser = () => {
this.props.deleteUser(this.props.user);
this.props.deleteUser(this.props.user, this.userDeleted);
};
confirmDelete = () => {
@@ -90,4 +95,12 @@ const mapStateToProps = (state, ownProps) => {
};
};
export default connect(mapStateToProps)(translate("users")(DeleteUser));
const mapDispatchToProps = dispatch => {
return {
deleteUser: (user: User, callback?: () => void) => {
dispatch(deleteUser(user, callback));
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(translate("users")(DeleteUser)));

View File

@@ -3,16 +3,13 @@ import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import UserForm from "../components/UserForm";
import DeleteUser from "../components/DeleteUser";
import DeleteUser from "./DeleteUser";
import type { User } from "@scm-manager/ui-types";
import {
modifyUser,
deleteUser,
isModifyUserPending,
getModifyUserFailure,
modifyUserReset,
isDeleteUserPending,
getDeleteUserFailure
} from "../modules/users";
import type { History } from "history";
import { ErrorNotification } from "@scm-manager/ui-components";
@@ -24,7 +21,6 @@ type Props = {
// dispatch functions
modifyUser: (user: User, callback?: () => void) => void,
modifyUserReset: User => void,
deleteUser: (user: User, callback?: () => void) => void,
// context objects
user: User,
@@ -45,14 +41,6 @@ class EditUser extends React.Component<Props> {
this.props.modifyUser(user, this.userModified(user));
};
userDeleted = () => {
this.props.history.push("/users");
};
deleteUser = (user: User) => {
this.props.deleteUser(user, this.userDeleted);
};
render() {
const { user, loading, error } = this.props;
return (
@@ -64,7 +52,7 @@ class EditUser extends React.Component<Props> {
loading={loading}
/>
<hr />
<DeleteUser user={user} deleteUser={this.deleteUser} />
<DeleteUser user={user} />
</div>
);
}
@@ -86,9 +74,6 @@ const mapDispatchToProps = dispatch => {
},
modifyUserReset: (user: User) => {
dispatch(modifyUserReset(user));
},
deleteUser: (user: User, callback?: () => void) => {
dispatch(deleteUser(user, callback));
}
};
};