From 04b4c2f7d5e998638930c178e23b02393d851d6f Mon Sep 17 00:00:00 2001 From: Stig Ofstad Date: Mon, 11 Mar 2024 09:29:26 +0100 Subject: [PATCH] fix(viewCreator): cache reference calculation --- .../src/view_selector/SidebarPlugin.tsx | 1 + packages/dm-core/src/components/EntityView.tsx | 6 +++++- .../src/components/ViewCreator/ViewCreator.tsx | 12 +++++++----- packages/dm-core/styleMock.js | 2 ++ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 packages/dm-core/styleMock.js diff --git a/packages/dm-core-plugins/src/view_selector/SidebarPlugin.tsx b/packages/dm-core-plugins/src/view_selector/SidebarPlugin.tsx index e10540b1a..573168b9b 100644 --- a/packages/dm-core-plugins/src/view_selector/SidebarPlugin.tsx +++ b/packages/dm-core-plugins/src/view_selector/SidebarPlugin.tsx @@ -46,6 +46,7 @@ export const SidebarPlugin = ( /> {viewItem.viewConfig ? ( { onChange, } = props if (!type) - throw new Error(` must be called with a type. Got "${type}"`) + throw new Error( + ` must be called with a type. Got "${type}", idReference: "${idReference}"` + ) const { recipe, isLoading, error, getUiPlugin } = useRecipe( type, recipeName, @@ -44,6 +46,7 @@ export const EntityView = (props: IEntityView): React.ReactElement => { // Refresh Button stuff const [reloadCounter, setReloadCounter] = useState(0) const [hoverRefresh, setHoverRefresh] = useState(false) + if (isLoading) return (
@@ -63,6 +66,7 @@ export const EntityView = (props: IEntityView): React.ReactElement => { return
No compatible uiRecipes for entity
const refreshable = showRefreshButton ?? recipe.showRefreshButton ?? false + return ( }> diff --git a/packages/dm-core/src/components/ViewCreator/ViewCreator.tsx b/packages/dm-core/src/components/ViewCreator/ViewCreator.tsx index 92ebab793..801ef4553 100644 --- a/packages/dm-core/src/components/ViewCreator/ViewCreator.tsx +++ b/packages/dm-core/src/components/ViewCreator/ViewCreator.tsx @@ -1,6 +1,6 @@ import { Typography } from '@equinor/eds-core-react' import { AxiosResponse } from 'axios' -import React, { useEffect, useState } from 'react' +import React, { useEffect, useMemo, useState } from 'react' import { EntityView, Loading, TAttribute, useApplication } from '../../index' import { IUIPlugin, @@ -43,9 +43,12 @@ export const ViewCreator = (props: TViewCreator): React.ReactElement => { const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState() const [attribute, setAttribute] = useState() - const [directAddress, setDirectAddress] = useState(idReference) + const [directAddress, setDirectAddress] = useState() - const reference = getTarget(idReference, viewConfig) + const reference = useMemo( + () => getTarget(idReference, viewConfig), + [idReference, viewConfig] + ) useEffect(() => { dmssAPI @@ -61,7 +64,7 @@ export const ViewCreator = (props: TViewCreator): React.ReactElement => { .finally(() => setIsLoading(false)) }, [reference]) - if (isLoading) return + if (isLoading || !directAddress) return if (error) return ( @@ -76,7 +79,6 @@ export const ViewCreator = (props: TViewCreator): React.ReactElement => { throw new Error( 'Cannot create a View without a "viewConfig". Sure the attribute is properly named?' ) - if (isInlineRecipeViewConfig(viewConfig)) { return (