From ee2d17ad6c1d5674181c7bbbf916fbbca3fe041a Mon Sep 17 00:00:00 2001
From: Nico <32375741+nulmete@users.noreply.github.com>
Date: Tue, 6 Jan 2026 15:30:01 -0300
Subject: [PATCH] Hide Add Query button on Host Details for unsupported host
platforms (#37912)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
**Related issue:** Resolves #37847
# Checklist for submitter
Issue is resolved by the `&& isSupportedHostQueriesPlatform` condition.
## Testing
- [x] Added/updated automated tests
- [ ] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)
- [x] QA'd all new/changed functionality manually
Manually tested by passing a mocked host platform (`"ios"`) and verified
the **Add Query** button is not shown.
### Before
### After
---
frontend/__mocks__/queryMock.ts | 28 +++++++
.../HostDetailsPage/HostDetailsPage.tsx | 10 ++-
.../cards/Queries/HostQueries.tests.tsx | 76 +++++++++++++++++++
3 files changed, 113 insertions(+), 1 deletion(-)
create mode 100644 frontend/pages/hosts/details/cards/Queries/HostQueries.tests.tsx
diff --git a/frontend/__mocks__/queryMock.ts b/frontend/__mocks__/queryMock.ts
index d1cdc4d849..40b205161d 100644
--- a/frontend/__mocks__/queryMock.ts
+++ b/frontend/__mocks__/queryMock.ts
@@ -1,4 +1,5 @@
import { ISchedulableQuery } from "interfaces/schedulable_query";
+import { IQueryStats } from "interfaces/query_stats";
const DEFAULT_QUERY_MOCK: ISchedulableQuery = {
created_at: "2022-11-03T17:22:14Z",
@@ -36,4 +37,31 @@ const createMockQuery = (
return { ...DEFAULT_QUERY_MOCK, ...overrides };
};
+const DEFAULT_QUERY_STATS_MOCK: IQueryStats = {
+ scheduled_query_name: "test-query",
+ scheduled_query_id: 1,
+ query_name: "Test Query",
+ discard_data: false,
+ last_fetched: "2025-01-01T00:00:00Z",
+ automations_enabled: false,
+ description: "A test query",
+ pack_name: "test-pack",
+ pack_id: 1,
+ average_memory: 100,
+ denylisted: false,
+ executions: 10,
+ interval: 3600,
+ last_executed: "2025-01-01T00:00:00Z",
+ output_size: 1024,
+ system_time: 50,
+ user_time: 100,
+ wall_time: 150,
+};
+
+export const createMockQueryStats = (
+ overrides?: Partial
+): IQueryStats => {
+ return { ...DEFAULT_QUERY_STATS_MOCK, ...overrides };
+};
+
export default createMockQuery;
diff --git a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx
index 59b71f16d1..4520766885 100644
--- a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx
+++ b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx
@@ -65,6 +65,7 @@ import {
isIPadOrIPhone,
isLinuxLike,
isWindows,
+ isChrome,
} from "interfaces/platform";
import Spinner from "components/Spinner";
@@ -1099,6 +1100,10 @@ const HostDetailsPage = ({
const isIosOrIpadosHost = isIPadOrIPhone(host.platform);
const isAndroidHost = isAndroid(host.platform);
const isWindowsHost = isWindows(host.platform);
+ const isChromeHost = isChrome(host.platform);
+
+ const isSupportedHostQueriesPlatform =
+ !isIosOrIpadosHost && !isAndroidHost && !isChromeHost;
const canResendProfiles =
(isMacOSHost || isWindowsHost) &&
@@ -1311,7 +1316,10 @@ const HostDetailsPage = ({
queryReportsDisabled={
config?.server_settings?.query_reports_disabled
}
- canAddQuery={isAnyMaintainerAdminObserverPlus}
+ canAddQuery={
+ isAnyMaintainerAdminObserverPlus &&
+ isSupportedHostQueriesPlatform
+ }
onClickAddQuery={onClickAddQuery}
/>
{
+ it("renders the queries table and add query button for supported platform with queries", () => {
+ const schedule = [
+ createMockQueryStats({ query_name: "Query 1", scheduled_query_id: 1 }),
+ createMockQueryStats({ query_name: "Query 2", scheduled_query_id: 2 }),
+ ];
+
+ render(
+
+ );
+
+ expect(screen.getByText("Queries")).toBeInTheDocument();
+ expect(screen.getByText("Add query")).toBeInTheDocument();
+ // Use getAllByText due to tooltip duplicates
+ expect(screen.getAllByText("Query 1").length).toBeGreaterThan(0);
+ expect(screen.getAllByText("Query 2").length).toBeGreaterThan(0);
+ });
+
+ it("renders 'Queries not supported for this host' message and hides add query button for unsupported host platform", () => {
+ render(
+
+ );
+
+ expect(screen.getByText("Queries")).toBeInTheDocument();
+ expect(
+ screen.getByText("Queries not supported for this host")
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText(/Interested in collecting data from your Chromebooks/)
+ ).toBeInTheDocument();
+ expect(screen.queryByText("Add query")).not.toBeInTheDocument();
+ });
+
+ it("renders empty state and add query button for supported platform with no queries", () => {
+ render(
+
+ );
+
+ expect(screen.getByText("Queries")).toBeInTheDocument();
+ expect(screen.getByText("Add query")).toBeInTheDocument();
+ expect(screen.getByText("No queries")).toBeInTheDocument();
+ expect(
+ screen.getByText("Add a query to view custom vitals.")
+ ).toBeInTheDocument();
+ });
+});