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 (