fix review findings

This commit is contained in:
Konstantin Schaper
2020-10-06 13:45:17 +02:00
parent fcbdb6c2f7
commit 330e974cac
6 changed files with 41 additions and 63 deletions

View File

@@ -81,6 +81,9 @@ export const ConfirmAlert: FC<Props> = ({ title, message, buttons, close }) => {
); );
}; };
/**
* @deprecated Please use {@link ConfirmAlert} directly.
*/
export function confirmAlert(properties: Props) { export function confirmAlert(properties: Props) {
const root = document.getElementById("modalRoot"); const root = document.getElementById("modalRoot");
if (root) { if (root) {

View File

@@ -23,35 +23,24 @@
*/ */
import React, { FC, useState } from "react"; import React, { FC, useState } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { compose } from "redux"; import { useHistory } from "react-router-dom";
import { withRouter } from "react-router-dom"; import { useTranslation } from "react-i18next";
import { WithTranslation, withTranslation } from "react-i18next";
import { History } from "history";
import { RepositoryRole } from "@scm-manager/ui-types"; import { RepositoryRole } from "@scm-manager/ui-types";
import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components"; import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components";
import { deleteRole, getDeleteRoleFailure, isDeleteRolePending } from "../modules/roles"; import { deleteRole, getDeleteRoleFailure, isDeleteRolePending } from "../modules/roles";
type Props = WithTranslation & { type Props = {
loading: boolean; loading: boolean;
error: Error; error: Error;
role: RepositoryRole; role: RepositoryRole;
confirmDialog?: boolean; confirmDialog?: boolean;
deleteRole: (role: RepositoryRole, callback?: () => void) => void; deleteRole: (role: RepositoryRole, callback?: () => void) => void;
// context props
history: History;
}; };
const DeleteRepositoryRole: FC<Props> = ({ const DeleteRepositoryRole: FC<Props> = ({ confirmDialog = true, deleteRole, role, loading, error }: Props) => {
confirmDialog = true,
history,
deleteRole,
role,
loading,
error,
t
}: Props) => {
const [showConfirmAlert, setShowConfirmAlert] = useState(false); const [showConfirmAlert, setShowConfirmAlert] = useState(false);
const [t] = useTranslation("admin");
const history = useHistory();
const roleDeleted = () => { const roleDeleted = () => {
history.push("/admin/roles/"); history.push("/admin/roles/");
@@ -122,8 +111,4 @@ const mapDispatchToProps = (dispatch: any) => {
}; };
}; };
export default compose( export default connect(mapStateToProps, mapDispatchToProps)(DeleteRepositoryRole);
connect(mapStateToProps, mapDispatchToProps),
withRouter,
withTranslation("admin")
)(DeleteRepositoryRole);

View File

@@ -23,27 +23,24 @@
*/ */
import React, { FC, useState } from "react"; import React, { FC, useState } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { compose } from "redux"; import { useHistory } from "react-router-dom";
import { withRouter } from "react-router-dom"; import { useTranslation } from "react-i18next";
import { WithTranslation, withTranslation } from "react-i18next";
import { History } from "history";
import { Group } from "@scm-manager/ui-types"; import { Group } from "@scm-manager/ui-types";
import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components"; import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components";
import { deleteGroup, getDeleteGroupFailure, isDeleteGroupPending } from "../modules/groups"; import { deleteGroup, getDeleteGroupFailure, isDeleteGroupPending } from "../modules/groups";
type Props = WithTranslation & { type Props = {
loading: boolean; loading: boolean;
error: Error; error: Error;
group: Group; group: Group;
confirmDialog?: boolean; confirmDialog?: boolean;
deleteGroup: (group: Group, callback?: () => void) => void; deleteGroup: (group: Group, callback?: () => void) => void;
// context props
history: History;
}; };
export const DeleteGroup: FC<Props> = ({ confirmDialog = true, group, history, t, deleteGroup, loading, error }) => { export const DeleteGroup: FC<Props> = ({ confirmDialog = true, group, deleteGroup, loading, error }) => {
const [showConfirmAlert, setShowConfirmAlert] = useState(false); const [showConfirmAlert, setShowConfirmAlert] = useState(false);
const [t] = useTranslation("groups");
const history = useHistory();
const deleteGroupCallback = () => { const deleteGroupCallback = () => {
deleteGroup(group, groupDeleted); deleteGroup(group, groupDeleted);
@@ -114,8 +111,4 @@ const mapDispatchToProps = (dispatch: any) => {
}; };
}; };
export default compose( export default connect(mapStateToProps, mapDispatchToProps)(DeleteGroup);
connect(mapStateToProps, mapDispatchToProps),
withRouter,
withTranslation("groups")
)(DeleteGroup);

View File

@@ -23,24 +23,24 @@
*/ */
import React, { FC, useState } from "react"; import React, { FC, useState } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { compose } from "redux"; import { useHistory } from "react-router-dom";
import { RouteComponentProps, withRouter } from "react-router-dom"; import { useTranslation } from "react-i18next";
import { WithTranslation, withTranslation } from "react-i18next";
import { Repository } from "@scm-manager/ui-types"; import { Repository } from "@scm-manager/ui-types";
import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components"; import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components";
import { deleteRepo, getDeleteRepoFailure, isDeleteRepoPending } from "../modules/repos"; import { deleteRepo, getDeleteRepoFailure, isDeleteRepoPending } from "../modules/repos";
type Props = RouteComponentProps & type Props = {
WithTranslation & { loading: boolean;
loading: boolean; error: Error;
error: Error; repository: Repository;
repository: Repository; confirmDialog?: boolean;
confirmDialog?: boolean; deleteRepo: (p1: Repository, p2: () => void) => void;
deleteRepo: (p1: Repository, p2: () => void) => void; };
};
const DeleteRepo: FC<Props> = ({ confirmDialog = true, repository, history, deleteRepo, loading, error, t }: Props) => { const DeleteRepo: FC<Props> = ({ confirmDialog = true, repository, deleteRepo, loading, error }: Props) => {
const [showConfirmAlert, setShowConfirmAlert] = useState(false); const [showConfirmAlert, setShowConfirmAlert] = useState(false);
const [t] = useTranslation("repos");
const history = useHistory();
const deleted = () => { const deleted = () => {
history.push("/repos/"); history.push("/repos/");
@@ -120,4 +120,4 @@ const mapDispatchToProps = (dispatch: any) => {
}; };
}; };
export default compose(connect(mapStateToProps, mapDispatchToProps), withRouter, withTranslation("repos"))(DeleteRepo); export default connect(mapStateToProps, mapDispatchToProps)(DeleteRepo);

View File

@@ -22,11 +22,11 @@
* SOFTWARE. * SOFTWARE.
*/ */
import React, { FC, useState } from "react"; import React, { FC, useState } from "react";
import { WithTranslation, withTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Permission } from "@scm-manager/ui-types"; import { Permission } from "@scm-manager/ui-types";
import { ConfirmAlert } from "@scm-manager/ui-components"; import { ConfirmAlert } from "@scm-manager/ui-components";
type Props = WithTranslation & { type Props = {
permission: Permission; permission: Permission;
namespace: string; namespace: string;
repoName: string; repoName: string;
@@ -39,11 +39,11 @@ const DeletePermissionButton: FC<Props> = ({
confirmDialog = true, confirmDialog = true,
permission, permission,
namespace, namespace,
t,
deletePermission, deletePermission,
repoName repoName
}) => { }) => {
const [showConfirmAlert, setShowConfirmAlert] = useState(false); const [showConfirmAlert, setShowConfirmAlert] = useState(false);
const [t] = useTranslation("repos");
const deletePermissionCallback = () => { const deletePermissionCallback = () => {
deletePermission(permission, namespace, repoName); deletePermission(permission, namespace, repoName);
@@ -93,4 +93,4 @@ const DeletePermissionButton: FC<Props> = ({
); );
}; };
export default withTranslation("repos")(DeletePermissionButton); export default DeletePermissionButton;

View File

@@ -23,27 +23,24 @@
*/ */
import React, { FC, useState } from "react"; import React, { FC, useState } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { compose } from "redux"; import { useHistory } from "react-router-dom";
import { withRouter } from "react-router-dom"; import { useTranslation } from "react-i18next";
import { WithTranslation, withTranslation } from "react-i18next";
import { History } from "history";
import { User } from "@scm-manager/ui-types"; import { User } from "@scm-manager/ui-types";
import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components"; import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components";
import { deleteUser, getDeleteUserFailure, isDeleteUserPending } from "../modules/users"; import { deleteUser, getDeleteUserFailure, isDeleteUserPending } from "../modules/users";
type Props = WithTranslation & { type Props = {
loading: boolean; loading: boolean;
error: Error; error: Error;
user: User; user: User;
confirmDialog?: boolean; confirmDialog?: boolean;
deleteUser: (user: User, callback?: () => void) => void; deleteUser: (user: User, callback?: () => void) => void;
// context props
history: History;
}; };
const DeleteUser: FC<Props> = ({ confirmDialog = true, loading, error, t, history, user, deleteUser }) => { const DeleteUser: FC<Props> = ({ confirmDialog = true, loading, error, user, deleteUser }) => {
const [showConfirmAlert, setShowConfirmAlert] = useState(false); const [showConfirmAlert, setShowConfirmAlert] = useState(false);
const [t] = useTranslation("users");
const history = useHistory();
const userDeleted = () => { const userDeleted = () => {
history.push("/users/"); history.push("/users/");
@@ -114,4 +111,4 @@ const mapDispatchToProps = (dispatch: any) => {
}; };
}; };
export default compose(connect(mapStateToProps, mapDispatchToProps), withRouter, withTranslation("users"))(DeleteUser); export default connect(mapStateToProps, mapDispatchToProps)(DeleteUser);