Skip to content

Commit 43abe23

Browse files
[ResponceOps][MaintenanceWindow] MX Pagination (#202539)
Fixes: #198252 In this PR I introduced pagination in MW frontend part and also pass filters(status and search) to the backend. Pagination arguments were passed to backend in another PR: https://github.com/elastic/kibana/pull/197172/files#diff-f375a192a08a6db3fbb6b6e927cecaab89ff401efc4034f00761e8fc4478734c How to test: Go to Maintenance Window, create more than 10 MW with different statuses. Try pagination, search on text and filter by status. Check the PR satisfies following conditions: - [x] 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/packages/kbn-i18n/README.md) - [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 - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] 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) --------- Co-authored-by: kibanamachine <[email protected]>
1 parent f8b7eda commit 43abe23

File tree

31 files changed

+1149
-184
lines changed

31 files changed

+1149
-184
lines changed

packages/kbn-check-mappings-update-cli/current_fields.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@
762762
],
763763
"maintenance-window": [
764764
"enabled",
765-
"events"
765+
"events",
766+
"expirationDate",
767+
"title",
768+
"updatedAt"
766769
],
767770
"map": [
768771
"bounds",

packages/kbn-check-mappings-update-cli/current_mappings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,20 @@
25212521
"events": {
25222522
"format": "epoch_millis||strict_date_optional_time",
25232523
"type": "date_range"
2524+
},
2525+
"expirationDate": {
2526+
"type": "date"
2527+
},
2528+
"title": {
2529+
"fields": {
2530+
"keyword": {
2531+
"type": "keyword"
2532+
}
2533+
},
2534+
"type": "text"
2535+
},
2536+
"updatedAt": {
2537+
"type": "date"
25242538
}
25252539
}
25262540
},

src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
132132
"lens": "5cfa2c52b979b4f8df56dd13c477e152183468b9",
133133
"lens-ui-telemetry": "8c47a9e393861f76e268345ecbadfc8a5fb1e0bd",
134134
"links": "1dd432cc94619a513b75cec43660a50be7aadc90",
135-
"maintenance-window": "bf36863f5577c2d22625258bdad906eeb4cccccc",
135+
"maintenance-window": "b84d9e0b3f89be0ae4b6fe1af6e38b4cd2554931",
136136
"map": "76c71023bd198fb6b1163b31bafd926fe2ceb9da",
137137
"metrics-data-source": "81b69dc9830699d9ead5ac8dcb9264612e2a3c89",
138138
"metrics-explorer-view": "98cf395d0e87b89ab63f173eae16735584a8ff42",

x-pack/plugins/alerting/common/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export {
6262
MAINTENANCE_WINDOW_PATHS,
6363
MAINTENANCE_WINDOW_DEEP_LINK_IDS,
6464
MAINTENANCE_WINDOW_DATE_FORMAT,
65+
MAINTENANCE_WINDOW_DEFAULT_PER_PAGE,
66+
MAINTENANCE_WINDOW_DEFAULT_TABLE_ACTIVE_PAGE,
6567
} from './maintenance_window';
6668

