Skip to content

Commit 72e7bc6

Browse files
author
CJ Cenizal
committed
Add tooltip to State header in Execution History flyout. Add Last executed header to Action Statuses Panel and tooltips. Update tests.
1 parent 6dc2959 commit 72e7bc6

File tree

9 files changed

+176
-85
lines changed

9 files changed

+176
-85
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import moment, { Moment } from 'moment';
9+
import { ACTION_STATES, WATCH_STATES } from '../common/constants';
10+
import { ClientWatchStatusModel, ClientActionStatusModel } from '../common/types';
11+
12+
interface WatchHistory {
13+
id: string;
14+
watchId: string;
15+
startTime: Moment;
16+
watchStatus: {
17+
state: ClientWatchStatusModel['state'];
18+
comment?: string;
19+
lastExecution: Moment;
20+
actionStatuses?: Array<{
21+
id: string;
22+
state: ClientActionStatusModel['state'];
23+
}>;
24+
};
25+
details?: object;
26+
}
27+
28+
export const getWatchHistory = ({
29+
id,
30+
startTime,
31+
}: {
32+
id: string;
33+
startTime: string;
34+
}): WatchHistory => ({
35+
id,
36+
startTime: moment(startTime),
37+
watchId: id,
38+
watchStatus: {
39+
state: WATCH_STATES.OK,
40+
lastExecution: moment('2019-06-03T19:44:11.088Z'),
41+
actionStatuses: [
42+
{
43+
id: 'a',
44+
state: ACTION_STATES.OK,
45+
},
46+
],
47+
},
48+
details: {},
49+
});

x-pack/plugins/watcher/__fixtures__/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
*/
77

88
export * from './watch';
9-
export * from './watch_history';
9+
export * from './get_watch_history';
1010
export * from './execute_details';

x-pack/plugins/watcher/__fixtures__/watch.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* 2.0.
66
*/
77

8-
import { Moment } from 'moment';
98
import { getRandomString } from '@kbn/test-jest-helpers';
9+
import { ClientWatchStatusModel } from '../common/types';
10+
import { WATCH_STATES, WATCH_STATE_COMMENTS } from '../common/constants';
1011

