Skip to content

Commit

Permalink
fix(viewCreator): cache reference calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Mar 11, 2024
1 parent a69493a commit 04b4c2f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const SidebarPlugin = (
/>
{viewItem.viewConfig ? (
<ViewCreator
key={`${viewItem.rootEntityId}-${viewItem.viewConfig.scope}`}
idReference={viewItem.rootEntityId}
viewConfig={viewItem.viewConfig}
onOpen={addView}
Expand Down
6 changes: 5 additions & 1 deletion packages/dm-core/src/components/EntityView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export const EntityView = (props: IEntityView): React.ReactElement => {
onChange,
} = props
if (!type)
throw new Error(`<EntityView> must be called with a type. Got "${type}"`)
throw new Error(
`<EntityView> must be called with a type. Got "${type}", idReference: "${idReference}"`
)
const { recipe, isLoading, error, getUiPlugin } = useRecipe(
type,
recipeName,
Expand All @@ -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 (
<div style={{ alignSelf: 'center', padding: '50px' }}>
Expand All @@ -63,6 +66,7 @@ export const EntityView = (props: IEntityView): React.ReactElement => {
return <div className='w-full flex'>No compatible uiRecipes for entity</div>

const refreshable = showRefreshButton ?? recipe.showRefreshButton ?? false

return (
<Suspense fallback={<Loading />}>
<ErrorBoundary message={`Plugin "${recipe.plugin}" crashed...`}>
Expand Down
12 changes: 7 additions & 5 deletions packages/dm-core/src/components/ViewCreator/ViewCreator.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -43,9 +43,12 @@ export const ViewCreator = (props: TViewCreator): React.ReactElement => {
const [isLoading, setIsLoading] = useState<boolean>(true)
const [error, setError] = useState<Error>()
const [attribute, setAttribute] = useState<TAttribute>()
const [directAddress, setDirectAddress] = useState<string>(idReference)
const [directAddress, setDirectAddress] = useState<string>()

const reference = getTarget(idReference, viewConfig)
const reference = useMemo(
() => getTarget(idReference, viewConfig),
[idReference, viewConfig]
)

useEffect(() => {
dmssAPI
Expand All @@ -61,7 +64,7 @@ export const ViewCreator = (props: TViewCreator): React.ReactElement => {
.finally(() => setIsLoading(false))
}, [reference])

if (isLoading) return <Loading />
if (isLoading || !directAddress) return <Loading />
if (error)
return (
<Typography>
Expand All @@ -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 (
<InlineRecipeView
Expand Down
2 changes: 2 additions & 0 deletions packages/dm-core/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Tests will fail if you delete this file.
// Has something to do with importing css files...

0 comments on commit 04b4c2f

Please sign in to comment.