From e1b4d284752f1b6c3db15b939bbc3e83aaf2723b Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Fri, 29 Nov 2024 08:47:55 +0100 Subject: [PATCH 01/24] Added tip on fim --- .../components/common/tables/table-wz-api.tsx | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index 196b81be8f..c28764d814 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -21,6 +21,7 @@ import { EuiToolTip, EuiIcon, EuiCheckboxGroup, + EuiIconTip, } from '@elastic/eui'; import { TableWithSearchBar } from './table-with-search-bar'; import { TableDefault } from './table-default'; @@ -227,16 +228,24 @@ export function TableWzAPI({ {rest.showReload && ReloadButton} {/* Render optional export to CSV button */} {rest.downloadCsv && ( - + <> + + + )} {/* Render optional post custom action button */} {renderActionButtons(postActionButtons, filters)} From f09523e82ba0143f8d45181836764b7765d50fbb Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Fri, 29 Nov 2024 08:53:45 +0100 Subject: [PATCH 02/24] Added Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12cf9a42f8..c2f3f83051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file. ### Added - Support for Wazuh 4.10.2 +- Added info message about too many files on FIM [#7182](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7182) ### Fixed From 2bd0fb94348028fd67e98d757da424db55c33281 Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Fri, 29 Nov 2024 11:41:35 +0100 Subject: [PATCH 03/24] Snaps updated --- .../__snapshots__/inventory.test.tsx.snap | 720 ++++++++++++++++++ .../__snapshots__/agents-table.test.tsx.snap | 60 ++ 2 files changed, 780 insertions(+) diff --git a/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap b/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap index 21933a7df0..120a756b34 100644 --- a/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap +++ b/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap @@ -391,6 +391,26 @@ exports[`Inventory data Network Network interfaces table A Apple agent should re + + + + + @@ -796,6 +816,26 @@ exports[`Inventory data Network Network interfaces table A Apple agent should re + + + + + @@ -1149,6 +1189,26 @@ exports[`Inventory data Network Network interfaces table A Apple agent should re + + + + + @@ -1842,6 +1902,26 @@ exports[`Inventory data Network Network interfaces table A Linux agent should re + + + + + @@ -2247,6 +2327,26 @@ exports[`Inventory data Network Network interfaces table A Linux agent should re + + + + + @@ -2632,6 +2732,26 @@ exports[`Inventory data Network Network interfaces table A Linux agent should re + + + + + @@ -3325,6 +3445,26 @@ exports[`Inventory data Network Network interfaces table A Windows agent should + + + + + @@ -3730,6 +3870,26 @@ exports[`Inventory data Network Network interfaces table A Windows agent should + + + + + @@ -4107,6 +4267,26 @@ exports[`Inventory data Network Network interfaces table A Windows agent should + + + + + @@ -4800,6 +4980,26 @@ exports[`Inventory data Network Network ports table A Apple agent should render + + + + + @@ -5205,6 +5405,26 @@ exports[`Inventory data Network Network ports table A Apple agent should render + + + + + @@ -5558,6 +5778,26 @@ exports[`Inventory data Network Network ports table A Apple agent should render + + + + + @@ -6251,6 +6491,26 @@ exports[`Inventory data Network Network ports table A Linux agent should render + + + + + @@ -6656,6 +6916,26 @@ exports[`Inventory data Network Network ports table A Linux agent should render + + + + + @@ -7041,6 +7321,26 @@ exports[`Inventory data Network Network ports table A Linux agent should render + + + + + @@ -7734,6 +8034,26 @@ exports[`Inventory data Network Network ports table A Windows agent should rende + + + + + @@ -8139,6 +8459,26 @@ exports[`Inventory data Network Network ports table A Windows agent should rende + + + + + @@ -8516,6 +8856,26 @@ exports[`Inventory data Network Network ports table A Windows agent should rende + + + + + @@ -9209,6 +9569,26 @@ exports[`Inventory data Network Network settings table A Apple agent should rend + + + + + @@ -9614,6 +9994,26 @@ exports[`Inventory data Network Network settings table A Apple agent should rend + + + + + @@ -9967,6 +10367,26 @@ exports[`Inventory data Network Network settings table A Apple agent should rend + + + + + @@ -10660,6 +11080,26 @@ exports[`Inventory data Network Network settings table A Linux agent should rend + + + + + @@ -11065,6 +11505,26 @@ exports[`Inventory data Network Network settings table A Linux agent should rend + + + + + @@ -11450,6 +11910,26 @@ exports[`Inventory data Network Network settings table A Linux agent should rend + + + + + @@ -12143,6 +12623,26 @@ exports[`Inventory data Network Network settings table A Windows agent should re + + + + + @@ -12548,6 +13048,26 @@ exports[`Inventory data Network Network settings table A Windows agent should re + + + + + @@ -12925,6 +13445,26 @@ exports[`Inventory data Network Network settings table A Windows agent should re + + + + + @@ -13615,6 +14155,26 @@ exports[`Inventory data Processes A Apple agent should render processes table wi + + + + + @@ -14330,6 +14890,26 @@ exports[`Inventory data Processes A Linux agent should render processes table wi + + + + + @@ -15192,6 +15772,26 @@ exports[`Inventory data Processes A Windows agent should render processes table + + + + + @@ -15932,6 +16532,26 @@ exports[`Inventory data Software Packages table A Apple agent should render soft + + + + + @@ -16624,6 +17244,26 @@ exports[`Inventory data Software Packages table A Linux agent should render soft + + + + + @@ -17317,6 +17957,26 @@ exports[`Inventory data Software Packages table A Windows agent should render so + + + + + @@ -17626,6 +18286,26 @@ exports[`Inventory data Software Packages table A Windows agent should render so + + + + + @@ -18294,6 +18974,26 @@ exports[`Inventory data Software Windows updates table A Windows agent should re + + + + + @@ -18603,6 +19303,26 @@ exports[`Inventory data Software Windows updates table A Windows agent should re + + + + + diff --git a/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap b/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap index c2618c9bae..f7f1fd7f33 100644 --- a/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap +++ b/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap @@ -156,6 +156,26 @@ exports[`AgentsTable component Renders correctly to match the snapshot 1`] = ` + + +
@@ -825,6 +845,26 @@ exports[`AgentsTable component Renders correctly to match the snapshot with cust
+ + + + +
@@ -1452,6 +1492,26 @@ exports[`AgentsTable component Renders correctly to match the snapshot with no p
+ + + + +
From 6379576788488321b03001eae314514c018fd13d Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Mon, 2 Dec 2024 13:49:44 +0100 Subject: [PATCH 04/24] Update alert message --- plugins/main/public/components/common/tables/table-wz-api.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index c28764d814..3f67263cb5 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -240,7 +240,7 @@ export function TableWzAPI({ } /> Date: Thu, 5 Dec 2024 14:11:24 -0300 Subject: [PATCH 05/24] Add limit of 10000 rows --- plugins/main/server/controllers/wazuh-api.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/main/server/controllers/wazuh-api.ts b/plugins/main/server/controllers/wazuh-api.ts index 545e989e85..8486574eb0 100644 --- a/plugins/main/server/controllers/wazuh-api.ts +++ b/plugins/main/server/controllers/wazuh-api.ts @@ -783,7 +783,10 @@ export class WazuhApiCtrl { if (totalItems && !isList) { params.offset = 0; itemsArray.push(...output.data.data.affected_items); - while (itemsArray.length < totalItems && params.offset < totalItems) { + while ( + itemsArray.length < Math.min(totalItems, 10000) && + params.offset < Math.min(totalItems, 10000) + ) { params.offset += params.limit; const tmpData = await context.wazuh.api.client.asCurrentUser.request( 'GET', From 36e1a164aa82f6b53352eb28b3e18fb0c638073a Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 5 Dec 2024 14:11:34 -0300 Subject: [PATCH 06/24] Add warning message and sorting filter --- .../components/common/tables/table-wz-api.tsx | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index 3f67263cb5..ecf0b73e3f 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -78,7 +78,7 @@ export function TableWzAPI({ const [totalItems, setTotalItems] = useState(0); const [filters, setFilters] = useState({}); const [isLoading, setIsLoading] = useState(false); - + const [sort, setSort] = useState({ field: 'file', direction: 'asc' }); const onFiltersChange = filters => typeof rest.onFiltersChange === 'function' ? rest.onFiltersChange(filters) @@ -87,6 +87,9 @@ export function TableWzAPI({ const onDataChange = data => typeof rest.onDataChange === 'function' ? rest.onDataChange(data) : null; + const formatSorting = sorting => { + return `${sorting.direction === 'asc' ? '+' : '-'}${sorting.field}`; + }; /** * Changing the reloadFootprint timestamp will trigger reloading the table */ @@ -111,7 +114,7 @@ export function TableWzAPI({ ) { try { const { pageIndex, pageSize } = pagination; - const { field, direction } = sorting.sort; + setSort(sorting.sort); setIsLoading(true); setFilters(filters); onFiltersChange(filters); @@ -119,9 +122,8 @@ export function TableWzAPI({ ...getFilters(filters), offset: pageIndex * pageSize, limit: pageSize, - sort: `${direction === 'asc' ? '+' : '-'}${field}`, + sort: formatSorting(sorting.sort), }; - const response = await WzRequest.apiReq('GET', endpoint, { params }); const { affected_items: items, total_affected_items: totalItems } = ( @@ -232,19 +234,24 @@ export function TableWzAPI({ - + {totalItems > 10000 && ( + + )} )} {/* Render optional post custom action button */} From 91304dd443a1ff81a8ad2a85133677c36660951f Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 5 Dec 2024 14:15:34 -0300 Subject: [PATCH 07/24] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67d115dae8..56bb694f6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file. ### Added - Support for Wazuh 4.10.2 -- Added info message about too many files on FIM [#7182](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7182) +- Limited the amount of rows that can be exported in csv in FIM [#7182](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7182) ### Fixed From dd336ae858e56a434cbed5c93f4b4d87db15b3e3 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Fri, 6 Dec 2024 08:36:25 -0300 Subject: [PATCH 08/24] Add constant to set the limit --- plugins/main/common/constants.ts | 2 ++ .../main/public/components/common/tables/table-wz-api.tsx | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/main/common/constants.ts b/plugins/main/common/constants.ts index 4da147db02..6d2e6958c5 100644 --- a/plugins/main/common/constants.ts +++ b/plugins/main/common/constants.ts @@ -535,3 +535,5 @@ export enum FilterStateStore { APP_STATE = 'appState', GLOBAL_STATE = 'globalState', } + +export const TABLE_EXPORT_MAX_ROWS = 10000; diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index ecf0b73e3f..4df3e51917 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -28,6 +28,7 @@ import { TableDefault } from './table-default'; import { WzRequest } from '../../../react-services/wz-request'; import { ExportTableCsv } from './components/export-table-csv'; import { useStateStorage } from '../hooks'; +import { TABLE_EXPORT_MAX_ROWS } from '../../../../common/constants'; /** * Search input custom filter button @@ -244,9 +245,9 @@ export function TableWzAPI({ : rest.title } /> - {totalItems > 10000 && ( + {totalItems > TABLE_EXPORT_MAX_ROWS && ( Date: Fri, 6 Dec 2024 09:21:34 -0300 Subject: [PATCH 09/24] Add constant to server side --- plugins/main/server/controllers/wazuh-api.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/main/server/controllers/wazuh-api.ts b/plugins/main/server/controllers/wazuh-api.ts index 8486574eb0..c7bfd8825a 100644 --- a/plugins/main/server/controllers/wazuh-api.ts +++ b/plugins/main/server/controllers/wazuh-api.ts @@ -16,7 +16,10 @@ import { Parser } from 'json2csv'; import { KeyEquivalence } from '../../common/csv-key-equivalence'; import { ApiErrorEquivalence } from '../lib/api-errors-equivalence'; import apiRequestList from '../../common/api-info/endpoints'; -import { HTTP_STATUS_CODES } from '../../common/constants'; +import { + HTTP_STATUS_CODES, + TABLE_EXPORT_MAX_ROWS, +} from '../../common/constants'; import { addJobToQueue } from '../start/queue'; import jwtDecode from 'jwt-decode'; import { @@ -784,8 +787,8 @@ export class WazuhApiCtrl { params.offset = 0; itemsArray.push(...output.data.data.affected_items); while ( - itemsArray.length < Math.min(totalItems, 10000) && - params.offset < Math.min(totalItems, 10000) + itemsArray.length < Math.min(totalItems, TABLE_EXPORT_MAX_ROWS) && + params.offset < Math.min(totalItems, TABLE_EXPORT_MAX_ROWS) ) { params.offset += params.limit; const tmpData = await context.wazuh.api.client.asCurrentUser.request( From 44e294887e1f7ed62561bd84f527a24554d27996 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 9 Dec 2024 14:18:12 -0300 Subject: [PATCH 10/24] Remove duplicated SVG elements in inventory and agents table snapshots for cleaner tests --- .../__snapshots__/inventory.test.tsx.snap | 720 ------------------ .../__snapshots__/agents-table.test.tsx.snap | 60 -- 2 files changed, 780 deletions(-) diff --git a/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap b/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap index 120a756b34..21933a7df0 100644 --- a/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap +++ b/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap @@ -391,26 +391,6 @@ exports[`Inventory data Network Network interfaces table A Apple agent should re
- - - - - @@ -816,26 +796,6 @@ exports[`Inventory data Network Network interfaces table A Apple agent should re - - - - - @@ -1189,26 +1149,6 @@ exports[`Inventory data Network Network interfaces table A Apple agent should re - - - - - @@ -1902,26 +1842,6 @@ exports[`Inventory data Network Network interfaces table A Linux agent should re - - - - - @@ -2327,26 +2247,6 @@ exports[`Inventory data Network Network interfaces table A Linux agent should re - - - - - @@ -2732,26 +2632,6 @@ exports[`Inventory data Network Network interfaces table A Linux agent should re - - - - - @@ -3445,26 +3325,6 @@ exports[`Inventory data Network Network interfaces table A Windows agent should - - - - - @@ -3870,26 +3730,6 @@ exports[`Inventory data Network Network interfaces table A Windows agent should - - - - - @@ -4267,26 +4107,6 @@ exports[`Inventory data Network Network interfaces table A Windows agent should - - - - - @@ -4980,26 +4800,6 @@ exports[`Inventory data Network Network ports table A Apple agent should render - - - - - @@ -5405,26 +5205,6 @@ exports[`Inventory data Network Network ports table A Apple agent should render - - - - - @@ -5778,26 +5558,6 @@ exports[`Inventory data Network Network ports table A Apple agent should render - - - - - @@ -6491,26 +6251,6 @@ exports[`Inventory data Network Network ports table A Linux agent should render - - - - - @@ -6916,26 +6656,6 @@ exports[`Inventory data Network Network ports table A Linux agent should render - - - - - @@ -7321,26 +7041,6 @@ exports[`Inventory data Network Network ports table A Linux agent should render - - - - - @@ -8034,26 +7734,6 @@ exports[`Inventory data Network Network ports table A Windows agent should rende - - - - - @@ -8459,26 +8139,6 @@ exports[`Inventory data Network Network ports table A Windows agent should rende - - - - - @@ -8856,26 +8516,6 @@ exports[`Inventory data Network Network ports table A Windows agent should rende - - - - - @@ -9569,26 +9209,6 @@ exports[`Inventory data Network Network settings table A Apple agent should rend - - - - - @@ -9994,26 +9614,6 @@ exports[`Inventory data Network Network settings table A Apple agent should rend - - - - - @@ -10367,26 +9967,6 @@ exports[`Inventory data Network Network settings table A Apple agent should rend - - - - - @@ -11080,26 +10660,6 @@ exports[`Inventory data Network Network settings table A Linux agent should rend - - - - - @@ -11505,26 +11065,6 @@ exports[`Inventory data Network Network settings table A Linux agent should rend - - - - - @@ -11910,26 +11450,6 @@ exports[`Inventory data Network Network settings table A Linux agent should rend - - - - - @@ -12623,26 +12143,6 @@ exports[`Inventory data Network Network settings table A Windows agent should re - - - - - @@ -13048,26 +12548,6 @@ exports[`Inventory data Network Network settings table A Windows agent should re - - - - - @@ -13445,26 +12925,6 @@ exports[`Inventory data Network Network settings table A Windows agent should re - - - - - @@ -14155,26 +13615,6 @@ exports[`Inventory data Processes A Apple agent should render processes table wi - - - - - @@ -14890,26 +14330,6 @@ exports[`Inventory data Processes A Linux agent should render processes table wi - - - - - @@ -15772,26 +15192,6 @@ exports[`Inventory data Processes A Windows agent should render processes table - - - - - @@ -16532,26 +15932,6 @@ exports[`Inventory data Software Packages table A Apple agent should render soft - - - - - @@ -17244,26 +16624,6 @@ exports[`Inventory data Software Packages table A Linux agent should render soft - - - - - @@ -17957,26 +17317,6 @@ exports[`Inventory data Software Packages table A Windows agent should render so - - - - - @@ -18286,26 +17626,6 @@ exports[`Inventory data Software Packages table A Windows agent should render so - - - - - @@ -18974,26 +18294,6 @@ exports[`Inventory data Software Windows updates table A Windows agent should re - - - - - @@ -19303,26 +18603,6 @@ exports[`Inventory data Software Windows updates table A Windows agent should re - - - - - diff --git a/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap b/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap index f7f1fd7f33..c2618c9bae 100644 --- a/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap +++ b/plugins/main/public/components/endpoints-summary/table/__snapshots__/agents-table.test.tsx.snap @@ -156,26 +156,6 @@ exports[`AgentsTable component Renders correctly to match the snapshot 1`] = ` - - -
@@ -845,26 +825,6 @@ exports[`AgentsTable component Renders correctly to match the snapshot with cust
- - - - -
@@ -1492,26 +1452,6 @@ exports[`AgentsTable component Renders correctly to match the snapshot with no p
- - - - -
From 0d603d71681756aa590bcfc557ab1682c2104883 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Tue, 10 Dec 2024 12:58:13 -0300 Subject: [PATCH 11/24] Add constant to wazuh-core --- plugins/wazuh-core/common/constants.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/wazuh-core/common/constants.ts b/plugins/wazuh-core/common/constants.ts index 3b51f2e9bf..42e22204f9 100644 --- a/plugins/wazuh-core/common/constants.ts +++ b/plugins/wazuh-core/common/constants.ts @@ -2193,3 +2193,5 @@ export const WAZUH_ROLE_ADMINISTRATOR_ID = 1; // ID used to refer the createOsdUrlStateStorage state export const OSD_URL_STATE_STORAGE_ID = 'state:storeInSessionStorage'; + +export const TABLE_EXPORT_MAX_ROWS = 10000; From e0bd7b1351c0ec6f9dced1053b1f5d343c40acbb Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Wed, 11 Dec 2024 10:25:13 -0300 Subject: [PATCH 12/24] Fix sort state --- .../main/public/components/common/tables/table-wz-api.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index 4df3e51917..fb6332f9b5 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -79,7 +79,7 @@ export function TableWzAPI({ const [totalItems, setTotalItems] = useState(0); const [filters, setFilters] = useState({}); const [isLoading, setIsLoading] = useState(false); - const [sort, setSort] = useState({ field: 'file', direction: 'asc' }); + const [sort, setSort] = useState({}); const onFiltersChange = filters => typeof rest.onFiltersChange === 'function' ? rest.onFiltersChange(filters) @@ -89,6 +89,9 @@ export function TableWzAPI({ typeof rest.onDataChange === 'function' ? rest.onDataChange(data) : null; const formatSorting = sorting => { + if (!sorting.field || !sorting.direction) { + return ''; + } return `${sorting.direction === 'asc' ? '+' : '-'}${sorting.field}`; }; /** From 41519781109f7a40021e4153cd09e90c626c2541 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 12 Dec 2024 11:29:19 -0300 Subject: [PATCH 13/24] Add option to set the max rows of csv reports --- plugins/wazuh-core/common/constants.ts | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugins/wazuh-core/common/constants.ts b/plugins/wazuh-core/common/constants.ts index 42e22204f9..d80a622d5b 100644 --- a/plugins/wazuh-core/common/constants.ts +++ b/plugins/wazuh-core/common/constants.ts @@ -1845,6 +1845,41 @@ hosts: return SettingsValidator.number(this.options.number)(value); }, }, + 'reports.csv.maxRows': { + title: 'Max rows in csv reports', + store: { + file: { + configurableManaged: true, + }, + }, + description: + 'Maximum rows that will be included in csv reports. If the number of rows exceeds this value, the report will be truncated. Setting a high value can cause instability of the report generating process.', + category: SettingCategory.GENERAL, + type: EpluginSettingType.number, + defaultValue: 10000, + isConfigurableFromSettings: true, + options: { + number: { + integer: true, + }, + }, + uiFormTransformConfigurationValueToInputValue: function (value: number) { + return String(value); + }, + uiFormTransformInputValueToConfigurationValue: function ( + value: string, + ): number { + return Number(value); + }, + validateUIForm: function (value) { + return this.validate( + this.uiFormTransformInputValueToConfigurationValue(value), + ); + }, + validate: function (value) { + return SettingsValidator.number(this.options.number)(value); + }, + }, 'wazuh.monitoring.creation': { title: 'Index creation', description: From 053c1be177c0b82342ff03c62737de30de2a38bb Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 12 Dec 2024 11:29:38 -0300 Subject: [PATCH 14/24] Add logic to read the max rows from configuration in frontend --- .../components/common/tables/table-wz-api.tsx | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index fb6332f9b5..dd8299b771 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -27,9 +27,7 @@ import { TableWithSearchBar } from './table-with-search-bar'; import { TableDefault } from './table-default'; import { WzRequest } from '../../../react-services/wz-request'; import { ExportTableCsv } from './components/export-table-csv'; -import { useStateStorage } from '../hooks'; -import { TABLE_EXPORT_MAX_ROWS } from '../../../../common/constants'; - +import { useStateStorage, useAppConfig } from '../hooks'; /** * Search input custom filter button */ @@ -39,11 +37,22 @@ interface CustomFilterButton { value: string; } -const getFilters = filters => { +interface Filters { + [key: string]: string; +} + +const getFilters = (filters: Filters) => { const { default: defaultFilters, ...restFilters } = filters; return Object.keys(restFilters).length ? restFilters : defaultFilters; }; +const formatSorting = sorting => { + if (!sorting.field || !sorting.direction) { + return ''; + } + return `${sorting.direction === 'asc' ? '+' : '-'}${sorting.field}`; +}; + export function TableWzAPI({ actionButtons, postActionButtons, @@ -55,12 +64,11 @@ export function TableWzAPI({ actionButtons?: | ReactNode | ReactNode[] - | (({ filters }: { filters }) => ReactNode); + | (({ filters }: { filters: Filters }) => ReactNode); postActionButtons?: | ReactNode | ReactNode[] - | (({ filters }: { filters }) => ReactNode); - + | (({ filters }: { filters: Filters }) => ReactNode); title?: string; addOnTitle?: ReactNode; description?: string; @@ -69,7 +77,7 @@ export function TableWzAPI({ searchTable?: boolean; endpoint: string; buttonOptions?: CustomFilterButton[]; - onFiltersChange?: Function; + onFiltersChange?: (filters: Filters) => void; showReload?: boolean; searchBarProps?: any; reload?: boolean; @@ -77,10 +85,10 @@ export function TableWzAPI({ setReload?: (newValue: number) => void; }) { const [totalItems, setTotalItems] = useState(0); - const [filters, setFilters] = useState({}); + const [filters, setFilters] = useState({}); const [isLoading, setIsLoading] = useState(false); const [sort, setSort] = useState({}); - const onFiltersChange = filters => + const onFiltersChange = (filters: Filters) => typeof rest.onFiltersChange === 'function' ? rest.onFiltersChange(filters) : null; @@ -88,12 +96,6 @@ export function TableWzAPI({ const onDataChange = data => typeof rest.onDataChange === 'function' ? rest.onDataChange(data) : null; - const formatSorting = sorting => { - if (!sorting.field || !sorting.direction) { - return ''; - } - return `${sorting.direction === 'asc' ? '+' : '-'}${sorting.field}`; - }; /** * Changing the reloadFootprint timestamp will trigger reloading the table */ @@ -109,10 +111,12 @@ export function TableWzAPI({ : undefined, ); const [isOpenFieldSelector, setIsOpenFieldSelector] = useState(false); + const appConfig = useAppConfig(); + const maxRows = appConfig.data['reports.csv.maxRows'] || 10000; const onSearch = useCallback(async function ( endpoint, - filters, + filters: Filters, pagination, sorting, ) { @@ -189,7 +193,9 @@ export function TableWzAPI({ }; useEffect(() => { - if (rest.reload) triggerReload(); + if (rest.reload) { + triggerReload(); + } }, [rest.reload]); const ReloadButton = ( @@ -248,9 +254,9 @@ export function TableWzAPI({ : rest.title } /> - {totalItems > TABLE_EXPORT_MAX_ROWS && ( + {totalItems > maxRows && ( App Settings`} size='m' color='warning' type='alert' From 4abe944166c8df02b838e4bd8f922506dbfbcf52 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 12 Dec 2024 11:30:40 -0300 Subject: [PATCH 15/24] Add logic to read rows limit from configuration in backend --- plugins/main/server/controllers/wazuh-api.ts | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/main/server/controllers/wazuh-api.ts b/plugins/main/server/controllers/wazuh-api.ts index c7bfd8825a..555f4b997b 100644 --- a/plugins/main/server/controllers/wazuh-api.ts +++ b/plugins/main/server/controllers/wazuh-api.ts @@ -16,10 +16,7 @@ import { Parser } from 'json2csv'; import { KeyEquivalence } from '../../common/csv-key-equivalence'; import { ApiErrorEquivalence } from '../lib/api-errors-equivalence'; import apiRequestList from '../../common/api-info/endpoints'; -import { - HTTP_STATUS_CODES, - TABLE_EXPORT_MAX_ROWS, -} from '../../common/constants'; +import { HTTP_STATUS_CODES } from '../../common/constants'; import { addJobToQueue } from '../start/queue'; import jwtDecode from 'jwt-decode'; import { @@ -737,6 +734,8 @@ export class WazuhApiCtrl { request: OpenSearchDashboardsRequest, response: OpenSearchDashboardsResponseFactory, ) { + const appConfig = await context.wazuh_core.configuration.get(); + const reportMaxRows = appConfig['reports.csv.maxRows'] || 10000; try { if (!request.body || !request.body.path) throw new Error('Field path is required'); @@ -785,19 +784,25 @@ export class WazuhApiCtrl { if (totalItems && !isList) { params.offset = 0; - itemsArray.push(...output.data.data.affected_items); while ( - itemsArray.length < Math.min(totalItems, TABLE_EXPORT_MAX_ROWS) && - params.offset < Math.min(totalItems, TABLE_EXPORT_MAX_ROWS) + itemsArray.length < Math.min(totalItems, reportMaxRows) && + params.offset < Math.min(totalItems, reportMaxRows) ) { - params.offset += params.limit; const tmpData = await context.wazuh.api.client.asCurrentUser.request( 'GET', `/${tmpPath}`, { params: params }, { apiHostID: request.body.id }, ); - itemsArray.push(...tmpData.data.data.affected_items); + + const affectedItems = tmpData.data.data.affected_items; + const remainingItems = reportMaxRows - itemsArray.length; + if (itemsArray.length + affectedItems.length > reportMaxRows) { + itemsArray.push(...affectedItems.slice(0, remainingItems)); + break; + } + itemsArray.push(...affectedItems); + params.offset += params.limit; } } From 89ee03f76896080be18998983fe1132938108658 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 12 Dec 2024 11:31:21 -0300 Subject: [PATCH 16/24] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3cee8f8c..6d8d7a74ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file. ### Added - Support for Wazuh 4.10.2 -- Limited the amount of rows that can be exported in csv in FIM [#7182](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7182) +- Add setting to limit the number of rows in csv reports [#7182](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7182) ### Changed From ee6729ac8c009cddf085ae2bddec16eda080061d Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 12 Dec 2024 11:32:23 -0300 Subject: [PATCH 17/24] Remove unused constants --- plugins/main/common/constants.ts | 2 -- plugins/wazuh-core/common/constants.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/main/common/constants.ts b/plugins/main/common/constants.ts index 6d2e6958c5..4da147db02 100644 --- a/plugins/main/common/constants.ts +++ b/plugins/main/common/constants.ts @@ -535,5 +535,3 @@ export enum FilterStateStore { APP_STATE = 'appState', GLOBAL_STATE = 'globalState', } - -export const TABLE_EXPORT_MAX_ROWS = 10000; diff --git a/plugins/wazuh-core/common/constants.ts b/plugins/wazuh-core/common/constants.ts index d80a622d5b..c9e10f7941 100644 --- a/plugins/wazuh-core/common/constants.ts +++ b/plugins/wazuh-core/common/constants.ts @@ -2228,5 +2228,3 @@ export const WAZUH_ROLE_ADMINISTRATOR_ID = 1; // ID used to refer the createOsdUrlStateStorage state export const OSD_URL_STATE_STORAGE_ID = 'state:storeInSessionStorage'; - -export const TABLE_EXPORT_MAX_ROWS = 10000; From 0b3c3d48d9584037e3b858301127b6910207ab74 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Thu, 12 Dec 2024 12:05:35 -0300 Subject: [PATCH 18/24] Update test --- .../components/common/tables/table-wz-api.test.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/main/public/components/common/tables/table-wz-api.test.tsx b/plugins/main/public/components/common/tables/table-wz-api.test.tsx index b6b98e5dde..00715188d1 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.test.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.test.tsx @@ -15,6 +15,12 @@ import React from 'react'; import { mount } from 'enzyme'; import { TableWzAPI } from './table-wz-api'; +import { useAppConfig, useStateStorage } from '../hooks'; + +jest.mock('../hooks', () => ({ + useAppConfig: jest.fn(), + useStateStorage: jest.fn(), +})); jest.mock('../../../kibana-services', () => ({ getHttp: () => ({ @@ -64,6 +70,13 @@ const columns = [ describe('Table WZ API component', () => { it('renders correctly to match the snapshot', () => { + (useAppConfig as jest.Mock).mockReturnValue({ + data: { + 'reports.csv.maxRows': 10000, + }, + }); + (useStateStorage as jest.Mock).mockReturnValue([[], jest.fn()]); + const wrapper = mount( Date: Thu, 12 Dec 2024 14:19:15 -0300 Subject: [PATCH 19/24] Update tests --- .../components/agents/syscollector/inventory.test.tsx | 10 ++++++++++ .../endpoints-summary/table/agents-table.test.tsx | 10 ++++++++++ .../overview/mitre/intelligence/intelligence.test.tsx | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/plugins/main/public/components/agents/syscollector/inventory.test.tsx b/plugins/main/public/components/agents/syscollector/inventory.test.tsx index b39238c7cc..95a08ff30e 100644 --- a/plugins/main/public/components/agents/syscollector/inventory.test.tsx +++ b/plugins/main/public/components/agents/syscollector/inventory.test.tsx @@ -4,6 +4,16 @@ import { SyscollectorInventory } from './inventory'; import { AgentTabs } from '../../endpoints-summary/agent/agent-tabs'; import { queryDataTestAttr } from '../../../../test/public/query-attr'; +jest.mock('../../common/hooks/use-app-config', () => ({ + useAppConfig: () => ({ + isReady: true, + isLoading: false, + data: { + 'reports.csv.maxRows': 10000, + }, + }), +})); + const TABLE_ID = '__table_7d62db31-1cd0-11ee-8e0c-33242698a3b9'; const SOFTWARE_PACKAGES = 'Packages'; const SOFTWARE_WINDOWS_UPDATES = 'Windows updates'; diff --git a/plugins/main/public/components/endpoints-summary/table/agents-table.test.tsx b/plugins/main/public/components/endpoints-summary/table/agents-table.test.tsx index fb164371c4..fa97f085b2 100644 --- a/plugins/main/public/components/endpoints-summary/table/agents-table.test.tsx +++ b/plugins/main/public/components/endpoints-summary/table/agents-table.test.tsx @@ -5,6 +5,16 @@ import { WzRequest } from '../../../react-services/wz-request'; import configureMockStore from 'redux-mock-store'; import { Provider } from 'react-redux'; +jest.mock('../../common/hooks/use-app-config', () => ({ + useAppConfig: () => ({ + isReady: true, + isLoading: false, + data: { + 'reports.csv.maxRows': 10000, + }, + }), +})); + const data = [ { id: '001', diff --git a/plugins/main/public/components/overview/mitre/intelligence/intelligence.test.tsx b/plugins/main/public/components/overview/mitre/intelligence/intelligence.test.tsx index 2f18e4262d..cabb0900ca 100644 --- a/plugins/main/public/components/overview/mitre/intelligence/intelligence.test.tsx +++ b/plugins/main/public/components/overview/mitre/intelligence/intelligence.test.tsx @@ -18,6 +18,15 @@ import { ModuleMitreAttackIntelligence } from './intelligence'; import configureMockStore from 'redux-mock-store'; import { Provider } from 'react-redux'; +jest.mock('../../../common/hooks/use-app-config', () => ({ + useAppConfig: () => ({ + isReady: true, + isLoading: false, + data: { + 'reports.csv.maxRows': 10000, + }, + }), +})); jest.mock( '../../../../../../../node_modules/@elastic/eui/lib/services/accessibility/html_id_generator', () => ({ From 5df89d1fd12aa9f6fd668e46efcecd7974b58fd1 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Fri, 13 Dec 2024 08:38:28 -0300 Subject: [PATCH 20/24] Remove unnecessary values --- plugins/main/public/components/common/tables/table-wz-api.tsx | 4 ++-- plugins/main/server/controllers/wazuh-api.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index dd8299b771..55c7cd297d 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -112,8 +112,8 @@ export function TableWzAPI({ ); const [isOpenFieldSelector, setIsOpenFieldSelector] = useState(false); const appConfig = useAppConfig(); - - const maxRows = appConfig.data['reports.csv.maxRows'] || 10000; + console.log(rest.tableColumns); + const maxRows = appConfig.data['reports.csv.maxRows']; const onSearch = useCallback(async function ( endpoint, filters: Filters, diff --git a/plugins/main/server/controllers/wazuh-api.ts b/plugins/main/server/controllers/wazuh-api.ts index 555f4b997b..c9992303c1 100644 --- a/plugins/main/server/controllers/wazuh-api.ts +++ b/plugins/main/server/controllers/wazuh-api.ts @@ -735,7 +735,7 @@ export class WazuhApiCtrl { response: OpenSearchDashboardsResponseFactory, ) { const appConfig = await context.wazuh_core.configuration.get(); - const reportMaxRows = appConfig['reports.csv.maxRows'] || 10000; + const reportMaxRows = appConfig['reports.csv.maxRows']; try { if (!request.body || !request.body.path) throw new Error('Field path is required'); @@ -797,6 +797,7 @@ export class WazuhApiCtrl { const affectedItems = tmpData.data.data.affected_items; const remainingItems = reportMaxRows - itemsArray.length; + console.log(affectedItems[0]); if (itemsArray.length + affectedItems.length > reportMaxRows) { itemsArray.push(...affectedItems.slice(0, remainingItems)); break; From 249ca5f8a02336c1b9cecb40416f6a5fe6b81f65 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Fri, 13 Dec 2024 09:12:08 -0300 Subject: [PATCH 21/24] Remove console logs --- plugins/main/public/components/common/tables/table-wz-api.tsx | 1 - plugins/main/server/controllers/wazuh-api.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index 55c7cd297d..ebc4358732 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -112,7 +112,6 @@ export function TableWzAPI({ ); const [isOpenFieldSelector, setIsOpenFieldSelector] = useState(false); const appConfig = useAppConfig(); - console.log(rest.tableColumns); const maxRows = appConfig.data['reports.csv.maxRows']; const onSearch = useCallback(async function ( endpoint, diff --git a/plugins/main/server/controllers/wazuh-api.ts b/plugins/main/server/controllers/wazuh-api.ts index c9992303c1..f215852177 100644 --- a/plugins/main/server/controllers/wazuh-api.ts +++ b/plugins/main/server/controllers/wazuh-api.ts @@ -797,7 +797,6 @@ export class WazuhApiCtrl { const affectedItems = tmpData.data.data.affected_items; const remainingItems = reportMaxRows - itemsArray.length; - console.log(affectedItems[0]); if (itemsArray.length + affectedItems.length > reportMaxRows) { itemsArray.push(...affectedItems.slice(0, remainingItems)); break; From bd7f5e0e7cb60f9a5131ed1c0f2ba7fa50f7b06d Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Fri, 13 Dec 2024 11:35:08 -0300 Subject: [PATCH 22/24] Replace icon --- plugins/main/public/components/common/tables/table-wz-api.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index ebc4358732..c1a2aa62f5 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -257,8 +257,8 @@ export function TableWzAPI({ App Settings`} size='m' - color='warning' - type='alert' + color='primary' + type='iInCircle' /> )} From be67522f26c3380ae72af57cde3cbc633a017449 Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Fri, 13 Dec 2024 12:10:16 -0300 Subject: [PATCH 23/24] Fix spacing at button sides --- .../common/tables/components/export-table-csv.tsx | 15 +++++++++++---- .../components/common/tables/table-wz-api.tsx | 11 ++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/main/public/components/common/tables/components/export-table-csv.tsx b/plugins/main/public/components/common/tables/components/export-table-csv.tsx index d4bc30b2dc..b31253c295 100644 --- a/plugins/main/public/components/common/tables/components/export-table-csv.tsx +++ b/plugins/main/public/components/common/tables/components/export-table-csv.tsx @@ -13,7 +13,8 @@ import React from 'react'; import { EuiFlexItem, - EuiButtonEmpty + EuiButtonEmpty, + EuiIconTip } from '@elastic/eui'; import exportCsv from '../../../../react-services/wz-csv'; import { getToasts } from '../../../../kibana-services'; @@ -21,7 +22,7 @@ import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrat import { UI_LOGGER_LEVELS } from '../../../../../common/constants'; import { getErrorOrchestrator } from '../../../../react-services/common-services'; -export function ExportTableCsv({ endpoint, totalItems, filters, title }) { +export function ExportTableCsv({ endpoint, totalItems, filters, title, maxRows }) { const showToast = (color, title, time) => { getToasts().add({ @@ -56,10 +57,16 @@ export function ExportTableCsv({ endpoint, totalItems, filters, title }) { getErrorOrchestrator().handleError(options); } } - + return downloadCsv()}> Export formatted + {totalItems > maxRows&&<> App Settings`} + size='m' + color='primary' + type='iInCircle' + />} } @@ -70,4 +77,4 @@ ExportTableCsv.defaultProps = { totalItems:0, filters: [], title:"" - }; \ No newline at end of file + }; diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index c1a2aa62f5..6746b0bc3b 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -21,7 +21,6 @@ import { EuiToolTip, EuiIcon, EuiCheckboxGroup, - EuiIconTip, } from '@elastic/eui'; import { TableWithSearchBar } from './table-with-search-bar'; import { TableDefault } from './table-default'; @@ -252,15 +251,9 @@ export function TableWzAPI({ ? rest.downloadCsv : rest.title } + maxRows={maxRows} /> - {totalItems > maxRows && ( - App Settings`} - size='m' - color='primary' - type='iInCircle' - /> - )} + )} {/* Render optional post custom action button */} From dd28d16651a90e42723df90f6209bb23859e063d Mon Sep 17 00:00:00 2001 From: Nicolas Agustin Guevara Pihen Date: Fri, 13 Dec 2024 14:55:34 -0300 Subject: [PATCH 24/24] Fix formatting --- .../tables/components/export-table-csv.tsx | 73 +++++++++++-------- .../components/common/tables/table-wz-api.tsx | 1 - 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/plugins/main/public/components/common/tables/components/export-table-csv.tsx b/plugins/main/public/components/common/tables/components/export-table-csv.tsx index b31253c295..1ec3e500f5 100644 --- a/plugins/main/public/components/common/tables/components/export-table-csv.tsx +++ b/plugins/main/public/components/common/tables/components/export-table-csv.tsx @@ -11,19 +11,20 @@ */ import React from 'react'; -import { - EuiFlexItem, - EuiButtonEmpty, - EuiIconTip -} from '@elastic/eui'; +import { EuiFlexItem, EuiButtonEmpty, EuiIconTip } from '@elastic/eui'; import exportCsv from '../../../../react-services/wz-csv'; -import { getToasts } from '../../../../kibana-services'; +import { getToasts } from '../../../../kibana-services'; import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types'; import { UI_LOGGER_LEVELS } from '../../../../../common/constants'; import { getErrorOrchestrator } from '../../../../react-services/common-services'; -export function ExportTableCsv({ endpoint, totalItems, filters, title, maxRows }) { - +export function ExportTableCsv({ + endpoint, + totalItems, + filters, + title, + maxRows, +}) { const showToast = (color, title, time) => { getToasts().add({ color: color, @@ -34,15 +35,12 @@ export function ExportTableCsv({ endpoint, totalItems, filters, title, maxRows } const downloadCsv = async () => { try { - const formatedFilters = Object.entries(filters).map(([name, value]) => ({name, value})); + const formatedFilters = Object.entries(filters).map(([name, value]) => ({ + name, + value, + })); showToast('success', 'Your download should begin automatically...', 3000); - await exportCsv( - endpoint, - [ - ...formatedFilters - ], - `${(title).toLowerCase()}` - ); + await exportCsv(endpoint, [...formatedFilters], `${title.toLowerCase()}`); } catch (error) { const options = { context: `${ExportTableCsv.name}.downloadCsv`, @@ -56,25 +54,36 @@ export function ExportTableCsv({ endpoint, totalItems, filters, title, maxRows } }; getErrorOrchestrator().handleError(options); } - } + }; - return - downloadCsv()}> - Export formatted - {totalItems > maxRows&&<> App Settings`} - size='m' - color='primary' - type='iInCircle' - />} - + return ( + + downloadCsv()} + > + Export formatted + {totalItems > maxRows && ( + <> + {' '} + App Settings`} + size='m' + color='primary' + type='iInCircle' + /> + + )} + + ); } // Set default props ExportTableCsv.defaultProps = { - endpoint:'/', - totalItems:0, - filters: [], - title:"" - }; + endpoint: '/', + totalItems: 0, + filters: [], + title: '', +}; diff --git a/plugins/main/public/components/common/tables/table-wz-api.tsx b/plugins/main/public/components/common/tables/table-wz-api.tsx index 6746b0bc3b..f40e81b955 100644 --- a/plugins/main/public/components/common/tables/table-wz-api.tsx +++ b/plugins/main/public/components/common/tables/table-wz-api.tsx @@ -253,7 +253,6 @@ export function TableWzAPI({ } maxRows={maxRows} /> - )} {/* Render optional post custom action button */}