Skip to content

Commit

Permalink
fix: unify message related to error fetching data of data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Desvelao committed Jun 27, 2024
1 parent afe01f2 commit ff58355
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const WazuhDiscoverComponent = (props: WazuhDiscoverProps) => {
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching vulnerabilities',
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
Expand Down Expand Up @@ -198,15 +198,15 @@ const WazuhDiscoverComponent = (props: WazuhDiscoverProps) => {
{isDataSourceLoading ? (
<LoadingSpinner />
) : (
<WzSearchBar
appName='wazuh-discover-search-bar'
{...searchBarProps}
fixedFilters={fixedFilters}
showQueryInput={true}
showQueryBar={true}
showSaveQuery={true}
/>
)}
<WzSearchBar
appName='wazuh-discover-search-bar'
{...searchBarProps}
fixedFilters={fixedFilters}
showQueryInput={true}
showQueryBar={true}
showSaveQuery={true}
/>
)}
{!isDataSourceLoading && results?.hits?.total === 0 ? (
<DiscoverNoResults timeFieldName={timeField} queryLanguage={''} />
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const WazuhFlyoutDiscoverComponent = (props: WazuhDiscoverProps) => {
.catch((error: HttpError) => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching discover data',
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const DashboardCT: React.FC<DashboardCTProps> = ({ statusRunning }) => {
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching vulnerabilities',
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
Expand Down Expand Up @@ -168,26 +168,26 @@ const DashboardCT: React.FC<DashboardCTProps> = ({ statusRunning }) => {
) : null}
<EuiSpacer size='m' />
{!isDataSourceLoading &&
dataSource &&
!state.showConfig &&
!state.showNodes ? (
<OverviewCards
goNodes={goNodes}
goAgents={goAgents}
goConfiguration={goConfiguration}
status={statusRunning}
configuration={state?.configuration}
version={state?.version}
nodesCount={state?.nodesCount}
nodeList={state?.nodeList}
clusterName={state.configuration?.name}
agentsCount={state?.agentsCount}
searchBarProps={searchBarProps}
results={results}
indexPattern={dataSource?.indexPattern}
filters={fetchFilters ?? []}
/>
) : null}
dataSource &&
!state.showConfig &&
!state.showNodes ? (
<OverviewCards
goNodes={goNodes}
goAgents={goAgents}
goConfiguration={goConfiguration}
status={statusRunning}
configuration={state?.configuration}
version={state?.version}
nodesCount={state?.nodesCount}
nodeList={state?.nodeList}
clusterName={state.configuration?.name}
agentsCount={state?.agentsCount}
searchBarProps={searchBarProps}
results={results}
indexPattern={dataSource?.indexPattern}
filters={fetchFilters ?? []}
/>
) : null}
{state.showConfig ? (
<ConfigurationCards
goBack={goBack}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const DashboardGDPRComponent: React.FC = () => {
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching alerts',
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
Expand All @@ -102,15 +102,15 @@ const DashboardGDPRComponent: React.FC = () => {
{isDataSourceLoading && !dataSource ? (
<LoadingSpinner />
) : (
<WzSearchBar
appName='gdpr-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
/>
)}
<WzSearchBar
appName='gdpr-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
/>
)}
{dataSource && results?.hits?.total === 0 ? (
<DiscoverNoResults />
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const DashboardGitHubComponent: React.FC = () => {
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching alerts',
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
Expand All @@ -102,22 +102,23 @@ const DashboardGitHubComponent: React.FC = () => {
{isDataSourceLoading && !dataSource ? (
<LoadingSpinner />
) : (
<WzSearchBar
appName='github-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
/>
)}
<WzSearchBar
appName='github-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
/>
)}
{dataSource && results?.hits?.total === 0 ? (
<DiscoverNoResults />
) : null}
{dataSource && results?.hits?.total > 0 ? (
<div
className={`github-dashboard-responsive ${dataSource && results?.hits?.total > 0 ? '' : 'wz-no-display'
}`}
className={`github-dashboard-responsive ${
dataSource && results?.hits?.total > 0 ? '' : 'wz-no-display'
}`}
>
<SampleDataWarning />
<DashboardByRenderer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,82 @@
import React, { useState, useEffect } from 'react';
import { EuiFlexItem } from '@elastic/eui';
import { ModuleConfigProps } from './module-config';
import { ErrorFactory, HttpError, ErrorHandler } from '../../../../../react-services/error-management';
import {
ErrorFactory,
HttpError,
ErrorHandler,
} from '../../../../../react-services/error-management';
import WazuhDataGrid from '../../../../common/wazuh-data-grid/wz-data-grid';
import { tDataGridColumn } from '../../../../common/data-grid';

type tDrillDownDataGridProps = {
defaultTableColumns: tDataGridColumn[]
defaultTableColumns: tDataGridColumn[];
} & ModuleConfigProps;

export default function DrillDownDataGrid(props: tDrillDownDataGridProps) {
const [results, setResults] = useState<any>([]);
const [pagination, setPagination] = useState({
pageIndex: 0,
pageSize: 15,
pageSizeOptions: [15, 25, 50, 100],
})
const [sorting, setSorting] = useState<any[]>([]);
const [results, setResults] = useState<any>([]);
const [pagination, setPagination] = useState({
pageIndex: 0,
pageSize: 15,
pageSizeOptions: [15, 25, 50, 100],
});
const [sorting, setSorting] = useState<any[]>([]);

const {
fetchData,
searchBarProps,
indexPattern,
fetchFilters,
defaultTableColumns,
} = props;
const {
fetchData,
searchBarProps,
indexPattern,
fetchFilters,
defaultTableColumns,
} = props;

useEffect(() => {
if (!indexPattern) {
return;
}
fetchData({
query: searchBarProps.query,
filters: fetchFilters,
pagination,
sorting,
dateRange: {
from: searchBarProps.dateRangeFrom || '',
to: searchBarProps.dateRangeTo || '',
},
})
.then(results => {
setResults(results);
})
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching actions',
});
ErrorHandler.handleError(searchError);
});
}, [
JSON.stringify(fetchFilters),
JSON.stringify(searchBarProps.query),
JSON.stringify(pagination),
JSON.stringify(sorting),
searchBarProps.dateRangeFrom,
searchBarProps.dateRangeTo,
])
useEffect(() => {
if (!indexPattern) {
return;
}
fetchData({
query: searchBarProps.query,
filters: fetchFilters,
pagination,
sorting,
dateRange: {
from: searchBarProps.dateRangeFrom || '',
to: searchBarProps.dateRangeTo || '',
},
})
.then(results => {
setResults(results);
})
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
}, [
JSON.stringify(fetchFilters),
JSON.stringify(searchBarProps.query),
JSON.stringify(pagination),
JSON.stringify(sorting),
searchBarProps.dateRangeFrom,
searchBarProps.dateRangeTo,
]);

return (
<EuiFlexItem>
<WazuhDataGrid
results={results}
defaultColumns={defaultTableColumns}
indexPattern={indexPattern}
isLoading={false}
exportFilters={fetchFilters}
defaultPagination={pagination}
onChangePagination={(pagination) => setPagination(pagination)}
onChangeSorting={(sorting) => {
setSorting(sorting);
}}
/>
</EuiFlexItem>);
return (
<EuiFlexItem>
<WazuhDataGrid
results={results}
defaultColumns={defaultTableColumns}
indexPattern={indexPattern}
isLoading={false}
exportFilters={fetchFilters}
defaultPagination={pagination}
onChangePagination={pagination => setPagination(pagination)}
onChangeSorting={sorting => {
setSorting(sorting);
}}
/>
</EuiFlexItem>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const DashboardGoogleCloudComponent: React.FC = () => {
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching alerts',
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
Expand All @@ -100,16 +100,16 @@ const DashboardGoogleCloudComponent: React.FC = () => {
{isDataSourceLoading && !dataSource ? (
<LoadingSpinner />
) : (
<WzSearchBar
appName='google-cloud-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
showSaveQuery={true}
/>
)}
<WzSearchBar
appName='google-cloud-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
showSaveQuery={true}
/>
)}
{dataSource && results?.hits?.total === 0 ? (
<DiscoverNoResults />
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const DashboardHIPAAComponent: React.FC = () => {
.catch(error => {
const searchError = ErrorFactory.create(HttpError, {
error,
message: 'Error fetching alerts',
message: 'Error fetching data',
});
ErrorHandler.handleError(searchError);
});
Expand All @@ -102,15 +102,15 @@ const DashboardHIPAAComponent: React.FC = () => {
{isDataSourceLoading && !dataSource ? (
<LoadingSpinner />
) : (
<WzSearchBar
appName='hipaa-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
/>
)}
<WzSearchBar
appName='hipaa-searchbar'
{...searchBarProps}
fixedFilters={fixedFilters}
showDatePicker={true}
showQueryInput={true}
showQueryBar={true}
/>
)}
{dataSource && results?.hits?.total === 0 ? (
<DiscoverNoResults />
) : null}
Expand Down
Loading

0 comments on commit ff58355

Please sign in to comment.