Skip to content

Commit

Permalink
fix(ui): only use visible and enabled tabs for selected tab and routi…
Browse files Browse the repository at this point in the history
…ng in entity profiles
  • Loading branch information
Masterchen09 committed Dec 7, 2022
1 parent 8a8b667 commit 9675391
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
16 changes: 8 additions & 8 deletions datahub-web-react/src/app/entity/dashboard/DashboardEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ export class DashboardEntity implements Entity<Dashboard> {
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,
Expand All @@ -117,14 +125,6 @@ export class DashboardEntity implements Entity<Dashboard> {
},
},
},
{
name: 'Datasets',
component: DashboardDatasetsTab,
display: {
visible: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.datasets?.total || 0) > 0,
enabled: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.datasets?.total || 0) > 0,
},
},
]}
sidebarSections={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,15 @@ export const EntityProfile = <T, U>({
},
})) || [];

const routedTab = useRoutedTab([...tabsWithDefaults, ...autoRenderTabs]);
const visibleTabs = tabsWithDefaults.filter((tab) =>
tab.display?.visible(entityData, dataPossiblyCombinedWithSiblings),
);

const enabledAndVisibleTabs = visibleTabs.filter((tab) =>
tab.display?.enabled(entityData, dataPossiblyCombinedWithSiblings),
);

const routedTab = useRoutedTab([...enabledAndVisibleTabs, ...autoRenderTabs]);

if (isCompact) {
return (
Expand Down Expand Up @@ -342,6 +350,7 @@ export const EntityProfile = <T, U>({
refreshBrowser={refreshBrowser}
/>
<EntityTabs
loading={loading}
tabs={[...tabsWithDefaults, ...autoRenderTabs]}
selectedTab={routedTab}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EntityTab } from '../../../types';
import { useBaseEntity, useEntityData, useRouteToTab } from '../../../EntityContext';

type Props = {
loading: boolean;
tabs: EntityTab[];
selectedTab?: EntityTab;
};
Expand All @@ -24,20 +25,19 @@ const Tab = styled(Tabs.TabPane)`
line-height: 22px;
`;

export const EntityTabs = <T,>({ tabs, selectedTab }: Props) => {
export const EntityTabs = <T,>({ loading, tabs, selectedTab }: Props) => {
const { entityData } = useEntityData();
const routeToTab = useRouteToTab();
const baseEntity = useBaseEntity<T>();

const visibleTabs = tabs.filter((tab) => tab.display?.visible(entityData, baseEntity));
const enabledAndVisibleTabs = visibleTabs.filter((tab) => tab.display?.enabled(entityData, baseEntity));

useEffect(() => {
if (!selectedTab) {
if (tabs[0]) {
routeToTab({ tabName: tabs[0].name, method: 'replace' });
}
if (!loading && !selectedTab && enabledAndVisibleTabs[0]) {
routeToTab({ tabName: enabledAndVisibleTabs[0].name, method: 'replace' });
}
}, [tabs, selectedTab, routeToTab]);

const visibleTabs = tabs.filter((tab) => tab.display?.visible(entityData, baseEntity));
}, [loading, enabledAndVisibleTabs, selectedTab, routeToTab]);

return (
<UnborderedTabs
Expand Down

0 comments on commit 9675391

Please sign in to comment.