Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Report Definition Details Display Change #136

Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,47 @@ export function ReportDefinitionDetails(props) {
setReportDefinitionRawResponse(e);
};

const humanReadableScheduleDetails = (trigger) => {
let scheduleDetails = '';
if (trigger.trigger_type === 'Schedule') {
if (trigger.trigger_params.schedule_type === 'Recurring') {
// Daily
if (
trigger.trigger_params.schedule.interval.unit === 'DAYS' &&
trigger.trigger_params.schedule.interval.period === 1
) {
const date = new Date(
trigger.trigger_params.schedule.interval.start_time
);
scheduleDetails = 'Daily @ ' + date.toTimeString();
}
// By interval
else {
const date = new Date(
trigger.trigger_params.schedule.interval.start_time
);
scheduleDetails =
'By interval, every ' +
trigger.trigger_params.schedule.interval.period +
' ' +
trigger.trigger_params.schedule.interval.unit.toLowerCase() +
', starting @ ' +
date.toTimeString();
}
}
// Cron
else if (trigger.trigger_params.schedule_type === 'Cron based') {
scheduleDetails =
'Cron based: ' +
trigger.trigger_params.schedule.cron.expression +
' (' +
trigger.trigger_params.schedule.cron.timezone +
')';
}
}
return scheduleDetails;
};

const getReportDefinitionDetailsMetadata = (data) => {
const reportDefinition: ReportDefinitionSchemaType = data.report_definition;
const {
Expand Down Expand Up @@ -205,26 +246,25 @@ export function ReportDefinitionDetails(props) {

let reportDefinitionDetails = {
name: reportParams.report_name,
description: reportParams.description,
description:
reportParams.description === '' ? `\u2014` : reportParams.description,
created: displayCreatedDate,
lastUpdated: displayUpdatedDate,
source: reportParams.report_source,
baseUrl: baseUrl,
// TODO: need better display
timePeriod: moment.duration(timeDuration).humanize(),
fileFormat: reportFormat,
// TODO: to be added to schema, currently hardcoded in backend
reportHeader:
reportParams.core_params.header != ''
? reportParams.core_params.header
: `\u2014`,
reportFooter:
reportParams.core_params.footer != ''
? reportParams.core_params.footer
: `\u2014`,
reportHeader: reportParams.core_params.hasOwnProperty('header')
? reportParams.core_params.header
: `\u2014`,
reportFooter: reportParams.core_params.hasOwnProperty('footer')
? reportParams.core_params.footer
: `\u2014`,
triggerType: triggerType,
scheduleDetails: triggerParams ? triggerParams.schedule_type : `\u2014`,
alertDetails: `\u2014`,
scheduleDetails: triggerParams
? humanReadableScheduleDetails(data.report_definition.trigger)
: `\u2014`,
channel: deliveryType,
status: reportDefinition.status,
kibanaRecipients: deliveryParams.kibana_recipients
Expand All @@ -236,11 +276,6 @@ export function ReportDefinitionDetails(props) {
deliveryType === 'Channel' ? deliveryParams.title : `\u2014`,
emailBody:
deliveryType === 'Channel' ? deliveryParams.textDescription : `\u2014`,
reportAsAttachment:
deliveryType === 'Channel' &&
deliveryParams.email_format === 'Attachment'
? 'True'
: 'False',
};
return reportDefinitionDetails;
};
Expand Down Expand Up @@ -392,6 +427,59 @@ export function ReportDefinitionDetails(props) {
<ScheduledDefinitionStatus />
);

const triggerSection =
reportDefinitionDetails.triggerType === 'On demand' ? (
davidcui1225 marked this conversation as resolved.
Show resolved Hide resolved
<ReportDetailsComponent
reportDetailsComponentTitle={'Trigger type'}
reportDetailsComponentContent={reportDefinitionDetails.triggerType}
/>
) : (
<EuiFlexGroup>
<ReportDetailsComponent
reportDetailsComponentTitle={'Trigger type'}
reportDetailsComponentContent={reportDefinitionDetails.triggerType}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Schedule details'}
reportDetailsComponentContent={
reportDefinitionDetails.scheduleDetails
}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Status'}
reportDetailsComponentContent={reportDefinitionDetails.status}
/>
<ReportDetailsComponent />
</EuiFlexGroup>
);

const showNotificationSection =
reportDefinitionDetails.triggerType === 'On demand' ? null : (
<div>
<EuiTitle>
<h3>Notification settings</h3>
</EuiTitle>
<EuiSpacer />
<EuiFlexGroup>
<ReportDetailsComponent
reportDetailsComponentTitle={'Email recipients'}
reportDetailsComponentContent={
reportDefinitionDetails.emailRecipients
}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Email subject'}
reportDetailsComponentContent={reportDefinitionDetails.emailSubject}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Optional message'}
reportDetailsComponentContent={reportDefinitionDetails.emailBody}
/>
<ReportDetailsComponent />
</EuiFlexGroup>
</div>
);

return (
<EuiPage>
<EuiPageBody>
Expand Down Expand Up @@ -502,74 +590,9 @@ export function ReportDefinitionDetails(props) {
<h3>Report trigger</h3>
</EuiTitle>
<EuiSpacer />
<EuiFlexGroup>
<ReportDetailsComponent
reportDetailsComponentTitle={'Trigger type'}
reportDetailsComponentContent={
reportDefinitionDetails.triggerType
}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Schedule details'}
reportDetailsComponentContent={
reportDefinitionDetails.scheduleDetails
}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Alert details'}
reportDetailsComponentContent={
reportDefinitionDetails.alertDetails
}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Status'}
reportDetailsComponentContent={reportDefinitionDetails.status}
/>
</EuiFlexGroup>
<EuiSpacer />
<EuiTitle>
<h3>Delivery settings</h3>
</EuiTitle>
<EuiSpacer />
<EuiFlexGroup>
<ReportDetailsComponent
reportDetailsComponentTitle={'Channel'}
reportDetailsComponentContent={reportDefinitionDetails.channel}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Kibana recipients'}
reportDetailsComponentContent={
reportDefinitionDetails.kibanaRecipients
}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Email recipients'}
reportDetailsComponentContent={
reportDefinitionDetails.emailRecipients
}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Email subject'}
reportDetailsComponentContent={
reportDefinitionDetails.emailSubject
}
/>
</EuiFlexGroup>
{triggerSection}
<EuiSpacer />
<EuiFlexGroup>
<ReportDetailsComponent
reportDetailsComponentTitle={'Email body'}
reportDetailsComponentContent={reportDefinitionDetails.emailBody}
/>
<ReportDetailsComponent
reportDetailsComponentTitle={'Include report as attachment'}
reportDetailsComponentContent={
reportDefinitionDetails.reportAsAttachment
}
/>
<ReportDetailsComponent />
<ReportDetailsComponent />
</EuiFlexGroup>
{showNotificationSection}
</EuiPageContent>
<EuiGlobalToastList
toasts={toasts}
Expand Down