import React from 'react';
import PropTypes from 'prop-types';
import {
Icon,
Button,
MessageDialog,
Table,
inlineEditFormatterFactory,
} from 'patternfly-react';
import * as resolve from 'table-resolver';
import { translate as __ } from 'foremanReact/common/I18n';
import Select from 'foremanReact/components/common/forms/Select';
import CommonForm from 'foremanReact/components/common/forms/CommonForm';
import RailsData from '../common/RailsData';
import { EasyHeaderFormatter } from '../../helper';
class ApplicationDefinitionImport extends React.Component {
onFileChange = event => {
// Update the state
this.setState({ selectedFile: event.target.files[0] });
};
static isEditing({ rowData }) {
return rowData.backup !== undefined;
}
componentDidMount() {
const { ansiblePlaybookServices, hostgroups } = this.props;
const {
initApplicationDefinitionImport,
changeEditApplicationDefinitionImportService,
} = this.props;
this.headerFormatter = EasyHeaderFormatter;
const inlineEditFormatterImpl = {
renderValue: (value, additionalData) => (
{value}
|
),
renderEditSelect: (value, additionalData, options) => (
|
),
};
const inlineEditFormatter = inlineEditFormatterFactory({
isEditing: additionalData => this.constructor.isEditing(additionalData),
renderValue: (value, additionalData) => {
let prettyValue = value;
if (additionalData.property === 'hostgroup') {
prettyValue = hostgroups[value];
}
return inlineEditFormatterImpl.renderValue(prettyValue, additionalData);
},
renderEdit: (value, additionalData) => {
if (additionalData.property === 'hostgroup') {
if (additionalData.rowData) {
return inlineEditFormatterImpl.renderEditSelect(
value,
additionalData,
hostgroups
);
}
return inlineEditFormatterImpl.renderValue(
hostgroups[value],
additionalData
);
}
return inlineEditFormatterImpl.renderValue(value, additionalData);
},
});
this.inlineEditFormatter = inlineEditFormatter;
initApplicationDefinitionImport(
ansiblePlaybookServices,
this.headerFormatter,
this.inlineEditFormatter
);
}
render() {
const {
showAlertModal,
alertModalText,
alertModalTitle,
closeAlertModal,
ansiblePlaybookServices,
columns,
handleImportAnsiblePlaybook,
} = this.props;
return (
}
title={alertModalTitle}
primaryContent={alertModalText}
/>
{ansiblePlaybookServices.length > 0 ? (
cellProps.children,
},
}}
>
({
role: 'row',
isEditable: () => this.isEditing({ rowData }),
last: ansiblePlaybookServices.length - 1,
})}
/>
) : null}
);
}
}
ApplicationDefinitionImport.defaultProps = {
// error: {},
showAlertModal: false,
alertModalText: '',
alertModalTitle: '',
columns: [],
ansiblePlaybookServices: [],
};
ApplicationDefinitionImport.propTypes = {
hostgroups: PropTypes.object.isRequired,
// error: PropTypes.object,
ansiblePlaybookServices: PropTypes.array,
// editMode: PropTypes.bool.isRequired,
columns: PropTypes.array,
showAlertModal: PropTypes.bool,
alertModalText: PropTypes.string,
alertModalTitle: PropTypes.string,
changeEditApplicationDefinitionImportService: PropTypes.func.isRequired,
closeAlertModal: PropTypes.func.isRequired,
handleImportAnsiblePlaybook: PropTypes.func.isRequired,
initApplicationDefinitionImport: PropTypes.func.isRequired,
};
export default ApplicationDefinitionImport;