use reflow to migrate from flow to typescript

This commit is contained in:
Sebastian Sdorra
2019-10-19 16:38:07 +02:00
parent f7b8050dfa
commit 6e7a08a3bb
495 changed files with 14239 additions and 13766 deletions

View File

@@ -1,31 +0,0 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import { Checkbox } from "@scm-manager/ui-components";
type Props = {
t: string => string,
disabled: boolean,
name: string,
checked: boolean,
onChange?: (value: boolean, name?: string) => void
};
class PermissionCheckbox extends React.Component<Props> {
render() {
const { t } = this.props;
return (
<Checkbox
key={this.props.name}
name={this.props.name}
helpText={t("verbs.repository." + this.props.name + ".description")}
label={t("verbs.repository." + this.props.name + ".displayName")}
checked={this.props.checked}
onChange={this.props.onChange}
disabled={this.props.disabled}
/>
);
}
}
export default translate("plugins")(PermissionCheckbox);

View File

@@ -0,0 +1,30 @@
import React from 'react';
import { translate } from 'react-i18next';
import { Checkbox } from '@scm-manager/ui-components';
type Props = {
t: (p: string) => string;
disabled: boolean;
name: string;
checked: boolean;
onChange?: (value: boolean, name?: string) => void;
};
class PermissionCheckbox extends React.Component<Props> {
render() {
const { t } = this.props;
return (
<Checkbox
key={this.props.name}
name={this.props.name}
helpText={t('verbs.repository.' + this.props.name + '.description')}
label={t('verbs.repository.' + this.props.name + '.displayName')}
checked={this.props.checked}
onChange={this.props.onChange}
disabled={this.props.disabled}
/>
);
}
}
export default translate('plugins')(PermissionCheckbox);

View File

@@ -1,16 +1,15 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import { Select } from "@scm-manager/ui-components";
import React from 'react';
import { translate } from 'react-i18next';
import { Select } from '@scm-manager/ui-components';
type Props = {
t: string => string,
availableRoles: string[],
handleRoleChange: string => void,
role: string,
label?: string,
helpText?: string,
loading?: boolean
t: (p: string) => string;
availableRoles: string[];
handleRoleChange: (p: string) => void;
role: string;
label?: string;
helpText?: string;
loading?: boolean;
};
class RoleSelector extends React.Component<Props> {
@@ -21,19 +20,19 @@ class RoleSelector extends React.Component<Props> {
handleRoleChange,
loading,
label,
helpText
helpText,
} = this.props;
if (!availableRoles) return null;
const options = role
? this.createSelectOptions(availableRoles)
: ["", ...this.createSelectOptions(availableRoles)];
: ['', ...this.createSelectOptions(availableRoles)];
return (
<Select
onChange={handleRoleChange}
value={role ? role : ""}
value={role ? role : ''}
options={options}
loading={loading}
label={label}
@@ -46,10 +45,10 @@ class RoleSelector extends React.Component<Props> {
return roles.map(role => {
return {
label: role,
value: role
value: role,
};
});
}
}
export default translate("repos")(RoleSelector);
export default translate('repos')(RoleSelector);

View File

@@ -1,92 +0,0 @@
import React from "react";
import { shallow, mount } from "@scm-manager/ui-tests/enzyme-router";
import "@scm-manager/ui-tests/enzyme";
import "@scm-manager/ui-tests/i18n";
import DeletePermissionButton from "./DeletePermissionButton";
import { confirmAlert } from "@scm-manager/ui-components";
jest.mock("@scm-manager/ui-components", () => ({
confirmAlert: jest.fn(),
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton
}));
describe("DeletePermissionButton", () => {
it("should render nothing, if the delete link is missing", () => {
const permission = {
_links: {}
};
const navLink = shallow(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>
);
expect(navLink.text()).toBe("");
});
it("should render the delete icon", () => {
const permission = {
_links: {
delete: {
href: "/permission"
}
}
};
const deleteIcon = mount(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>
);
expect(deleteIcon.html()).not.toBe("");
});
it("should open the confirm dialog on button click", () => {
const permission = {
_links: {
delete: {
href: "/permission"
}
}
};
const button = mount(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>
);
button.find(".fa-trash").simulate("click");
expect(confirmAlert.mock.calls.length).toBe(1);
});
it("should call the delete permission function with delete url", () => {
const permission = {
_links: {
delete: {
href: "/permission"
}
}
};
let calledUrl = null;
function capture(permission) {
calledUrl = permission._links.delete.href;
}
const button = mount(
<DeletePermissionButton
permission={permission}
confirmDialog={false}
deletePermission={capture}
/>
);
button.find(".fa-trash").simulate("click");
expect(calledUrl).toBe("/permission");
});
});

View File

@@ -0,0 +1,92 @@
import React from 'react';
import { shallow, mount } from '@scm-manager/ui-tests/enzyme-router';
import '@scm-manager/ui-tests/enzyme';
import '@scm-manager/ui-tests/i18n';
import DeletePermissionButton from './DeletePermissionButton';
import { confirmAlert } from '@scm-manager/ui-components';
jest.mock('@scm-manager/ui-components', () => ({
confirmAlert: jest.fn(),
DeleteButton: require.requireActual('@scm-manager/ui-components')
.DeleteButton,
}));
describe('DeletePermissionButton', () => {
it('should render nothing, if the delete link is missing', () => {
const permission = {
_links: {},
};
const navLink = shallow(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>,
);
expect(navLink.text()).toBe('');
});
it('should render the delete icon', () => {
const permission = {
_links: {
delete: {
href: '/permission',
},
},
};
const deleteIcon = mount(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>,
);
expect(deleteIcon.html()).not.toBe('');
});
it('should open the confirm dialog on button click', () => {
const permission = {
_links: {
delete: {
href: '/permission',
},
},
};
const button = mount(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>,
);
button.find('.fa-trash').simulate('click');
expect(confirmAlert.mock.calls.length).toBe(1);
});
it('should call the delete permission function with delete url', () => {
const permission = {
_links: {
delete: {
href: '/permission',
},
},
};
let calledUrl = null;
function capture(permission) {
calledUrl = permission._links.delete.href;
}
const button = mount(
<DeletePermissionButton
permission={permission}
confirmDialog={false}
deletePermission={capture}
/>,
);
button.find('.fa-trash').simulate('click');
expect(calledUrl).toBe('/permission');
});
});

View File

@@ -1,51 +1,50 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import type { Permission } from "@scm-manager/ui-types";
import { confirmAlert } from "@scm-manager/ui-components";
import React from 'react';
import { translate } from 'react-i18next';
import { Permission } from '@scm-manager/ui-types';
import { confirmAlert } from '@scm-manager/ui-components';
type Props = {
permission: Permission,
namespace: string,
repoName: string,
confirmDialog?: boolean,
t: string => string,
permission: Permission;
namespace: string;
repoName: string;
confirmDialog?: boolean;
t: (p: string) => string;
deletePermission: (
permission: Permission,
namespace: string,
repoName: string
) => void,
loading: boolean
repoName: string,
) => void;
loading: boolean;
};
class DeletePermissionButton extends React.Component<Props> {
static defaultProps = {
confirmDialog: true
confirmDialog: true,
};
deletePermission = () => {
this.props.deletePermission(
this.props.permission,
this.props.namespace,
this.props.repoName
this.props.repoName,
);
};
confirmDelete = () => {
const { t } = this.props;
confirmAlert({
title: t("permission.delete-permission-button.confirm-alert.title"),
message: t("permission.delete-permission-button.confirm-alert.message"),
title: t('permission.delete-permission-button.confirm-alert.title'),
message: t('permission.delete-permission-button.confirm-alert.message'),
buttons: [
{
label: t("permission.delete-permission-button.confirm-alert.submit"),
onClick: () => this.deletePermission()
label: t('permission.delete-permission-button.confirm-alert.submit'),
onClick: () => this.deletePermission(),
},
{
label: t("permission.delete-permission-button.confirm-alert.cancel"),
onClick: () => null
}
]
label: t('permission.delete-permission-button.confirm-alert.cancel'),
onClick: () => null,
},
],
});
};
@@ -70,4 +69,4 @@ class DeletePermissionButton extends React.Component<Props> {
}
}
export default translate("repos")(DeletePermissionButton);
export default translate('repos')(DeletePermissionButton);

