Skip to content

Commit

Permalink
Only fetch saved elements once (elastic#71310)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Corey Robertson and elasticmachine committed Jul 14, 2020
1 parent b0ba9e6 commit f16c3a0
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment, ChangeEvent, FunctionComponent, useState, useEffect } from 'react';
import React, {
Fragment,
ChangeEvent,
FunctionComponent,
useState,
useEffect,
useRef,
} from 'react';
import PropTypes from 'prop-types';
import {
EuiModal,
Expand Down Expand Up @@ -72,12 +79,16 @@ export const SavedElementsModal: FunctionComponent<Props> = ({
removeCustomElement,
updateCustomElement,
}) => {
const hasLoadedElements = useRef<boolean>(false);
const [elementToDelete, setElementToDelete] = useState<CustomElement | null>(null);
const [elementToEdit, setElementToEdit] = useState<CustomElement | null>(null);

useEffect(() => {
findCustomElements();
});
if (!hasLoadedElements.current) {
hasLoadedElements.current = true;
findCustomElements();
}
}, [findCustomElements, hasLoadedElements]);

const showEditModal = (element: CustomElement) => setElementToEdit(element);
const hideEditModal = () => setElementToEdit(null);
Expand Down

0 comments on commit f16c3a0

Please sign in to comment.