Skip to content

Commit

Permalink
Findings iter (elastic#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
orouz authored Jan 4, 2022
1 parent 317b17e commit 017e7e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const getResultCards = ({ result, agent, host, ...rest }: CspFinding): Card[] =>
['Evidence', <EuiCode>{JSON.stringify(result.evidence, null, 2)}</EuiCode>],
['Timestamp', rest['@timestamp']],
result.evaluation === 'failed' && ['Remediation', rest.rule.remediation],
].filter(Boolean) as Card['listItems'], // TODO: is a type guard,
].filter(Boolean) as Card['listItems'],
},
{
title: 'Agent',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';
import React, { useEffect } from 'react';
import type { Query } from '@kbn/es-query';
import type { Filter } from '@kbn/es-query';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
Expand All @@ -13,6 +13,7 @@ import type { DataView, TimeRange } from '../../../../../../src/plugins/data/com
import type { FindingsFetchState } from './types';
import type { CspPluginSetup } from '../../types';
import type { URLState } from './findings_container';
import { PLUGIN_NAME } from '../../../common';

interface BaseFindingsSearchBarProps {
dataView: DataView;
Expand All @@ -34,19 +35,33 @@ export const FindingsSearchBar = ({
}: FindingsSearchBarProps) => {
const {
data: {
query: queryService,
ui: { SearchBar },
},
} = useKibana<CspPluginSetup>().services;

useEffect(() => {
const subscription = queryService.filterManager.getUpdates$().subscribe(() =>
// TODO: add a condition to check if component is mounted
setSource({
filters: queryService.filterManager.getFilters(),
query,
dateRange,
})
);

return () => subscription.unsubscribe();
}, [dateRange, query, queryService.filterManager, setSource]);

return (
<SearchBar
appName="" // TODO: remove
appName={PLUGIN_NAME}
dataTestSubj={TEST_SUBJECTS.FINDINGS_SEARCH_BAR}
showFilterBar={true}
showDatePicker={true}
showQueryBar={true}
showQueryInput={true}
showSaveQuery={true}
showSaveQuery={false}
isLoading={status === 'loading'}
indexPatterns={[dataView]}
dateRangeFrom={dateRange?.from}
Expand All @@ -60,16 +75,6 @@ export const FindingsSearchBar = ({
...v,
})
}
// 'onFiltersUpdated' is not on StatefulSearchBarProps
// TODO: use SearchBar by import and not via props?
// @ts-ignore
onFiltersUpdated={(v) =>
setSource({
filters: v,
query,
dateRange,
})
}
onQuerySubmit={(v) =>
setSource({
...v,
Expand Down

0 comments on commit 017e7e7

Please sign in to comment.