View File

@@ -1,70 +1,69 @@
//@flow
import * as validator from "./permissionValidation";
import * as validator from './permissionValidation';
describe("permission validation", () => {
it("should return true if permission is valid and does not exist", () => {
describe('permission validation', () => {
it('should return true if permission is valid and does not exist', () => {
const permissions = [];
const name = "PermissionName";
const name = 'PermissionName';
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
validator.isPermissionValid(name, groupPermission, permissions),
).toBe(true);
});
it("should return true if permission is valid and does not exists with same group permission", () => {
it('should return true if permission is valid and does not exists with same group permission', () => {
const permissions = [
{
name: "PermissionName",
name: 'PermissionName',
groupPermission: true,
type: "READ",
type: 'READ',
_links: {},
verbs: []
}
verbs: [],
},
];
const name = "PermissionName";
const name = 'PermissionName';
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
validator.isPermissionValid(name, groupPermission, permissions),
).toBe(true);
});
it("should return false if permission is valid but exists", () => {
it('should return false if permission is valid but exists', () => {
const permissions = [
{
name: "PermissionName",
name: 'PermissionName',
groupPermission: false,
type: "READ",
type: 'READ',
_links: {},
verbs: []
}
verbs: [],
},
];
const name = "PermissionName";
const name = 'PermissionName';
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
validator.isPermissionValid(name, groupPermission, permissions),
).toBe(false);
});
it("should return false if permission does not exist but is invalid", () => {
it('should return false if permission does not exist but is invalid', () => {
const permissions = [];
const name = "@PermissionName";
const name = '@PermissionName';
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
validator.isPermissionValid(name, groupPermission, permissions),
).toBe(false);
});
it("should return false if permission is not valid and does not exist", () => {
it('should return false if permission is not valid and does not exist', () => {
const permissions = [];
const name = "@PermissionName";
const name = '@PermissionName';
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
validator.isPermissionValid(name, groupPermission, permissions),
).toBe(false);
});
});

View File

@@ -1,6 +1,5 @@
// @flow
import {validation} from "@scm-manager/ui-components";
import type {PermissionCollection} from "@scm-manager/ui-types";
import { validation } from '@scm-manager/ui-components';
import { PermissionCollection } from '@scm-manager/ui-types';
const isNameValid = validation.isNameValid;
@@ -9,7 +8,7 @@ export { isNameValid };
export const isPermissionValid = (
name: string,
groupPermission: boolean,
permissions: PermissionCollection
permissions: PermissionCollection,
) => {
return (
isNameValid(name) &&
@@ -20,7 +19,7 @@ export const isPermissionValid = (
const currentPermissionIncludeName = (
name: string,
groupPermission: boolean,
permissions: PermissionCollection
permissions: PermissionCollection,
) => {
for (let i = 0; i < permissions.length; i++) {
if (