Skip to content

Commit 812c7ee

Browse files
committed
Add loadMoreOptions callback
1 parent 9d74ea8 commit 812c7ee

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/platform/plugins/shared/controls/public/controls/data_controls/options_list_control/components/options_list_popover_action_bar.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import React, { useMemo } from 'react';
10+
import React, { useCallback, useMemo } from 'react';
1111

1212
import {
1313
EuiButtonEmpty,
@@ -73,6 +73,11 @@ export const OptionsListPopoverActionBar = ({
7373
[searchTechnique, compatibleSearchTechniques]
7474
);
7575

76+
const loadMoreOptions = useCallback(() => {
77+
stateManager.requestSize.next(Math.min(totalCardinality, MAX_OPTIONS_LIST_REQUEST_SIZE));
78+
api.loadMoreSubject.next(); // trigger refetch with loadMoreSubject
79+
}, [api.loadMoreSubject, stateManager, totalCardinality]);
80+
7681
return (
7782
<div className="optionsList__actions">
7883
{compatibleSearchTechniques.length > 0 && (
@@ -117,15 +122,8 @@ export const OptionsListPopoverActionBar = ({
117122
availableOptions.length < 1 || totalCardinality < 1 || totalCardinality > 100
118123
}
119124
onClick={() => {
120-
if (
121-
availableOptions.length > 0 &&
122-
totalCardinality > availableOptions.length
123-
) {
124-
// load more options
125-
stateManager.requestSize.next(
126-
Math.min(totalCardinality, MAX_OPTIONS_LIST_REQUEST_SIZE)
127-
);
128-
api.loadMoreSubject.next(); // trigger refetch with loadMoreSubject
125+
if (totalCardinality > availableOptions.length) {
126+
loadMoreOptions();
129127

130128
const subscription = api.availableOptions$.subscribe((options = []) => {
131129
if (options.length === totalCardinality) {
@@ -150,17 +148,12 @@ export const OptionsListPopoverActionBar = ({
150148
>
151149
<EuiButtonEmpty
152150
size="s"
153-
isDisabled={!availableOptions || totalCardinality < 1 || totalCardinality > 100}
151+
isDisabled={
152+
availableOptions.length < 1 || totalCardinality < 1 || totalCardinality > 100
153+
}
154154
onClick={() => {
155-
if (
156-
availableOptions.length > 0 &&
157-
totalCardinality > availableOptions.length
158-
) {
159-
// load more options
160-
stateManager.requestSize.next(
161-
Math.min(totalCardinality, MAX_OPTIONS_LIST_REQUEST_SIZE)
162-
);
163-
api.loadMoreSubject.next(); // trigger refetch with loadMoreSubject
155+
if (totalCardinality > availableOptions.length) {
156+
loadMoreOptions();
164157

165158
const subscription = api.availableOptions$.subscribe((options = []) => {
166159
if (options.length === totalCardinality) {

0 commit comments

Comments
 (0)