mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
If the `team_id` parameter is included the query report will filter the hosts by the team id specified. The `team_id` parameter is included by default from the front end queries pages. https://github.com/fleetdm/fleet/issues/24006 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [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/Committing-Changes.md#changes-files) for more information. - [X] Added/updated tests - [X] Manual QA for all new/changed functionality --------- Co-authored-by: Ian Littman <iansltx@gmail.com>
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
import sendRequest from "services";
|
|
import endpoints from "utilities/endpoints";
|
|
|
|
import { buildQueryStringFromParams } from "utilities/url";
|
|
|
|
export interface ISortOption {
|
|
key: string;
|
|
direction: string;
|
|
}
|
|
|
|
export interface ILoadQueryReportOptions {
|
|
id: number;
|
|
sortBy: ISortOption[];
|
|
teamId?: number;
|
|
}
|
|
|
|
interface ILoadQueryReportQueryParams {
|
|
order_key: string | undefined;
|
|
order_direction: string | undefined;
|
|
team_id?: number;
|
|
}
|
|
|
|
const getSortParams = (sortOptions?: ISortOption[]) => {
|
|
if (sortOptions === undefined || sortOptions.length === 0) {
|
|
return {};
|
|
}
|
|
|
|
const sortItem = sortOptions[0];
|
|
return {
|
|
order_key: sortItem.key,
|
|
order_direction: sortItem.direction,
|
|
};
|
|
};
|
|
|
|
export default {
|
|
load: ({ id, sortBy, teamId }: ILoadQueryReportOptions) => {
|
|
const sortParams = getSortParams(sortBy);
|
|
|
|
const queryParams: ILoadQueryReportQueryParams = {
|
|
order_key: sortParams.order_key,
|
|
order_direction: sortParams.order_direction,
|
|
};
|
|
if (teamId && teamId > 0) {
|
|
queryParams.team_id = teamId;
|
|
}
|
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
|
|
|
const path = `${endpoints.QUERY_REPORT(id)}?${queryString}`;
|
|
return sendRequest("GET", path);
|
|
},
|
|
};
|