Skip to content

Commit

Permalink
[Search Sessions] Enable extend from management (#90558)
Browse files Browse the repository at this point in the history
* Enable extend from management

* fix extend jest test
  • Loading branch information
lizozom authored Feb 9, 2021
1 parent f94aace commit 7b5d62f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/plugins/data/public/search/session/sessions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export class SessionsClient {
});
}

public extend(sessionId: string, keepAlive: string): Promise<SavedObjectsFindResponse> {
public extend(sessionId: string, expires: string): Promise<SavedObjectsFindResponse> {
return this.http!.post(`/internal/session/${encodeURIComponent(sessionId)}/_extend`, {
body: JSON.stringify({ keepAlive }),
body: JSON.stringify({ expires }),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const ExtendConfirm = ({
onCancel={onConfirmDismiss}
onConfirm={async () => {
setIsLoading(true);
await api.sendExtend(id, `${extendByDuration.asMilliseconds()}ms`);
await api.sendExtend(id, `${newExpiration.toISOString()}`);
setIsLoading(false);
onConfirmDismiss();
onActionComplete();
}}
confirmButtonText={confirm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('Search Sessions Management API', () => {

describe('extend', () => {
beforeEach(() => {
sessionsClient.find = jest.fn().mockImplementation(async () => {
sessionsClient.extend = jest.fn().mockImplementation(async () => {
return {
saved_objects: [
{
Expand All @@ -188,6 +188,20 @@ describe('Search Sessions Management API', () => {
});
await api.sendExtend('my-id', '5d');

expect(sessionsClient.extend).toHaveBeenCalledTimes(1);
expect(mockCoreStart.notifications.toasts.addSuccess).toHaveBeenCalled();
});

test('displays error on reject', async () => {
sessionsClient.extend = jest.fn().mockRejectedValue({});
const api = new SearchSessionsMgmtAPI(sessionsClient, mockConfig, {
urls: mockUrls,
notifications: mockCoreStart.notifications,
application: mockCoreStart.application,
});
await api.sendExtend('my-id', '5d');

expect(sessionsClient.extend).toHaveBeenCalledTimes(1);
expect(mockCoreStart.notifications.toasts.addError).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ export class SearchSessionsMgmtAPI {
}),
});
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);

this.deps.notifications.toasts.addError(err, {
title: i18n.translate('xpack.data.mgmt.searchSessions.api.deletedError', {
defaultMessage: 'Failed to delete the search session!',
Expand All @@ -178,11 +175,21 @@ export class SearchSessionsMgmtAPI {
}

// Extend
public async sendExtend(id: string, ttl: string): Promise<void> {
this.deps.notifications.toasts.addError(new Error('Not implemented'), {
title: i18n.translate('xpack.data.mgmt.searchSessions.api.extendError', {
defaultMessage: 'Failed to extend the session expiration!',
}),
});
public async sendExtend(id: string, expires: string): Promise<void> {
try {
await this.sessionsClient.extend(id, expires);

this.deps.notifications.toasts.addSuccess({
title: i18n.translate('xpack.data.mgmt.searchSessions.api.extended', {
defaultMessage: 'The search session was extended.',
}),
});
} catch (err) {
this.deps.notifications.toasts.addError(err, {
title: i18n.translate('xpack.data.mgmt.searchSessions.api.extendError', {
defaultMessage: 'Failed to extend the search session!',
}),
});
}
}
}

0 comments on commit 7b5d62f

Please sign in to comment.