Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/platform/packages/private/kbn-reporting/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export { checkLicense } from './license_check';
import type { CoreSetup, CoreStart, NotificationsStart } from '@kbn/core/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { useKibana as _useKibana } from '@kbn/kibana-react-plugin/public';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';

/* Services received through useKibana context
Expand All @@ -35,6 +36,7 @@ export interface KibanaContext {
share: SharePluginStart;
actions: ActionsPublicPluginSetup;
notifications: NotificationsStart;
license$: LicensingPluginStart['license$'];
}

export const useKibana = () => _useKibana<KibanaContext>();
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,25 @@ describe('ReportingAPIClient', () => {

describe('getScheduledReportInfo', () => {
beforeEach(() => {
httpClient.get.mockResolvedValueOnce({ data: [{ id: '123', title: 'Scheduled Report 1' }] });
httpClient.get.mockResolvedValueOnce({
data: [
{ id: 'scheduled-report-1', title: 'Scheduled Report 1' },
{ id: 'scheduled-report-2', title: 'Schedule Report 2' },
],
});
});

it('should send a get request', async () => {
await apiClient.getScheduledReportInfo('123');
await apiClient.getScheduledReportInfo('scheduled-report-1');

expect(httpClient.get).toHaveBeenCalledWith(
expect.stringContaining('/internal/reporting/scheduled/list')
);
});

it('should return a report', async () => {
await expect(apiClient.getScheduledReportInfo('123')).resolves.toEqual({
id: '123',
await expect(apiClient.getScheduledReportInfo('scheduled-report-1')).resolves.toEqual({
id: 'scheduled-report-1',
title: 'Scheduled Report 1',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,9 @@ export const IlmPolicyStatusContextProvider: FC<PropsWithChildren<unknown>> = ({

export type UseIlmPolicyStatusReturn = ReturnType<typeof useIlmPolicyStatus>;

export const useIlmPolicyStatus = (isEnabled: boolean): ContextValue => {
export const useIlmPolicyStatus = (): ContextValue => {
const ctx = useContext(IlmPolicyStatusContext);
if (!ctx) {
if (!isEnabled) {
return {
status: undefined,
isLoading: false,
recheckStatus: () => {},
};
}

throw new Error('"useIlmPolicyStatus" can only be used inside of "IlmPolicyStatusContext"');
}
return ctx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ export const createTestBed = registerTestBed(
<InternalApiClientProvider apiClient={reportingAPIClient} http={http}>
<IlmPolicyStatusContextProvider>
<ReportingTabs
coreStart={coreMock.createStart()}
dataService={data}
shareService={share}
license$={l$}
config={mockConfig}
redirect={jest.fn()}
navigateToUrl={jest.fn()}
apiClient={reportingAPIClient}
{...routeProps}
{...rest}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,21 @@ import { HttpFetchQuery, HttpSetup } from '@kbn/core/public';
import { INTERNAL_ROUTES } from '@kbn/reporting-common';
import { type ScheduledReportApiJSON } from '@kbn/reporting-common/types';

export interface Pagination {
index: number;
size: number;
}

export const getScheduledReportsList = async ({
http,
index,
size,
perPage,
page,
}: {
http: HttpSetup;
index?: number;
size?: number;
page?: number;
perPage?: number;
}): Promise<{
page: number;
size: number;
total: number;
data: ScheduledReportApiJSON[];
}> => {
const query: HttpFetchQuery = { page: index, size };
const query: HttpFetchQuery = { page, size: perPage };

const res = await http.get<{
page: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner } from '@elastic/eui';
import { RouteComponentProps } from 'react-router-dom';
import { ClientConfigType, ReportingAPIClient, useKibana } from '@kbn/reporting-public';
import { Section } from '../../constants';

import { IlmPolicyLink } from './ilm_policy_link';
import { ReportDiagnostic } from './report_diagnostic';
import { useIlmPolicyStatus } from '../../lib/ilm_policy_status_context';
import { MigrateIlmPolicyCallOut } from './migrate_ilm_policy_callout';

export interface MatchParams {
section: Section;
}

export interface ReportingTabsProps {
config: ClientConfigType;
apiClient: ReportingAPIClient;
}

export const IlmPolicyWrapper: React.FunctionComponent<
Partial<RouteComponentProps> & ReportingTabsProps
> = (props) => {
const { config, apiClient } = props;
const {
services: {
application: { capabilities },
share: { url: urlService },
notifications,
},
} = useKibana();

const ilmLocator = urlService.locators.get('ILM_LOCATOR_ID');
const ilmPolicyContextValue = useIlmPolicyStatus();
const hasIlmPolicy = ilmPolicyContextValue?.status !== 'policy-not-found';
const showIlmPolicyLink = Boolean(ilmLocator && hasIlmPolicy);

return (
<>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center" gutterSize="s">
<EuiFlexGroup justifyContent="flexEnd">
{capabilities?.management?.data?.index_lifecycle_management && (
<EuiFlexItem grow={false}>
{ilmPolicyContextValue?.isLoading ? (
<EuiLoadingSpinner />
) : (
showIlmPolicyLink && <IlmPolicyLink locator={ilmLocator!} />
)}
</EuiFlexItem>
)}
</EuiFlexGroup>
<MigrateIlmPolicyCallOut toasts={notifications.toasts} />
<EuiFlexItem grow={false}>
<ReportDiagnostic clientConfig={config} apiClient={apiClient} />
</EuiFlexItem>
</EuiFlexGroup>
</>
);
};

// eslint-disable-next-line import/no-default-export
export { IlmPolicyWrapper as default };
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface Props {
}

export const MigrateIlmPolicyCallOut: FunctionComponent<Props> = ({ toasts }) => {
const { isLoading, recheckStatus, status } = useIlmPolicyStatus(true);
const { isLoading, recheckStatus, status } = useIlmPolicyStatus();

if (isLoading || !status || status === 'ok') {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ export class ReportExportsTable extends Component<ListingPropsInternal, State> {
width: tableColumnWidths.title,
render: (objectTitle: string, job) => {
return (
<div data-test-subj="reportingListItemObjectTitle">
<div
data-test-subj="reportingListItemObjectTitle"
css={({ euiTheme }: UseEuiTheme) => css({ paddingTop: euiTheme.size.s })}
>
<EuiLink
data-test-subj={`viewReportingLink-${job.id}`}
onClick={() => this.setState({ selectedJob: job })}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { render, screen } from '@testing-library/react';
import React from 'react';
import { Frequency } from '@kbn/rrule';
import { ReportScheduleIndicator } from './report_schedule_indicator';

describe('ReportScheduleIndicator', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('renders daily schedule indicator correctly', async () => {
render(
<ReportScheduleIndicator
schedule={{
rrule: {
freq: Frequency.DAILY,
interval: 1,
tzid: 'UTC',
},
}}
/>
);

expect(await screen.findByTestId('reportScheduleIndicator-3')).toBeInTheDocument();
expect(await screen.findByText('Daily')).toBeInTheDocument();
});

it('renders weekly schedule indicator correctly', async () => {
render(
<ReportScheduleIndicator
schedule={{
rrule: { freq: Frequency.WEEKLY, interval: 3, tzid: 'Europe/London' },
}}
/>
);

expect(await screen.findByTestId('reportScheduleIndicator-2')).toBeInTheDocument();
expect(await screen.findByText('Weekly')).toBeInTheDocument();
});

it('renders monthly schedule indicator correctly', async () => {
render(
<ReportScheduleIndicator
schedule={{
rrule: { freq: Frequency.MONTHLY, interval: 6, tzid: 'America/NewYork' },
}}
/>
);

expect(await screen.findByTestId('reportScheduleIndicator-1')).toBeInTheDocument();
expect(await screen.findByText('Monthly')).toBeInTheDocument();
});

it('returns null when no frequency do not match', async () => {
render(
<ReportScheduleIndicator
// @ts-expect-error we don't need to provide all props for the test
schedule={{ rrule: { freq: Frequency.YEARLY, interval: 1, tzid: 'UTC' } }}
/>
);

expect(screen.queryByTestId('reportScheduleIndicator-0')).not.toBeInTheDocument();
expect(screen.queryByText('Yearly')).not.toBeInTheDocument();
});

it('returns null when no rrule', async () => {
// @ts-expect-error we don't need to provide all props for the test
const res = render(<ReportScheduleIndicator schedule={{}} />);

expect(res.container.getElementsByClassName('euiBadge').length).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const ReportScheduleIndicator: FC<ReportScheduleIndicatorProps> = ({ sche

const statusText = translations[schedule.rrule.freq];

if (!statusText) {
return null;
}

return (
<EuiBadge
data-test-subj={`reportScheduleIndicator-${schedule.rrule.freq}`}
Expand Down
Loading