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

[Search Session][Management] Rename "cancel" button and delete "Reload" button #90015

Merged
merged 13 commits into from
Feb 4, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ import { SearchSessionsMgmtAPI } from '../../lib/api';
import { TableText } from '../';
import { OnActionComplete } from './types';

interface CancelButtonProps {
interface DeleteButtonProps {
id: string;
name: string;
api: SearchSessionsMgmtAPI;
onActionComplete: OnActionComplete;
}

const CancelConfirm = ({
onConfirmDismiss,
const DeleteConfirm = ({
onConfirmCancel,
...props
}: CancelButtonProps & { onConfirmDismiss: () => void }) => {
}: DeleteButtonProps & { onConfirmCancel: () => void }) => {
const { id, name, api, onActionComplete } = props;
const [isLoading, setIsLoading] = useState(false);

const title = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.title', {
defaultMessage: 'Cancel search session',
defaultMessage: 'Delete search session',
});
const confirm = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.cancelButton', {
defaultMessage: 'Cancel',
const confirm = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.deleteButton', {
defaultMessage: 'Delete',
});
const cancel = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.dontCancelButton', {
defaultMessage: 'Dismiss',
const cancel = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.cancelButton', {
defaultMessage: 'Cancel',
});
const message = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.message', {
defaultMessage: `Canceling the search session \'{name}\' will expire any cached results, so that quick restore will no longer be available. You will still be able to re-run it, using the reload action.`,
defaultMessage: `Deleting the search session \'{name}\' will expire any cached results.`,
values: {
name,
},
Expand All @@ -46,7 +46,7 @@ const CancelConfirm = ({
<EuiOverlayMask>
<EuiConfirmModal
title={title}
onCancel={onConfirmDismiss}
onCancel={onConfirmCancel}
onConfirm={async () => {
setIsLoading(true);
await api.sendCancel(id);
Expand All @@ -64,26 +64,26 @@ const CancelConfirm = ({
);
};

export const CancelButton = (props: CancelButtonProps) => {
export const DeleteButton = (props: DeleteButtonProps) => {
const [showConfirm, setShowConfirm] = useState(false);

const onClick = () => {
setShowConfirm(true);
};

const onConfirmDismiss = () => {
const onConfirmCancel = () => {
setShowConfirm(false);
};

return (
<>
<TableText onClick={onClick}>
<FormattedMessage
id="xpack.data.mgmt.searchSessions.actionCancel"
defaultMessage="Cancel"
id="xpack.data.mgmt.searchSessions.actionDelete"
defaultMessage="Delete"
/>
</TableText>
{showConfirm ? <CancelConfirm {...props} onConfirmDismiss={onConfirmDismiss} /> : null}
{showConfirm ? <DeleteConfirm {...props} onConfirmCancel={onConfirmCancel} /> : null}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,22 @@ import { IClickActionDescriptor } from '../';
import extendSessionIcon from '../../icons/extend_session.svg';
import { SearchSessionsMgmtAPI } from '../../lib/api';
import { UISession } from '../../types';
import { CancelButton } from './cancel_button';
import { DeleteButton } from './delete_button';
import { ExtendButton } from './extend_button';
import { ReloadButton } from './reload_button';
import { ACTION, OnActionComplete } from './types';

export const getAction = (
api: SearchSessionsMgmtAPI,
actionType: string,
{ id, name, expires, reloadUrl }: UISession,
{ id, name, expires }: UISession,
onActionComplete: OnActionComplete
): IClickActionDescriptor | null => {
switch (actionType) {
case ACTION.CANCEL:
case ACTION.DELETE:
return {
iconType: 'crossInACircleFilled',
textColor: 'default',
label: <CancelButton api={api} id={id} name={name} onActionComplete={onActionComplete} />,
};

case ACTION.RELOAD:
return {
iconType: 'refresh',
textColor: 'default',
label: <ReloadButton api={api} reloadUrl={reloadUrl} />,
label: <DeleteButton api={api} id={id} name={name} onActionComplete={onActionComplete} />,
};

case ACTION.EXTEND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const PopoverActionsMenu = ({ api, onActionComplete, session }: PopoverAc

// add a line above the delete action (when there are multiple)
// NOTE: Delete action MUST be the final action[] item
if (actions.length > 1 && actionType === ACTION.CANCEL) {
if (actions.length > 1 && actionType === ACTION.DELETE) {
itemSet.push({ isSeparator: true, key: 'separadorable' });
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ export type OnActionComplete = () => void;

export enum ACTION {
EXTEND = 'extend',
CANCEL = 'cancel',
RELOAD = 'reload',
DELETE = 'delete',
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ describe('Search Sessions Management API', () => {
Array [
Object {
"actions": Array [
"reload",
"extend",
"cancel",
"delete",
],
"appId": "pizza",
"created": undefined,
Expand Down Expand Up @@ -166,32 +165,6 @@ describe('Search Sessions Management API', () => {
});
});

describe('reload', () => {
beforeEach(() => {
sessionsClient.find = jest.fn().mockImplementation(async () => {
return {
saved_objects: [
{
id: 'hello-pizza-123',
attributes: { name: 'Veggie', appId: 'pizza', status: SearchSessionStatus.COMPLETE },
},
],
} as SavedObjectsFindResponse;
});
});

test('send cancel calls the cancel endpoint with a session ID', async () => {
const api = new SearchSessionsMgmtAPI(sessionsClient, mockConfig, {
urls: mockUrls,
notifications: mockCoreStart.notifications,
application: mockCoreStart.application,
});
await api.reloadSearchSession('www.myurl.com');

expect(mockCoreStart.application.navigateToUrl).toHaveBeenCalledWith('www.myurl.com');
});
});

describe('extend', () => {
beforeEach(() => {
sessionsClient.find = jest.fn().mockImplementation(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ type UrlGeneratorsStart = SharePluginStart['urlGenerators'];

function getActions(status: SearchSessionStatus) {
const actions: ACTION[] = [];
actions.push(ACTION.RELOAD);
if (status === SearchSessionStatus.IN_PROGRESS || status === SearchSessionStatus.COMPLETE) {
actions.push(ACTION.EXTEND);
actions.push(ACTION.CANCEL);
actions.push(ACTION.DELETE);
}
return actions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export function SearchSessionsPageProvider({ getService, getPageObjects }: FtrPr
'[data-test-subj="sessionManagementPopoverAction-reload"]'
);
},
cancel: async () => {
delete: async () => {
await actionsCell.click();
await find.clickByCssSelector(
'[data-test-subj="sessionManagementPopoverAction-cancel"]'
'[data-test-subj="sessionManagementPopoverAction-delete"]'
);
await PageObjects.common.clickConfirmOnModal();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await searchSessions.expectState('completed');
});

it('Cancels a session from management', async () => {
it('Deletes a session from management', async () => {
await PageObjects.searchSessionsManagement.goTo();

const searchSessionList = await PageObjects.searchSessionsManagement.getList();

expect(searchSessionList.length).to.be(1);
await searchSessionList[0].cancel();
await searchSessionList[0].delete();

// TODO: update this once canceling doesn't delete the object!
await retry.waitFor(`wait for list to be empty`, async function () {
const s = await PageObjects.searchSessionsManagement.getList();

Expand Down