Skip to content

Commit 1175c4b

Browse files
authored
Merge branch 'main' into ska/relocate-cases_api_integration
2 parents d6fa6ac + 0c377fa commit 1175c4b

123 files changed

Lines changed: 6817 additions & 1341 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev_docs/contributing/kibana_http_api_guidelines.mdx

Lines changed: 502 additions & 0 deletions
Large diffs are not rendered by default.

dev_docs/nav-kibana-dev.docnav.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
{
4747
"id": "kibStyleGuide"
4848
},
49+
{
50+
"id": "kibHttpApiGuidelines"
51+
},
4952
{
5053
"id": "ktRFCProcess"
5154
},

src/platform/packages/private/kbn-reporting/common/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
LENS_APP_LOCATOR,
1414
VISUALIZE_APP_LOCATOR,
1515
} from '@kbn/deeplinks-analytics';
16+
import { LicenseType } from '@kbn/licensing-plugin/common/types';
1617

1718
export const ALLOWED_JOB_CONTENT_TYPES = [
1819
'application/json',
@@ -40,6 +41,13 @@ export const LICENSE_TYPE_CLOUD_STANDARD = 'standard' as const;
4041
export const LICENSE_TYPE_GOLD = 'gold' as const;
4142
export const LICENSE_TYPE_PLATINUM = 'platinum' as const;
4243
export const LICENSE_TYPE_ENTERPRISE = 'enterprise' as const;
44+
export const SCHEDULED_REPORT_VALID_LICENSES: LicenseType[] = [
45+
LICENSE_TYPE_TRIAL,
46+
LICENSE_TYPE_CLOUD_STANDARD,
47+
LICENSE_TYPE_GOLD,
48+
LICENSE_TYPE_PLATINUM,
49+
LICENSE_TYPE_ENTERPRISE,
50+
];
4351

4452
/*
4553
* Notifications
@@ -66,6 +74,8 @@ export const REPORTING_REDIRECT_LOCATOR_STORE_KEY = '__REPORTING_REDIRECT_LOCATO
6674

6775
// Management UI route
6876
export const REPORTING_MANAGEMENT_HOME = '/app/management/insightsAndAlerting/reporting';
77+
export const REPORTING_MANAGEMENT_SCHEDULES =
78+
'/app/management/insightsAndAlerting/reporting/schedules';
6979

7080
/*
7181
* ILM

src/platform/packages/private/kbn-reporting/common/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
"@kbn/i18n",
2222
"@kbn/task-manager-plugin",
2323
"@kbn/deeplinks-analytics",
24+
"@kbn/licensing-plugin",
2425
]
2526
}

src/platform/packages/private/kbn-reporting/common/types.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
LayoutParams,
1212
PerformanceMetrics as ScreenshotMetrics,
1313
} from '@kbn/screenshotting-plugin/common';
14-
import type { ConcreteTaskInstance } from '@kbn/task-manager-plugin/server';
14+
import type { ConcreteTaskInstance, RruleSchedule } from '@kbn/task-manager-plugin/server';
1515
import { JOB_STATUS } from './constants';
1616
import type { LocatorParams } from './url';
1717

@@ -211,3 +211,24 @@ export interface LicenseCheckResults {
211211
showLinks: boolean;
212212
message: string;
213213
}
214+
215+
export interface ScheduledReportApiJSON {
216+
id: string;
217+
created_at: string;
218+
created_by: string;
219+
enabled: boolean;
220+
jobtype: string;
221+
last_run: string | undefined;
222+
next_run: string | undefined;
223+
notification?: {
224+
email?: {
225+
to?: string[];
226+
cc?: string[];
227+
bcc?: string[];
228+
};
229+
};
230+
payload?: ReportApiJSON['payload'];
231+
schedule: RruleSchedule;
232+
space_id: string;
233+
title: string;
234+
}

src/platform/packages/private/kbn-reporting/public/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10+
import type { ActionsPublicPluginSetup } from '@kbn/actions-plugin/public';
11+
1012
export type { ClientConfigType } from './types';
1113
export { Job } from './job';
1214
export * from './job_completion_notifications';
@@ -15,7 +17,7 @@ export { useCheckIlmPolicyStatus } from './hooks';
1517
export { ReportingAPIClient } from './reporting_api_client';
1618
export { checkLicense } from './license_check';
1719

18-
import type { CoreSetup, CoreStart } from '@kbn/core/public';
20+
import type { CoreSetup, CoreStart, NotificationsStart } from '@kbn/core/public';
1921
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
2022
import { useKibana as _useKibana } from '@kbn/kibana-react-plugin/public';
2123
import type { SharePluginStart } from '@kbn/share-plugin/public';
@@ -26,10 +28,13 @@ import type { SharePluginStart } from '@kbn/share-plugin/public';
2628
export interface KibanaContext {
2729
http: CoreSetup['http'];
2830
application: CoreStart['application'];
31+
settings: CoreStart['settings'];
2932
uiSettings: CoreStart['uiSettings'];
3033
docLinks: CoreStart['docLinks'];
3134
data: DataPublicPluginStart;
3235
share: SharePluginStart;
36+
actions: ActionsPublicPluginSetup;
37+
notifications: NotificationsStart;
3338
}
3439

3540
export const useKibana = () => _useKibana<KibanaContext>();

src/platform/packages/private/kbn-reporting/public/job.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class Job {
7979

8080
public readonly queue_time_ms?: Required<ReportFields>['queue_time_ms'][number];
8181
public readonly execution_time_ms?: Required<ReportFields>['execution_time_ms'][number];
82+
public readonly scheduled_report_id?: ReportSource['scheduled_report_id'];
8283

8384
constructor(report: ReportApiJSON) {
8485
this.id = report.id;
@@ -117,6 +118,7 @@ export class Job {
117118
this.metrics = report.metrics;
118119
this.queue_time_ms = report.queue_time_ms;
119120
this.execution_time_ms = report.execution_time_ms;
121+
this.scheduled_report_id = report.scheduled_report_id;
120122
}
121123

122124
public isSearch() {

src/platform/packages/private/kbn-reporting/public/reporting_api_client.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ describe('ReportingAPIClient', () => {
118118
});
119119
});
120120

121+
describe('getScheduledReportInfo', () => {
122+
beforeEach(() => {
123+
httpClient.get.mockResolvedValueOnce({ data: [{ id: '123', title: 'Scheduled Report 1' }] });
124+
});
125+
126+
it('should send a get request', async () => {
127+
await apiClient.getScheduledReportInfo('123');
128+
129+
expect(httpClient.get).toHaveBeenCalledWith(
130+
expect.stringContaining('/internal/reporting/scheduled/list')
131+
);
132+
});
133+
134+
it('should return a report', async () => {
135+
await expect(apiClient.getScheduledReportInfo('123')).resolves.toEqual({
136+
id: '123',
137+
title: 'Scheduled Report 1',
138+
});
139+
});
140+
});
141+
121142
describe('getError', () => {
122143
it('should get an error message', async () => {
123144
httpClient.get.mockResolvedValueOnce({

src/platform/packages/private/kbn-reporting/public/reporting_api_client.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ import {
1818
buildKibanaPath,
1919
REPORTING_REDIRECT_APP,
2020
} from '@kbn/reporting-common';
21-
import { BaseParams, JobId, ManagementLinkFn, ReportApiJSON } from '@kbn/reporting-common/types';
21+
import {
22+
BaseParams,
23+
JobId,
24+
ManagementLinkFn,
25+
ReportApiJSON,
26+
ScheduledReportApiJSON,
27+
} from '@kbn/reporting-common/types';
2228
import rison from '@kbn/rison';
2329
import moment from 'moment';
2430
import { stringify } from 'query-string';
@@ -83,7 +89,10 @@ export class ReportingAPIClient implements IReportingAPI {
8389
}
8490

8591
public getKibanaAppHref(job: Job): string {
86-
const searchParams = stringify({ jobId: job.id });
92+
const searchParams = stringify({
93+
jobId: job.id,
94+
...(job.scheduled_report_id ? { scheduledReportId: job.scheduled_report_id } : {}),
95+
});
8796

8897
const path = buildKibanaPath({
8998
basePath: this.http.basePath.serverBasePath,
@@ -158,6 +167,15 @@ export class ReportingAPIClient implements IReportingAPI {
158167
return new Job(report);
159168
}
160169

170+
public async getScheduledReportInfo(id: string) {
171+
const { data: reportList = [] }: { data: ScheduledReportApiJSON[] } = await this.http.get(
172+
`${INTERNAL_ROUTES.SCHEDULED.LIST}`
173+
);
174+
175+
const report = reportList.find((item) => item.id === id);
176+
return report;
177+
}
178+
161179
public async findForJobIds(jobIds: JobId[]) {
162180
const reports: ReportApiJSON[] = await this.http.fetch(INTERNAL_ROUTES.JOBS.LIST, {
163181
query: { page: 0, ids: jobIds.join(',') },

src/platform/packages/private/kbn-reporting/public/share/share_context_menu/register_csv_modal_reporting.tsx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,42 @@ import type { SerializedSearchSourceFields } from '@kbn/data-plugin/common';
1515
import { FormattedMessage, InjectedIntl } from '@kbn/i18n-react';
1616
import { ShareContext, type ExportShare } from '@kbn/share-plugin/public';
1717
import { LocatorParams } from '@kbn/reporting-common/types';
18+
import { ReportParamsGetter, ReportParamsGetterOptions } from '../../types';
1819
import { getSearchCsvJobParams, CsvSearchModeParams } from '../shared/get_search_csv_job_params';
1920
import type { ExportModalShareOpts } from '.';
2021
import { checkLicense } from '../..';
2122

23+
export const getCsvReportParams: ReportParamsGetter<
24+
ReportParamsGetterOptions & { forShareUrl?: boolean },
25+
CsvSearchModeParams
26+
> = ({ sharingData, forShareUrl = false }) => {
27+
const getSearchSource = sharingData.getSearchSource as ({
28+
addGlobalTimeFilter,
29+
absoluteTime,
30+
}: {
31+
addGlobalTimeFilter?: boolean;
32+
absoluteTime?: boolean;
33+
}) => SerializedSearchSourceFields;
34+
35+
if (sharingData.isTextBased) {
36+
// csv v2 uses locator params
37+
return {
38+
isEsqlMode: true,
39+
locatorParams: sharingData.locatorParams as LocatorParams[],
40+
};
41+
}
42+
43+
// csv v1 uses search source and columns
44+
return {
45+
isEsqlMode: false,
46+
columns: sharingData.columns as string[] | undefined,
47+
searchSource: getSearchSource({
48+
addGlobalTimeFilter: true,
49+
absoluteTime: !forShareUrl,
50+
}),
51+
};
52+
};
53+
2254
export const reportingCsvExportProvider = ({
2355
apiClient,
2456
startServices$,
@@ -27,33 +59,8 @@ export const reportingCsvExportProvider = ({
2759
objectType,
2860
sharingData,
2961
}: ShareContext): ReturnType<ExportShare['config']> => {
30-
const getSearchSource = sharingData.getSearchSource as ({
31-
addGlobalTimeFilter,
32-
absoluteTime,
33-
}: {
34-
addGlobalTimeFilter?: boolean;
35-
absoluteTime?: boolean;
36-
}) => SerializedSearchSourceFields;
37-
38-
const getSearchModeParams = (forShareUrl?: boolean): CsvSearchModeParams => {
39-
if (sharingData.isTextBased) {
40-
// csv v2 uses locator params
41-
return {
42-
isEsqlMode: true,
43-
locatorParams: sharingData.locatorParams as LocatorParams[],
44-
};
45-
}
46-
47-
// csv v1 uses search source and columns
48-
return {
49-
isEsqlMode: false,
50-
columns: sharingData.columns as string[] | undefined,
51-
searchSource: getSearchSource({
52-
addGlobalTimeFilter: true,
53-
absoluteTime: !forShareUrl,
54-
}),
55-
};
56-
};
62+
const getSearchModeParams = (forShareUrl?: boolean): CsvSearchModeParams =>
63+
getCsvReportParams({ sharingData, forShareUrl });
5764

5865
const generateReportingJobCSV = ({ intl }: { intl: InjectedIntl }) => {
5966
const { reportType, decoratedJobParams } = getSearchCsvJobParams({

0 commit comments

Comments
 (0)