Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fleet UI: Fix observer persisting host_id when querying host from host details page #22249

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/20959-query-host-flow-fix-observer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix UI flow for observers to easily query hosts from the host details page
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ interface IQueryDetailsPageProps {
params: Params;
location: {
pathname: string;
query: { team_id?: string; order_key?: string; order_direction?: string };
query: {
team_id?: string;
order_key?: string;
order_direction?: string;
host_id?: string;
};
search: string;
};
}
Expand All @@ -67,6 +72,12 @@ const QueryDetailsPage = ({
}
const queryParams = location.query;

// Present when observer is redirected from host details > query
// since observer does not have access to edit page
const hostId = queryParams?.host_id
? parseInt(queryParams.host_id, 10)
: undefined;

const { currentTeamId } = useTeamIdParam({
location,
router,
Expand Down Expand Up @@ -295,7 +306,7 @@ const QueryDetailsPage = ({
onClick={() => {
queryId &&
router.push(
PATHS.LIVE_QUERY(queryId, currentTeamId)
PATHS.LIVE_QUERY(queryId, currentTeamId, hostId)
);
}}
disabled={isLiveQueryDisabled}
Expand Down
9 changes: 8 additions & 1 deletion frontend/pages/queries/edit/EditQueryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ const EditQueryPage = ({
queryId > 0 &&
!canEditExistingQuery
) {
router.push(PATHS.QUERY_DETAILS(queryId));
// Reroute to query report page still maintains query params for live query purposes
const baseUrl = PATHS.QUERY_DETAILS(queryId);
const queryParams = buildQueryStringFromParams({
host_id: location.query.host_id,
team_id: location.query.team_id,
});

router.push(queryParams ? `${baseUrl}?${queryParams}` : baseUrl);
}
}, [queryId, isTeamMaintainerOrTeamAdmin, isStoredQueryLoading]);

Expand Down
17 changes: 13 additions & 4 deletions frontend/router/paths.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { buildQueryStringFromParams } from "utilities/url";

import { IPolicy } from "../interfaces/policy";
import URL_PREFIX from "./url_prefix";

Expand Down Expand Up @@ -95,10 +97,17 @@ export default {
teamId ? `?team_id=${teamId}` : ""
}`;
},
LIVE_QUERY: (queryId: number | null, teamId?: number): string => {
return `${URL_PREFIX}/queries/${queryId || "new"}/live${
teamId ? `?team_id=${teamId}` : ""
}`;
LIVE_QUERY: (
queryId: number | null,
teamId?: number,
hostId?: number
): string => {
const baseUrl = `${URL_PREFIX}/queries/${queryId || "new"}/live`;
const queryParams = buildQueryStringFromParams({
team_id: teamId,
host_id: hostId,
});
return queryParams ? `${baseUrl}?${queryParams}` : baseUrl;
},
QUERY_DETAILS: (queryId: number, teamId?: number): string => {
return `${URL_PREFIX}/queries/${queryId}${
Expand Down
Loading