Skip to content

Commit

Permalink
[Search Sessions] added an info flyout to session management (#90559) (
Browse files Browse the repository at this point in the history
…#90943)

* added an info flyout to session management

* better filter serialization

* Fix jest tests

* jest

* display the originalState as a json object

* code review

* Text improvements

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
lizozom and kibanamachine authored Feb 10, 2021
1 parent fe77025 commit 09e80b0
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ExtendConfirm = ({
defaultMessage: 'Extend search session expiration',
});
const confirm = i18n.translate('xpack.data.mgmt.searchSessions.extendModal.extendButton', {
defaultMessage: 'Extend',
defaultMessage: 'Extend expiration',
});
const extend = i18n.translate('xpack.data.mgmt.searchSessions.extendModal.dontExtendButton', {
defaultMessage: 'Cancel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ import { SearchSessionsMgmtAPI } from '../../lib/api';
import { UISession } from '../../types';
import { DeleteButton } from './delete_button';
import { ExtendButton } from './extend_button';
import { InspectButton } from './inspect_button';
import { ACTION, OnActionComplete } from './types';

export const getAction = (
api: SearchSessionsMgmtAPI,
actionType: string,
{ id, name, expires }: UISession,
uiSession: UISession,
onActionComplete: OnActionComplete
): IClickActionDescriptor | null => {
const { id, name, expires } = uiSession;
switch (actionType) {
case ACTION.INSPECT:
return {
iconType: 'document',
textColor: 'default',
label: <InspectButton searchSession={uiSession} />,
};

case ACTION.DELETE:
return {
iconType: 'crossInACircleFilled',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.searchSessionsFlyout .euiFlyoutBody__overflowContent {
height: 100%;
> div {
height: 100%;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
EuiFlyout,
EuiFlyoutBody,
EuiFlyoutHeader,
EuiPortal,
EuiSpacer,
EuiText,
EuiTitle,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Component, Fragment } from 'react';
import { UISession } from '../../types';
import { TableText } from '..';
import { CodeEditor } from '../../../../../../../../src/plugins/kibana_react/public';
import './inspect_button.scss';

interface Props {
searchSession: UISession;
}

interface State {
isFlyoutVisible: boolean;
}

export class InspectButton extends Component<Props, State> {
constructor(props: Props) {
super(props);

this.state = {
isFlyoutVisible: false,
};

this.closeFlyout = this.closeFlyout.bind(this);
this.showFlyout = this.showFlyout.bind(this);
}

public renderInfo() {
return (
<Fragment>
<CodeEditor
languageId="json"
value={JSON.stringify(this.props.searchSession.initialState, null, 2)}
onChange={() => {}}
options={{
readOnly: true,
lineNumbers: 'off',
fontSize: 12,
minimap: {
enabled: false,
},
scrollBeyondLastLine: false,
wordWrap: 'on',
wrappingIndent: 'indent',
automaticLayout: true,
}}
/>
</Fragment>
);
}

public render() {
let flyout;

if (this.state.isFlyoutVisible) {
flyout = (
<EuiPortal>
<EuiFlyout
ownFocus
onClose={this.closeFlyout}
size="s"
aria-labelledby="flyoutTitle"
data-test-subj="searchSessionsFlyout"
className="searchSessionsFlyout"
>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="m">
<h2 id="flyoutTitle">
<FormattedMessage
id="xpack.data.sessions.management.flyoutTitle"
defaultMessage="Inspect search session"
/>
</h2>
</EuiTitle>
</EuiFlyoutHeader>
<EuiFlyoutBody>
<EuiText>
<EuiText size="xs">
<p>
<FormattedMessage
id="xpack.data.sessions.management.flyoutText"
defaultMessage="Configuration for this search session"
/>
</p>
</EuiText>
<EuiSpacer />
{this.renderInfo()}
</EuiText>
</EuiFlyoutBody>
</EuiFlyout>
</EuiPortal>
);
}

return (
<Fragment>
<TableText onClick={this.showFlyout}>
<FormattedMessage
id="xpack.data.mgmt.searchSessions.flyoutTitle"
aria-label="Inspect"
defaultMessage="Inspect"
/>
</TableText>
{flyout}
</Fragment>
);
}

private closeFlyout = () => {
this.setState({
isFlyoutVisible: false,
});
};

private showFlyout = () => {
this.setState({ isFlyoutVisible: true });
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export type OnActionComplete = () => void;

export enum ACTION {
INSPECT = 'inspect',
EXTEND = 'extend',
DELETE = 'delete',
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe('Background Search Session management status labels', () => {
status: SearchSessionStatus.IN_PROGRESS,
created: '2020-12-02T00:19:32Z',
expires: '2020-12-07T00:19:32Z',
initialState: {},
restoreState: {},
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ describe('Search Sessions Management API', () => {
saved_objects: [
{
id: 'hello-pizza-123',
attributes: { name: 'Veggie', appId: 'pizza', status: 'complete' },
attributes: {
name: 'Veggie',
appId: 'pizza',
status: 'complete',
initialState: {},
restoreState: {},
},
},
],
} as SavedObjectsFindResponse;
Expand All @@ -61,15 +67,18 @@ describe('Search Sessions Management API', () => {
Array [
Object {
"actions": Array [
"inspect",
"extend",
"delete",
],
"appId": "pizza",
"created": undefined,
"expires": undefined,
"id": "hello-pizza-123",
"initialState": Object {},
"name": "Veggie",
"reloadUrl": "hello-cool-undefined-url",
"restoreState": Object {},
"restoreUrl": "hello-cool-undefined-url",
"status": "complete",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type UrlGeneratorsStart = SharePluginStart['urlGenerators'];

function getActions(status: SearchSessionStatus) {
const actions: ACTION[] = [];
actions.push(ACTION.INSPECT);
if (status === SearchSessionStatus.IN_PROGRESS || status === SearchSessionStatus.COMPLETE) {
actions.push(ACTION.EXTEND);
actions.push(ACTION.DELETE);
Expand Down Expand Up @@ -78,6 +79,8 @@ const mapToUISession = (urls: UrlGeneratorsStart, config: SessionsConfigSchema)
actions,
restoreUrl,
reloadUrl,
initialState,
restoreState,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe('Search Sessions Management table column factory', () => {
status: SearchSessionStatus.IN_PROGRESS,
created: '2020-12-02T00:19:32Z',
expires: '2020-12-07T00:19:32Z',
initialState: {},
restoreState: {},
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ export interface UISession {
actions?: ACTION[];
reloadUrl: string;
restoreUrl: string;
initialState: Record<string, unknown>;
restoreState: Record<string, unknown>;
}

0 comments on commit 09e80b0

Please sign in to comment.