You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.2 KiB
89 lines
2.2 KiB
6 years ago
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { createSelector } from 'reselect';
|
||
4 years ago
|
import { saveIndexer, setIndexerFieldValue, setIndexerValue, testIndexer } from 'Store/Actions/indexerActions';
|
||
3 years ago
|
import createIndexerSchemaSelector from 'Store/Selectors/createIndexerSchemaSelector';
|
||
6 years ago
|
import EditIndexerModalContent from './EditIndexerModalContent';
|
||
|
|
||
|
function createMapStateToProps() {
|
||
|
return createSelector(
|
||
|
(state) => state.settings.advancedSettings,
|
||
3 years ago
|
createIndexerSchemaSelector(),
|
||
6 years ago
|
(advancedSettings, indexer) => {
|
||
|
return {
|
||
|
advancedSettings,
|
||
|
...indexer
|
||
|
};
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
const mapDispatchToProps = {
|
||
|
setIndexerValue,
|
||
|
setIndexerFieldValue,
|
||
|
saveIndexer,
|
||
|
testIndexer
|
||
|
};
|
||
|
|
||
|
class EditIndexerModalContentConnector extends Component {
|
||
|
|
||
|
//
|
||
|
// Lifecycle
|
||
|
|
||
|
componentDidUpdate(prevProps, prevState) {
|
||
|
if (prevProps.isSaving && !this.props.isSaving && !this.props.saveError) {
|
||
|
this.props.onModalClose();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Listeners
|
||
|
|
||
|
onInputChange = ({ name, value }) => {
|
||
|
this.props.setIndexerValue({ name, value });
|
||
|
}
|
||
|
|
||
|
onFieldChange = ({ name, value }) => {
|
||
|
this.props.setIndexerFieldValue({ name, value });
|
||
|
}
|
||
|
|
||
|
onSavePress = () => {
|
||
|
this.props.saveIndexer({ id: this.props.id });
|
||
|
}
|
||
|
|
||
|
onTestPress = () => {
|
||
|
this.props.testIndexer({ id: this.props.id });
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Render
|
||
|
|
||
|
render() {
|
||
|
return (
|
||
|
<EditIndexerModalContent
|
||
|
{...this.props}
|
||
|
onSavePress={this.onSavePress}
|
||
|
onTestPress={this.onTestPress}
|
||
|
onInputChange={this.onInputChange}
|
||
|
onFieldChange={this.onFieldChange}
|
||
|
/>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
EditIndexerModalContentConnector.propTypes = {
|
||
|
id: PropTypes.number,
|
||
|
isFetching: PropTypes.bool.isRequired,
|
||
|
isSaving: PropTypes.bool.isRequired,
|
||
|
saveError: PropTypes.object,
|
||
|
item: PropTypes.object.isRequired,
|
||
|
setIndexerValue: PropTypes.func.isRequired,
|
||
|
setIndexerFieldValue: PropTypes.func.isRequired,
|
||
|
saveIndexer: PropTypes.func.isRequired,
|
||
|
testIndexer: PropTypes.func.isRequired,
|
||
|
onModalClose: PropTypes.func.isRequired
|
||
|
};
|
||
|
|
||
|
export default connect(createMapStateToProps, mapDispatchToProps)(EditIndexerModalContentConnector);
|