[Canvas] [8.0] Fixes ESDocs Index argument not being initially applied. (#123026)

This commit is contained in:
Yaroslav Kuznietsov 2022-01-14 17:53:18 +02:00 committed by GitHub
parent ab38a7073c
commit 98e8d874f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import React from 'react';
import React, { useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import {
EuiFormRow,
@ -27,13 +27,16 @@ import { DataSourceStrings, LUCENE_QUERY_URL } from '../../../i18n';
const { ESDocs: strings } = DataSourceStrings;
const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => {
const setArg = (name, value) => {
updateArgs &&
updateArgs({
...args,
...setSimpleArg(name, value),
});
};
const setArg = useCallback(
(name, value) => {
updateArgs &&
updateArgs({
...args,
...setSimpleArg(name, value),
});
},
[args, updateArgs]
);
// TODO: This is a terrible way of doing defaults. We need to find a way to read the defaults for the function
// and set them for the data source UI.
@ -73,6 +76,12 @@ const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => {
const index = getIndex();
useEffect(() => {
if (getSimpleArg('index', args)[0] !== index) {
setArg('index', index);
}
}, [args, index, setArg]);
const sortOptions = [
{ value: 'asc', text: strings.getAscendingOption() },
{ value: 'desc', text: strings.getDescendingOption() },