fleet/frontend/components/App/App.jsx
RachelElysia b85fbcbc83
Table Checkboxes: Checkboxes uncheck only on success notification (#1707)
- Uses Context API to track state
- resetSelectedRows default to false and only momentarily becomes true upon successful notification

Several other ideas were explored and ruled out including: asyncDebounce (impossible approach), applying state throughout the app (not concise nor maintainable), modifications directly to DataTable only (react-table did not have the right key combinations to reset selected rows manually when we needed).

Closes #1540 

Co-authored by: @martavis
2021-08-18 16:58:56 -07:00

72 lines
1.6 KiB
JavaScript

import React, { Component } from "react";
import TableProvider from "context/table";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { noop } from "lodash";
import classnames from "classnames";
import { authToken } from "utilities/local";
import { fetchCurrentUser } from "redux/nodes/auth/actions";
import { getConfig, getEnrollSecret } from "redux/nodes/app/actions";
import userInterface from "interfaces/user";
export class App extends Component {
static propTypes = {
children: PropTypes.element,
dispatch: PropTypes.func,
user: userInterface,
};
static defaultProps = {
dispatch: noop,
};
componentWillMount() {
const { dispatch, user } = this.props;
if (!user && authToken()) {
dispatch(fetchCurrentUser()).catch(() => false);
}
if (user) {
dispatch(getConfig()).catch(() => false);
dispatch(getEnrollSecret()).catch(() => false);
}
return false;
}
componentWillReceiveProps(nextProps) {
const { dispatch, user } = nextProps;
if (user && this.props.user !== user) {
dispatch(getConfig()).catch(() => false);
dispatch(getEnrollSecret()).catch(() => false);
}
}
render() {
const { children } = this.props;
const wrapperStyles = classnames("wrapper");
return (
<TableProvider>
<div className={wrapperStyles}>{children}</div>
</TableProvider>
);
}
}
const mapStateToProps = (state) => {
const { app, auth } = state;
const { showBackgroundImage } = app;
const { user } = auth;
return {
showBackgroundImage,
user,
};
};
export default connect(mapStateToProps)(App);