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

Commit

Permalink
Header & Footer Plaintext Support (#120)
Browse files Browse the repository at this point in the history
Added header and footer to schema and avoided hard-coding; plaintext header and footer supported
  • Loading branch information
davidcui1225 authored Oct 13, 2020
1 parent 2aad0f0 commit 3c182ed
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,14 @@ export function ReportDefinitionDetails(props) {
timePeriod: moment.duration(timeDuration).humanize(),
fileFormat: reportFormat,
// TODO: to be added to schema, currently hardcoded in backend
reportHeader: `\u2014`,
reportFooter: `\u2014`,
reportHeader:
reportParams.core_params.header != ''
? reportParams.core_params.header
: `\u2014`,
reportFooter:
reportParams.core_params.footer != ''
? reportParams.core_params.footer
: `\u2014`,
triggerType: triggerType,
scheduleDetails: triggerParams ? triggerParams.schedule_type : `\u2014`,
alertDetails: `\u2014`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ export function ReportDetails(props) {
time_period: lastUpdated,
defaultFileFormat: coreParams.report_format,
state: state,
reportHeader: `\u2014`,
reportFooter: `\u2014`,
reportHeader:
reportParams.core_params.header != ''
? reportParams.core_params.header
: `\u2014`,
reportFooter:
reportParams.core_params.footer != ''
? reportParams.core_params.footer
: `\u2014`,
triggerType: triggerType,
scheduleType: triggerParams ? triggerParams.schedule_type : `\u2014`,
scheduleDetails: `\u2014`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ interface reportParamsType {
interface visualReportParams {
base_url: string;
report_format: string;
header: string;
footer: string;
time_duration: string;
}

Expand Down Expand Up @@ -101,6 +103,8 @@ export function CreateReport(props) {
core_params: {
base_url: '',
report_format: '',
header: '',
footer: '',
time_duration: '',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export function EditReportDefinition(props) {
core_params: {
base_url: '',
report_format: '',
header: '',
footer: '',
time_duration: '',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ export function ReportSettings(props: ReportSettingProps) {
'write' | 'preview'
>('write');

const handleHeader = (e) => {
setHeader(e);
reportDefinitionRequest.report_params.core_params.header = e;
};

const handleFooter = (e) => {
setFooter(e);
reportDefinitionRequest.report_params.core_params.footer = e;
};

const handleCheckboxHeaderFooter = (optionId) => {
const newCheckboxIdToSelectedMap = {
...checkboxIdSelectHeaderFooter,
Expand All @@ -221,7 +231,7 @@ export function ReportSettings(props: ReportSettingProps) {
<EuiFormRow label="Footer" fullWidth={true}>
<ReactMde
value={footer}
onChange={setFooter}
onChange={handleFooter}
selectedTab={selectedTabFooter}
onTabChange={setSelectedTabFooter}
toolbarCommands={[
Expand All @@ -239,7 +249,7 @@ export function ReportSettings(props: ReportSettingProps) {
<EuiFormRow label="Header" fullWidth={true}>
<ReactMde
value={header}
onChange={setHeader}
onChange={handleHeader}
selectedTab={selectedTabHeader}
onTabChange={setSelectedTabHeader}
toolbarCommands={[
Expand All @@ -253,6 +263,55 @@ export function ReportSettings(props: ReportSettingProps) {
</EuiFormRow>
) : null;

useEffect(() => {
let unmounted = false;
if (edit) {
httpClientProps
.get(`../api/reporting/reportDefinitions/${editDefinitionId}`)
.then(async (response: {}) => {
// set header/footer default
if (
response.report_definition.report_params.core_params.header != ''
) {
checkboxIdSelectHeaderFooter.header = true;
if (!unmounted) {
setHeader(
response.report_definition.report_params.core_params.header
);
}
}
if (
response.report_definition.report_params.core_params.footer != ''
) {
checkboxIdSelectHeaderFooter.footer = true;
if (!unmounted) {
setFooter(
response.report_definition.report_params.core_params.footer
);
}
}
})
.catch((error: any) => {
console.error(
'error in fetching report definition details:',
error
);
});
} else {
if (reportDefinitionRequest.report_params.core_params.header != '') {
checkboxIdSelectHeaderFooter.header = true;
setHeader(reportDefinitionRequest.report_params.core_params.header);
}
if (reportDefinitionRequest.report_params.core_params.footer != '') {
checkboxIdSelectHeaderFooter.footer = true;
setFooter(reportDefinitionRequest.report_params.core_params.footer);
}
}
return () => {
unmounted = true;
};
}, []);

return (
<div>
<EuiCheckboxGroup
Expand Down Expand Up @@ -321,7 +380,6 @@ export function ReportSettings(props: ReportSettingProps) {
<div>
<PDFandPNGFileFormats />
<EuiSpacer />
<SettingsMarkdown />
</div>
);
};
Expand Down Expand Up @@ -503,7 +561,10 @@ export function ReportSettings(props: ReportSettingProps) {

const displayVisualReportsFormatAndMarkdown =
reportSourceId != 'savedSearchReportSource' ? (
<VisualReportFormatAndMarkdown />
<div>
<VisualReportFormatAndMarkdown />
<SettingsMarkdown />
</div>
) : (
<div>
<EuiFormRow label="File format">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,12 @@ export function ReportTrigger(props: ReportTriggerProps) {

const defaultConfigurationEdit = (trigger) => {
defaultEditTriggerType(trigger.trigger_type);
defaultEditRequestType(trigger);
if (trigger.trigger_type === 'Schedule') {
defaultEditScheduleFrequency(trigger.trigger_params);
defaultEditRequestType(trigger);
} else if (trigger.trigger_type == 'On demand') {
setReportTriggerType('On demand');
reportDefinitionRequest.trigger.trigger_type = 'On demand';
}
};

Expand Down
3 changes: 2 additions & 1 deletion kibana-reports/server/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const visualReportSchema = schema.object({
schema.literal(FORMAT.pdf),
schema.literal(FORMAT.png),
]),
header: schema.string(),
footer: schema.string(),
time_duration: schema.string(),
});

Expand Down Expand Up @@ -113,7 +115,6 @@ export const reportDefinitionSchema = schema.object({
schema.literal(REPORT_TYPE.savedSearch),
]),
description: schema.string(),

core_params: schema.conditional(
schema.siblingRef('report_source'),
REPORT_TYPE.savedSearch,
Expand Down
4 changes: 2 additions & 2 deletions kibana-reports/server/routes/utils/reportHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const createVisualReport = async (
const reportFormat = coreParams.report_format;

// TODO: replace placeholders with actual schema data fields
const header = 'Test report header sample text';
const footer = 'Test report footer sample text';
const header = reportParams.header;
const footer = reportParams.footer;
// set up puppeteer
const browser = await puppeteer.launch({
headless: true,
Expand Down

0 comments on commit 3c182ed

Please sign in to comment.