Skip to content

Commit 9c22e68

Browse files
committed
[Search sessions] Add singulars/plurals to expiration badges (#227035)
## Summary Closes #122931 Adds singulars and plurals to the search sessions expiration badges. | Scenario | Screenshot | |----------|-------------| | More than 1 day | ![image](https://github.com/user-attachments/assets/1935820f-80be-4748-864b-6bf4a9aa62ee) | | 1 day | ![image](https://github.com/user-attachments/assets/37ca52b5-8712-444f-bf04-ff2f43013583) | | More than 1 hour | ![image](https://github.com/user-attachments/assets/b000789f-2396-430d-a1a8-a398f183815c) | | 1 hour | ![image](https://github.com/user-attachments/assets/5af02abc-0a8c-492c-9e9f-2a0f16e6c8f2) | | 0 hours🙈 | ![image](https://github.com/user-attachments/assets/0b8cea3d-ab70-4059-a758-828df5f67a35) | ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... (cherry picked from commit e5f374a)
1 parent e945264 commit 9c22e68

2 files changed

Lines changed: 113 additions & 4 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import moment from 'moment';
11+
import { getExpirationStatus } from './get_expiration_status';
12+
13+
const CURRENT_MOCK_DATE = '2025-01-01T00:00:00.000Z';
14+
15+
beforeEach(() => {
16+
jest.useFakeTimers().setSystemTime(new Date(CURRENT_MOCK_DATE));
17+
});
18+
19+
const setup = ({
20+
expiresSoonWarning = moment.duration(7, 'days'),
21+
expires,
22+
}: {
23+
expiresSoonWarning?: moment.Duration;
24+
expires: string;
25+
}) => {
26+
return getExpirationStatus(
27+
{
28+
enabled: true,
29+
notTouchedTimeout: moment.duration(0),
30+
maxUpdateRetries: 0,
31+
defaultExpiration: moment.duration(0),
32+
management: {
33+
expiresSoonWarning,
34+
refreshInterval: moment.duration(0),
35+
refreshTimeout: moment.duration(0),
36+
maxSessions: 0,
37+
},
38+
},
39+
expires || CURRENT_MOCK_DATE
40+
);
41+
};
42+
43+
describe('getExpirationStatus', () => {
44+
describe('when it expires in more than the configured expiresSoonWarning', () => {
45+
it('returns undefined', () => {
46+
const status = setup({
47+
expiresSoonWarning: moment.duration(7, 'days'),
48+
expires: moment.utc(CURRENT_MOCK_DATE).add(8, 'days').toISOString(),
49+
});
50+
expect(status).toBeUndefined();
51+
});
52+
});
53+
54+
describe('when it expires in less than the configured expiresSoonWarning', () => {
55+
describe('when it expires in 1 day', () => {
56+
it('should return the correct stastus', () => {
57+
const status = setup({
58+
expiresSoonWarning: moment.duration(7, 'days'),
59+
expires: moment.utc(CURRENT_MOCK_DATE).add(1, 'day').toISOString(),
60+
});
61+
expect(status).toEqual({
62+
toolTipContent: 'Expires in 1 day',
63+
statusContent: '1 day',
64+
});
65+
});
66+
});
67+
68+
describe('when it expires in 2 days', () => {
69+
it('should return the correct status', () => {
70+
const status = setup({
71+
expiresSoonWarning: moment.duration(7, 'days'),
72+
expires: moment.utc(CURRENT_MOCK_DATE).add(2, 'days').toISOString(),
73+
});
74+
expect(status).toEqual({
75+
toolTipContent: 'Expires in 2 days',
76+
statusContent: '2 days',
77+
});
78+
});
79+
});
80+
81+
describe('when it expires in less than 1 day', () => {
82+
describe('when it expires in 1 hour', () => {
83+
it('should return the correct status', () => {
84+
const status = setup({
85+
expiresSoonWarning: moment.duration(7, 'days'),
86+
expires: moment.utc(CURRENT_MOCK_DATE).add(1, 'hour').toISOString(),
87+
});
88+
expect(status).toEqual({
89+
toolTipContent: 'This session expires in 1 hour',
90+
statusContent: '1 hour',
91+
});
92+
});
93+
});
94+
95+
describe('when it expires in 2 hours', () => {
96+
it('should return the correct status', () => {
97+
const status = setup({
98+
expiresSoonWarning: moment.duration(7, 'days'),
99+
expires: moment.utc(CURRENT_MOCK_DATE).add(2, 'hours').toISOString(),
100+
});
101+
expect(status).toEqual({
102+
toolTipContent: 'This session expires in 2 hours',
103+
statusContent: '2 hours',
104+
});
105+
});
106+
});
107+
});
108+
});
109+
});

src/platform/plugins/shared/data/public/search/session/sessions_mgmt/lib/get_expiration_status.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export const getExpirationStatus = (config: SearchSessionsConfigSchema, expires:
2222
const sufficientDays = Math.ceil(moment.duration(config.management.expiresSoonWarning).asDays());
2323

2424
let toolTipContent = i18n.translate('data.mgmt.searchSessions.status.expiresSoonInDays', {
25-
defaultMessage: 'Expires in {numDays} days',
25+
defaultMessage: 'Expires in {numDays, plural, one {# day} other {# days}}',
2626
values: { numDays: expiresInDays },
2727
});
2828
let statusContent = i18n.translate('data.mgmt.searchSessions.status.expiresSoonInDaysTooltip', {
29-
defaultMessage: '{numDays} days',
29+
defaultMessage: '{numDays, plural, one {# day} other {# days}}',
3030
values: { numDays: expiresInDays },
3131
});
3232

@@ -35,11 +35,11 @@ export const getExpirationStatus = (config: SearchSessionsConfigSchema, expires:
3535
const expiresInHours = Math.floor(durationToExpire.asHours());
3636

3737
toolTipContent = i18n.translate('data.mgmt.searchSessions.status.expiresSoonInHours', {
38-
defaultMessage: 'This session expires in {numHours} hours',
38+
defaultMessage: 'This session expires in {numHours, plural, one {# hour} other {# hours}}',
3939
values: { numHours: expiresInHours },
4040
});
4141
statusContent = i18n.translate('data.mgmt.searchSessions.status.expiresSoonInHoursTooltip', {
42-
defaultMessage: '{numHours} hours',
42+
defaultMessage: '{numHours, plural, one {# hour} other {# hours}}',
4343
values: { numHours: expiresInHours },
4444
});
4545
}

0 commit comments

Comments
 (0)