2021-04-12 13:32:25 +00:00
|
|
|
import { push } from "react-router-redux";
|
|
|
|
|
import { join, omit, values } from "lodash";
|
2016-11-07 16:42:39 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import PATHS from "router/paths";
|
|
|
|
|
import queryActions from "redux/nodes/entities/queries/actions";
|
|
|
|
|
import { renderFlash } from "redux/nodes/notifications/actions";
|
2016-11-07 16:42:39 +00:00
|
|
|
|
|
|
|
|
export const fetchQuery = (dispatch, queryID) => {
|
2021-04-12 13:32:25 +00:00
|
|
|
return dispatch(queryActions.load(queryID)).catch((errors) => {
|
2021-06-22 23:44:40 +00:00
|
|
|
const { MANAGE_QUERIES } = PATHS;
|
|
|
|
|
let errorMessage = join(values(omit(errors, "http_status")), ", ");
|
2016-11-07 16:42:39 +00:00
|
|
|
|
2021-06-22 23:44:40 +00:00
|
|
|
if (errorMessage.includes("no rows in result set")) {
|
|
|
|
|
errorMessage = "The query you requested does not exist in Fleet.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispatch(push(MANAGE_QUERIES));
|
2021-04-12 13:32:25 +00:00
|
|
|
dispatch(renderFlash("error", errorMessage));
|
2016-11-07 16:42:39 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
return false;
|
|
|
|
|
});
|
2016-11-07 16:42:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default { fetchQuery };
|