Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect Notifications APIs to Reporting #131

Merged
merged 9 commits into from
Jul 30, 2021
24 changes: 19 additions & 5 deletions dashboards-reports/public/components/main/main_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,34 @@
import 'babel-polyfill';
import { i18n } from '@osd/i18n';
import { HttpFetchOptions, HttpSetup } from '../../../../../src/core/public';
import { placeholderChannels } from '../report_definitions/delivery/delivery_constants';

export const displayDeliveryChannels = (configIds: Array<string>) => {
export const displayDeliveryChannels = (configIds: Array<string>, channels: Array<{label: string, id: string}>) => {
let displayChannels = [];
for (let i = 0; i < configIds.length; ++i) {
for (let j = 0; j < placeholderChannels.length; ++j) {
if (configIds[i] === placeholderChannels[j].id) {
displayChannels.push(placeholderChannels[i].label);
for (let j = 0; j < channels.length; ++j) {
if (configIds[i] === channels[j].id) {
davidcui1225 marked this conversation as resolved.
Show resolved Hide resolved
displayChannels.push(channels[j].label);
}
}
}
return displayChannels.toString();
}

export const getAvailableNotificationsChannels = (configList: any) => {
let availableChannels = [];
for (let i = 0; i < configList.length; ++i) {
let channelEntry = {};
if (configList[i].config.feature_list.includes('reports')) {
channelEntry = {
label: configList[i].config.name,
id: configList[i].config_id
}
availableChannels.push(channelEntry);
}
}
return availableChannels;
}

type fileFormatsOptions = {
[key: string]: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('<ReportDefinitionDetails /> panel', () => {

httpClientMock.get = jest.fn().mockResolvedValue({
report_definition,
config_list: []
});

const { container } = render(
Expand Down Expand Up @@ -137,6 +138,7 @@ describe('<ReportDefinitionDetails /> panel', () => {

httpClientMock.get = jest.fn().mockResolvedValue({
report_definition,
config_list: []
});

const { container } = render(
Expand Down Expand Up @@ -191,6 +193,7 @@ describe('<ReportDefinitionDetails /> panel', () => {

httpClientMock.get = jest.fn().mockResolvedValue({
report_definition,
config_list: []
});

const { container } = render(
Expand Down Expand Up @@ -234,6 +237,7 @@ describe('<ReportDefinitionDetails /> panel', () => {

httpClientMock.get = jest.fn().mockResolvedValue({
report_definition,
config_list: []
});

const component = mount(
Expand Down Expand Up @@ -292,6 +296,7 @@ describe('<ReportDefinitionDetails /> panel', () => {

httpClientMock.get = jest.fn().mockResolvedValue({
report_definition,
config_list: []
});

const component = mount(
Expand Down Expand Up @@ -351,6 +356,7 @@ describe('<ReportDefinitionDetails /> panel', () => {

httpClientMock.get = jest.fn().mockResolvedValue({
report_definition,
config_list: []
});

httpClientMock.put = jest.fn().mockResolvedValue({});
Expand Down Expand Up @@ -412,6 +418,7 @@ describe('<ReportDefinitionDetails /> panel', () => {

httpClientMock.get = jest.fn().mockResolvedValue({
report_definition,
config_list: []
});

httpClientMock.put = jest.fn().mockResolvedValue({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
displayDeliveryChannels,
fileFormatsUpper,
generateReportFromDefinitionId,
getAvailableNotificationsChannels,
} from '../main_utils';
import { ReportDefinitionSchemaType } from '../../../../server/model';
import moment from 'moment';
Expand All @@ -62,7 +63,7 @@ import {
permissionsMissingActions,
} from '../../utils/utils';
import { GenerateReportLoadingModal } from '../loading_modal';
import { placeholderChannels } from '../../report_definitions/delivery/delivery_constants';
import { getChannelsQueryObject, placeholderChannels } from '../../report_definitions/delivery/delivery_constants';

const ON_DEMAND = 'On demand';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np: move constancts like this to a common place for easy reuse. e.g. constants.ts, or /common/index.ts


Expand Down Expand Up @@ -410,19 +411,7 @@ export function ReportDefinitionDetails(props: { match?: any; setBreadcrumbs?: a
return scheduleDetails;
};

// const displayDeliveryChannels = (configIds: Array<string>) => {
// let displayChannels = [];
// for (let i = 0; i < configIds.length; ++i) {
// for (let j = 0; j < placeholderChannels.length; ++j) {
// if (configIds[i] === placeholderChannels[j].id) {
// displayChannels.push(placeholderChannels[i].label);
// }
// }
// }
// return displayChannels.toString();
// }

const getReportDefinitionDetailsMetadata = (data: ReportDefinitionSchemaType) : ReportDefinitionDetails => {
const getReportDefinitionDetailsMetadata = (data: ReportDefinitionSchemaType, availableChannels) : ReportDefinitionDetails => {
const reportDefinition: ReportDefinitionSchemaType = data;
const {
report_params: reportParams,
Expand Down Expand Up @@ -485,7 +474,7 @@ export function ReportDefinitionDetails(props: { match?: any; setBreadcrumbs?: a
? humanReadableScheduleDetails(data.trigger)
: `\u2014`,
status: reportDefinition.status,
configIds: (configIds.length > 0) ? displayDeliveryChannels(configIds) : `\u2014`,
configIds: (configIds.length > 0) ? displayDeliveryChannels(configIds, availableChannels) : `\u2014`,
title: (title !== '') ? title : `\u2014`,
textDescription: (textDescription !== '') ? textDescription : `\u2014`,
htmlDescription: (htmlDescription !== '') ? htmlDescription : `\u2014`
Expand All @@ -496,10 +485,19 @@ export function ReportDefinitionDetails(props: { match?: any; setBreadcrumbs?: a
useEffect(() => {
const { httpClient } = props;
httpClient
.get('../api/notifications/get_configs', {
query: getChannelsQueryObject
})
.then(async (response: any) => {
let availableChannels = getAvailableNotificationsChannels(response.config_list);
return availableChannels;
})
.then((availableChannels: any) => {
httpClient
.get(`../api/reporting/reportDefinitions/${reportDefinitionId}`)
.then((response: {report_definition: ReportDefinitionSchemaType}) => {
handleReportDefinitionRawResponse(response);
handleReportDefinitionDetails(getReportDefinitionDetailsMetadata(response.report_definition));
handleReportDefinitionDetails(getReportDefinitionDetailsMetadata(response.report_definition, availableChannels));
props.setBreadcrumbs([
{
text: i18n.translate(
Expand Down Expand Up @@ -534,6 +532,7 @@ export function ReportDefinitionDetails(props: { match?: any; setBreadcrumbs?: a
);
handleDetailsErrorToast();
});
})
}, []);

const downloadIconDownload = async () => {
Expand Down
Loading