2019-06-19 02:50:17 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
2021-01-31 06:02:51 +00:00
|
|
|
import { reprocessInteractiveImportItems, updateInteractiveImportItems } from 'Store/Actions/interactiveImportActions';
|
2020-07-28 18:47:25 +00:00
|
|
|
import { fetchLanguages } from 'Store/Actions/settingsActions';
|
2019-06-19 02:50:17 +00:00
|
|
|
import SelectLanguageModalContent from './SelectLanguageModalContent';
|
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
|
|
|
(state) => state.settings.languages,
|
|
|
|
(languages) => {
|
|
|
|
const {
|
|
|
|
isFetching,
|
|
|
|
isPopulated,
|
|
|
|
error,
|
|
|
|
items
|
|
|
|
} = languages;
|
|
|
|
|
2020-09-09 03:13:42 +00:00
|
|
|
const filterItems = ['Any', 'Original'];
|
|
|
|
const filteredLanguages = items.filter((lang) => !filterItems.includes(lang.name));
|
|
|
|
|
2019-06-19 02:50:17 +00:00
|
|
|
return {
|
|
|
|
isFetching,
|
|
|
|
isPopulated,
|
|
|
|
error,
|
2020-09-09 03:13:42 +00:00
|
|
|
items: filteredLanguages
|
2019-06-19 02:50:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
dispatchFetchLanguages: fetchLanguages,
|
2021-01-31 06:02:51 +00:00
|
|
|
dispatchReprocessInteractiveImportItems: reprocessInteractiveImportItems,
|
2019-06-19 02:50:17 +00:00
|
|
|
dispatchUpdateInteractiveImportItems: updateInteractiveImportItems
|
|
|
|
};
|
|
|
|
|
|
|
|
class SelectLanguageModalContentConnector extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
componentDidMount = () => {
|
|
|
|
if (!this.props.isPopulated) {
|
|
|
|
this.props.dispatchFetchLanguages();
|
|
|
|
}
|
2022-03-20 23:20:34 +00:00
|
|
|
};
|
2019-06-19 02:50:17 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
2020-01-03 02:11:47 +00:00
|
|
|
onLanguageSelect = ({ languageIds }) => {
|
2021-01-31 06:02:51 +00:00
|
|
|
const {
|
|
|
|
ids,
|
|
|
|
dispatchUpdateInteractiveImportItems,
|
|
|
|
dispatchReprocessInteractiveImportItems
|
|
|
|
} = this.props;
|
|
|
|
|
2020-01-03 02:11:47 +00:00
|
|
|
const languages = [];
|
2019-06-19 02:50:17 +00:00
|
|
|
|
2020-01-03 02:11:47 +00:00
|
|
|
languageIds.forEach((languageId) => {
|
|
|
|
const language = _.find(this.props.items,
|
|
|
|
(item) => item.id === parseInt(languageId));
|
|
|
|
|
2020-09-09 03:13:42 +00:00
|
|
|
if (language !== undefined) {
|
|
|
|
languages.push(language);
|
|
|
|
}
|
2020-01-03 02:11:47 +00:00
|
|
|
});
|
2019-06-19 02:50:17 +00:00
|
|
|
|
2021-01-31 06:02:51 +00:00
|
|
|
dispatchUpdateInteractiveImportItems({
|
|
|
|
ids,
|
2020-01-03 02:11:47 +00:00
|
|
|
languages
|
2019-06-19 02:50:17 +00:00
|
|
|
});
|
|
|
|
|
2021-01-31 06:02:51 +00:00
|
|
|
dispatchReprocessInteractiveImportItems({ ids });
|
|
|
|
|
2019-06-19 02:50:17 +00:00
|
|
|
this.props.onModalClose(true);
|
2022-03-20 23:20:34 +00:00
|
|
|
};
|
2019-06-19 02:50:17 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<SelectLanguageModalContent
|
|
|
|
{...this.props}
|
|
|
|
onLanguageSelect={this.onLanguageSelect}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectLanguageModalContentConnector.propTypes = {
|
|
|
|
ids: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
|
|
isFetching: PropTypes.bool.isRequired,
|
|
|
|
isPopulated: PropTypes.bool.isRequired,
|
|
|
|
error: PropTypes.object,
|
|
|
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
dispatchFetchLanguages: PropTypes.func.isRequired,
|
|
|
|
dispatchUpdateInteractiveImportItems: PropTypes.func.isRequired,
|
2021-01-31 06:02:51 +00:00
|
|
|
dispatchReprocessInteractiveImportItems: PropTypes.func.isRequired,
|
2019-06-19 02:50:17 +00:00
|
|
|
onModalClose: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(SelectLanguageModalContentConnector);
|