Skip to content

Commit

Permalink
Fix save session UI appears in report (elastic#115746)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant authored Oct 20, 2021
1 parent c6fcde9 commit a7a1e54
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
10 changes: 9 additions & 1 deletion x-pack/plugins/data_enhanced/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
"githubTeam": "kibana-app-services"
},
"configPath": ["xpack", "data_enhanced"],
"requiredPlugins": ["bfetch", "data", "features", "management", "share", "taskManager"],
"requiredPlugins": [
"bfetch",
"data",
"features",
"management",
"share",
"taskManager",
"screenshotMode"
],
"optionalPlugins": ["kibanaUtils", "usageCollection", "security"],
"server": true,
"ui": true,
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/data_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { toMountPoint } from '../../../../src/plugins/kibana_react/public';
import { createConnectedSearchSessionIndicator } from './search';
import { ConfigSchema } from '../config';
import { Storage } from '../../../../src/plugins/kibana_utils/public';
import { ScreenshotModePluginStart } from '../../../../src/plugins/screenshot_mode/public';

export interface DataEnhancedSetupDependencies {
bfetch: BfetchPublicSetup;
Expand All @@ -31,6 +32,7 @@ export interface DataEnhancedSetupDependencies {
export interface DataEnhancedStartDependencies {
data: DataPublicPluginStart;
share: SharePluginStart;
screenshotMode: ScreenshotModePluginStart;
}

export type DataEnhancedSetup = ReturnType<DataEnhancedPlugin['setup']>;
Expand Down Expand Up @@ -77,6 +79,7 @@ export class DataEnhancedPlugin
.duration(this.config.search.sessions.notTouchedTimeout)
.asMilliseconds(),
usageCollector: this.usageCollector,
tourDisabled: plugins.screenshotMode.isScreenshotMode(),
})
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ timeFilter.getRefreshIntervalUpdate$.mockImplementation(() => refreshInterval$);
timeFilter.getRefreshInterval.mockImplementation(() => refreshInterval$.getValue());

const disableSaveAfterSessionCompletesTimeout = 5 * 60 * 1000;
const tourDisabled = false;

function Container({ children }: { children?: ReactNode }) {
return <IntlProvider locale="en">{children}</IntlProvider>;
Expand All @@ -64,6 +65,7 @@ test("shouldn't show indicator in case no active search session", async () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});
const { getByTestId, container } = render(
<Container>
Expand Down Expand Up @@ -92,6 +94,7 @@ test("shouldn't show indicator in case app hasn't opt-in", async () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});
const { getByTestId, container } = render(
<Container>
Expand Down Expand Up @@ -122,6 +125,7 @@ test('should show indicator in case there is an active search session', async ()
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});
const { getByTestId } = render(
<Container>
Expand All @@ -147,6 +151,7 @@ test('should be disabled in case uiConfig says so ', async () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});

render(
Expand All @@ -170,6 +175,7 @@ test('should be disabled in case not enough permissions', async () => {
storage,
disableSaveAfterSessionCompletesTimeout,
basePath,
tourDisabled,
});

render(
Expand Down Expand Up @@ -203,6 +209,7 @@ describe('Completed inactivity', () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});

render(
Expand Down Expand Up @@ -264,6 +271,7 @@ describe('tour steps', () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});
const rendered = render(
<Container>
Expand Down Expand Up @@ -305,6 +313,7 @@ describe('tour steps', () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});
const rendered = render(
<Container>
Expand All @@ -329,6 +338,51 @@ describe('tour steps', () => {
expect(usageCollector.trackSessionIndicatorTourLoading).toHaveBeenCalledTimes(0);
expect(usageCollector.trackSessionIndicatorTourRestored).toHaveBeenCalledTimes(0);
});

test("doesn't show tour step on slow loading when tour is disabled", async () => {
const state$ = new BehaviorSubject(SearchSessionState.Loading);
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled: true,
});
const rendered = render(
<Container>
<SearchSessionIndicator />
</Container>
);

await waitFor(() => rendered.getByTestId('searchSessionIndicator'));

expect(() => screen.getByTestId('searchSessionIndicatorPopoverContainer')).toThrow();

act(() => {
jest.advanceTimersByTime(10001);
});

expect(
screen.queryByTestId('searchSessionIndicatorPopoverContainer')
).not.toBeInTheDocument();

act(() => {
jest.advanceTimersByTime(5000);
state$.next(SearchSessionState.Completed);
});

expect(
screen.queryByTestId('searchSessionIndicatorPopoverContainer')
).not.toBeInTheDocument();

expect(storage.get(TOUR_RESTORE_STEP_KEY)).toBeFalsy();
expect(storage.get(TOUR_TAKING_TOO_LONG_STEP_KEY)).toBeFalsy();

expect(usageCollector.trackSessionIndicatorTourLoading).toHaveBeenCalledTimes(0);
expect(usageCollector.trackSessionIndicatorTourRestored).toHaveBeenCalledTimes(0);
});
});

test('shows tour step for restored', async () => {
Expand All @@ -340,6 +394,7 @@ describe('tour steps', () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});
const rendered = render(
<Container>
Expand Down Expand Up @@ -367,6 +422,7 @@ describe('tour steps', () => {
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
});
const rendered = render(
<Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface SearchSessionIndicatorDeps {
* after the last search in the session has completed
*/
disableSaveAfterSessionCompletesTimeout: number;
tourDisabled: boolean;
usageCollector?: SearchUsageCollector;
}

Expand All @@ -41,6 +42,7 @@ export const createConnectedSearchSessionIndicator = ({
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
tourDisabled,
}: SearchSessionIndicatorDeps): React.FC => {
const searchSessionsManagementUrl = basePath.prepend('/app/management/kibana/search_sessions');

Expand Down Expand Up @@ -113,6 +115,7 @@ export const createConnectedSearchSessionIndicator = ({
searchSessionIndicator,
state,
saveDisabled,
tourDisabled,
usageCollector
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function useSearchSessionTour(
searchSessionIndicatorRef: SearchSessionIndicatorRef | null,
state: SearchSessionState,
searchSessionsDisabled: boolean,
disableSearchSessionsTour: boolean,
usageCollector?: SearchUsageCollector
) {
const markOpenedDone = useCallback(() => {
Expand Down Expand Up @@ -55,6 +56,7 @@ export function useSearchSessionTour(

useEffect(() => {
if (searchSessionsDisabled) return;
if (disableSearchSessionsTour) return;
if (!searchSessionIndicatorRef) return;
let timeoutHandle: number;

Expand Down Expand Up @@ -82,6 +84,7 @@ export function useSearchSessionTour(
searchSessionIndicatorRef,
state,
searchSessionsDisabled,
disableSearchSessionsTour,
markOpenedDone,
markRestoredDone,
usageCollector,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/data_enhanced/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{ "path": "../../../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../../../src/plugins/usage_collection/tsconfig.json" },
{ "path": "../../../src/plugins/management/tsconfig.json" },
{ "path": "../../../src/plugins/screenshot_mode/tsconfig.json"},
{ "path": "../security/tsconfig.json" },
{ "path": "../task_manager/tsconfig.json" },

Expand Down

0 comments on commit a7a1e54

Please sign in to comment.