Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
mockGlobalState,
SUB_PLUGINS_REDUCER,
TestProviders,
} from '../../mock';
import type { State } from '../../store';
import { createStore } from '../../store';
import { useKibana } from '../../lib/kibana';
import { InputsModelId } from '../../store/inputs/constants';
} from '../../common/mock';
import type { State } from '../../common/store';
import { createStore } from '../../common/store';
import { useKibana } from '../../common/lib/kibana';
import { InputsModelId } from '../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from './use_refetch_by_session';
import { inputsActions } from '../../store/actions';
import type { Refetch } from '../../store/inputs/model';
import { inputsActions } from '../../common/store/actions';
import type { Refetch } from '../../common/store/inputs/model';

const state: State = mockGlobalState;

Expand All @@ -40,13 +40,13 @@ jest.mock('react-redux', () => {
};
});

jest.mock('../../lib/kibana', () => {
jest.mock('../../common/lib/kibana', () => {
return {
useKibana: jest.fn(),
};
});

jest.mock('../../store/actions', () => {
jest.mock('../../common/store/actions', () => {
return {
inputsActions: {
setInspectionParameter: jest.fn(),
Expand All @@ -60,7 +60,7 @@ describe(`useRefetchByRestartingSession`, () => {
children: React.ReactNode;
},
{
searchSessionId: string;
searchSessionId?: string;
refetchByRestartingSession: Refetch;
}
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* 2.0.
*/

import { useCallback, useRef, useEffect, useMemo } from 'react';
import { useCallback, useRef, useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { useDeepEqualSelector } from '../../hooks/use_selector';
import { useKibana } from '../../lib/kibana';
import { inputsSelectors } from '../../store';
import { inputsActions } from '../../store/actions';
import { InputsModelId } from '../../store/inputs/constants';
import type { Refetch } from '../../store/inputs/model';
import { useDeepEqualSelector } from '../../common/hooks/use_selector';
import { useKibana } from '../../common/lib/kibana';
import { inputsSelectors } from '../../common/store';
import { inputsActions } from '../../common/store/actions';
import { InputsModelId } from '../../common/store/inputs/constants';
import type { Refetch } from '../../common/store/inputs/model';

interface UseRefetchByRestartingSessionProps {
inputId?: InputsModelId;
Expand All @@ -24,14 +24,15 @@ export const useRefetchByRestartingSession = ({
inputId,
queryId,
}: UseRefetchByRestartingSessionProps): {
searchSessionId: string;
searchSessionId?: string;
refetchByRestartingSession: Refetch;
} => {
const dispatch = useDispatch();
const { data } = useKibana().services;

const session = useRef(data.search.session);
const searchSessionId = useMemo(() => session.current.start(), [session]);
const [searchSessionId, setSearchSessionId] = useState<string | undefined>(undefined);

const getGlobalQuery = inputsSelectors.globalQueryByIdSelector();
const getTimelineQuery = inputsSelectors.timelineQueryByIdSelector();
const { selectedInspectIndex } = useDeepEqualSelector((state) =>
Expand All @@ -57,10 +58,12 @@ export const useRefetchByRestartingSession = ({
}, [dispatch, queryId, selectedInspectIndex]);

useEffect(() => {
setSearchSessionId(session.current.start());
const currentSession = session.current;
return () => {
data.search.session.clear();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to use the session.current ref since its the only place we're not using the ref. I think it was done like this in the first place because of the following error:

ESLint: The ref value 'session.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'session.current' to a variable inside the effect, and use that variable in the cleanup function.(react-hooks/exhaustive-deps)

Thus the variable on L62

currentSession.clear();
};
});
}, []);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react wants empty dependency argument now that we're using a setState call in the effect


return { searchSessionId, refetchByRestartingSession };
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { HostsKpiHosts } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as i18n from './translations';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';

export const fieldsMapping: Readonly<StatItems[]> = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { HostsKpiUniqueIps } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as i18n from './translations';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';

export const fieldsMapping: Readonly<StatItems[]> = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { NetworkKpiDns } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../../../../hosts/components/kpi_hosts/common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as i18n from './translations';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';

export const fieldsMapping: Readonly<StatItems[]> = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { NetworkKpiNetworkEvents } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../../../../hosts/components/kpi_hosts/common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { kpiNetworkEventsLensAttributes } from '../../../../../common/components
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';

const euiVisColorPalette = euiPaletteColorBlind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { NetworkKpiTlsHandshakes } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../../../../hosts/components/kpi_hosts/common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as i18n from './translations';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';

export const fieldsMapping: Readonly<StatItems[]> = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { NetworkKpiUniqueFlows } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../../../../hosts/components/kpi_hosts/common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { NetworkKpiProps } from '../types';
import * as i18n from './translations';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';

export const fieldsMapping: Readonly<StatItems[]> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { NetworkKpiUniquePrivateIps } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../../../../hosts/components/kpi_hosts/common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/c
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';

const euiVisColorPalette = euiPaletteColorBlind();
const euiColorVis2 = euiVisColorPalette[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestProviders } from '../../../../../common/mock';
import React from 'react';
import { UsersKpiAuthentications } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../../../../hosts/components/kpi_hosts/common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));
describe('Authentications KPI', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as i18n from './translations';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import type { UsersKpiProps } from '../types';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';

enum ChartColors {
Expand Down Expand Up @@ -79,7 +79,7 @@ const UsersKpiAuthenticationsComponent: React.FC<UsersKpiProps> = ({
endDate: to,
indexNames,
startDate: from,
skip: querySkip,
skip: querySkip || isChartEmbeddablesEnabled,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happened to notice this was the only chart embeddables query without this condition, I think this is correct??

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the check!

});

const { searchSessionId, refetchByRestartingSession } = useRefetchByRestartingSession({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React from 'react';
import { TotalUsersKpi } from '.';
import { useSearchStrategy } from '../../../../../common/containers/use_search_strategy';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { KpiBaseComponentManage } from '../../../../hosts/components/kpi_hosts/common';

jest.mock('../../../../../common/containers/query_toggle');
Expand All @@ -25,7 +25,7 @@ jest.mock('../../../../hosts/components/kpi_hosts/common', () => ({
jest.mock('../../../../../common/hooks/use_experimental_features', () => ({
useIsExperimentalFeatureEnabled: jest.fn(),
}));
jest.mock('../../../../../common/components/page/use_refetch_by_session', () => ({
jest.mock('../../../../containers/use_refetch_by_session', () => ({
useRefetchByRestartingSession: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as i18n from './translations';
import { useQueryToggle } from '../../../../../common/containers/query_toggle';
import type { UsersKpiProps } from '../types';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useRefetchByRestartingSession } from '../../../../../common/components/page/use_refetch_by_session';
import { useRefetchByRestartingSession } from '../../../../containers/use_refetch_by_session';
import { InputsModelId } from '../../../../../common/store/inputs/constants';

const euiVisColorPalette = euiPaletteColorBlind();
Expand Down