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.
Sonarr/frontend/src/System/Events/LogsTableConnector.js

149 lines
3.5 KiB

7 years ago
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import * as commandNames from 'Commands/commandNames';
import withCurrentPage from 'Components/withCurrentPage';
7 years ago
import { executeCommand } from 'Store/Actions/commandActions';
import * as systemActions from 'Store/Actions/systemActions';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
7 years ago
import LogsTable from './LogsTable';
function createMapStateToProps() {
return createSelector(
(state) => state.system.logs,
createCommandExecutingSelector(commandNames.CLEAR_LOGS),
(logs, clearLogExecuting) => {
return {
clearLogExecuting,
...logs
};
}
);
}
const mapDispatchToProps = {
executeCommand,
...systemActions
};
class LogsTableConnector extends Component {
//
// Lifecycle
componentDidMount() {
const {
useCurrentPage,
fetchLogs,
gotoLogsFirstPage
} = this.props;
if (useCurrentPage) {
fetchLogs();
} else {
gotoLogsFirstPage();
}
7 years ago
}
componentDidUpdate(prevProps) {
if (prevProps.clearLogExecuting && !this.props.clearLogExecuting) {
this.props.gotoLogsFirstPage();
}
}
//
// Listeners
onFirstPagePress = () => {
this.props.gotoLogsFirstPage();
};
7 years ago
onPreviousPagePress = () => {
this.props.gotoLogsPreviousPage();
};
7 years ago
onNextPagePress = () => {
this.props.gotoLogsNextPage();
};
7 years ago
onLastPagePress = () => {
this.props.gotoLogsLastPage();
};
7 years ago
onPageSelect = (page) => {
this.props.gotoLogsPage({ page });
};
7 years ago
onSortPress = (sortKey) => {
this.props.setLogsSort({ sortKey });
};
7 years ago
onFilterSelect = (selectedFilterKey) => {
this.props.setLogsFilter({ selectedFilterKey });
};
7 years ago
onTableOptionChange = (payload) => {
this.props.setLogsTableOption(payload);
if (payload.pageSize) {
this.props.gotoLogsFirstPage();
}
};
7 years ago
onRefreshPress = () => {
this.props.gotoLogsFirstPage();
};
7 years ago
onClearLogsPress = () => {
this.props.executeCommand({
name: commandNames.CLEAR_LOGS,
commandFinished: this.onCommandFinished
});
};
onCommandFinished = () => {
this.props.gotoLogsFirstPage();
};
7 years ago
//
// Render
render() {
return (
<LogsTable
onFirstPagePress={this.onFirstPagePress}
onPreviousPagePress={this.onPreviousPagePress}
onNextPagePress={this.onNextPagePress}
onLastPagePress={this.onLastPagePress}
onPageSelect={this.onPageSelect}
onSortPress={this.onSortPress}
onFilterSelect={this.onFilterSelect}
onTableOptionChange={this.onTableOptionChange}
onRefreshPress={this.onRefreshPress}
onClearLogsPress={this.onClearLogsPress}
{...this.props}
/>
);
}
}
LogsTableConnector.propTypes = {
useCurrentPage: PropTypes.bool.isRequired,
7 years ago
clearLogExecuting: PropTypes.bool.isRequired,
fetchLogs: PropTypes.func.isRequired,
gotoLogsFirstPage: PropTypes.func.isRequired,
gotoLogsPreviousPage: PropTypes.func.isRequired,
gotoLogsNextPage: PropTypes.func.isRequired,
gotoLogsLastPage: PropTypes.func.isRequired,
gotoLogsPage: PropTypes.func.isRequired,
setLogsSort: PropTypes.func.isRequired,
setLogsFilter: PropTypes.func.isRequired,
setLogsTableOption: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired
};
export default withCurrentPage(
connect(createMapStateToProps, mapDispatchToProps)(LogsTableConnector)
);