Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Search Sessions] Remove auto-refresh limitation (#96539) #96979

Merged
merged 1 commit into from
Apr 13, 2021
Merged
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
1 change: 0 additions & 1 deletion x-pack/plugins/data_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export class DataEnhancedPlugin
sessionService: plugins.data.search.session,
application: core.application,
basePath: core.http.basePath,
timeFilter: plugins.data.query.timefilter.timefilter,
storage: this.storage,
disableSaveAfterSessionCompletesTimeout: moment
.duration(this.config.search.sessions.notTouchedTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ test("shouldn't show indicator in case no active search session", async () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService,
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand Down Expand Up @@ -89,7 +88,6 @@ test("shouldn't show indicator in case app hasn't opt-in", async () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService,
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand Down Expand Up @@ -120,7 +118,6 @@ test('should show indicator in case there is an active search session', async ()
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand All @@ -146,7 +143,6 @@ test('should be disabled in case uiConfig says so ', async () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand All @@ -171,7 +167,6 @@ test('should be disabled in case not enough permissions', async () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$, hasAccess: () => false },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
basePath,
Expand All @@ -191,38 +186,6 @@ test('should be disabled in case not enough permissions', async () => {
expect(screen.getByRole('button', { name: 'Manage sessions' })).toBeDisabled();
});

test('should be disabled during auto-refresh', async () => {
const state$ = new BehaviorSubject(SearchSessionState.Loading);

const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
});

render(
<Container>
<SearchSessionIndicator />
</Container>
);

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

await userEvent.click(screen.getByLabelText('Search session loading'));

expect(screen.getByRole('button', { name: 'Save session' })).not.toBeDisabled();

act(() => {
refreshInterval$.next({ value: 0, pause: false });
});

expect(screen.getByRole('button', { name: 'Save session' })).toBeDisabled();
});

describe('Completed inactivity', () => {
beforeEach(() => {
jest.useFakeTimers();
Expand All @@ -236,7 +199,6 @@ describe('Completed inactivity', () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand Down Expand Up @@ -298,7 +260,6 @@ describe('tour steps', () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand Down Expand Up @@ -340,7 +301,6 @@ describe('tour steps', () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand Down Expand Up @@ -376,7 +336,6 @@ describe('tour steps', () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand Down Expand Up @@ -404,7 +363,6 @@ describe('tour steps', () => {
const SearchSessionIndicator = createConnectedSearchSessionIndicator({
sessionService: { ...sessionService, state$ },
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
*/

import React, { useCallback, useEffect, useState } from 'react';
import { debounce, distinctUntilChanged, map, mapTo, switchMap, tap } from 'rxjs/operators';
import { debounce, distinctUntilChanged, mapTo, switchMap, tap } from 'rxjs/operators';
import { merge, of, timer } from 'rxjs';
import useObservable from 'react-use/lib/useObservable';
import { i18n } from '@kbn/i18n';
import { SearchSessionIndicator, SearchSessionIndicatorRef } from '../search_session_indicator';
import {
ISessionService,
SearchSessionState,
TimefilterContract,
SearchUsageCollector,
} from '../../../../../../../src/plugins/data/public';
import { RedirectAppLinks } from '../../../../../../../src/plugins/kibana_react/public';
Expand All @@ -24,7 +23,6 @@ import { useSearchSessionTour } from './search_session_tour';

export interface SearchSessionIndicatorDeps {
sessionService: ISessionService;
timeFilter: TimefilterContract;
application: ApplicationStart;
basePath: IBasePath;
storage: IStorageWrapper;
Expand All @@ -39,17 +37,12 @@ export interface SearchSessionIndicatorDeps {
export const createConnectedSearchSessionIndicator = ({
sessionService,
application,
timeFilter,
storage,
disableSaveAfterSessionCompletesTimeout,
usageCollector,
basePath,
}: SearchSessionIndicatorDeps): React.FC => {
const searchSessionsManagementUrl = basePath.prepend('/app/management/kibana/search_sessions');
const isAutoRefreshEnabled = () => !timeFilter.getRefreshInterval().pause;
const isAutoRefreshEnabled$ = timeFilter
.getRefreshIntervalUpdate$()
.pipe(map(isAutoRefreshEnabled), distinctUntilChanged());

const debouncedSessionServiceState$ = sessionService.state$.pipe(
debounce((_state) => timer(_state === SearchSessionState.None ? 50 : 300)) // switch to None faster to quickly remove indicator when navigating away
Expand All @@ -69,7 +62,6 @@ export const createConnectedSearchSessionIndicator = ({

return () => {
const state = useObservable(debouncedSessionServiceState$, SearchSessionState.None);
const autoRefreshEnabled = useObservable(isAutoRefreshEnabled$, isAutoRefreshEnabled());
const isSaveDisabledByApp = sessionService.getSearchSessionIndicatorUiConfig().isDisabled();
const disableSaveAfterSessionCompleteTimedOut = useObservable(
disableSaveAfterSessionCompleteTimedOut$,
Expand All @@ -91,16 +83,6 @@ export const createConnectedSearchSessionIndicator = ({
let managementDisabled = false;
let managementDisabledReasonText: string = '';

if (autoRefreshEnabled) {
saveDisabled = true;
saveDisabledReasonText = i18n.translate(
'xpack.data.searchSessionIndicator.disabledDueToAutoRefreshMessage',
{
defaultMessage: 'Saving search session is not available when auto refresh is enabled.',
}
);
}

if (disableSaveAfterSessionCompleteTimedOut) {
saveDisabled = true;
saveDisabledReasonText = i18n.translate(
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -7331,7 +7331,6 @@
"xpack.data.searchSessionIndicator.canceledTitleText": "検索セッションが停止しました",
"xpack.data.searchSessionIndicator.canceledTooltipText": "検索セッションが停止しました",
"xpack.data.searchSessionIndicator.continueInBackgroundButtonText": "セッションの保存",
"xpack.data.searchSessionIndicator.disabledDueToAutoRefreshMessage": "自動更新が有効な場合は、検索セッションの保存を使用できません。",
"xpack.data.searchSessionIndicator.disabledDueToDisabledGloballyMessage": "検索セッションを管理するアクセス権がありません",
"xpack.data.searchSessionIndicator.disabledDueToTimeoutMessage": "検索セッション結果が期限切れです。",
"xpack.data.searchSessionIndicator.loadingInTheBackgroundDescriptionText": "管理から完了した結果に戻ることができます。",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7394,7 +7394,6 @@
"xpack.data.searchSessionIndicator.canceledTitleText": "搜索会话已停止",
"xpack.data.searchSessionIndicator.canceledTooltipText": "搜索会话已停止",
"xpack.data.searchSessionIndicator.continueInBackgroundButtonText": "保存会话",
"xpack.data.searchSessionIndicator.disabledDueToAutoRefreshMessage": "启用自动刷新时,保存搜索会话不可用。",
"xpack.data.searchSessionIndicator.disabledDueToDisabledGloballyMessage": "您无权管理搜索会话",
"xpack.data.searchSessionIndicator.disabledDueToTimeoutMessage": "搜索会话结果已过期。",
"xpack.data.searchSessionIndicator.loadingInTheBackgroundDescriptionText": "可以从“管理”中返回至完成的结果。",
Expand Down