[Metrics UI] Saved views bugs (#72518)

* Add test for logs and metrics telemetry

* wait before you go

* Remove kubenetes

* Fix type check

* Add back kubernetes test

* Remove kubernetes

* Don't allow deleting default default view.

* Fix bug with duplicate loads of data.

Because the load data function takes options.source and the source of options can change, we need to remove it from deps

* Remove unused variable

* Reload when loadData function is changed

* Don't send the request immediately

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Phillip Burch 2020-07-27 21:28:39 -05:00 committed by GitHub
parent 82d7e7db69
commit cc84ee3185
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 8 deletions

View file

@ -96,6 +96,10 @@ export function SavedViewManageViewsFlyout<ViewState>({
const renderDeleteAction = useCallback( const renderDeleteAction = useCallback(
(item: SavedView<ViewState>) => { (item: SavedView<ViewState>) => {
if (item.id === '0') {
return <></>;
}
return ( return (
<DeleteConfimation <DeleteConfimation
isDisabled={item.isDefault} isDisabled={item.isDefault}

View file

@ -161,7 +161,7 @@ export function SavedViewsToolbarControls<ViewState>(props: Props<ViewState>) {
/> />
</EuiFlexItem> </EuiFlexItem>
<EuiFlexItem> <EuiFlexItem>
<EuiDescriptionList onClick={showSavedViewMenu}> <EuiDescriptionList compressed={true} onClick={showSavedViewMenu}>
<EuiDescriptionListTitle> <EuiDescriptionListTitle>
<FormattedMessage <FormattedMessage
defaultMessage="Current view" defaultMessage="Current view"

View file

@ -50,7 +50,7 @@ export const useSavedView = (props: Props) => {
const { data, loading, find, error: errorOnFind, hasView } = useFindSavedObject< const { data, loading, find, error: errorOnFind, hasView } = useFindSavedObject<
SavedViewSavedObject<ViewState> SavedViewSavedObject<ViewState>
>(viewType); >(viewType);
const [shouldLoadDefault] = useState(props.shouldLoadDefault);
const [currentView, setCurrentView] = useState<SavedView<any> | null>(null); const [currentView, setCurrentView] = useState<SavedView<any> | null>(null);
const [loadingDefaultView, setLoadingDefaultView] = useState<boolean | null>(null); const [loadingDefaultView, setLoadingDefaultView] = useState<boolean | null>(null);
const { create, error: errorOnCreate, data: createdViewData, createdId } = useCreateSavedObject( const { create, error: errorOnCreate, data: createdViewData, createdId } = useCreateSavedObject(
@ -211,8 +211,6 @@ export const useSavedView = (props: Props) => {
}, [setCurrentView, defaultViewId, defaultViewState]); }, [setCurrentView, defaultViewId, defaultViewState]);
useEffect(() => { useEffect(() => {
const shouldLoadDefault = props.shouldLoadDefault;
if (loadingDefaultView || currentView || !shouldLoadDefault) { if (loadingDefaultView || currentView || !shouldLoadDefault) {
return; return;
} }
@ -225,7 +223,7 @@ export const useSavedView = (props: Props) => {
} }
}, [ }, [
loadDefaultView, loadDefaultView,
props.shouldLoadDefault, shouldLoadDefault,
setDefault, setDefault,
loadingDefaultView, loadingDefaultView,
currentView, currentView,
@ -246,7 +244,7 @@ export const useSavedView = (props: Props) => {
errorOnUpdate, errorOnUpdate,
errorOnFind, errorOnFind,
errorOnCreate: createError, errorOnCreate: createError,
shouldLoadDefault: props.shouldLoadDefault, shouldLoadDefault,
makeDefault, makeDefault,
sourceIsLoading, sourceIsLoading,
deleteView, deleteView,

View file

@ -55,7 +55,8 @@ export const Layout = () => {
sourceId, sourceId,
currentTime, currentTime,
accountId, accountId,
region region,
false
); );
const options = { const options = {

View file

@ -57,7 +57,8 @@ export const MetricsExplorerPage = ({ source, derivedIndexPattern }: MetricsExpl
// load metrics explorer data after default view loaded, unless we're not loading a view // load metrics explorer data after default view loaded, unless we're not loading a view
loadData(); loadData();
} }
}, [loadData, currentView, shouldLoadDefault]); /* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [loadData, shouldLoadDefault]);
return ( return (
<EuiErrorBoundary> <EuiErrorBoundary>