Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Canvas] Only fetch saved elements once #71310

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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