mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
9768186048
- Remove mock api service and uncomment real api service - Handle if query_report.results is `null` – should be updated on backend to return empty array, but doing this as well to facilitate team-wide manual testing/QA --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
47 lines
1.1 KiB
TypeScript
47 lines
1.1 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[];
|
|
}
|
|
|
|
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 }: ILoadQueryReportOptions) => {
|
|
const sortParams = getSortParams(sortBy);
|
|
|
|
const { QUERIES } = endpoints;
|
|
|
|
const queryParams = {
|
|
order_key: sortParams.order_key,
|
|
order_direction: sortParams.order_direction,
|
|
};
|
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
|
|
|
const endpoint = `${QUERIES}/${id}/report`;
|
|
const path = `${endpoint}?${queryString}`;
|
|
return sendRequest("GET", path);
|
|
},
|
|
};
|