fix tab url link (#51993)

This commit is contained in:
Xavier Mouligneau 2019-12-02 14:10:10 -05:00 committed by GitHub
parent 1c6bd0992c
commit b1a3a619a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 70 deletions

View file

@ -16,6 +16,6 @@ export const ALL_HOSTS_WIDGET_DRAGGABLE_HOSTS = `${ALL_HOSTS_WIDGET} ${ALL_HOSTS
/** Clicking this button displays the `Events` tab */
export const EVENTS_TAB_BUTTON = '[data-test-subj="navigation-events"]';
export const NAVIGATION_HOSTS_ALL_HOSTS = '[data-test-subj="navigation-link-allHosts"]';
export const NAVIGATION_HOSTS_ALL_HOSTS = '[data-test-subj="navigation-allHosts"]';
export const NAVIGATION_HOSTS_ANOMALIES = '[data-test-subj="navigation-link-anomalies"]';
export const NAVIGATION_HOSTS_ANOMALIES = '[data-test-subj="navigation-anomalies"]';

View file

@ -181,7 +181,7 @@ describe('url state', () => {
cy.url().should('include', `query=(language:kuery,query:'source.ip:%20%2210.142.0.9%22%20')`);
});
it.skip('sets the url state when kql is set and check if href reflect this change', () => {
it('sets the url state when kql is set and check if href reflect this change', () => {
loginAndWaitForPage(ABSOLUTE_DATE_RANGE.url);
cy.get(KQL_INPUT, { timeout: 5000 }).type('source.ip: "10.142.0.9" {enter}');
cy.get(NAVIGATION_HOSTS)
@ -194,7 +194,7 @@ describe('url state', () => {
);
});
it.skip('sets KQL in host page and detail page and check if href match on breadcrumb, tabs and subTabs', () => {
it('sets KQL in host page and detail page and check if href match on breadcrumb, tabs and subTabs', () => {
loginAndWaitForPage(ABSOLUTE_DATE_RANGE.urlHost);
cy.get(KQL_INPUT, { timeout: 5000 }).type('host.name: "siem-kibana" {enter}');
cy.get(NAVIGATION_HOSTS_ALL_HOSTS, { timeout: 5000 })

View file

@ -11,49 +11,51 @@ import { CONSTANTS } from '../url_state/constants';
import { SiemNavigationComponent } from './';
import { setBreadcrumbs } from './breadcrumbs';
import { navTabs } from '../../pages/home/home_navigations';
import { TabNavigationProps } from './tab_navigation/types';
import { HostsTableType } from '../../store/hosts/model';
import { RouteSpyState } from '../../utils/route/types';
import { SiemNavigationProps, SiemNavigationComponentProps } from './types';
jest.mock('./breadcrumbs', () => ({
setBreadcrumbs: jest.fn(),
}));
describe('SIEM Navigation', () => {
const mockProps: TabNavigationProps & RouteSpyState = {
const mockProps: SiemNavigationComponentProps & SiemNavigationProps & RouteSpyState = {
pageName: 'hosts',
pathName: '/hosts',
detailName: undefined,
search: '',
tabName: HostsTableType.authentications,
navTabs,
[CONSTANTS.timerange]: {
global: {
[CONSTANTS.timerange]: {
from: 1558048243696,
fromStr: 'now-24h',
kind: 'relative',
to: 1558134643697,
toStr: 'now',
urlState: {
[CONSTANTS.timerange]: {
global: {
[CONSTANTS.timerange]: {
from: 1558048243696,
fromStr: 'now-24h',
kind: 'relative',
to: 1558134643697,
toStr: 'now',
},
linkTo: ['timeline'],
},
linkTo: ['timeline'],
},
timeline: {
[CONSTANTS.timerange]: {
from: 1558048243696,
fromStr: 'now-24h',
kind: 'relative',
to: 1558134643697,
toStr: 'now',
timeline: {
[CONSTANTS.timerange]: {
from: 1558048243696,
fromStr: 'now-24h',
kind: 'relative',
to: 1558134643697,
toStr: 'now',
},
linkTo: ['global'],
},
linkTo: ['global'],
},
},
[CONSTANTS.appQuery]: { query: '', language: 'kuery' },
[CONSTANTS.filters]: [],
[CONSTANTS.timeline]: {
id: '',
isOpen: false,
[CONSTANTS.appQuery]: { query: '', language: 'kuery' },
[CONSTANTS.filters]: [],
[CONSTANTS.timeline]: {
id: '',
isOpen: false,
},
},
};
const wrapper = mount(<SiemNavigationComponent {...mockProps} />);

View file

@ -14,54 +14,42 @@ import { useRouteSpy } from '../../utils/route/use_route_spy';
import { makeMapStateToProps } from '../url_state/helpers';
import { setBreadcrumbs } from './breadcrumbs';
import { TabNavigation } from './tab_navigation';
import { TabNavigationProps } from './tab_navigation/types';
import { SiemNavigationComponentProps } from './types';
import { SiemNavigationProps, SiemNavigationComponentProps } from './types';
export const SiemNavigationComponent = React.memo<TabNavigationProps & RouteSpyState>(
({
query,
detailName,
display,
filters,
navTabs,
pageName,
pathName,
savedQuery,
search,
tabName,
timeline,
timerange,
}) => {
export const SiemNavigationComponent = React.memo<
SiemNavigationComponentProps & SiemNavigationProps & RouteSpyState
>(
({ detailName, display, navTabs, pageName, pathName, search, tabName, urlState }) => {
useEffect(() => {
if (pathName) {
setBreadcrumbs({
query,
query: urlState.query,
detailName,
filters,
filters: urlState.filters,
navTabs,
pageName,
pathName,
savedQuery,
savedQuery: urlState.savedQuery,
search,
tabName,
timerange,
timeline,
timerange: urlState.timerange,
timeline: urlState.timeline,
});
}
}, [query, pathName, search, filters, navTabs, savedQuery, timerange, timeline]);
}, [pathName, search, navTabs, urlState]);
return (
<TabNavigation
query={query}
query={urlState.query}
display={display}
filters={filters}
filters={urlState.filters}
navTabs={navTabs}
pageName={pageName}
pathName={pathName}
savedQuery={savedQuery}
savedQuery={urlState.savedQuery}
tabName={tabName}
timeline={timeline}
timerange={timerange}
timeline={urlState.timeline}
timerange={urlState.timerange}
/>
);
},
@ -69,12 +57,8 @@ export const SiemNavigationComponent = React.memo<TabNavigationProps & RouteSpyS
return (
prevProps.pathName === nextProps.pathName &&
prevProps.search === nextProps.search &&
prevProps.savedQuery === nextProps.savedQuery &&
isEqual(prevProps.query, nextProps.query) &&
isEqual(prevProps.filters, nextProps.filters) &&
isEqual(prevProps.navTabs, nextProps.navTabs) &&
isEqual(prevProps.timerange, nextProps.timerange) &&
isEqual(prevProps.timeline, nextProps.timeline)
isEqual(prevProps.urlState, nextProps.urlState)
);
}
);
@ -82,12 +66,12 @@ export const SiemNavigationComponent = React.memo<TabNavigationProps & RouteSpyS
SiemNavigationComponent.displayName = 'SiemNavigationComponent';
export const SiemNavigationRedux = compose<
React.ComponentClass<SiemNavigationComponentProps & RouteSpyState>
React.ComponentClass<SiemNavigationProps & RouteSpyState>
>(connect(makeMapStateToProps))(SiemNavigationComponent);
export const SiemNavigation = React.memo<SiemNavigationComponentProps>(props => {
export const SiemNavigation = React.memo<SiemNavigationProps>(props => {
const [routeProps] = useRouteSpy();
const stateNavReduxProps: RouteSpyState & SiemNavigationComponentProps = {
const stateNavReduxProps: RouteSpyState & SiemNavigationProps = {
...routeProps,
...props,
};

View file

@ -10,9 +10,9 @@ import { Timeline } from '../../url_state/types';
import { HostsTableType } from '../../../store/hosts/model';
import { esFilters, Query } from '../../../../../../../../src/plugins/data/public';
import { SiemNavigationComponentProps } from '../types';
import { SiemNavigationProps } from '../types';
export interface TabNavigationProps extends SiemNavigationComponentProps {
export interface TabNavigationProps extends SiemNavigationProps {
pathName: string;
pageName: string;
tabName: HostsTableType | undefined;

View file

@ -4,13 +4,30 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { UrlStateType } from '../url_state/constants';
import { esFilters, Query } from '../../../../../../../src/plugins/data/public';
import { HostsTableType } from '../../store/hosts/model';
import { UrlInputsModel } from '../../store/inputs/model';
import { CONSTANTS, UrlStateType } from '../url_state/constants';
import { Timeline } from '../url_state/types';
export interface SiemNavigationComponentProps {
export interface SiemNavigationProps {
display?: 'default' | 'condensed';
navTabs: Record<string, NavTab>;
}
export interface SiemNavigationComponentProps {
pathName: string;
pageName: string;
tabName: HostsTableType | undefined;
urlState: {
[CONSTANTS.appQuery]?: Query;
[CONSTANTS.filters]?: esFilters.Filter[];
[CONSTANTS.savedQuery]?: string;
[CONSTANTS.timerange]: UrlInputsModel;
[CONSTANTS.timeline]: Timeline;
};
}
export type SearchNavTab = NavTab | { urlKey: UrlStateType; isDetailPage: boolean };
export interface NavTab {