Skip to content

Commit 052333e

Browse files
Implemented light option in getInspection
1 parent d623535 commit 052333e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/network/src/api/inspection/mappers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,3 +789,14 @@ export function mapApiAllInspectionsUrlParamsGet(
789789
const paramsStr = params.toString();
790790
return `${paramsStr.length > 0 ? '?' : ''}${paramsStr}`;
791791
}
792+
793+
export function mapApiInspectionUrlParamsGet(
794+
light: boolean | undefined,
795+
) : string {
796+
const params = new URLSearchParams();
797+
if (light) {
798+
params.append('verbose', 'light');
799+
}
800+
const paramsStr = params.toString();
801+
return `${paramsStr.length > 0 ? '?' : ''}${paramsStr}`;
802+
}

packages/network/src/api/inspection/requests.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
mapApiAllInspectionsVerboseGet,
2323
mapApiInspectionGet,
2424
mapApiInspectionPost,
25+
mapApiInspectionUrlParamsGet,
2526
} from './mappers';
2627
import { MonkApiResponse, PaginationResponse } from '../types';
2728

@@ -37,6 +38,12 @@ export interface GetInspectionOptions {
3738
* Additional options used to configure the compliance locally.
3839
*/
3940
compliance?: ComplianceOptions;
41+
/**
42+
* In light mode, only essential data is fetched, for improved performance.
43+
*
44+
* @default false
45+
*/
46+
light?: boolean;
4047
}
4148

4249
/**
@@ -73,7 +80,10 @@ export async function getInspection(
7380
dispatch?: Dispatch<MonkGotOneInspectionAction>,
7481
): Promise<MonkApiResponse<GetInspectionResponse, ApiInspectionGet>> {
7582
const kyOptions = getDefaultOptions(config);
76-
const response = await ky.get(`inspections/${options.id}`, kyOptions);
83+
const response = await ky.get(
84+
`inspections/${options.id}${mapApiInspectionUrlParamsGet(options.light)}`,
85+
kyOptions
86+
);
7787
const body = await response.json<ApiInspectionGet>();
7888
const entities = mapApiInspectionGet(body, config.thumbnailDomain, options.compliance);
7989
dispatch?.({

0 commit comments

Comments
 (0)