"@types/react-dropzone": "4.2.2",
"@types/react-highlight-words": "0.12.0",
"@types/redux-form": "7.4.5",
+ "@types/reselect": "2.2.0",
"@types/shell-quote": "1.6.0",
"axios": "0.18.0",
"classnames": "2.2.6",
}
updateCursorPosition = () => {
- console.log('cursorPoristion');
if (this.timeout) {
clearTimeout(this.timeout);
}
- this.timeout = setTimeout(() => this.forceUpdate());
+ this.timeout = setTimeout(() => this.setState({ ...this.state }));
}
getInputStyles = (): React.CSSProperties => ({
}
render() {
- console.log(`Render: ${this.props.values}`);
return <>
<div className={this.props.classes.chips}>
<Chips
componentDidUpdate(prevProps: ChipsInputProps<Value>) {
if (prevProps.values !== this.props.values) {
- console.log('didUpdate');
this.updateCursorPosition();
}
}
import { Field } from 'redux-form';
import { ERROR_MESSAGE } from '~/validators/require';
import { GenericInputProps, GenericInput } from '~/views/run-process-panel/inputs/generic-input';
-import { ChipsInput } from '../../../components/chips-input/chips-input';
+import { ChipsInput } from '~/components/chips-input/chips-input';
+import { identity } from 'lodash';
+import { createSelector } from 'reselect';
export interface StringArrayInputProps {
input: StringArrayCommandInputParameter;
name={input.id}
commandInput={input}
component={StringArrayInputComponent}
- validate={[
- isRequiredInput(input)
- ? (value: string[]) => value.length > 0 ? undefined : ERROR_MESSAGE
- : () => undefined,
- ]} />;
+ validate={validationSelector(input)} />;
+
+
+const validationSelector = createSelector(
+ isRequiredInput,
+ isRequired => isRequired
+ ? [required]
+ : undefined
+);
+
+const required = (value: string[]) =>
+ value.length > 0
+ ? undefined
+ : ERROR_MESSAGE;
const StringArrayInputComponent = (props: GenericInputProps) =>
<GenericInput
component={Input}
{...props} />;
-const Input = (props: GenericInputProps) =>
- <ChipsInput
- values={props.input.value}
- onChange={props.input.onChange}
- createNewValue={v => v} />;
+class Input extends React.PureComponent<GenericInputProps>{
+ render() {
+ return <ChipsInput
+ values={this.props.input.value}
+ onChange={this.handleChange}
+ createNewValue={identity} />;
+ }
+
+ handleChange = (values: {}[]) => {
+ const { input, meta } = this.props;
+ if (!meta.touched) {
+ input.onBlur(values);
+ }
+ input.onChange(values);
+ }
+}
import { EnumInput } from './inputs/enum-input';
import { DirectoryInput } from './inputs/directory-input';
import { StringArrayInput } from './inputs/string-array-input';
+import { createStructuredSelector, createSelector } from 'reselect';
export const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm';
inputs: CommandInputParameter[];
}
+const inputsSelector = (props: RunProcessInputFormProps) =>
+ props.inputs;
+
+const initialValuesSelector = createSelector(
+ inputsSelector,
+ inputs => inputs.reduce(
+ (values, input) => ({ ...values, [input.id]: input.default }),
+ {}));
+
+const propsSelector = createStructuredSelector({
+ initialValues: initialValuesSelector,
+});
+
+const mapStateToProps = (_: any, props: RunProcessInputFormProps) =>
+ propsSelector(props);
+
export const RunProcessInputsForm = compose(
- connect((_: any, props: RunProcessInputFormProps) => ({
- initialValues: props.inputs.reduce(
- (values, input) => ({ ...values, [input.id]: input.default }),
- {}),
- })),
+ connect(mapStateToProps),
reduxForm<WorkflowInputsData, RunProcessInputFormProps>({
form: RUN_PROCESS_INPUTS_FORM
}))(
import { isValid } from 'redux-form';
import { RUN_PROCESS_INPUTS_FORM } from './run-process-inputs-form';
import { RunProcessAdvancedForm } from './run-process-advanced-form';
+import { createSelector, createStructuredSelector } from 'reselect';
export interface RunProcessSecondStepFormDataProps {
inputs: CommandInputParameter[];
runProcess: () => void;
}
-const mapStateToProps = (state: RootState): RunProcessSecondStepFormDataProps => ({
- inputs: state.runProcessPanel.inputs,
- valid: isValid(RUN_PROCESS_BASIC_FORM)(state) &&
- isValid(RUN_PROCESS_INPUTS_FORM)(state),
+const inputsSelector = (state: RootState) =>
+ state.runProcessPanel.inputs;
+
+const validSelector = (state: RootState) =>
+ isValid(RUN_PROCESS_BASIC_FORM)(state) && isValid(RUN_PROCESS_INPUTS_FORM)(state);
+
+const mapStateToProps = createStructuredSelector({
+ inputs: inputsSelector,
+ valid: validSelector,
});
export type RunProcessSecondStepFormProps = RunProcessSecondStepFormDataProps & RunProcessSecondStepFormActionProps;
"@types/react" "*"
redux "^3.6.0 || ^4.0.0"
+"@types/reselect@2.2.0":
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/@types/reselect/-/reselect-2.2.0.tgz#c667206cfdc38190e1d379babe08865b2288575f"
+ dependencies:
+ reselect "*"
+
"@types/shell-quote@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@types/shell-quote/-/shell-quote-1.6.0.tgz#537b2949a2ebdcb0d353e448fee45b081021963f"
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
-reselect@4.0.0:
+reselect@*, reselect@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"