From b1028465e1428547c6e58e68e81abfb5d401364a Mon Sep 17 00:00:00 2001 From: Luke Heath Date: Mon, 23 May 2022 22:46:40 -0500 Subject: [PATCH] Export hosts to CSV with selected columns (#5841) --- changes/5168-export-hosts-to-csv | 1 + .../hosts/ManageHostsPage/ManageHostsPage.tsx | 25 ++++++++++++++++--- frontend/services/entities/hosts.ts | 7 +++++- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 changes/5168-export-hosts-to-csv diff --git a/changes/5168-export-hosts-to-csv b/changes/5168-export-hosts-to-csv new file mode 100644 index 0000000000..26a4752219 --- /dev/null +++ b/changes/5168-export-hosts-to-csv @@ -0,0 +1 @@ +* Export hosts to csv with selected columns only. diff --git a/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx b/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx index f5d95773f5..e76582fd44 100644 --- a/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx +++ b/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx @@ -1280,6 +1280,27 @@ const ManageHostsPage = ({ ) => { evt.preventDefault(); + const hiddenColumnsStorage = localStorage.getItem("hostHiddenColumns"); + let currentHiddenColumns; + let visibleColumns; + if (hiddenColumnsStorage) { + currentHiddenColumns = JSON.parse(hiddenColumnsStorage); + } + + if (config && currentUser) { + const tableColumns = generateVisibleTableColumns( + currentHiddenColumns, + config, + currentUser, + currentTeam + ); + + const columnAccessors = tableColumns + .map((column) => (column.accessor ? column.accessor : "")) + .filter((element) => element); + visibleColumns = columnAccessors.join(","); + } + let options = { selectedLabels: selectedFilters, globalFilter: searchQuery, @@ -1288,6 +1309,7 @@ const ManageHostsPage = ({ policyId, policyResponse, softwareId, + visibleColumns, }; options = { @@ -1500,9 +1522,6 @@ const ManageHostsPage = ({ currentTeam ); - const columnAccessors = tableColumns.map((column) => column.accessor); - columnAccessors.shift(); - return (