Skip to content

Commit

Permalink
Make clientAPI lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
adcoelho committed May 12, 2023
1 parent 53135ec commit e201ab1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions x-pack/plugins/cases/public/client/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
} from '../../../common/api';
import { getCasesFromAlertsUrl } from '../../../common/api';
import type { CasesFindResponseUI, CasesStatus, CasesMetrics } from '../../../common/ui';
import { bulkGetCases, getCases, getCasesMetrics, getCasesStatus } from '../../api';
import type { CasesUiStart } from '../../types';

export const createClientAPI = ({ http }: { http: HttpStart }): CasesUiStart['api'] => {
Expand All @@ -26,13 +25,28 @@ export const createClientAPI = ({ http }: { http: HttpStart }): CasesUiStart['ap
): Promise<CasesByAlertId> =>
http.get<CasesByAlertId>(getCasesFromAlertsUrl(alertId), { query }),
cases: {
find: (query: CasesFindRequest, signal?: AbortSignal): Promise<CasesFindResponseUI> =>
getCases({ http, query, signal }),
getCasesStatus: (query: CasesStatusRequest, signal?: AbortSignal): Promise<CasesStatus> =>
getCasesStatus({ http, query, signal }),
getCasesMetrics: (query: CasesMetricsRequest, signal?: AbortSignal): Promise<CasesMetrics> =>
getCasesMetrics({ http, signal, query }),
bulkGet: (params, signal?: AbortSignal) => bulkGetCases({ http, signal, params }),
find: async (query: CasesFindRequest, signal?: AbortSignal): Promise<CasesFindResponseUI> => {
const { getCases } = await import('../../api');
return getCases({ http, query, signal });
},
getCasesStatus: async (
query: CasesStatusRequest,
signal?: AbortSignal
): Promise<CasesStatus> => {
const { getCasesStatus } = await import('../../api');
return getCasesStatus({ http, query, signal });
},
getCasesMetrics: async (
query: CasesMetricsRequest,
signal?: AbortSignal
): Promise<CasesMetrics> => {
const { getCasesMetrics } = await import('../../api');
return getCasesMetrics({ http, query, signal });
},
bulkGet: async (params, signal?: AbortSignal) => {
const { bulkGetCases } = await import('../../api');
return bulkGetCases({ http, signal, params });
},
},
};
};

0 comments on commit e201ab1

Please sign in to comment.