1112
interface Watch {
1213
id: string;
@@ -22,14 +23,7 @@ interface Watch {
2223
timeWindowUnit?: string;
2324
threshold?: number[];
2425
isSystemWatch: boolean;
25-
watchStatus: {
26-
state: 'OK' | 'Firing' | 'Error' | 'Config error' | 'Disabled';
27-
comment?: string;
28-
lastMetCondition?: Moment;
29-
lastChecked?: Moment;
30-
isActive: boolean;
31-
actionStatuses?: any[];
32-
};
26+
watchStatus: ClientWatchStatusModel;
3327
}
3428

3529
export const getWatch = ({
@@ -47,8 +41,13 @@ export const getWatch = ({
4741
threshold,
4842
isSystemWatch = false,
4943
watchStatus = {
50-
state: 'OK',
44+
id: 'a',
45+
state: WATCH_STATES.OK,
5146
isActive: true,
47+
lastChecked: null,
48+
lastMetCondition: null,
49+
comment: WATCH_STATE_COMMENTS.OK,
50+
actionStatuses: [],
5251
},
5352
}: Partial<Watch> = {}): Watch => ({
5453
id,

x-pack/plugins/watcher/__fixtures__/watch_history.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

x-pack/plugins/watcher/__jest__/client_integration/watch_list_page.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ describe('<WatchListPage />', () => {
8686
// Expect "watch1" is only visible in the table
8787
expect(tableCellsValues.length).toEqual(1);
8888
const row = tableCellsValues[0];
89-
const { name, id, watchStatus } = watch1;
89+
const { name, id } = watch1;
9090

9191
const expectedRow = [
9292
'', // checkbox
9393
id,
9494
name,
95-
watchStatus.state,
96-
'', // comment
95+
'', // state
9796
'', // lastMetCondition
9897
'', // lastChecked
99-
'', // actions
98+
'', // comment
99+
'', // row actions
100100
];
101101

102102
expect(row).toEqual(expectedRow);
@@ -128,7 +128,7 @@ describe('<WatchListPage />', () => {
128128
const { table } = testBed;
129129
const { tableCellsValues } = table.getMetaData('watchesTable');
130130

131-
const getExpectedValue = (value: any) => (typeof value === 'undefined' ? '' : value);
131+
const getExpectedValue = (value: any) => value ?? '';
132132

133133
tableCellsValues.forEach((row, i) => {
134134
const watch = watches[i];
@@ -138,11 +138,11 @@ describe('<WatchListPage />', () => {
138138
'',
139139
id, // required value
140140
getExpectedValue(name),
141-
watchStatus.state, // required value
142-
getExpectedValue(watchStatus.comment),
141+
'', // state
143142
getExpectedValue(watchStatus.lastMetCondition),
144143
getExpectedValue(watchStatus.lastChecked),
145-
'',
144+
getExpectedValue(watchStatus.comment),
145+
'', // row actions
146146
]);
147147
});
148148
});

x-pack/plugins/watcher/__jest__/client_integration/watch_status_page.test.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { API_BASE_PATH } from '../../common/constants';
1616

1717
const { setup } = pageHelpers.watchStatusPage;
1818

19-
const watchHistory1 = getWatchHistory({ startTime: '2019-06-04T01:11:11.294' });
20-
const watchHistory2 = getWatchHistory({ startTime: '2019-06-04T01:10:10.987Z' });
19+
const watchHistory1 = getWatchHistory({ id: 'a', startTime: '2019-06-04T01:11:11.294' });
20+
const watchHistory2 = getWatchHistory({ id: 'b', startTime: '2019-06-04T01:10:10.987Z' });
2121

2222
const watchHistoryItems = { watchHistoryItems: [watchHistory1, watchHistory2] };
2323

@@ -28,11 +28,13 @@ const watch = {
2828
watchStatus: {
2929
state: WATCH_STATES.ACTIVE,
3030
isActive: true,
31+
lastExecution: moment('2019-06-03T19:44:11.088Z'),
3132
actionStatuses: [
3233
{
3334
id: ACTION_ID,
3435
state: ACTION_STATES.OK,
3536
isAckable: true,
37+
lastExecution: moment('2019-06-03T19:44:11.088Z'),
3638
},
3739
],
3840
},
@@ -100,7 +102,8 @@ describe('<WatchStatusPage />', () => {
100102
expect(row).toEqual([
101103
getExpectedValue(moment(startTime).format()),
102104
getExpectedValue(watchStatus.state),
103-
getExpectedValue(watchStatus.comment),
105+
'',
106+
'',
104107
]);
105108
});
106109
});
@@ -231,16 +234,20 @@ describe('<WatchStatusPage />', () => {
231234

232235
tableCellsValues.forEach((row, i) => {
233236
const action = watch.watchStatus.actionStatuses[i];
234-
const { id, state, isAckable } = action;
237+
const { id, state, lastExecution, isAckable } = action;
235238

236-
expect(row).toEqual([id, state, isAckable ? 'Acknowledge' : '']);
239+
expect(row).toEqual([
240+
id, // Name
241+
state, // State
242+
lastExecution.format(), // Last executed
243+
isAckable ? 'Acknowledge' : '', // Row actions
244+
]);
237245
});
238246
});
239247

240248
test('should allow an action to be acknowledged', async () => {
241249
const { actions, table } = testBed;
242-
243-
httpRequestsMockHelpers.setAcknowledgeWatchResponse(WATCH_ID, ACTION_ID, {
250+
const watchHistoryItem = {
244251
watchStatus: {
245252
state: WATCH_STATES.FIRING,
246253
isActive: true,
@@ -250,10 +257,13 @@ describe('<WatchStatusPage />', () => {
250257
id: ACTION_ID,
251258
state: ACTION_STATES.ACKNOWLEDGED,
252259
isAckable: false,
260+
lastExecution: moment('2019-06-03T19:44:11.088Z'),
253261
},
254262
],
255263
},
256-
});
264+
};
265+
266+
httpRequestsMockHelpers.setAcknowledgeWatchResponse(WATCH_ID, ACTION_ID, watchHistoryItem);
257267

258268
await actions.clickAcknowledgeButton(0);
259269

@@ -268,7 +278,12 @@ describe('<WatchStatusPage />', () => {
268278
const { tableCellsValues } = table.getMetaData('watchActionStatusTable');
269279

270280
tableCellsValues.forEach((row) => {
271-
expect(row).toEqual([ACTION_ID, ACTION_STATES.ACKNOWLEDGED, '']);
281+
expect(row).toEqual([
282+
ACTION_ID, // Name
283+
ACTION_STATES.ACKNOWLEDGED, // State
284+
watchHistoryItem.watchStatus.actionStatuses[0].lastExecution.format(), // Last executed
285+
'', // Row actions
286+
]);
272287
});
273288
});
274289
});

x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit_form.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import React, { Fragment, useContext, useState } from 'react';
8+
import React, { Fragment, useContext, useEffect, useState } from 'react';
99

1010
import {
1111
EuiButton,
@@ -67,9 +67,11 @@ export const JsonWatchEditForm = () => {
6767
json: hasActionErrors ? [...errors.json, invalidActionMessage] : [...errors.json],
6868
};
6969

70-
if (errors.json.length === 0) {
71-
setWatchProperty('watch', JSON.parse(watch.watchString));
72-
}
70+
useEffect(() => {
71+
if (errors.json.length === 0) {
72+
setWatchProperty('watch', JSON.parse(watch.watchString));
73+
}
74+
}, [setWatchProperty, errors, watch]);
7375

7476
return (
7577
<Fragment>

x-pack/plugins/watcher/public/application/sections/watch_status_page/components/action_statuses_panel.tsx

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import React, { Fragment, useState, useEffect, useContext } from 'react';
99
import { i18n } from '@kbn/i18n';
1010
import { FormattedMessage } from '@kbn/i18n-react';
11+
import { Moment } from 'moment';
1112

1213
import {
1314
EuiInMemoryTable,
@@ -18,6 +19,7 @@ import {
1819
EuiFlyout,
1920
EuiFlyoutHeader,
2021
EuiFlyoutBody,
22+
EuiIcon,
2123
} from '@elastic/eui';
2224

2325
import { PAGINATION } from '../../../../../common/constants';
@@ -72,17 +74,57 @@ export const ActionStatusesPanel = () => {
7274
defaultMessage: 'Name',
7375
}),
7476
sortable: true,
75-
truncateText: true,
77+
truncateText: false,
7678
},
7779
{
7880
field: 'state',
79-
name: i18n.translate('xpack.watcher.sections.watchDetail.watchTable.stateHeader', {
80-
defaultMessage: 'State',
81-
}),
81+
name: (
82+
<EuiToolTip
83+
content={i18n.translate(
84+
'xpack.watcher.sections.watchDetail.watchTable.stateHeader.tooltipText',
85+
{
86+
defaultMessage: 'OK, acked, throttled, or error state',
87+
}
88+
)}
89+
>
90+
<span>
91+
{i18n.translate('xpack.watcher.sections.watchDetail.watchTable.stateHeader', {
92+
defaultMessage: 'State',
93+
})}{' '}
94+
<EuiIcon size="s" color="subdued" type="questionInCircle" className="eui-alignTop" />
95+
</span>
96+
</EuiToolTip>
97+
),
8298
sortable: true,
8399
truncateText: true,
84100
render: (state: string) => <ActionStateBadge state={state} />,
85101
},
102+
{
103+
field: 'lastExecution',
104+
name: (
105+
<EuiToolTip
106+
content={i18n.translate(
107+
'xpack.watcher.sections.watchHistory.watchActionStatusTable.lastExecuted.tooltipText',
108+
{
109+
defaultMessage: `When this action was last executed`,
110+
}
111+
)}
112+
>
113+
<span>
114+
{i18n.translate(
115+
'xpack.watcher.sections.watchHistory.watchActionStatusTable.lastExecuted',
116+
{
117+
defaultMessage: 'Last executed',
118+
}
119+
)}{' '}
120+
<EuiIcon size="s" color="subdued" type="questionInCircle" className="eui-alignTop" />
121+
</span>
122+
</EuiToolTip>
123+
),
124+
sortable: true,
125+
truncateText: false,
126+
render: (lastExecution?: Moment) => lastExecution?.format() ?? '',
127+
},
86128
];
87129

88130
const errorColumn = {

0 commit comments

Comments
 (0)