{
hidePanelTitles: false,
}}
/>
- >
+
) : null}
>
diff --git a/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/vulnerability_detector_filters.scss b/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/vulnerability_detector_filters.scss
index 631158a73e..041fb3f19c 100644
--- a/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/vulnerability_detector_filters.scss
+++ b/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/vulnerability_detector_filters.scss
@@ -4,3 +4,10 @@
}
}
+.vulnerability-dashboard-responsive {
+ @media (max-width: 767px) {
+ .react-grid-layout {
+ height: auto !important;
+ }
+ }
+}
diff --git a/plugins/main/public/components/overview/vulnerabilities/data_grid/use_data_grid.ts b/plugins/main/public/components/overview/vulnerabilities/data_grid/use_data_grid.ts
deleted file mode 100644
index 86dacd8b5d..0000000000
--- a/plugins/main/public/components/overview/vulnerabilities/data_grid/use_data_grid.ts
+++ /dev/null
@@ -1,105 +0,0 @@
-import { EuiDataGridCellValueElementProps, EuiDataGridColumn, EuiDataGridProps, EuiDataGridSorting } from "@elastic/eui"
-import { useEffect, useMemo, useState, Fragment } from "react";
-import { SearchResponse } from "@opensearch-project/opensearch/api/types";
-import { IFieldType, IndexPattern } from "../../../../../../../src/plugins/data/common";
-import { parseData, getFieldValueFormatted } from '../dashboards/inventory/inventory_service';
-import { MAX_ENTRIES_PER_QUERY } from "../dashboards/inventory/config";
-
-type tDataGridProps = {
- indexPattern: IndexPattern;
- results: SearchResponse;
- defaultColumns: EuiDataGridColumn[];
- DocViewInspectButton: ({ rowIndex }: EuiDataGridCellValueElementProps) => React.JSX.Element
- ariaLabelledBy: string;
-};
-
-export const parseColumns = (fields: IFieldType[]): EuiDataGridColumn[] => {
- // remove _source field becuase is a object field and is not supported
- fields = fields.filter((field) => field.name !== '_source');
- return fields.map((field) => {
- return {
- ...field,
- id: field.name,
- display: field.name,
- schema: field.type,
- actions: {
- showHide: true,
- },
- };
- }) || [];
-}
-
-export const useDataGrid = (props: tDataGridProps): EuiDataGridProps => {
- const { indexPattern, DocViewInspectButton, results, defaultColumns } = props;
- /** Columns **/
- const [columns, setColumns] = useState
(defaultColumns);
- const [columnVisibility, setVisibility] = useState(() =>
- columns.map(({ id }) => id)
- );
- /** Rows */
- const [rows, setRows] = useState([]);
- const rowCount = results ? results?.hits?.total as number : 0;
- /** Sorting **/
- // get default sorting from default columns
- const getDefaultSorting = () => {
- const defaultSort = columns.find((column) => column.isSortable || column.defaultSortDirection);
- return defaultSort ? [{ id: defaultSort.id, direction: defaultSort.defaultSortDirection || 'desc' }] : [];
- }
- const defaultSorting: EuiDataGridSorting['columns'] = getDefaultSorting();
- const [sortingColumns, setSortingColumns] = useState(defaultSorting);
- const onSort = (sortingColumns) => {setSortingColumns(sortingColumns)};
- /** Pagination **/
- const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 20 });
- const onChangeItemsPerPage = useMemo(() => (pageSize) =>
- setPagination((pagination) => ({
- ...pagination,
- pageSize,
- pageIndex: 0,
- })), [rows, rowCount]);
- const onChangePage = (pageIndex) => setPagination((pagination) => ({ ...pagination, pageIndex }))
-
- useEffect(() => {
- setRows(results?.hits?.hits || [])
- }, [results, results?.hits, results?.hits?.total])
-
- useEffect(() => {
- setPagination((pagination) => ({ ...pagination, pageIndex: 0 }));
- }, [rowCount])
-
- const renderCellValue = ({ rowIndex, columnId, setCellProps }) => {
- const rowsParsed = parseData(rows);
- // On the context data always is stored the current page data (pagination)
- // then the rowIndex is relative to the current page
- const relativeRowIndex = rowIndex % pagination.pageSize;
- return rowsParsed.hasOwnProperty(relativeRowIndex)
- ? getFieldValueFormatted(relativeRowIndex, columnId, indexPattern, rowsParsed)
- : null;
- };
-
- const leadingControlColumns = useMemo(() => {
- return [
- {
- id: 'inspectCollapseColumn',
- headerCellRender: () => null,
- rowCellRender: (props) => DocViewInspectButton({ ...props, rowIndex: props.rowIndex % pagination.pageSize }),
- width: 40,
- },
- ];
- }, [results]);
-
- return {
- "aria-labelledby": props.ariaLabelledBy,
- columns: parseColumns(indexPattern?.fields || []),
- columnVisibility: { visibleColumns: columnVisibility, setVisibleColumns: setVisibility },
- renderCellValue: renderCellValue,
- leadingControlColumns: leadingControlColumns,
- rowCount: rowCount < MAX_ENTRIES_PER_QUERY ? rowCount : MAX_ENTRIES_PER_QUERY,
- sorting: { columns: sortingColumns, onSort },
- pagination: {
- ...pagination,
- pageSizeOptions: [20, 50, 100],
- onChangeItemsPerPage: onChangeItemsPerPage,
- onChangePage: onChangePage,
- }
- }
-}
\ No newline at end of file
diff --git a/plugins/main/public/components/overview/vulnerabilities/doc_viewer/doc_viewer.tsx b/plugins/main/public/components/overview/vulnerabilities/doc_viewer/doc_viewer.tsx
deleted file mode 100644
index 08e170f9d5..0000000000
--- a/plugins/main/public/components/overview/vulnerabilities/doc_viewer/doc_viewer.tsx
+++ /dev/null
@@ -1,150 +0,0 @@
-import React, { useState } from 'react';
-import classNames from 'classnames';
-import { escapeRegExp } from 'lodash';
-import { i18n } from '@osd/i18n';
-import { FieldIcon } from '../../../../../../../src/plugins/opensearch_dashboards_react/public';
-import { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';
-
-const COLLAPSE_LINE_LENGTH = 350;
-const DOT_PREFIX_RE = /(.).+?\./g;
-
-export type tDocViewerProps = {
- flattened: any;
- formatted: any;
- mapping: any;
- indexPattern: any;
-}
-
-/**
- * Convert a dot.notated.string into a short
- * version (d.n.string)
- */
-export const shortenDottedString = (input: string) => input.replace(DOT_PREFIX_RE, '$1.');
-
-export function getFieldTypeName(type: string) {
- switch (type) {
- case 'boolean':
- return i18n.translate('discover.fieldNameIcons.booleanAriaLabel', {
- defaultMessage: 'Boolean field',
- });
- case 'conflict':
- return i18n.translate('discover.fieldNameIcons.conflictFieldAriaLabel', {
- defaultMessage: 'Conflicting field',
- });
- case 'date':
- return i18n.translate('discover.fieldNameIcons.dateFieldAriaLabel', {
- defaultMessage: 'Date field',
- });
- case 'geo_point':
- return i18n.translate('discover.fieldNameIcons.geoPointFieldAriaLabel', {
- defaultMessage: 'Geo point field',
- });
- case 'geo_shape':
- return i18n.translate('discover.fieldNameIcons.geoShapeFieldAriaLabel', {
- defaultMessage: 'Geo shape field',
- });
- case 'ip':
- return i18n.translate('discover.fieldNameIcons.ipAddressFieldAriaLabel', {
- defaultMessage: 'IP address field',
- });
- case 'murmur3':
- return i18n.translate('discover.fieldNameIcons.murmur3FieldAriaLabel', {
- defaultMessage: 'Murmur3 field',
- });
- case 'number':
- return i18n.translate('discover.fieldNameIcons.numberFieldAriaLabel', {
- defaultMessage: 'Number field',
- });
- case 'source':
- // Note that this type is currently not provided, type for _source is undefined
- return i18n.translate('discover.fieldNameIcons.sourceFieldAriaLabel', {
- defaultMessage: 'Source field',
- });
- case 'string':
- return i18n.translate('discover.fieldNameIcons.stringFieldAriaLabel', {
- defaultMessage: 'String field',
- });
- case 'nested':
- return i18n.translate('discover.fieldNameIcons.nestedFieldAriaLabel', {
- defaultMessage: 'Nested field',
- });
- default:
- return i18n.translate('discover.fieldNameIcons.unknownFieldAriaLabel', {
- defaultMessage: 'Unknown field',
- });
- }
-}
-
-const DocViewer = (props: tDocViewerProps) => {
- const [fieldRowOpen, setFieldRowOpen] = useState({} as Record);
- const { flattened, formatted, mapping, indexPattern } = props;
-
- return (<>
- {flattened && (
-
-
- {Object.keys(flattened)
- .sort()
- .map((field, index) => {
- const value = String(formatted[field]);
- const fieldMapping = mapping(field);
- const isCollapsible = value.length > COLLAPSE_LINE_LENGTH;
- const isCollapsed = isCollapsible && !fieldRowOpen[field];
- const valueClassName = classNames({
- // eslint-disable-next-line @typescript-eslint/naming-convention
- osdDocViewer__value: true,
- 'truncate-by-height': isCollapsible && isCollapsed,
- });
- const isNestedField =
- !indexPattern.fields.getByName(field) &&
- !!indexPattern.fields.getAll().find((patternField) => {
- // We only want to match a full path segment
- const nestedRootRegex = new RegExp(escapeRegExp(field) + '(\\.|$)');
- return nestedRootRegex.test(patternField.subType?.nested?.path ?? '');
- });
- const fieldType = isNestedField ? 'nested' : indexPattern.fields.getByName(field)?.type;
- const typeName = getFieldTypeName(String(fieldType));
- const displayName = field;
- const fieldIconProps = { fill: 'none', color: 'gray' }
- const scripted = Boolean(fieldMapping?.scripted)
-
- return (
-
-
-
-
-
-
-
-
- {displayName}
-
-
-
- |
-
-
- |
-
- );
- })}
-
-
- )}>)
-};
-
-export default DocViewer;
\ No newline at end of file
diff --git a/plugins/main/public/components/overview/vulnerabilities/doc_viewer/use_doc_viewer.ts b/plugins/main/public/components/overview/vulnerabilities/doc_viewer/use_doc_viewer.ts
deleted file mode 100644
index d38e58bc3a..0000000000
--- a/plugins/main/public/components/overview/vulnerabilities/doc_viewer/use_doc_viewer.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { tDocViewerProps } from "./doc_viewer"
-import { IndexPattern } from "../../../../../../../src/plugins/data/common";
-
-type tUseDocViewerInputs = {
- indexPattern: IndexPattern;
- doc: any;
-}
-
-export const useDocViewer = (props: tUseDocViewerInputs): tDocViewerProps => {
- const { indexPattern, doc } = props;
-
- if (!indexPattern || !doc) {
- return {
- flattened: {},
- formatted: {},
- indexPattern: undefined,
- mapping: undefined
- }
- }
-
- const mapping = indexPattern?.fields.getByName;
- return {
- flattened: indexPattern?.flattenHit(doc),
- formatted: indexPattern?.formatHit(doc, 'html'),
- indexPattern,
- mapping
- }
-}
\ No newline at end of file
diff --git a/plugins/main/public/components/overview/vulnerabilities/search_bar/index.ts b/plugins/main/public/components/overview/vulnerabilities/search_bar/index.ts
deleted file mode 100644
index 22509f1244..0000000000
--- a/plugins/main/public/components/overview/vulnerabilities/search_bar/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-// searchbar index
\ No newline at end of file
diff --git a/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.test.ts b/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.test.ts
deleted file mode 100644
index 8ec10959b9..0000000000
--- a/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.test.ts
+++ /dev/null
@@ -1,210 +0,0 @@
-import { renderHook } from '@testing-library/react-hooks';
-import '@testing-library/jest-dom/extend-expect';
-// osd dependencies
-import {
- Start,
- dataPluginMock,
-} from '../../../../../../../src/plugins/data/public/mocks';
-import {
- Filter,
- IndexPattern,
- Query,
- TimeRange,
-} from '../../../../../../../src/plugins/data/public';
-// wazuh plugin dependencies
-import useSearchBar from './use_search_bar_configuration';
-import { getDataPlugin } from '../../../../kibana-services';
-import * as timeFilterHook from '../../../common/hooks/use-time-filter';
-import * as queryManagerHook from '../../../common/hooks/use-query';
-
-/**
- * Mocking Data Plugin
- **/
-jest.mock('../../../../kibana-services', () => {
- return {
- getDataPlugin: jest.fn(),
- };
-});
-/* using osd mock utils */
-const mockDataPlugin = dataPluginMock.createStartContract();
-const mockedGetDataPlugin = getDataPlugin as jest.Mock;
-mockedGetDataPlugin.mockImplementation(
- () =>
- ({
- ...mockDataPlugin,
- ...{
- query: {
- ...mockDataPlugin.query,
- queryString: {
- ...mockDataPlugin.query.queryString,
- getUpdates$: jest.fn(() => ({
- subscribe: jest.fn(),
- unsubscribe: jest.fn(),
- })),
- },
- },
- },
- } as Start),
-);
-///////////////////////////////////////////////////////////
-
-const mockedDefaultIndexPatternData: Partial = {
- // used partial not avoid fill all the interface, it's only for testing purpose
- id: 'default-index-pattern',
- title: '',
-};
-
-describe('[hook] useSearchBarConfiguration', () => {
- beforeAll(() => {
- /***** mock use-time-filter hook *****/
- const spyUseTimeFilter = jest.spyOn(timeFilterHook, 'useTimeFilter');
- const mockTimeFilterResult: TimeRange = {
- from: 'now/d',
- to: 'now/d',
- };
- spyUseTimeFilter.mockImplementation(() => ({
- timeFilter: mockTimeFilterResult,
- setTimeFilter: jest.fn(),
- timeHistory: [],
- }));
- /***** mock use-time-filter hook *****/
- const spyUseQueryManager = jest.spyOn(queryManagerHook, 'useQueryManager');
- const mockQueryResult: Query = {
- language: 'kuery',
- query: '',
- };
- spyUseQueryManager.mockImplementation(() => [mockQueryResult, jest.fn()]);
- });
-
- it('should return default app index pattern when not receiving a default index pattern', async () => {
- jest
- .spyOn(mockDataPlugin.indexPatterns, 'getDefault')
- .mockResolvedValue(mockedDefaultIndexPatternData);
- jest
- .spyOn(mockDataPlugin.query.filterManager, 'getFilters')
- .mockReturnValue([]);
- const { result, waitForNextUpdate } = renderHook(() => useSearchBar({}));
- await waitForNextUpdate();
- expect(mockDataPlugin.indexPatterns.getDefault).toBeCalled();
- expect(result.current.searchBarProps.indexPatterns).toMatchObject([
- mockedDefaultIndexPatternData,
- ]);
- });
-
- it('should return the same index pattern when receiving a default index pattern', async () => {
- const exampleIndexPatternId = 'wazuh-index-pattern';
- const mockedIndexPatternData: Partial = {
- // used partial not avoid fill all the interface, it's only for testing purpose
- id: exampleIndexPatternId,
- title: '',
- };
- jest
- .spyOn(mockDataPlugin.indexPatterns, 'get')
- .mockResolvedValue(mockedIndexPatternData);
- const { result, waitForNextUpdate } = renderHook(() =>
- useSearchBar({
- defaultIndexPatternID: 'wazuh-index-pattern',
- }),
- );
- await waitForNextUpdate();
- expect(mockDataPlugin.indexPatterns.get).toBeCalledWith(
- exampleIndexPatternId,
- );
- expect(result.current.searchBarProps.indexPatterns).toMatchObject([
- mockedIndexPatternData,
- ]);
- });
-
- it('should show an ERROR message and get the default app index pattern when not found the index pattern data by the ID received', async () => {
- const INDEX_NOT_FOUND_ERROR = new Error('Index Pattern not found');
- jest.spyOn(mockDataPlugin.indexPatterns, 'get').mockImplementation(() => {
- throw INDEX_NOT_FOUND_ERROR;
- });
- jest
- .spyOn(mockDataPlugin.indexPatterns, 'getDefault')
- .mockResolvedValue(mockedDefaultIndexPatternData);
- jest
- .spyOn(mockDataPlugin.query.filterManager, 'getFilters')
- .mockReturnValue([]);
-
- // mocking console error to avoid logs in test and check if is called
- const mockedConsoleError = jest
- .spyOn(console, 'error')
- .mockImplementationOnce(() => {});
- const { result, waitForNextUpdate } = renderHook(() =>
- useSearchBar({
- defaultIndexPatternID: 'invalid-index-pattern-id',
- }),
- );
-
- await waitForNextUpdate();
- expect(mockDataPlugin.indexPatterns.getDefault).toBeCalled();
- expect(mockDataPlugin.indexPatterns.get).toBeCalledWith(
- 'invalid-index-pattern-id',
- );
- expect(result.current.searchBarProps.indexPatterns).toMatchObject([
- mockedDefaultIndexPatternData,
- ]);
- expect(mockedConsoleError).toBeCalledWith(INDEX_NOT_FOUND_ERROR);
- });
-
- it('should return the same filters and apply them to the filter manager when are received by props', async () => {
- const defaultFilters: Filter[] = [
- {
- query: 'something to filter',
- meta: {
- alias: 'filter-mocked',
- disabled: false,
- negate: true,
- },
- },
- ];
- jest
- .spyOn(mockDataPlugin.indexPatterns, 'getDefault')
- .mockResolvedValue(mockedDefaultIndexPatternData);
- jest
- .spyOn(mockDataPlugin.query.filterManager, 'getFilters')
- .mockReturnValue(defaultFilters);
- const { result, waitForNextUpdate } = renderHook(() =>
- useSearchBar({
- filters: defaultFilters,
- }),
- );
-
- await waitForNextUpdate();
-
- expect(result.current.searchBarProps.filters).toMatchObject(defaultFilters);
- expect(mockDataPlugin.query.filterManager.setFilters).toBeCalledWith(
- defaultFilters,
- );
- expect(mockDataPlugin.query.filterManager.getFilters).toBeCalled();
- });
-
- it('should return empty filters when the index pattern is NOT equal to the default app index pattern', async () => {
- const exampleIndexPatternId = 'wazuh-index-pattern';
- const mockedExampleIndexPatternData: Partial = {
- // used partial not avoid fill all the interface, it's only for testing purpose
- id: exampleIndexPatternId,
- title: '',
- };
- jest
- .spyOn(mockDataPlugin.indexPatterns, 'get')
- .mockResolvedValue(mockedExampleIndexPatternData);
- jest
- .spyOn(mockDataPlugin.indexPatterns, 'getDefault')
- .mockResolvedValue(mockedDefaultIndexPatternData);
- jest
- .spyOn(mockDataPlugin.query.filterManager, 'getFilters')
- .mockReturnValue([]);
- const { result, waitForNextUpdate } = renderHook(() =>
- useSearchBar({
- defaultIndexPatternID: exampleIndexPatternId,
- }),
- );
- await waitForNextUpdate();
- expect(result.current.searchBarProps.indexPatterns).toMatchObject([
- mockedExampleIndexPatternData,
- ]);
- expect(result.current.searchBarProps.filters).toStrictEqual([]);
- });
-});
diff --git a/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.tsx b/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.tsx
deleted file mode 100644
index 06e4bb7648..0000000000
--- a/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.tsx
+++ /dev/null
@@ -1,194 +0,0 @@
-import { useEffect, useState } from 'react';
-import {
- SearchBarProps,
- FilterManager,
- TimeRange,
- Query,
-} from '../../../../../../../src/plugins/data/public';
-import {
- Filter,
- IIndexPattern,
- IndexPatternsContract,
-} from '../../../../../../../src/plugins/data/public';
-import { getDataPlugin } from '../../../../kibana-services';
-
-import {
- useFilterManager,
- useQueryManager,
- useTimeFilter,
-} from '../../../common/hooks';
-import { AUTHORIZED_AGENTS } from '../../../../../common/constants';
-
-// Input - types
-type tUseSearchBarCustomInputs = {
- defaultIndexPatternID: IIndexPattern['id'];
- onFiltersUpdated?: (filters: Filter[]) => void;
- onQuerySubmitted?: (
- payload: { dateRange: TimeRange; query?: Query },
- isUpdate?: boolean,
- ) => void;
-};
-type tUseSearchBarProps = Partial & tUseSearchBarCustomInputs;
-
-// Output types
-type tUserSearchBarResponse = {
- searchBarProps: Partial;
-};
-
-/**
- * Hook used to compose the searchbar configuration props
- * @param props
- * @returns
- */
-const useSearchBarConfiguration = (
- props?: tUseSearchBarProps,
-): tUserSearchBarResponse => {
- // dependencies
- const SESSION_STORAGE_FILTERS_NAME = 'wazuh_persistent_searchbar_filters';
- const filterManager = useFilterManager().filterManager as FilterManager;
- const { filters } = useFilterManager();
- const [query, setQuery] = props?.query
- ? useState(props?.query)
- : useQueryManager();
- const { timeFilter, timeHistory, setTimeFilter } = useTimeFilter();
- // states
- const [isLoading, setIsLoading] = useState(false);
- const [indexPatternSelected, setIndexPatternSelected] =
- useState();
-
- useEffect(() => {
- if (filters && filters.length > 0) {
- sessionStorage.setItem(
- SESSION_STORAGE_FILTERS_NAME,
- JSON.stringify(filters),
- );
- }
- initSearchBar();
- /**
- * When the component is disassembled, the original filters that arrived
- * when the component was assembled are added.
- */
- return () => {
- const storagePreviousFilters = sessionStorage.getItem(
- SESSION_STORAGE_FILTERS_NAME,
- );
- if (storagePreviousFilters) {
- const previousFilters = JSON.parse(storagePreviousFilters);
- const cleanedFilters = cleanFilters(previousFilters);
- filterManager.setFilters(cleanedFilters);
- }
- };
- }, []);
-
- /**
- * Initialize the searchbar props with the corresponding index pattern and filters
- */
- const initSearchBar = async () => {
- setIsLoading(true);
- const indexPattern = await getIndexPattern(props?.defaultIndexPatternID);
- setIndexPatternSelected(indexPattern);
- const initialFilters = props?.filters ?? filters;
- filterManager.setFilters(initialFilters);
- setIsLoading(false);
- };
-
- /**
- * Return the index pattern data by ID.
- * If not receive a ID return the default index from the index pattern service
- * @returns
- */
- const getIndexPattern = async (indexPatternID?: string) => {
- const indexPatternService = getDataPlugin()
- .indexPatterns as IndexPatternsContract;
- if (indexPatternID) {
- try {
- return await indexPatternService.get(indexPatternID);
- } catch (error) {
- // when the index pattern id not exists will get the default
- console.error(error);
- return await indexPatternService.getDefault();
- }
- } else {
- return await indexPatternService.getDefault();
- }
- };
-
- /**
- * Return filters from filters manager.
- * Additionally solve the known issue with the auto loaded agent.id filters from the searchbar
- * and filters those filters that are not related to the default index pattern
- * @returns
- */
- const getFilters = () => {
- const originalFilters = filterManager ? filterManager.getFilters() : [];
- return originalFilters.filter(
- (filter: Filter) =>
- filter?.meta?.controlledBy !== AUTHORIZED_AGENTS && // remove auto loaded agent.id filters
- filter?.meta?.index === props?.defaultIndexPatternID,
- );
- };
-
- /**
- * Return cleaned filters.
- * Clean the known issue with the auto loaded agent.id filters from the searchbar
- * and filters those filters that are not related to the default index pattern
- * @param previousFilters
- * @returns
- */
- const cleanFilters = (previousFilters: Filter[]) => {
- return previousFilters.filter(
- (filter: Filter) =>
- filter?.meta?.controlledBy !== AUTHORIZED_AGENTS &&
- filter?.meta?.index !== props?.defaultIndexPatternID,
- );
- };
-
- /**
- * Search bar properties necessary to render and initialize the osd search bar component
- */
- const searchBarProps: Partial = {
- isLoading,
- ...(indexPatternSelected && { indexPatterns: [indexPatternSelected] }), // indexPattern cannot be empty or empty []
- filters: getFilters(),
- query,
- timeHistory,
- dateRangeFrom: timeFilter.from,
- dateRangeTo: timeFilter.to,
- onFiltersUpdated: (filters: Filter[]) => {
- const storagePreviousFilters = sessionStorage.getItem(
- SESSION_STORAGE_FILTERS_NAME,
- );
- /**
- * If there are persisted filters, it is necessary to add them when
- * updating the filters in the filterManager
- */
- if (storagePreviousFilters) {
- const previousFilters = JSON.parse(storagePreviousFilters);
- const cleanedFilters = cleanFilters(previousFilters);
- filterManager.setFilters([...cleanedFilters, ...filters]);
-
- props?.onFiltersUpdated &&
- props?.onFiltersUpdated([...cleanedFilters, ...filters]);
- } else {
- filterManager.setFilters(filters);
- props?.onFiltersUpdated && props?.onFiltersUpdated(filters);
- }
- },
- onQuerySubmit: (
- payload: { dateRange: TimeRange; query?: Query },
- _isUpdate?: boolean,
- ): void => {
- const { dateRange, query } = payload;
- // its necessary execute setter to apply query filters
- setTimeFilter(dateRange);
- setQuery(query);
- props?.onQuerySubmitted && props?.onQuerySubmitted(payload);
- },
- };
-
- return {
- searchBarProps,
- };
-};
-
-export default useSearchBarConfiguration;