6769
export {

x-pack/plugins/alerting/common/maintenance_window.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ export type MaintenanceWindowDeepLinkIds =
110110
(typeof MAINTENANCE_WINDOW_DEEP_LINK_IDS)[keyof typeof MAINTENANCE_WINDOW_DEEP_LINK_IDS];
111111

112112
export const MAINTENANCE_WINDOW_DATE_FORMAT = 'MM/DD/YY hh:mm A';
113+
114+
export const MAINTENANCE_WINDOW_DEFAULT_PER_PAGE = 10 as const;
115+
export const MAINTENANCE_WINDOW_DEFAULT_TABLE_ACTIVE_PAGE = 1 as const;

x-pack/plugins/alerting/common/routes/maintenance_window/apis/find/schemas/v1.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import { maintenanceWindowResponseSchemaV1 } from '../../../response';
1010

1111
const MAX_DOCS = 10000;
1212

13+
const statusSchema = schema.oneOf([
14+
schema.literal('running'),
15+
schema.literal('finished'),
16+
schema.literal('upcoming'),
17+
schema.literal('archived'),
18+
]);
19+
1320
export const findMaintenanceWindowsRequestQuerySchema = schema.object(
1421
{
1522
// we do not need to use schema.maybe here, because if we do not pass property page, defaultValue will be used
@@ -30,6 +37,15 @@ export const findMaintenanceWindowsRequestQuerySchema = schema.object(
3037
description: 'The number of maintenance windows to return per page.',
3138
},
3239
}),
40+
search: schema.maybe(
41+
schema.string({
42+
meta: {
43+
description:
44+
'An Elasticsearch simple_query_string query that filters the objects in the response.',
45+
},
46+
})
47+
),
48+
status: schema.maybe(schema.oneOf([statusSchema, schema.arrayOf(statusSchema)])),
3349
},
3450
{
3551
validate: (params) => {

x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.test.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AppMockRenderer, createAppMockRenderer } from '../lib/test_utils';
1111
import { useFindMaintenanceWindows } from './use_find_maintenance_windows';
1212

1313
const mockAddDanger = jest.fn();
14+
const mockedHttp = jest.fn();
1415

1516
jest.mock('../utils/kibana_react', () => {
1617
const originalModule = jest.requireActual('../utils/kibana_react');
@@ -21,6 +22,7 @@ jest.mock('../utils/kibana_react', () => {
2122
return {
2223
services: {
2324
...services,
25+
http: mockedHttp,
2426
notifications: { toasts: { addDanger: mockAddDanger } },
2527
},
2628
};
@@ -33,6 +35,8 @@ jest.mock('../services/maintenance_windows_api/find', () => ({
3335

3436
const { findMaintenanceWindows } = jest.requireMock('../services/maintenance_windows_api/find');
3537

38+
const defaultHookProps = { page: 1, perPage: 10, search: '', selectedStatus: [] };
39+
3640
let appMockRenderer: AppMockRenderer;
3741

3842
describe('useFindMaintenanceWindows', () => {
@@ -42,10 +46,20 @@ describe('useFindMaintenanceWindows', () => {
4246
appMockRenderer = createAppMockRenderer();
4347
});
4448

49+
it('should call findMaintenanceWindows with correct arguments on successful scenario', async () => {
50+
renderHook(() => useFindMaintenanceWindows({ ...defaultHookProps }), {
51+
wrapper: appMockRenderer.AppWrapper,
52+
});
53+
54+
await waitFor(() =>
55+
expect(findMaintenanceWindows).toHaveBeenCalledWith({ http: mockedHttp, ...defaultHookProps })
56+
);
57+
});
58+
4559
it('should call onError if api fails', async () => {
4660
findMaintenanceWindows.mockRejectedValue('This is an error.');
4761

48-
renderHook(() => useFindMaintenanceWindows(), {
62+
renderHook(() => useFindMaintenanceWindows({ ...defaultHookProps }), {
4963
wrapper: appMockRenderer.AppWrapper,
5064
});
5165

@@ -55,7 +69,7 @@ describe('useFindMaintenanceWindows', () => {
5569
});
5670

5771
it('should not try to find maintenance windows if not enabled', async () => {
58-
renderHook(() => useFindMaintenanceWindows({ enabled: false }), {
72+
renderHook(() => useFindMaintenanceWindows({ enabled: false, ...defaultHookProps }), {
5973
wrapper: appMockRenderer.AppWrapper,
6074
});
6175

x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,32 @@ import { i18n } from '@kbn/i18n';
99
import { useQuery } from '@tanstack/react-query';
1010
import { useKibana } from '../utils/kibana_react';
1111
import { findMaintenanceWindows } from '../services/maintenance_windows_api/find';
12+
import { type MaintenanceWindowStatus } from '../../common';
1213

1314
interface UseFindMaintenanceWindowsProps {
1415
enabled?: boolean;
16+
page: number;
17+
perPage: number;
18+
search: string;
19+
selectedStatus: MaintenanceWindowStatus[];
1520
}
1621

17-
export const useFindMaintenanceWindows = (props?: UseFindMaintenanceWindowsProps) => {
18-
const { enabled = true } = props || {};
22+
export const useFindMaintenanceWindows = (params: UseFindMaintenanceWindowsProps) => {
23+
const { enabled = true, page, perPage, search, selectedStatus } = params;
1924

2025
const {
2126
http,
2227
notifications: { toasts },
2328
} = useKibana().services;
2429

2530
const queryFn = () => {
26-
return findMaintenanceWindows({ http });
31+
return findMaintenanceWindows({
32+
http,
33+
page,
34+
perPage,
35+
search,
36+
selectedStatus,
37+
});
2738
};
2839

2940
const onErrorFn = (error: Error) => {
@@ -36,24 +47,22 @@ export const useFindMaintenanceWindows = (props?: UseFindMaintenanceWindowsProps
3647
}
3748
};
3849

39-
const {
40-
isLoading,
41-
isFetching,
42-
isInitialLoading,
43-
data = [],
44-
refetch,
45-
} = useQuery({
46-
queryKey: ['findMaintenanceWindows'],
50+
const queryKey = ['findMaintenanceWindows', page, perPage, search, selectedStatus];
51+
52+
const { isLoading, isFetching, isInitialLoading, data, refetch } = useQuery({
53+
queryKey,
4754
queryFn,
4855
onError: onErrorFn,
4956
refetchOnWindowFocus: false,
5057
retry: false,
5158
cacheTime: 0,
5259
enabled,
60+
placeholderData: { maintenanceWindows: [], total: 0 },
61+
keepPreviousData: true,
5362
});
5463

5564
return {
56-
maintenanceWindows: data,
65+
data,
5766
isLoading: enabled && (isLoading || isFetching),
5867
isInitialLoading,
5968
refetch,

x-pack/plugins/alerting/public/pages/maintenance_windows/components/maintenance_windows_list.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ describe('MaintenanceWindowsList', () => {
9595
isLoading={false}
9696
items={items}
9797
readOnly={false}
98+
page={1}
99+
perPage={10}
100+
total={22}
101+
onPageChange={() => {}}
102+
onStatusChange={() => {}}
103+
selectedStatus={[]}
104+
onSearchChange={() => {}}
98105
/>
99106
);
100107

@@ -128,6 +135,13 @@ describe('MaintenanceWindowsList', () => {
128135
isLoading={false}
129136
items={items}
130137
readOnly={true}
138+
page={1}
139+
perPage={10}
140+
total={22}
141+
onPageChange={() => {}}
142+
onStatusChange={() => {}}
143+
selectedStatus={[]}
144+
onSearchChange={() => {}}
131145
/>
132146
);
133147

@@ -145,6 +159,13 @@ describe('MaintenanceWindowsList', () => {
145159
isLoading={false}
146160
items={items}
147161
readOnly={false}
162+
page={1}
163+
perPage={10}
164+
total={22}
165+
onPageChange={() => {}}
166+
onStatusChange={() => {}}
167+
selectedStatus={[]}
168+
onSearchChange={() => {}}
148169
/>
149170
);
150171
fireEvent.click(result.getByTestId('refresh-button'));

0 commit comments

Comments
 (0)