From 0cfbec72c84d97c72981ef901a46a84201f66d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20L=C3=BCdin?= <13187726+Masterchen09@users.noreply.github.com> Date: Wed, 25 Jan 2023 02:38:07 +0100 Subject: [PATCH] fix(ui): only use visible and enabled tabs for selected tab and routing in entity profiles (#6629) Co-authored-by: John Joyce --- .../app/entity/dashboard/DashboardEntity.tsx | 16 +++++++-------- .../src/app/entity/shared/EntityContext.tsx | 5 +++-- .../containers/profile/EntityProfile.tsx | 17 +++++++++++----- .../containers/profile/header/EntityTabs.tsx | 20 +++++++++---------- .../src/app/entity/shared/types.ts | 1 + 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/datahub-web-react/src/app/entity/dashboard/DashboardEntity.tsx b/datahub-web-react/src/app/entity/dashboard/DashboardEntity.tsx index 3bc21b2cce..c2fe713039 100644 --- a/datahub-web-react/src/app/entity/dashboard/DashboardEntity.tsx +++ b/datahub-web-react/src/app/entity/dashboard/DashboardEntity.tsx @@ -94,6 +94,14 @@ export class DashboardEntity implements Entity { enabled: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.charts?.total || 0) > 0, }, }, + { + name: 'Datasets', + component: DashboardDatasetsTab, + display: { + visible: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.datasets?.total || 0) > 0, + enabled: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.datasets?.total || 0) > 0, + }, + }, { name: 'Documentation', component: DocumentationTab, @@ -117,14 +125,6 @@ export class DashboardEntity implements Entity { name: 'Properties', component: PropertiesTab, }, - { - name: 'Datasets', - component: DashboardDatasetsTab, - display: { - visible: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.datasets?.total || 0) > 0, - enabled: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.datasets?.total || 0) > 0, - }, - }, ]} sidebarSections={[ { diff --git a/datahub-web-react/src/app/entity/shared/EntityContext.tsx b/datahub-web-react/src/app/entity/shared/EntityContext.tsx index c6b31c1b77..02f36cb2f0 100644 --- a/datahub-web-react/src/app/entity/shared/EntityContext.tsx +++ b/datahub-web-react/src/app/entity/shared/EntityContext.tsx @@ -7,6 +7,7 @@ const EntityContext = React.createContext({ urn: '', entityType: EntityType.Dataset, entityData: null, + loading: true, baseEntity: null, updateEntity: () => Promise.resolve({}), routeToTab: () => {}, @@ -33,8 +34,8 @@ export const useEntityUpdate = (): UpdateEntityType | null | undefined => }; export const useEntityData = () => { - const { urn, entityType, entityData } = useContext(EntityContext); - return { urn, entityType, entityData }; + const { urn, entityType, entityData, loading } = useContext(EntityContext); + return { urn, entityType, entityData, loading }; }; export const useRouteToTab = () => { diff --git a/datahub-web-react/src/app/entity/shared/containers/profile/EntityProfile.tsx b/datahub-web-react/src/app/entity/shared/containers/profile/EntityProfile.tsx index 74c9daa36e..1ac5c99ea5 100644 --- a/datahub-web-react/src/app/entity/shared/containers/profile/EntityProfile.tsx +++ b/datahub-web-react/src/app/entity/shared/containers/profile/EntityProfile.tsx @@ -245,7 +245,15 @@ export const EntityProfile = ({ }, })) || []; - const routedTab = useRoutedTab([...tabsWithDefaults, ...autoRenderTabs]); + const visibleTabs = [...tabsWithDefaults, ...autoRenderTabs].filter((tab) => + tab.display?.visible(entityData, dataPossiblyCombinedWithSiblings), + ); + + const enabledAndVisibleTabs = visibleTabs.filter((tab) => + tab.display?.enabled(entityData, dataPossiblyCombinedWithSiblings), + ); + + const routedTab = useRoutedTab(enabledAndVisibleTabs); if (isCompact) { return ( @@ -254,6 +262,7 @@ export const EntityProfile = ({ urn, entityType, entityData, + loading, baseEntity: dataPossiblyCombinedWithSiblings, dataNotCombinedWithSiblings, updateEntity, @@ -291,6 +300,7 @@ export const EntityProfile = ({ urn, entityType, entityData, + loading, baseEntity: dataPossiblyCombinedWithSiblings, dataNotCombinedWithSiblings, updateEntity, @@ -344,10 +354,7 @@ export const EntityProfile = ({ subHeader={subHeader} refreshBrowser={refreshBrowser} /> - + {routedTab && } diff --git a/datahub-web-react/src/app/entity/shared/containers/profile/header/EntityTabs.tsx b/datahub-web-react/src/app/entity/shared/containers/profile/header/EntityTabs.tsx index 0b02953d4f..ea5c263ef7 100644 --- a/datahub-web-react/src/app/entity/shared/containers/profile/header/EntityTabs.tsx +++ b/datahub-web-react/src/app/entity/shared/containers/profile/header/EntityTabs.tsx @@ -25,27 +25,25 @@ const Tab = styled(Tabs.TabPane)` `; export const EntityTabs = ({ tabs, selectedTab }: Props) => { - const { entityData } = useEntityData(); + const { entityData, loading } = useEntityData(); const routeToTab = useRouteToTab(); const baseEntity = useBaseEntity(); - useEffect(() => { - if (!selectedTab) { - if (tabs[0]) { - routeToTab({ tabName: tabs[0].name, method: 'replace' }); - } - } - }, [tabs, selectedTab, routeToTab]); + const enabledTabs = tabs.filter((tab) => tab.display?.enabled(entityData, baseEntity)); - const visibleTabs = tabs.filter((tab) => tab.display?.visible(entityData, baseEntity)); + useEffect(() => { + if (!loading && !selectedTab && enabledTabs[0]) { + routeToTab({ tabName: enabledTabs[0].name, method: 'replace' }); + } + }, [loading, enabledTabs, selectedTab, routeToTab]); return ( routeToTab({ tabName: tab })} > - {visibleTabs.map((tab) => { + {tabs.map((tab) => { if (!tab.display?.enabled(entityData, baseEntity)) { return ; } diff --git a/datahub-web-react/src/app/entity/shared/types.ts b/datahub-web-react/src/app/entity/shared/types.ts index 41b7132dbb..49d7aa7650 100644 --- a/datahub-web-react/src/app/entity/shared/types.ts +++ b/datahub-web-react/src/app/entity/shared/types.ts @@ -131,6 +131,7 @@ export type EntityContextType = { entityType: EntityType; dataNotCombinedWithSiblings: any; entityData: GenericEntityProperties | null; + loading: boolean; baseEntity: any; updateEntity?: UpdateEntityType | null; routeToTab: (params: { tabName: string; tabParams?: Record; method?: 'push' | 'replace' }) => void;