mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import * as React from "react";
|
||||
import { binder } from "@scm-manager/ui-extensions";
|
||||
|
||||
type Props = {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import type { Changeset, Repository } from "../../../../../scm-ui-components/packages/ui-types/src/index";
|
||||
import type {
|
||||
Changeset,
|
||||
Repository
|
||||
} from "../../../../../scm-ui-components/packages/ui-types/src/index";
|
||||
import { Interpolate, translate } from "react-i18next";
|
||||
import injectSheet from "react-jss";
|
||||
import ChangesetTag from "./ChangesetTag";
|
||||
@@ -11,6 +14,7 @@ import AvatarWrapper from "./AvatarWrapper";
|
||||
import AvatarImage from "./AvatarImage";
|
||||
import classNames from "classnames";
|
||||
import ChangesetId from "./ChangesetId";
|
||||
import type { Tag } from "@scm-manager/ui-types";
|
||||
|
||||
const styles = {
|
||||
spacing: {
|
||||
@@ -27,7 +31,7 @@ type Props = {
|
||||
|
||||
class ChangesetDetails extends React.Component<Props> {
|
||||
render() {
|
||||
const { changeset, repository, t, classes } = this.props;
|
||||
const { changeset, repository, classes } = this.props;
|
||||
|
||||
const description = parseDescription(changeset.description);
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ describe("changesets", () => {
|
||||
{
|
||||
"foo/bar": {
|
||||
byId: {
|
||||
["id2"]: {
|
||||
"id2": {
|
||||
id: "id2",
|
||||
author: { mail: "mail@author.com", name: "author" }
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import { Checkbox, InputField, SubmitButton } from "@scm-manager/ui-components";
|
||||
import TypeSelector from "./TypeSelector";
|
||||
import type {
|
||||
PermissionCollection,
|
||||
PermissionEntry
|
||||
PermissionCreateEntry
|
||||
} from "@scm-manager/ui-types";
|
||||
import * as validator from "./permissionValidation";
|
||||
|
||||
type Props = {
|
||||
t: string => string,
|
||||
createPermission: (permission: PermissionEntry) => void,
|
||||
createPermission: (permission: PermissionCreateEntry) => void,
|
||||
loading: boolean,
|
||||
currentPermissions: PermissionCollection
|
||||
};
|
||||
@@ -65,7 +65,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
<SubmitButton
|
||||
label={t("permission.add-permission.submit-button")}
|
||||
loading={loading}
|
||||
disabled={!this.state.valid || this.state.name == ""}
|
||||
disabled={!this.state.valid || this.state.name === ""}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
// @flow
|
||||
import { validation } from "@scm-manager/ui-components";
|
||||
import type {
|
||||
PermissionCollection,
|
||||
} from "@scm-manager/ui-types";
|
||||
import type { PermissionCollection } from "@scm-manager/ui-types";
|
||||
const isNameValid = validation.isNameValid;
|
||||
|
||||
export { isNameValid };
|
||||
|
||||
export const isPermissionValid = (name: string, groupPermission: boolean, permissions: PermissionCollection) => {
|
||||
return isNameValid(name) && !currentPermissionIncludeName(name, groupPermission, permissions);
|
||||
export const isPermissionValid = (
|
||||
name: string,
|
||||
groupPermission: boolean,
|
||||
permissions: PermissionCollection
|
||||
) => {
|
||||
return (
|
||||
isNameValid(name) &&
|
||||
!currentPermissionIncludeName(name, groupPermission, permissions)
|
||||
);
|
||||
};
|
||||
|
||||
const currentPermissionIncludeName = (name: string, groupPermission: boolean, permissions: PermissionCollection) => {
|
||||
const currentPermissionIncludeName = (
|
||||
name: string,
|
||||
groupPermission: boolean,
|
||||
permissions: PermissionCollection
|
||||
) => {
|
||||
for (let i = 0; i < permissions.length; i++) {
|
||||
if (
|
||||
permissions[i].name === name &&
|
||||
permissions[i].groupPermission == groupPermission
|
||||
permissions[i].groupPermission === groupPermission
|
||||
)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ describe("permission validation", () => {
|
||||
{
|
||||
name: "PermissionName",
|
||||
groupPermission: true,
|
||||
type: "READ"
|
||||
type: "READ",
|
||||
_links: {}
|
||||
}
|
||||
];
|
||||
const name = "PermissionName";
|
||||
@@ -33,7 +34,8 @@ describe("permission validation", () => {
|
||||
{
|
||||
name: "PermissionName",
|
||||
groupPermission: false,
|
||||
type: "READ"
|
||||
type: "READ",
|
||||
_links: {}
|
||||
}
|
||||
];
|
||||
const name = "PermissionName";
|
||||
|
||||
@@ -21,7 +21,7 @@ import { Loading, ErrorPage } from "@scm-manager/ui-components";
|
||||
import type {
|
||||
Permission,
|
||||
PermissionCollection,
|
||||
PermissionEntry
|
||||
PermissionCreateEntry
|
||||
} from "@scm-manager/ui-types";
|
||||
import SinglePermission from "./SinglePermission";
|
||||
import CreatePermissionForm from "../components/CreatePermissionForm";
|
||||
@@ -39,7 +39,7 @@ type Props = {
|
||||
//dispatch functions
|
||||
fetchPermissions: (namespace: string, repoName: string) => void,
|
||||
createPermission: (
|
||||
permission: PermissionEntry,
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
@@ -176,7 +176,7 @@ const mapDispatchToProps = dispatch => {
|
||||
dispatch(fetchPermissions(namespace, repoName));
|
||||
},
|
||||
createPermission: (
|
||||
permission: PermissionEntry,
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { Action } from "@scm-manager/ui-components";
|
||||
import type {
|
||||
PermissionCollection,
|
||||
Permission,
|
||||
PermissionEntry
|
||||
PermissionCreateEntry
|
||||
} from "@scm-manager/ui-types";
|
||||
import { isPending } from "../../../modules/pending";
|
||||
import { getFailure } from "../../../modules/failure";
|
||||
@@ -219,7 +219,7 @@ export function modifyPermissionReset(namespace: string, repoName: string) {
|
||||
|
||||
// create permission
|
||||
export function createPermission(
|
||||
permission: PermissionEntry,
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
@@ -260,7 +260,7 @@ export function createPermission(
|
||||
}
|
||||
|
||||
export function createPermissionPending(
|
||||
permission: PermissionEntry,
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
@@ -272,7 +272,7 @@ export function createPermissionPending(
|
||||
}
|
||||
|
||||
export function createPermissionSuccess(
|
||||
permission: PermissionEntry,
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
|
||||
@@ -640,7 +640,7 @@ describe("permissions selectors", () => {
|
||||
it("should return true, when createPermission is true", () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
["hitchhiker/puzzle42"]: {
|
||||
"hitchhiker/puzzle42": {
|
||||
createPermission: true
|
||||
}
|
||||
}
|
||||
@@ -651,7 +651,7 @@ describe("permissions selectors", () => {
|
||||
it("should return false, when createPermission is false", () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
["hitchhiker/puzzle42"]: {
|
||||
"hitchhiker/puzzle42": {
|
||||
createPermission: false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user