Skip to content

Commit ffdc507

Browse files
authored
fixed pagination in connectors list (#83638)
Ensures we specify the page on the EuiTable so that pagination is retain after rerenders.
1 parent 514b50e commit ffdc507

File tree

2 files changed

+72
-28
lines changed

2 files changed

+72
-28
lines changed

x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_list.test.tsx

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { chartPluginMock } from '../../../../../../../../src/plugins/charts/publ
1616
import { dataPluginMock } from '../../../../../../../../src/plugins/data/public/mocks';
1717
import { alertingPluginMock } from '../../../../../../alerts/public/mocks';
1818
import { featuresPluginMock } from '../../../../../../features/public/mocks';
19+
import { ActionConnector } from '../../../../types';
20+
import { times } from 'lodash';
1921

2022
jest.mock('../../../lib/action_connector_api', () => ({
2123
loadAllActions: jest.fn(),
@@ -109,36 +111,38 @@ describe('actions_connectors_list component empty', () => {
109111
describe('actions_connectors_list component with items', () => {
110112
let wrapper: ReactWrapper<any>;
111113

112-
async function setup() {
114+
async function setup(actionConnectors?: ActionConnector[]) {
113115
const { loadAllActions, loadActionTypes } = jest.requireMock(
114116
'../../../lib/action_connector_api'
115117
);
116-
loadAllActions.mockResolvedValueOnce([
117-
{
118-
id: '1',
119-
actionTypeId: 'test',
120-
description: 'My test',
121-
isPreconfigured: false,
122-
referencedByCount: 1,
123-
config: {},
124-
},
125-
{
126-
id: '2',
127-
actionTypeId: 'test2',
128-
description: 'My test 2',
129-
referencedByCount: 1,
130-
isPreconfigured: false,
131-
config: {},
132-
},
133-
{
134-
id: '3',
135-
actionTypeId: 'test2',
136-
description: 'My preconfigured test 2',
137-
referencedByCount: 1,
138-
isPreconfigured: true,
139-
config: {},
140-
},
141-
]);
118+
loadAllActions.mockResolvedValueOnce(
119+
actionConnectors ?? [
120+
{
121+
id: '1',
122+
actionTypeId: 'test',
123+
description: 'My test',
124+
isPreconfigured: false,
125+
referencedByCount: 1,
126+
config: {},
127+
},
128+
{
129+
id: '2',
130+
actionTypeId: 'test2',
131+
description: 'My test 2',
132+
referencedByCount: 1,
133+
isPreconfigured: false,
134+
config: {},
135+
},
136+
{
137+
id: '3',
138+
actionTypeId: 'test2',
139+
description: 'My preconfigured test 2',
140+
referencedByCount: 1,
141+
isPreconfigured: true,
142+
config: {},
143+
},
144+
]
145+
);
142146
loadActionTypes.mockResolvedValueOnce([
143147
{
144148
id: 'test',
@@ -217,6 +221,36 @@ describe('actions_connectors_list component with items', () => {
217221
expect(wrapper.find('[data-test-subj="preConfiguredTitleMessage"]')).toHaveLength(2);
218222
});
219223

224+
it('supports pagination', async () => {
225+
await setup(
226+
times(15, (index) => ({
227+
id: `connector${index}`,
228+
actionTypeId: 'test',
229+
name: `My test ${index}`,
230+
secrets: {},
231+
description: `My test ${index}`,
232+
isPreconfigured: false,
233+
referencedByCount: 1,
234+
config: {},
235+
}))
236+
);
237+
expect(wrapper.find('[data-test-subj="actionsTable"]').first().prop('pagination'))
238+
.toMatchInlineSnapshot(`
239+
Object {
240+
"initialPageIndex": 0,
241+
"pageIndex": 0,
242+
}
243+
`);
244+
wrapper.find('[data-test-subj="pagination-button-1"]').first().simulate('click');
245+
expect(wrapper.find('[data-test-subj="actionsTable"]').first().prop('pagination'))
246+
.toMatchInlineSnapshot(`
247+
Object {
248+
"initialPageIndex": 0,
249+
"pageIndex": 1,
250+
}
251+
`);
252+
});
253+
220254
test('if select item for edit should render ConnectorEditFlyout', async () => {
221255
await setup();
222256
await wrapper.find('[data-test-subj="edit1"]').first().simulate('click');

x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
EuiToolTip,
1919
EuiButtonIcon,
2020
EuiEmptyPrompt,
21+
Criteria,
2122
} from '@elastic/eui';
2223
import { i18n } from '@kbn/i18n';
2324
import { omit } from 'lodash';
@@ -54,6 +55,7 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
5455

5556
const [actionTypesIndex, setActionTypesIndex] = useState<ActionTypeIndex | undefined>(undefined);
5657
const [actions, setActions] = useState<ActionConnector[]>([]);
58+
const [pageIndex, setPageIndex] = useState<number>(0);
5759
const [selectedItems, setSelectedItems] = useState<ActionConnectorTableItem[]>([]);
5860
const [isLoadingActionTypes, setIsLoadingActionTypes] = useState<boolean>(false);
5961
const [isLoadingActions, setIsLoadingActions] = useState<boolean>(false);
@@ -233,7 +235,15 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
233235
: '',
234236
})}
235237
data-test-subj="actionsTable"
236-
pagination={true}
238+
pagination={{
239+
initialPageIndex: 0,
240+
pageIndex,
241+
}}
242+
onTableChange={({ page }: Criteria<ActionConnectorTableItem>) => {
243+
if (page) {
244+
setPageIndex(page.index);
245+
}
246+
}}
237247
selection={
238248
canDelete
239249
? {

0 commit comments

Comments
 (0)