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

Use the longest value in column to get column width in PDF report tables #3326

Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed dark mode visualization background in pdf reports [#3315](https://github.com/wazuh/wazuh-kibana-app/pull/3315)
- Adapt Kibana integrations to Kibana 7.11 and 7.12 [#3309](https://github.com/wazuh/wazuh-kibana-app/pull/3309)
- Fixed error agent view does not render correctly [#3306](https://github.com/wazuh/wazuh-kibana-app/pull/3306)
- Fixed miscalculation in table column width in PDF reports [#3326](https://github.com/wazuh/wazuh-kibana-app/pull/3326)

## Wazuh v4.2.0 - Kibana 7.10.2 , 7.11.2 - Revision 4201

Expand Down
14 changes: 13 additions & 1 deletion server/lib/reporting/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,19 @@ export class ReportPrinter{
const widths = [];

for (let step = 0; step < columns.length - 1; step++) {
let columnLength = tableRows[0][step].text.length * widthCharacter;

//Get the longest row value
const maxRowLength = tableRows.reduce((maxLength, row)=>{
return (row[step].text.length > maxLength ? row[step].text.length : maxLength);
},0);

//Get column name length
const headerLength = columns[step].label.length;

//Use the longest to get the column width
const maxLength = maxRowLength > headerLength ? maxRowLength : headerLength;
let columnLength = maxLength * widthCharacter;

if (columnLength <= Math.round(totalWidth / totalLength)) {
widths.push(columnLength);
totalWidth -= columnLength;
Expand Down