2021-04-12 13:32:25 +00:00
|
|
|
|
import React, { Component } from "react";
|
|
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
|
import { logoutUser } from "redux/nodes/auth/actions";
|
|
|
|
|
|
import { push } from "react-router-redux";
|
2021-08-18 23:58:56 +00:00
|
|
|
|
import { TableContext } from "context/table";
|
|
|
|
|
|
|
|
|
|
|
|
import { isEqual } from "lodash";
|
2021-04-12 13:32:25 +00:00
|
|
|
|
|
2021-08-30 19:52:13 +00:00
|
|
|
|
import permissionUtils from "utilities/permissions";
|
2021-04-12 13:32:25 +00:00
|
|
|
|
import configInterface from "interfaces/config";
|
|
|
|
|
|
import FlashMessage from "components/flash_messages/FlashMessage";
|
|
|
|
|
|
import PersistentFlash from "components/flash_messages/PersistentFlash";
|
2021-08-16 18:47:04 +00:00
|
|
|
|
import SiteTopNav from "components/side_panels/SiteTopNav";
|
2021-04-12 13:32:25 +00:00
|
|
|
|
import userInterface from "interfaces/user";
|
|
|
|
|
|
import notificationInterface from "interfaces/notification";
|
|
|
|
|
|
import { hideFlash } from "redux/nodes/notifications/actions";
|
2021-08-30 19:52:13 +00:00
|
|
|
|
import { licenseExpirationWarning } from "fleet/helpers";
|
|
|
|
|
|
|
|
|
|
|
|
const expirationMessage = (
|
|
|
|
|
|
<>
|
|
|
|
|
|
Your license for Fleet Premium is about to expire. If you’d like to renew or
|
|
|
|
|
|
have questions about downgrading,{" "}
|
|
|
|
|
|
<a
|
|
|
|
|
|
href="https://github.com/fleetdm/fleet/blob/main/docs/1-Using-Fleet/10-Teams.md#expired_license"
|
|
|
|
|
|
target="_blank"
|
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
|
>
|
|
|
|
|
|
please head to the Fleet documentation
|
|
|
|
|
|
</a>
|
|
|
|
|
|
.
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
2016-09-21 03:07:32 +00:00
|
|
|
|
|
|
|
|
|
|
export class CoreLayout extends Component {
|
|
|
|
|
|
static propTypes = {
|
|
|
|
|
|
children: PropTypes.node,
|
2016-10-21 23:13:41 +00:00
|
|
|
|
config: configInterface,
|
2016-09-21 03:07:32 +00:00
|
|
|
|
dispatch: PropTypes.func,
|
2016-10-21 23:13:41 +00:00
|
|
|
|
user: userInterface,
|
2017-01-05 18:08:19 +00:00
|
|
|
|
fullWidthFlash: PropTypes.bool,
|
|
|
|
|
|
notifications: notificationInterface,
|
2017-02-10 03:16:51 +00:00
|
|
|
|
persistentFlash: PropTypes.shape({
|
|
|
|
|
|
showFlash: PropTypes.bool.isRequired,
|
|
|
|
|
|
message: PropTypes.string.isRequired,
|
|
|
|
|
|
}).isRequired,
|
2021-09-03 16:05:23 +00:00
|
|
|
|
isPremiumTier: PropTypes.bool,
|
2016-09-21 03:07:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-08-30 19:52:13 +00:00
|
|
|
|
constructor(props) {
|
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
|
showExpirationFlashMessage: false,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-18 23:58:56 +00:00
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2021-08-30 19:52:13 +00:00
|
|
|
|
const { notifications, config } = nextProps;
|
2021-08-18 23:58:56 +00:00
|
|
|
|
const table = this.context;
|
|
|
|
|
|
|
|
|
|
|
|
// on success of an action, the table will reset its checkboxes.
|
|
|
|
|
|
// setTimeout is to help with race conditions as table reloads
|
|
|
|
|
|
// in some instances (i.e. Manage Hosts)
|
|
|
|
|
|
if (!isEqual(this.props.notifications, notifications)) {
|
|
|
|
|
|
if (notifications.alertType === "success") {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
table.setResetSelectedRows(true);
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
table.setResetSelectedRows(false);
|
|
|
|
|
|
}, 300);
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-08-30 19:52:13 +00:00
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
showExpirationFlashMessage: licenseExpirationWarning(config.expiration),
|
|
|
|
|
|
});
|
2021-08-18 23:58:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-05 17:55:30 +00:00
|
|
|
|
onLogoutUser = () => {
|
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
dispatch(logoutUser());
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
2021-04-12 13:32:25 +00:00
|
|
|
|
};
|
2016-12-05 17:55:30 +00:00
|
|
|
|
|
2016-12-29 20:27:43 +00:00
|
|
|
|
onNavItemClick = (path) => {
|
2016-12-13 15:24:58 +00:00
|
|
|
|
return (evt) => {
|
|
|
|
|
|
evt.preventDefault();
|
2016-12-05 17:55:30 +00:00
|
|
|
|
|
2016-12-13 15:24:58 +00:00
|
|
|
|
const { dispatch } = this.props;
|
2016-12-05 17:55:30 +00:00
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
|
if (path.indexOf("http") !== -1) {
|
|
|
|
|
|
global.window.open(path, "_blank");
|
2017-01-18 14:40:28 +00:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-13 15:24:58 +00:00
|
|
|
|
dispatch(push(path));
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
};
|
2021-04-12 13:32:25 +00:00
|
|
|
|
};
|
2016-12-05 17:55:30 +00:00
|
|
|
|
|
2017-01-05 18:08:19 +00:00
|
|
|
|
onRemoveFlash = () => {
|
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
dispatch(hideFlash);
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
2021-04-12 13:32:25 +00:00
|
|
|
|
};
|
2017-01-05 18:08:19 +00:00
|
|
|
|
|
2021-08-30 19:52:13 +00:00
|
|
|
|
onRemoveExpirationWarning = () => {
|
|
|
|
|
|
const { showExpirationFlashMessage } = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
showExpirationFlashMessage: !showExpirationFlashMessage,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-01-05 18:08:19 +00:00
|
|
|
|
onUndoActionClick = (undoAction) => {
|
|
|
|
|
|
return (evt) => {
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
const { onRemoveFlash } = this;
|
|
|
|
|
|
|
|
|
|
|
|
dispatch(undoAction);
|
|
|
|
|
|
|
|
|
|
|
|
return onRemoveFlash();
|
|
|
|
|
|
};
|
2021-04-12 13:32:25 +00:00
|
|
|
|
};
|
2017-01-05 18:08:19 +00:00
|
|
|
|
|
2021-08-18 23:58:56 +00:00
|
|
|
|
static contextType = TableContext;
|
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
|
render() {
|
2017-02-24 23:01:43 +00:00
|
|
|
|
const {
|
|
|
|
|
|
fullWidthFlash,
|
|
|
|
|
|
notifications,
|
|
|
|
|
|
children,
|
|
|
|
|
|
config,
|
|
|
|
|
|
persistentFlash,
|
|
|
|
|
|
user,
|
2021-09-03 16:05:23 +00:00
|
|
|
|
isPremiumTier,
|
2017-02-24 23:01:43 +00:00
|
|
|
|
} = this.props;
|
2021-08-30 19:52:13 +00:00
|
|
|
|
const { showExpirationFlashMessage } = this.state;
|
|
|
|
|
|
const {
|
|
|
|
|
|
onRemoveFlash,
|
|
|
|
|
|
onRemoveExpirationWarning,
|
|
|
|
|
|
onUndoActionClick,
|
|
|
|
|
|
} = this;
|
|
|
|
|
|
|
|
|
|
|
|
const expirationNotification = {
|
|
|
|
|
|
alertType: "warning-filled",
|
|
|
|
|
|
isVisible: true,
|
|
|
|
|
|
message: expirationMessage,
|
|
|
|
|
|
};
|
2016-09-21 03:07:32 +00:00
|
|
|
|
|
|
|
|
|
|
if (!user) return false;
|
|
|
|
|
|
|
2016-12-29 20:27:43 +00:00
|
|
|
|
const { onLogoutUser, onNavItemClick } = this;
|
2016-09-30 18:55:15 +00:00
|
|
|
|
const { pathname } = global.window.location;
|
|
|
|
|
|
|
2016-09-21 03:07:32 +00:00
|
|
|
|
return (
|
2016-12-06 16:55:48 +00:00
|
|
|
|
<div className="app-wrap">
|
2021-03-08 16:48:29 +00:00
|
|
|
|
<nav className="site-nav">
|
2021-08-16 18:47:04 +00:00
|
|
|
|
<SiteTopNav
|
2016-12-01 22:14:39 +00:00
|
|
|
|
config={config}
|
2020-11-30 17:07:44 +00:00
|
|
|
|
onLogoutUser={onLogoutUser}
|
2016-12-29 20:27:43 +00:00
|
|
|
|
onNavItemClick={onNavItemClick}
|
2016-12-01 22:14:39 +00:00
|
|
|
|
pathname={pathname}
|
|
|
|
|
|
user={user}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</nav>
|
2021-03-08 16:48:29 +00:00
|
|
|
|
<div className="core-wrapper">
|
2021-04-12 13:32:25 +00:00
|
|
|
|
{persistentFlash.showFlash && (
|
|
|
|
|
|
<PersistentFlash message={persistentFlash.message} />
|
|
|
|
|
|
)}
|
2021-09-03 16:05:23 +00:00
|
|
|
|
{isPremiumTier && showExpirationFlashMessage && (
|
2021-08-30 19:52:13 +00:00
|
|
|
|
<FlashMessage
|
|
|
|
|
|
fullWidth={fullWidthFlash}
|
|
|
|
|
|
notification={expirationNotification}
|
|
|
|
|
|
onRemoveFlash={onRemoveExpirationWarning}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2017-01-05 18:08:19 +00:00
|
|
|
|
<FlashMessage
|
|
|
|
|
|
fullWidth={fullWidthFlash}
|
|
|
|
|
|
notification={notifications}
|
|
|
|
|
|
onRemoveFlash={onRemoveFlash}
|
|
|
|
|
|
onUndoActionClick={onUndoActionClick}
|
|
|
|
|
|
/>
|
2016-09-30 18:55:15 +00:00
|
|
|
|
{children}
|
|
|
|
|
|
</div>
|
2016-11-03 19:40:54 +00:00
|
|
|
|
</div>
|
2016-09-21 03:07:32 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
2016-10-11 15:32:39 +00:00
|
|
|
|
const {
|
2021-04-12 13:32:25 +00:00
|
|
|
|
app: { config },
|
2016-10-11 15:32:39 +00:00
|
|
|
|
auth: { user },
|
2017-01-05 18:08:19 +00:00
|
|
|
|
notifications,
|
2017-02-10 03:16:51 +00:00
|
|
|
|
persistentFlash,
|
2016-10-11 15:32:39 +00:00
|
|
|
|
} = state;
|
|
|
|
|
|
|
2021-09-03 16:05:23 +00:00
|
|
|
|
const isPremiumTier = permissionUtils.isPremiumTier(state.app.config);
|
2021-08-30 19:52:13 +00:00
|
|
|
|
|
2017-01-05 18:08:19 +00:00
|
|
|
|
const fullWidthFlash = !user;
|
|
|
|
|
|
|
2016-10-11 15:32:39 +00:00
|
|
|
|
return {
|
|
|
|
|
|
config,
|
2017-02-10 03:16:51 +00:00
|
|
|
|
fullWidthFlash,
|
|
|
|
|
|
notifications,
|
|
|
|
|
|
persistentFlash,
|
2016-10-11 15:32:39 +00:00
|
|
|
|
user,
|
2021-09-03 16:05:23 +00:00
|
|
|
|
isPremiumTier,
|
2016-10-11 15:32:39 +00:00
|
|
|
|
};
|
2016-09-21 03:07:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(CoreLayout);
|