Skip to content

Commit

Permalink
[Security Solution] Fixing ESQL Timeline tab content availability and…
Browse files Browse the repository at this point in the history
… variables naming (elastic#168421)

This PR revert the changes made
[here](elastic#168144) and changing the
variables naming in the code to avoid the future confusion

---------

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Michael Olorunnisola <[email protected]>
Co-authored-by: Jatin Kathuria <[email protected]>
  • Loading branch information
4 people authored Oct 12, 2023
1 parent f5caf78 commit 7f6b201
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ export const allowedExperimentalValues = Object.freeze({
* Enables experimental Entity Analytics HTTP endpoints
*/
riskScoringRoutesEnabled: true,
/*
*
* Enables Discover embedded within timeline
*
* */
discoverInTimeline: true,

/**
* disables ES|QL rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export enum TimelineTabs {
eql = 'eql',
session = 'session',
securityAssistant = 'securityAssistant',
discover = 'discover',
esql = 'esql',
}

/*
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/public/actions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export enum SecurityCellActionsTrigger {
ALERTS_COUNT = 'security-alertsCount-cellActions',
}

export enum DiscoverInTimelineTrigger {
export enum EsqlInTimelineTrigger {
HISTOGRAM_TRIGGER = 'security-discoverInTimeline-histogramTrigger',
}

export enum DiscoverInTimelineAction {
export enum EsqlInTimelineAction {
VIS_FILTER_ACTION = 'security-discoverInTimeline-visFilterAction',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createFilterAction } from '@kbn/unified-search-plugin/public';
import type { History } from 'history';
import type { SecurityAppStore } from '../../common/store';
import type { StartServices } from '../../types';
import { DiscoverInTimelineTrigger, DiscoverInTimelineAction } from '../constants';
import { EsqlInTimelineTrigger, EsqlInTimelineAction } from '../constants';

const createDiscoverHistogramCustomFilterAction = (
store: SecurityAppStore,
Expand All @@ -20,8 +20,8 @@ const createDiscoverHistogramCustomFilterAction = (
services.customDataService.query.filterManager,
services.customDataService.query.timefilter.timefilter,
services.theme,
DiscoverInTimelineAction.VIS_FILTER_ACTION,
DiscoverInTimelineAction.VIS_FILTER_ACTION
EsqlInTimelineAction.VIS_FILTER_ACTION,
EsqlInTimelineAction.VIS_FILTER_ACTION
);
services.uiActions.registerAction(histogramApplyFilter);

Expand All @@ -34,7 +34,7 @@ const createDiscoverHistogramCustomTrigger = (
services: StartServices
) => {
services.uiActions.registerTrigger({
id: DiscoverInTimelineTrigger.HISTOGRAM_TRIGGER,
id: EsqlInTimelineTrigger.HISTOGRAM_TRIGGER,
});
};

Expand All @@ -47,8 +47,5 @@ export const registerDiscoverHistogramActions = (

const histogramApplyFilter = createDiscoverHistogramCustomFilterAction(store, history, services);

services.uiActions.attachAction(
DiscoverInTimelineTrigger.HISTOGRAM_TRIGGER,
histogramApplyFilter.id
);
services.uiActions.attachAction(EsqlInTimelineTrigger.HISTOGRAM_TRIGGER, histogramApplyFilter.id);
};
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/public/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { CellAction, CellActionExecutionContext, CellActionFactory } from '@kbn/cell-actions';
import type { QueryOperator } from '../../common/types';
export { DiscoverInTimelineAction, DiscoverInTimelineTrigger } from './constants';
export { EsqlInTimelineTrigger, EsqlInTimelineAction } from './constants';
export interface AndFilter {
field: string;
value: string | string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
jest.mock('./api');
jest.mock('../../../../common/hooks/use_app_toasts');
jest.mock('../../../../common/components/user_privileges/endpoint/use_endpoint_privileges');
jest.mock('../../../../timelines/components/timeline/discover_tab_content');
jest.mock('../../../../timelines/components/timeline/esql_tab_content');

describe('useSignalIndex', () => {
let appToastsMock: jest.Mocked<ReturnType<typeof useAppToastsMock.create>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { MockDiscoverTabContent } from '../mocks/discover_tab_content';
import { MockEsqlTabContent } from '../mocks/esql_tab_content';

export const DiscoverTabContent = MockDiscoverTabContent;
export const EsqlTabContent = MockEsqlTabContent;

// eslint-disable-next-line import/no-default-export
export default DiscoverTabContent;
export default EsqlTabContent;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { CustomizationCallback } from '@kbn/discover-plugin/public';
import type { UnifiedHistogramContainerProps } from '@kbn/unified-histogram-plugin/public';
import { ACTION_GLOBAL_APPLY_FILTER } from '@kbn/unified-search-plugin/public';
import { useCallback } from 'react';
import { DiscoverInTimelineTrigger } from '../../../../../actions/constants';
import { EsqlInTimelineTrigger } from '../../../../../actions/constants';
import { useKibana } from '../../../../../common/lib/kibana';

export type WithPreventableEvent<T> = T & {
Expand Down Expand Up @@ -67,9 +67,7 @@ export const useHistogramCustomization = () => {
}

if (filters && filters.length > 0) {
const applyFilterTrigger = uiActions.getTrigger(
DiscoverInTimelineTrigger.HISTOGRAM_TRIGGER
);
const applyFilterTrigger = uiActions.getTrigger(EsqlInTimelineTrigger.HISTOGRAM_TRIGGER);

await applyFilterTrigger.exec({
filters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
*/

import type { CustomizationCallback } from '@kbn/discover-plugin/public';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useGetStatefulQueryBar } from '../use_get_stateful_query_bar';

export const useSearchBarCustomizations = () => {
const { CustomStatefulTopNavKqlQueryBar } = useGetStatefulQueryBar();
const isDiscoverInTimelineEnabled = useIsExperimentalFeatureEnabled('discoverInTimeline');

const setSearchBarCustomizations: CustomizationCallback = ({ customizations }) => {
customizations.set({
id: 'search_bar',
CustomSearchBar: CustomStatefulTopNavKqlQueryBar,
hideDataViewPicker: isDiscoverInTimelineEnabled,
hideDataViewPicker: true,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import React from 'react';
import { EmbeddedDiscoverContainer } from '../styles';

export function MockDiscoverTabContent() {
export function MockEsqlTabContent() {
return (
<EmbeddedDiscoverContainer data-test-subj="timeline-embedded-discover">
{'Mock Discover Tab Content'}
{'Mock ESQL Tab Content'}
</EmbeddedDiscoverContainer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { DiscoverInTimelineTrigger } from '../../../../../actions/constants';
export { MockDiscoverTabContent } from './discover_tab_content';
import { EsqlInTimelineTrigger } from '../../../../../actions/constants';
export { MockEsqlTabContent } from './esql_tab_content';

export const mockApplyFilterTrigger = {
exec: jest.fn().mockResolvedValue(undefined),
Expand All @@ -16,7 +16,7 @@ export const mockPreventDefault = jest.fn();

export const mockUIActionsGetTrigger = jest.fn().mockImplementation((triggerName: string) => {
switch (triggerName) {
case DiscoverInTimelineTrigger.HISTOGRAM_TRIGGER:
case EsqlInTimelineTrigger.HISTOGRAM_TRIGGER:
return mockApplyFilterTrigger;
default:
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { useDispatch } from 'react-redux';
import styled from 'styled-components';

import { FormattedMessage } from '@kbn/i18n-react';
import { useKibana } from '../../../../common/lib/kibana';
import { useAssistantTelemetry } from '../../../../assistant/use_assistant_telemetry';
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features';
import { useConversationStore } from '../../../../assistant/use_conversation_store';
import { useAssistantAvailability } from '../../../../assistant/use_assistant_availability';
import type { SessionViewConfig } from '../../../../../common/types';
Expand Down Expand Up @@ -88,6 +88,7 @@ const GraphTab = tabWithSuspense(lazy(() => import('../graph_tab_content')));
const NotesTab = tabWithSuspense(lazy(() => import('../notes_tab_content')));
const PinnedTab = tabWithSuspense(lazy(() => import('../pinned_tab_content')));
const SessionTab = tabWithSuspense(lazy(() => import('../session_tab_content')));
const EsqlTab = tabWithSuspense(lazy(() => import('../esql_tab_content')));
interface BasicTimelineTab {
renderCellValue: (props: CellValueElementProps) => React.ReactNode;
rowRenderers: RowRenderer[];
Expand Down Expand Up @@ -132,6 +133,7 @@ const ActiveTimelineTab = memo<ActiveTimelineTabProps>(
setConversationId,
showTimeline,
}) => {
const isEsqlSettingEnabled = useKibana().services.configSettings.ESQLEnabled;
const { hasAssistantPrivilege } = useAssistantAvailability();
const getTab = useCallback(
(tab: TimelineTabs) => {
Expand Down Expand Up @@ -179,6 +181,14 @@ const ActiveTimelineTab = memo<ActiveTimelineTabProps>(
timelineId={timelineId}
/>
</HideShowContainer>
{isEsqlSettingEnabled && (
<HideShowContainer
$isVisible={TimelineTabs.esql === activeTimelineTab}
data-test-subj={`timeline-tab-content-${TimelineTabs.esql}`}
>
<EsqlTab timelineId={timelineId} />
</HideShowContainer>
)}
<HideShowContainer
$isVisible={TimelineTabs.pinned === activeTimelineTab}
data-test-subj={`timeline-tab-content-${TimelineTabs.pinned}`}
Expand Down Expand Up @@ -275,7 +285,7 @@ const TabsContentComponent: React.FC<BasicTimelineTab> = ({
sessionViewConfig,
timelineDescription,
}) => {
const isDiscoverInTimelineEnabled = useIsExperimentalFeatureEnabled('discoverInTimeline');
const isEsqlSettingEnabled = useKibana().services.configSettings.ESQLEnabled;
const { hasAssistantPrivilege } = useAssistantAvailability();
const dispatch = useDispatch();
const getActiveTab = useMemo(() => getActiveTabSelector(), []);
Expand Down Expand Up @@ -360,13 +370,13 @@ const TabsContentComponent: React.FC<BasicTimelineTab> = ({
}
}, [activeTab, conversationId, reportAssistantInvoked, setActiveTab]);

const setDiscoverAsActiveTab = useCallback(() => {
const setEsqlAsActiveTab = useCallback(() => {
dispatch(
initializeTimelineSettings({
id: timelineId,
})
);
setActiveTab(TimelineTabs.discover);
setActiveTab(TimelineTabs.esql);
}, [setActiveTab, dispatch, timelineId]);

useEffect(() => {
Expand All @@ -389,13 +399,13 @@ const TabsContentComponent: React.FC<BasicTimelineTab> = ({
<span>{i18n.QUERY_TAB}</span>
{showTimeline && <TimelineEventsCountBadge />}
</StyledEuiTab>
{isDiscoverInTimelineEnabled && (
{isEsqlSettingEnabled && (
<StyledEuiTab
data-test-subj={`timelineTabs-${TimelineTabs.discover}`}
onClick={setDiscoverAsActiveTab}
isSelected={activeTab === TimelineTabs.discover}
data-test-subj={`timelineTabs-${TimelineTabs.esql}`}
onClick={setEsqlAsActiveTab}
isSelected={activeTab === TimelineTabs.esql}
disabled={false}
key={TimelineTabs.discover}
key={TimelineTabs.esql}
>
<span>{i18n.DISCOVER_ESQL_IN_TIMELINE_TAB}</span>
<StyledEuiBetaBadge
Expand Down
1 change: 0 additions & 1 deletion x-pack/test/security_solution_cypress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
`--xpack.securitySolution.enableExperimental=${JSON.stringify([
'alertDetailsPageEnabled',
'chartEmbeddablesEnabled',
'discoverInTimeline',
])}`,
// mock cloud to enable the guided onboarding tour in e2e tests
'--xpack.cloud.id=test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { waitForDiscoverGridToLoad } from '../../../../tasks/discover';
import { updateDateRangeInLocalDatePickers } from '../../../../tasks/date_picker';
import { login } from '../../../../tasks/login';
import { visitWithTimeRange } from '../../../../tasks/navigation';
import { createNewTimeline, gotToDiscoverTab } from '../../../../tasks/timeline';
import { createNewTimeline, gotToEsqlTab } from '../../../../tasks/timeline';
import { ALERTS_URL } from '../../../../urls/navigation';

const INITIAL_START_DATE = 'Jan 18, 2021 @ 20:33:29.186';
Expand All @@ -24,17 +24,16 @@ const TIMESTAMP_COLUMN_NAME = '@timestamp';

// FLAKY: https://github.com/elastic/kibana/issues/165650
describe.skip(
`Discover Datagrid Cell Actions`,
`ESQL Datagrid Cell Actions`,
{
env: { ftrConfig: { enableExperimental: ['discoverInTimeline'] } },
tags: ['@ess'],
},
() => {
beforeEach(() => {
login();
visitWithTimeRange(ALERTS_URL);
createNewTimeline();
gotToDiscoverTab();
gotToEsqlTab();
updateDateRangeInLocalDatePickers(DISCOVER_CONTAINER, INITIAL_START_DATE, INITIAL_END_DATE);
waitForDiscoverGridToLoad();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
addDescriptionToTimeline,
addNameToTimeline,
createNewTimeline,
gotToDiscoverTab,
gotToEsqlTab,
openTimelineById,
openTimelineFromSettings,
waitForTimelineChanges,
Expand All @@ -60,11 +60,9 @@ const TIMELINE_RESPONSE_SAVED_OBJECT_ID_PATH =
'response.body.data.persistTimeline.timeline.savedObjectId';
const esqlQuery = 'from auditbeat-* | where ecs.version == "8.0.0"';

// TODO: reuse or remove this tests when ESQL tab will be added
describe.skip(
describe(
'Discover Timeline State Integration',
{
env: { ftrConfig: { enableExperimental: ['discoverInTimeline'] } },
tags: ['@ess', '@brokenInServerless'],
// ESQL and test involving STACK_MANAGEMENT_PAGE are broken in serverless
},
Expand Down Expand Up @@ -109,14 +107,14 @@ describe.skip(
login();
visitWithTimeRange(ALERTS_URL);
createNewTimeline();
gotToDiscoverTab();
gotToEsqlTab();
updateDateRangeInLocalDatePickers(DISCOVER_CONTAINER, INITIAL_START_DATE, INITIAL_END_DATE);
});
context('save/restore', () => {
it('should be able create an empty timeline with default discover state', () => {
addNameToTimeline('Timerange timeline');
createNewTimeline();
gotToDiscoverTab();
gotToEsqlTab();
cy.get(GET_LOCAL_SHOW_DATES_BUTTON(DISCOVER_CONTAINER)).should(
'contain.text',
`Last 15 minutes`
Expand All @@ -143,7 +141,7 @@ describe.skip(
openTimelineFromSettings();
openTimelineById(timelineId);
cy.get(LOADING_INDICATOR).should('not.exist');
gotToDiscoverTab();
gotToEsqlTab();
verifyDiscoverEsqlQuery(esqlQuery);
cy.get(GET_DISCOVER_DATA_GRID_CELL_HEADER(column1)).should('exist');
cy.get(GET_DISCOVER_DATA_GRID_CELL_HEADER(column2)).should('exist');
Expand Down Expand Up @@ -193,7 +191,7 @@ describe.skip(
openTimelineFromSettings();
openTimelineById(timelineId);
cy.get(LOADING_INDICATOR).should('not.exist');
gotToDiscoverTab();
gotToEsqlTab();
cy.get(DISCOVER_DATA_VIEW_SWITCHER.BTN).should('not.exist');
});
});
Expand Down
Loading

0 comments on commit 7f6b201

Please sign in to comment.