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,34 +1,37 @@
//@flow
import React from "react";
import React from 'react';
import { AddButton } from "../buttons";
import InputField from "./InputField";
import { AddButton } from '../buttons';
import InputField from './InputField';
type Props = {
addEntry: string => void,
disabled: boolean,
buttonLabel: string,
fieldLabel: string,
errorMessage: string,
helpText?: string,
validateEntry?: string => boolean
addEntry: (p: string) => void;
disabled: boolean;
buttonLabel: string;
fieldLabel: string;
errorMessage: string;
helpText?: string;
validateEntry?: (p: string) => boolean;
};
type State = {
entryToAdd: string
entryToAdd: string;
};
class AddEntryToTableField extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
entryToAdd: ""
entryToAdd: '',
};
}
isValid = () => {
const {validateEntry} = this.props;
if (!this.state.entryToAdd || this.state.entryToAdd === "" || !validateEntry) {
const { validateEntry } = this.props;
if (
!this.state.entryToAdd ||
this.state.entryToAdd === '' ||
!validateEntry
) {
return true;
} else {
return validateEntry(this.state.entryToAdd);
@@ -41,7 +44,7 @@ class AddEntryToTableField extends React.Component<Props, State> {
buttonLabel,
fieldLabel,
errorMessage,
helpText
helpText,
} = this.props;
return (
<div className="field">
@@ -58,7 +61,7 @@ class AddEntryToTableField extends React.Component<Props, State> {
<AddButton
label={buttonLabel}
action={this.addButtonClicked}
disabled={disabled || this.state.entryToAdd ==="" || !this.isValid()}
disabled={disabled || this.state.entryToAdd === '' || !this.isValid()}
/>
</div>
);
@@ -72,13 +75,16 @@ class AddEntryToTableField extends React.Component<Props, State> {
appendEntry = () => {
const { entryToAdd } = this.state;
this.props.addEntry(entryToAdd);
this.setState({ ...this.state, entryToAdd: "" });
this.setState({
...this.state,
entryToAdd: '',
});
};
handleAddEntryChange = (entryname: string) => {
this.setState({
...this.state,
entryToAdd: entryname
entryToAdd: entryname,
});
};
}

View File

@@ -1,30 +1,31 @@
//@flow
import React from "react";
import React from 'react';
import type { AutocompleteObject, SelectValue } from "@scm-manager/ui-types";
import Autocomplete from "../Autocomplete";
import AddButton from "../buttons/AddButton";
import { AutocompleteObject, SelectValue } from '@scm-manager/ui-types';
import Autocomplete from '../Autocomplete';
import AddButton from '../buttons/AddButton';
type Props = {
addEntry: SelectValue => void,
disabled: boolean,
buttonLabel: string,
fieldLabel: string,
helpText?: string,
loadSuggestions: string => Promise<AutocompleteObject>,
placeholder?: string,
loadingMessage?: string,
noOptionsMessage?: string
addEntry: (p: SelectValue) => void;
disabled: boolean;
buttonLabel: string;
fieldLabel: string;
helpText?: string;
loadSuggestions: (p: string) => Promise<AutocompleteObject>;
placeholder?: string;
loadingMessage?: string;
noOptionsMessage?: string;
};
type State = {
selectedValue?: SelectValue
selectedValue?: SelectValue;
};
class AutocompleteAddEntryToTableField extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { selectedValue: undefined };
this.state = {
selectedValue: undefined,
};
}
render() {
const {
@@ -35,7 +36,7 @@ class AutocompleteAddEntryToTableField extends React.Component<Props, State> {
loadSuggestions,
placeholder,
loadingMessage,
noOptionsMessage
noOptionsMessage,
} = this.props;
const { selectedValue } = this.state;
@@ -73,15 +74,19 @@ class AutocompleteAddEntryToTableField extends React.Component<Props, State> {
return;
}
// $FlowFixMe null is needed to clear the selection; undefined does not work
this.setState({ ...this.state, selectedValue: null }, () =>
this.props.addEntry(selectedValue)
this.setState(
{
...this.state,
selectedValue: null,
},
() => this.props.addEntry(selectedValue),
);
};
handleAddEntryChange = (selection: SelectValue) => {
this.setState({
...this.state,
selectedValue: selection
selectedValue: selection,
});
};
}

View File

@@ -1,18 +1,16 @@
//@flow
import React from "react";
import { Help } from "../index";
import React from 'react';
import { Help } from '../index';
type Props = {
label?: string,
name?: string,
checked: boolean,
onChange?: (value: boolean, name?: string) => void,
disabled?: boolean,
helpText?: string
label?: string;
name?: string;
checked: boolean;
onChange?: (value: boolean, name?: string) => void;
disabled?: boolean;
helpText?: string;
};
class Checkbox extends React.Component<Props> {
onCheckboxChange = (event: SyntheticInputEvent<HTMLInputElement>) => {
if (this.props.onChange) {
this.props.onChange(event.target.checked, this.props.name);
@@ -36,8 +34,7 @@ class Checkbox extends React.Component<Props> {
checked={this.props.checked}
onChange={this.onCheckboxChange}
disabled={this.props.disabled}
/>
{" "}
/>{' '}
{this.props.label}
{this.renderHelp()}
</label>

View File

@@ -1,43 +0,0 @@
// @flow
import React from "react";
import classNames from "classnames";
type Props = {
options: string[],
optionValues?: string[],
optionSelected: string => void,
preselectedOption?: string,
className: any,
disabled?: boolean
};
class DropDown extends React.Component<Props> {
render() {
const { options, optionValues, preselectedOption, className, disabled } = this.props;
return (
<div className={classNames(className, "select", disabled ? "disabled": "")}>
<select
value={preselectedOption ? preselectedOption : ""}
onChange={this.change}
disabled={disabled}
>
<option key="" />
{options.map((option, index) => {
return (
<option key={option} value={optionValues && optionValues[index] ? optionValues[index] : option}>
{option}
</option>
);
})}
</select>
</div>
);
}
change = (event: SyntheticInputEvent<HTMLSelectElement>) => {
this.props.optionSelected(event.target.value);
};
}
export default DropDown;

View File

@@ -0,0 +1,56 @@
import React from 'react';
import classNames from 'classnames';
type Props = {
options: string[];
optionValues?: string[];
optionSelected: (p: string) => void;
preselectedOption?: string;
className: any;
disabled?: boolean;
};
class DropDown extends React.Component<Props> {
render() {
const {
options,
optionValues,
preselectedOption,
className,
disabled,
} = this.props;
return (
<div
className={classNames(className, 'select', disabled ? 'disabled' : '')}
>
<select
value={preselectedOption ? preselectedOption : ''}
onChange={this.change}
disabled={disabled}
>
<option key="" />
{options.map((option, index) => {
return (
<option
key={option}
value={
optionValues && optionValues[index]
? optionValues[index]
: option
}
>
{option}
</option>
);
})}
</select>
</div>
);
}
change = (event: SyntheticInputEvent<HTMLSelectElement>) => {
this.props.optionSelected(event.target.value);
};
}
export default DropDown;

View File

@@ -1,18 +1,17 @@
//@flow
import React from "react";
import { translate } from "react-i18next";
import styled from "styled-components";
import React from 'react';
import { translate } from 'react-i18next';
import styled from 'styled-components';
type Props = {
filter: string => void,
value?: string,
filter: (p: string) => void;
value?: string;
// context props
t: string => string
t: (p: string) => string;
};
type State = {
value: string
value: string;
};
const FixedHeightInput = styled.input`
@@ -22,11 +21,15 @@ const FixedHeightInput = styled.input`
class FilterInput extends React.Component<Props, State> {
constructor(props) {
super(props);
this.state = { value: this.props.value ? this.props.value : "" };
this.state = {
value: this.props.value ? this.props.value : '',
};
}
handleChange = event => {
this.setState({ value: event.target.value });
this.setState({
value: event.target.value,
});
};
handleSubmit = event => {
@@ -42,7 +45,7 @@ class FilterInput extends React.Component<Props, State> {
<FixedHeightInput
className="input"
type="search"
placeholder={t("filterEntries")}
placeholder={t('filterEntries')}
value={this.state.value}
onChange={this.handleChange}
/>
@@ -55,4 +58,4 @@ class FilterInput extends React.Component<Props, State> {
}
}
export default translate("commons")(FilterInput);
export default translate('commons')(FilterInput);

View File

@@ -1,30 +1,29 @@
//@flow
import React from "react";
import classNames from "classnames";
import LabelWithHelpIcon from "./LabelWithHelpIcon";
import React from 'react';
import classNames from 'classnames';
import LabelWithHelpIcon from './LabelWithHelpIcon';
type Props = {
label?: string,
name?: string,
placeholder?: string,
value?: string,
type?: string,
autofocus?: boolean,
onChange: (value: string, name?: string) => void,
onReturnPressed?: () => void,
validationError: boolean,
errorMessage: string,
disabled?: boolean,
helpText?: string
label?: string;
name?: string;
placeholder?: string;
value?: string;
type?: string;
autofocus?: boolean;
onChange: (value: string, name?: string) => void;
onReturnPressed?: () => void;
validationError: boolean;
errorMessage: string;
disabled?: boolean;
helpText?: string;
};
class InputField extends React.Component<Props> {
static defaultProps = {
type: "text",
placeholder: ""
type: 'text',
placeholder: '',
};
field: ?HTMLInputElement;
field: HTMLInputElement | null | undefined;
componentDidMount() {
if (this.props.autofocus && this.field) {
@@ -41,7 +40,7 @@ class InputField extends React.Component<Props> {
if (!onReturnPressed) {
return;
}
if (event.key === "Enter") {
if (event.key === 'Enter') {
event.preventDefault();
onReturnPressed();
}
@@ -56,13 +55,13 @@ class InputField extends React.Component<Props> {
errorMessage,
disabled,
label,
helpText
helpText,
} = this.props;
const errorView = validationError ? "is-danger" : "";
const errorView = validationError ? 'is-danger' : '';
const helper = validationError ? (
<p className="help is-danger">{errorMessage}</p>
) : (
""
''
);
return (
<div className="field">
@@ -72,7 +71,7 @@ class InputField extends React.Component<Props> {
ref={input => {
this.field = input;
}}
className={classNames("input", errorView)}
className={classNames('input', errorView)}
type={type}
placeholder={placeholder}
value={value}

View File

@@ -1,36 +1,32 @@
//@flow
import React from "react";
import Help from "../Help.js";
import React from 'react';
import Help from '../Help';
type Props = {
label?: string,
helpText?: string
label?: string;
helpText?: string;
};
class LabelWithHelpIcon extends React.Component<Props> {
renderHelp() {
const { helpText } = this.props;
if (helpText) {
return (
<Help message={helpText} />
);
return <Help message={helpText} />;
}
}
render() {
const {label } = this.props;
const { label } = this.props;
if (label) {
const help = this.renderHelp();
return (
<label className="label">
{label} { help }
{label} {help}
</label>
);
}
return "";
return '';
}
}

View File

@@ -1,39 +0,0 @@
//@flow
import React from "react";
import { translate } from "react-i18next";
import type { DisplayedUser } from "@scm-manager/ui-types";
import TagGroup from "./TagGroup";
type Props = {
members: string[],
memberListChanged: (string[]) => void,
label?: string,
helpText?: string,
t: string => string
};
class MemberNameTagGroup extends React.Component<Props> {
render() {
const { members, label, helpText, t } = this.props;
const membersExtended = members.map(id => {
return { id, displayName: id, mail: "" };
});
return (
<TagGroup
items={membersExtended}
label={label ? label : t("group.members")}
helpText={helpText ? helpText : t("groupForm.help.memberHelpText")}
onRemove={this.removeEntry}
/>
);
}
removeEntry = (membersExtended: DisplayedUser[]) => {
const members = membersExtended.map(function(item) {
return item["id"];
});
this.props.memberListChanged(members);
};
}
export default translate("groups")(MemberNameTagGroup);

View File

@@ -0,0 +1,42 @@
import React from 'react';
import { translate } from 'react-i18next';
import { DisplayedUser } from '@scm-manager/ui-types';
import TagGroup from './TagGroup';
type Props = {
members: string[];
memberListChanged: (p: string[]) => void;
label?: string;
helpText?: string;
t: (p: string) => string;
};
class MemberNameTagGroup extends React.Component<Props> {
render() {
const { members, label, helpText, t } = this.props;
const membersExtended = members.map(id => {
return {
id,
displayName: id,
mail: '',
};
});
return (
<TagGroup
items={membersExtended}
label={label ? label : t('group.members')}
helpText={helpText ? helpText : t('groupForm.help.memberHelpText')}
onRemove={this.removeEntry}
/>
);
}
removeEntry = (membersExtended: DisplayedUser[]) => {
const members = membersExtended.map(function(item) {
return item['id'];
});
this.props.memberListChanged(members);
};
}
export default translate('groups')(MemberNameTagGroup);

View File

@@ -1,39 +1,37 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import InputField from "./InputField";
import React from 'react';
import { translate } from 'react-i18next';
import InputField from './InputField';
type State = {
password: string,
confirmedPassword: string,
passwordValid: boolean,
passwordConfirmationFailed: boolean
password: string;
confirmedPassword: string;
passwordValid: boolean;
passwordConfirmationFailed: boolean;
};
type Props = {
passwordChanged: (string, boolean) => void,
passwordValidator?: string => boolean,
passwordChanged: (p1: string, p2: boolean) => void;
passwordValidator?: (p: string) => boolean;
// Context props
t: string => string
t: (p: string) => string;
};
class PasswordConfirmation extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
password: "",
confirmedPassword: "",
password: '',
confirmedPassword: '',
passwordValid: true,
passwordConfirmationFailed: false
passwordConfirmationFailed: false,
};
}
componentDidMount() {
this.setState({
password: "",
confirmedPassword: "",
password: '',
confirmedPassword: '',
passwordValid: true,
passwordConfirmationFailed: false
passwordConfirmationFailed: false,
});
}
@@ -43,22 +41,22 @@ class PasswordConfirmation extends React.Component<Props, State> {
<div className="columns is-multiline">
<div className="column is-half">
<InputField
label={t("password.newPassword")}
label={t('password.newPassword')}
type="password"
onChange={this.handlePasswordChange}
value={this.state.password ? this.state.password : ""}
value={this.state.password ? this.state.password : ''}
validationError={!this.state.passwordValid}
errorMessage={t("password.passwordInvalid")}
errorMessage={t('password.passwordInvalid')}
/>
</div>
<div className="column is-half">
<InputField
label={t("password.confirmPassword")}
label={t('password.confirmPassword')}
type="password"
onChange={this.handlePasswordValidationChange}
value={this.state ? this.state.confirmedPassword : ""}
value={this.state ? this.state.confirmedPassword : ''}
validationError={this.state.passwordConfirmationFailed}
errorMessage={t("password.passwordConfirmFailed")}
errorMessage={t('password.passwordConfirmFailed')}
/>
</div>
</div>
@@ -80,9 +78,9 @@ class PasswordConfirmation extends React.Component<Props, State> {
this.setState(
{
confirmedPassword,
passwordConfirmationFailed: !passwordConfirmed
passwordConfirmationFailed: !passwordConfirmed,
},
this.propagateChange
this.propagateChange,
);
};
@@ -94,9 +92,9 @@ class PasswordConfirmation extends React.Component<Props, State> {
{
passwordValid: this.validatePassword(password),
passwordConfirmationFailed,
password: password
password: password,
},
this.propagateChange
this.propagateChange,
);
};
@@ -109,4 +107,4 @@ class PasswordConfirmation extends React.Component<Props, State> {
};
}
export default translate("commons")(PasswordConfirmation);
export default translate('commons')(PasswordConfirmation);

View File

@@ -1,15 +1,14 @@
//@flow
import React from "react";
import { Help } from "../index";
import React from 'react';
import { Help } from '../index';
type Props = {
label?: string,
name?: string,
value?: string,
checked: boolean,
onChange?: (value: boolean, name?: string) => void,
disabled?: boolean,
helpText?: string
label?: string;
name?: string;
value?: string;
checked: boolean;
onChange?: (value: boolean, name?: string) => void;
disabled?: boolean;
helpText?: string;
};
class Radio extends React.Component<Props> {
@@ -30,7 +29,7 @@ class Radio extends React.Component<Props> {
checked={this.props.checked}
onChange={this.props.onChange}
disabled={this.props.disabled}
/>{" "}
/>{' '}
{this.props.label}
{this.renderHelp()}
</label>

View File

@@ -1,26 +1,25 @@
//@flow
import React from "react";
import classNames from "classnames";
import LabelWithHelpIcon from "./LabelWithHelpIcon";
import React from 'react';
import classNames from 'classnames';
import LabelWithHelpIcon from './LabelWithHelpIcon';
export type SelectItem = {
value: string,
label: string
value: string;
label: string;
};
type Props = {
name?: string,
label?: string,
options: SelectItem[],
value?: string,
onChange: (value: string, name?: string) => void,
loading?: boolean,
helpText?: string,
disabled?: boolean
name?: string;
label?: string;
options: SelectItem[];
value?: string;
onChange: (value: string, name?: string) => void;
loading?: boolean;
helpText?: string;
disabled?: boolean;
};
class Select extends React.Component<Props> {
field: ?HTMLSelectElement;
field: HTMLSelectElement | null | undefined;
componentDidMount() {
// trigger change after render, if value is null to set it to the first value
@@ -36,16 +35,12 @@ class Select extends React.Component<Props> {
render() {
const { options, value, label, helpText, loading, disabled } = this.props;
const loadingClass = loading ? "is-loading" : "";
const loadingClass = loading ? 'is-loading' : '';
return (
<div className="field">
<LabelWithHelpIcon label={label} helpText={helpText} />
<div className={classNames(
"control select",
loadingClass
)}>
<div className={classNames('control select', loadingClass)}>
<select
ref={input => {
this.field = input;
@@ -56,7 +51,7 @@ class Select extends React.Component<Props> {
>
{options.map(opt => {
return (
<option value={opt.value} key={"KEY_" + opt.value}>
<option value={opt.value} key={'KEY_' + opt.value}>
{opt.label}
</option>
);

View File

@@ -1,13 +1,12 @@
//@flow
import * as React from "react";
import type { DisplayedUser } from "@scm-manager/ui-types";
import { Help, Tag } from "../index";
import * as React from 'react';
import { DisplayedUser } from '@scm-manager/ui-types';
import { Help, Tag } from '../index';
type Props = {
items: DisplayedUser[],
label: string,
helpText?: string,
onRemove: (DisplayedUser[]) => void
items: DisplayedUser[];
label: string;
helpText?: string;
onRemove: (p: DisplayedUser[]) => void;
};
export default class TagGroup extends React.Component<Props> {
@@ -24,11 +23,11 @@ export default class TagGroup extends React.Component<Props> {
<strong>
{label}
{help}
{items.length > 0 ? ":" : ""}
{items.length > 0 ? ':' : ''}
</strong>
</div>
) : (
""
''
)}
{items.map((item, key) => {
return (

View File

@@ -1,25 +1,24 @@
//@flow
import React from "react";
import LabelWithHelpIcon from "./LabelWithHelpIcon";
import React from 'react';
import LabelWithHelpIcon from './LabelWithHelpIcon';
export type SelectItem = {
value: string,
label: string
value: string;
label: string;
};
type Props = {
name?: string,
label?: string,
placeholder?: SelectItem[],
value?: string,
autofocus?: boolean,
onChange: (value: string, name?: string) => void,
helpText?: string,
disabled?: boolean
name?: string;
label?: string;
placeholder?: SelectItem[];
value?: string;
autofocus?: boolean;
onChange: (value: string, name?: string) => void;
helpText?: string;
disabled?: boolean;
};
class Textarea extends React.Component<Props> {
field: ?HTMLTextAreaElement;
field: HTMLTextAreaElement | null | undefined;
componentDidMount() {
if (this.props.autofocus && this.field) {

View File

@@ -1,16 +0,0 @@
// @create-index
export { default as AddEntryToTableField } from "./AddEntryToTableField.js";
export { default as AutocompleteAddEntryToTableField } from "./AutocompleteAddEntryToTableField.js";
export { default as TagGroup } from "./TagGroup.js";
export { default as MemberNameTagGroup } from "./MemberNameTagGroup.js";
export { default as Checkbox } from "./Checkbox.js";
export { default as Radio } from "./Radio.js";
export { default as FilterInput } from "./FilterInput.js";
export { default as InputField } from "./InputField.js";
export { default as Select } from "./Select.js";
export { default as Textarea } from "./Textarea.js";
export { default as PasswordConfirmation } from "./PasswordConfirmation.js";
export { default as LabelWithHelpIcon } from "./LabelWithHelpIcon.js";
export { default as DropDown } from "./DropDown.js";

View File

@@ -0,0 +1,17 @@
// @create-index
export { default as AddEntryToTableField } from './AddEntryToTableField';
export {
default as AutocompleteAddEntryToTableField,
} from './AutocompleteAddEntryToTableField';
export { default as TagGroup } from './TagGroup';
export { default as MemberNameTagGroup } from './MemberNameTagGroup';
export { default as Checkbox } from './Checkbox';
export { default as Radio } from './Radio';
export { default as FilterInput } from './FilterInput';
export { default as InputField } from './InputField';
export { default as Select } from './Select';
export { default as Textarea } from './Textarea';
export { default as PasswordConfirmation } from './PasswordConfirmation';
export { default as LabelWithHelpIcon } from './LabelWithHelpIcon';
export { default as DropDown } from './DropDown';