2018-02-06 23:08:36 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
2018-08-08 00:57:15 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-02-06 23:08:36 +00:00
|
|
|
import { createSelector } from 'reselect';
|
2024-03-26 17:24:49 +00:00
|
|
|
import {
|
|
|
|
saveImportList,
|
|
|
|
setImportListFieldValue,
|
|
|
|
setImportListValue,
|
|
|
|
testImportList,
|
|
|
|
toggleAdvancedSettings
|
|
|
|
} from 'Store/Actions/settingsActions';
|
2018-02-06 23:08:36 +00:00
|
|
|
import createProviderSettingsSelector from 'Store/Selectors/createProviderSettingsSelector';
|
|
|
|
import EditImportListModalContent from './EditImportListModalContent';
|
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
|
|
|
(state) => state.settings.advancedSettings,
|
|
|
|
(state) => state.settings.metadataProfiles,
|
2018-08-08 00:57:15 +00:00
|
|
|
createProviderSettingsSelector('importLists'),
|
2019-08-02 11:50:09 +00:00
|
|
|
(advancedSettings, metadataProfiles, importList) => {
|
2018-02-06 23:08:36 +00:00
|
|
|
return {
|
|
|
|
advancedSettings,
|
|
|
|
showMetadataProfile: metadataProfiles.items.length > 1,
|
|
|
|
...importList
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
setImportListValue,
|
|
|
|
setImportListFieldValue,
|
|
|
|
saveImportList,
|
2024-03-26 17:24:49 +00:00
|
|
|
testImportList,
|
|
|
|
toggleAdvancedSettings
|
2018-02-06 23:08:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EditImportListModalContentConnector extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (prevProps.isSaving && !this.props.isSaving && !this.props.saveError) {
|
|
|
|
this.props.onModalClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
onInputChange = ({ name, value }) => {
|
|
|
|
this.props.setImportListValue({ name, value });
|
2021-12-24 18:18:14 +00:00
|
|
|
};
|
2018-02-06 23:08:36 +00:00
|
|
|
|
|
|
|
onFieldChange = ({ name, value }) => {
|
|
|
|
this.props.setImportListFieldValue({ name, value });
|
2021-12-24 18:18:14 +00:00
|
|
|
};
|
2018-02-06 23:08:36 +00:00
|
|
|
|
|
|
|
onSavePress = () => {
|
|
|
|
this.props.saveImportList({ id: this.props.id });
|
2021-12-24 18:18:14 +00:00
|
|
|
};
|
2018-02-06 23:08:36 +00:00
|
|
|
|
|
|
|
onTestPress = () => {
|
|
|
|
this.props.testImportList({ id: this.props.id });
|
2021-12-24 18:18:14 +00:00
|
|
|
};
|
2018-02-06 23:08:36 +00:00
|
|
|
|
2024-03-26 17:24:49 +00:00
|
|
|
onAdvancedSettingsPress = () => {
|
|
|
|
this.props.toggleAdvancedSettings();
|
|
|
|
};
|
|
|
|
|
2018-02-06 23:08:36 +00:00
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<EditImportListModalContent
|
|
|
|
{...this.props}
|
|
|
|
onSavePress={this.onSavePress}
|
|
|
|
onTestPress={this.onTestPress}
|
2024-03-26 17:24:49 +00:00
|
|
|
onAdvancedSettingsPress={this.onAdvancedSettingsPress}
|
2018-02-06 23:08:36 +00:00
|
|
|
onInputChange={this.onInputChange}
|
|
|
|
onFieldChange={this.onFieldChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditImportListModalContentConnector.propTypes = {
|
|
|
|
id: PropTypes.number,
|
|
|
|
isFetching: PropTypes.bool.isRequired,
|
|
|
|
isSaving: PropTypes.bool.isRequired,
|
|
|
|
saveError: PropTypes.object,
|
|
|
|
item: PropTypes.object.isRequired,
|
|
|
|
setImportListValue: PropTypes.func.isRequired,
|
|
|
|
setImportListFieldValue: PropTypes.func.isRequired,
|
|
|
|
saveImportList: PropTypes.func.isRequired,
|
|
|
|
testImportList: PropTypes.func.isRequired,
|
2024-03-26 17:24:49 +00:00
|
|
|
toggleAdvancedSettings: PropTypes.func.isRequired,
|
2018-02-06 23:08:36 +00:00
|
|
|
onModalClose: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2018-08-08 00:57:15 +00:00
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(EditImportListModalContentConnector);
|