mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #41533 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [ ] Added/updated automated tests - [x] QA'd all new/changed functionality manually https://github.com/user-attachments/assets/64a5f726-1e9f-4508-8726-6227813dcc77 Below I show the `Report clipped` and the `X additional results not shown` states. For that, I manually inserted records in my DB: ```sql -- make "clipped" INSERT INTO query_results (query_id, host_id, last_fetched, data) SELECT 1, t.n + 1000, NOW(), '{"fake_key": "fake_value"}' FROM ( SELECT a.N + b.N * 10 + c.N * 100 AS n FROM (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) a, (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) b, (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) c ) t WHERE t.n BETWEEN 1 AND 999; -- populate extra query results INSERT INTO query_results (query_id, host_id, last_fetched, data) VALUES (1, 2, NOW(), '{"pid": "9999", "version": "5.21.0"}'), (1, 2, NOW(), '{"pid": "8888", "version": "5.20.0"}'); ``` https://github.com/user-attachments/assets/8056ea4c-b042-47cf-a05f-ee9d8621252a Pagination (manually changed to 3 items per page for testing purposes) https://github.com/user-attachments/assets/87a97259-0821-4659-a612-c952e98a158c
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import sendRequest from "services";
|
|
import endpoints from "utilities/endpoints";
|
|
import { buildQueryStringFromParams } from "utilities/url";
|
|
|
|
export interface IHostReport {
|
|
report_id: number;
|
|
name: string;
|
|
description: string;
|
|
last_fetched: string | null;
|
|
first_result: Record<string, string> | null;
|
|
n_host_results: number;
|
|
report_clipped: boolean;
|
|
store_results: boolean;
|
|
}
|
|
|
|
export interface IListHostReportsResponse {
|
|
reports: IHostReport[];
|
|
count: number;
|
|
meta: {
|
|
has_previous_results: boolean;
|
|
has_next_results: boolean;
|
|
};
|
|
}
|
|
|
|
export interface IListHostReportsParams {
|
|
page?: number;
|
|
per_page?: number;
|
|
order_key?: string;
|
|
order_direction?: string;
|
|
query?: string;
|
|
include_reports_dont_store_results?: boolean;
|
|
}
|
|
|
|
export default {
|
|
list: (
|
|
hostId: number,
|
|
params?: IListHostReportsParams
|
|
): Promise<IListHostReportsResponse> => {
|
|
const { query, ...rest } = params || {};
|
|
const queryParams: Record<string, string | number | boolean> = {};
|
|
|
|
if (rest.page !== undefined) queryParams.page = rest.page;
|
|
if (rest.per_page !== undefined) queryParams.per_page = rest.per_page;
|
|
if (rest.order_key) queryParams.order_key = rest.order_key;
|
|
if (rest.order_direction)
|
|
queryParams.order_direction = rest.order_direction;
|
|
if (query) queryParams.query = query;
|
|
if (rest.include_reports_dont_store_results) {
|
|
queryParams.include_reports_dont_store_results = true;
|
|
}
|
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
|
const path = `${endpoints.HOST_REPORTS(hostId)}?${queryString}`;
|
|
return sendRequest("GET", path);
|
|
},
|
|
};
|