/* Copyright (C) 2017 Cloudbase Solutions SRL This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ import React from "react"; import { observer } from "mobx-react"; import styled from "styled-components"; import Button from "@src/components/ui/Button"; import FieldInput from "@src/components/ui/FieldInput"; import LabelDictionary from "@src/utils/LabelDictionary"; import KeyboardManager from "@src/utils/KeyboardManager"; import { executionOptions } from "@src/constants"; import type { Field } from "@src/@types/Field"; import executionImage from "./images/execution.svg"; import LoadingButton from "@src/components/ui/LoadingButton/LoadingButton"; const Wrapper = styled.div` display: flex; flex-direction: column; align-items: center; padding: 0 32px 32px 32px; `; const ExecutionImage = styled.div` margin-top: 48px; margin-bottom: 96px; width: 96px; height: 96px; background: url("${executionImage}") no-repeat center; `; const Form = styled.div` height: 120px; `; const Buttons = styled.div` display: flex; justify-content: space-between; width: 100%; `; const FieldInputStyled = styled(FieldInput)` width: 319px; justify-content: space-between; `; type Props = { options?: { [prop: string]: any } | null; disableExecutionOptions: boolean; onChange?: (fieldName: string, fieldValue: string) => void; executionLabel: string; executing?: boolean; onCancelClick: () => void; onExecuteClick: (options: Field[]) => void; }; type State = { fields: Field[]; }; @observer class TransferExecutionOptions extends React.Component { static defaultProps = { executionLabel: "Execute", executing: false, }; state: State = { fields: [...executionOptions], }; componentDidMount() { KeyboardManager.onEnter( "execution-options", () => { this.props.onExecuteClick(this.state.fields); }, 2 ); } componentWillUnmount() { KeyboardManager.removeKeyDown("execution-options"); } getFieldValue(field: Field) { if (!this.props.options || this.props.options[field.name] == null) { return field.value; } return this.props.options[field.name]; } handleValueChange(field: Field, value: string) { this.setState(prevState => { const fields = prevState.fields.map(f => { if (f.name === field.name) { return { ...f, value }; } return { ...f }; }); return { fields }; }); if (this.props.onChange) { this.props.onChange(field.name, value); } } render() { return (
{this.state.fields.map(field => ( this.handleValueChange(field, value)} disabled={this.props.disableExecutionOptions} description={ this.props.disableExecutionOptions ? "The execution options are disabled for the source provider" : "" } /> ))} {this.props.executing ? ( Executing ... ) : ( )}
); } } export default TransferExecutionOptions;