-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add column filter in generated XLSX document
This is part of story #23469: export reports with linked artifact in xlsx format Artifact columns can now be filtered in the generated XLSX document. The autofilter generation done by sheetjs does not work with LibreOffice [1][2] [1] https://bugs.documentfoundation.org/show_bug.cgi?id=118592 [2] SheetJS/sheetjs#1165 Change-Id: Iecce314804d910651df4a6d81d93068f7897a5d5
- Loading branch information
1 parent
8484242
commit 3416842
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...ration/scripts/tracker-cross-report-action/src/Exporter/XLSX/autofilter-generator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (c) Enalean, 2022-Present. All Rights Reserved. | ||
* | ||
* This file is a part of Tuleap. | ||
* | ||
* Tuleap is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Tuleap is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { generateAutofilterRange } from "./autofilter-generator"; | ||
import type { ReportSection } from "../../Data/data-formator"; | ||
import { EmptyCell, TextCell } from "@tuleap/plugin-docgen-xlsx"; | ||
|
||
describe("autofilter-generator", () => { | ||
it("generates the autofilter range", (): void => { | ||
const formatted_data: ReportSection = { | ||
headers: { | ||
tracker_names: [], | ||
reports_fields_labels: [ | ||
new TextCell("Field01"), | ||
new TextCell("Field02"), | ||
new TextCell("Field03"), | ||
new TextCell("Field04"), | ||
], | ||
}, | ||
artifacts_rows: [ | ||
[ | ||
new TextCell("Value01"), | ||
new TextCell("Value02"), | ||
new TextCell("Value03"), | ||
new EmptyCell(), | ||
], | ||
[ | ||
new TextCell("Value04"), | ||
new TextCell("Value05"), | ||
new EmptyCell(), | ||
new TextCell("Value06"), | ||
], | ||
], | ||
}; | ||
|
||
const autofilter_range: string = generateAutofilterRange(formatted_data); | ||
|
||
expect(autofilter_range).toBe("A2:D4"); | ||
}); | ||
it("generates empty autofilter range if headers is missing in formatted_data", (): void => { | ||
const formatted_data: ReportSection = { | ||
artifacts_rows: [ | ||
[ | ||
new TextCell("Value01"), | ||
new TextCell("Value02"), | ||
new TextCell("Value03"), | ||
new EmptyCell(), | ||
], | ||
[ | ||
new TextCell("Value04"), | ||
new TextCell("Value05"), | ||
new EmptyCell(), | ||
new TextCell("Value06"), | ||
], | ||
], | ||
}; | ||
|
||
const autofilter_range: string = generateAutofilterRange(formatted_data); | ||
|
||
expect(autofilter_range).toBe(""); | ||
}); | ||
it("generates empty autofilter range if artifacts_rows is missing in formatted_data", (): void => { | ||
const formatted_data: ReportSection = { | ||
headers: { | ||
tracker_names: [], | ||
reports_fields_labels: [ | ||
new TextCell("Field01"), | ||
new TextCell("Field02"), | ||
new TextCell("Field03"), | ||
new TextCell("Field04"), | ||
], | ||
}, | ||
}; | ||
|
||
const autofilter_range: string = generateAutofilterRange(formatted_data); | ||
|
||
expect(autofilter_range).toBe(""); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
..._generation/scripts/tracker-cross-report-action/src/Exporter/XLSX/autofilter-generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright (c) Enalean, 2022-Present. All Rights Reserved. | ||
* | ||
* This file is a part of Tuleap. | ||
* | ||
* Tuleap is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Tuleap is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import type { HeadersSection, ReportSection } from "../../Data/data-formator"; | ||
import type { ReportCell } from "@tuleap/plugin-docgen-xlsx"; | ||
import { utils } from "xlsx"; | ||
|
||
const RANGE_SEPARATOR = ":"; | ||
const STARTING_COLUMN = "A"; | ||
const STARTING_ROW = 2; | ||
|
||
export function generateAutofilterRange(formatted_data: ReportSection): string { | ||
if (formatted_data.headers === undefined || formatted_data.artifacts_rows === undefined) { | ||
return ""; | ||
} | ||
|
||
const all_headers: HeadersSection = formatted_data.headers; | ||
const all_artifacts_rows: ReadonlyArray<ReadonlyArray<ReportCell>> = | ||
formatted_data.artifacts_rows; | ||
|
||
return ( | ||
getAutofilterStartingRange() + | ||
RANGE_SEPARATOR + | ||
getAutofilterEndingRange(all_headers, all_artifacts_rows) | ||
); | ||
} | ||
|
||
function getAutofilterStartingRange(): string { | ||
return STARTING_COLUMN + STARTING_ROW.toString(); | ||
} | ||
|
||
function getAutofilterEndingRange( | ||
all_headers: HeadersSection, | ||
all_artifacts_rows: ReadonlyArray<ReadonlyArray<ReportCell>> | ||
): string { | ||
const ending_column: string = utils.encode_col(all_headers.reports_fields_labels.length - 1); | ||
const ending_row: number = all_artifacts_rows.length + STARTING_ROW; | ||
return ending_column + ending_row.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters