mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-19 22:58:05 +00:00
fix(ui): only use visible and enabled tabs for selected tab and routing in entity profiles (#6629)
Co-authored-by: John Joyce <john@acryl.io>
This commit is contained in:
parent
ea7b2abca5
commit
0cfbec72c8
@ -94,6 +94,14 @@ export class DashboardEntity implements Entity<Dashboard> {
|
|||||||
enabled: (_, dashboard: GetDashboardQuery) => (dashboard?.dashboard?.charts?.total || 0) > 0,
|
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',
|
name: 'Documentation',
|
||||||
component: DocumentationTab,
|
component: DocumentationTab,
|
||||||
@ -117,14 +125,6 @@ export class DashboardEntity implements Entity<Dashboard> {
|
|||||||
name: 'Properties',
|
name: 'Properties',
|
||||||
component: PropertiesTab,
|
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={[
|
sidebarSections={[
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,7 @@ const EntityContext = React.createContext<EntityContextType>({
|
|||||||
urn: '',
|
urn: '',
|
||||||
entityType: EntityType.Dataset,
|
entityType: EntityType.Dataset,
|
||||||
entityData: null,
|
entityData: null,
|
||||||
|
loading: true,
|
||||||
baseEntity: null,
|
baseEntity: null,
|
||||||
updateEntity: () => Promise.resolve({}),
|
updateEntity: () => Promise.resolve({}),
|
||||||
routeToTab: () => {},
|
routeToTab: () => {},
|
||||||
@ -33,8 +34,8 @@ export const useEntityUpdate = <U,>(): UpdateEntityType<U> | null | undefined =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useEntityData = () => {
|
export const useEntityData = () => {
|
||||||
const { urn, entityType, entityData } = useContext(EntityContext);
|
const { urn, entityType, entityData, loading } = useContext(EntityContext);
|
||||||
return { urn, entityType, entityData };
|
return { urn, entityType, entityData, loading };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useRouteToTab = () => {
|
export const useRouteToTab = () => {
|
||||||
|
@ -245,7 +245,15 @@ export const EntityProfile = <T, U>({
|
|||||||
},
|
},
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
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) {
|
if (isCompact) {
|
||||||
return (
|
return (
|
||||||
@ -254,6 +262,7 @@ export const EntityProfile = <T, U>({
|
|||||||
urn,
|
urn,
|
||||||
entityType,
|
entityType,
|
||||||
entityData,
|
entityData,
|
||||||
|
loading,
|
||||||
baseEntity: dataPossiblyCombinedWithSiblings,
|
baseEntity: dataPossiblyCombinedWithSiblings,
|
||||||
dataNotCombinedWithSiblings,
|
dataNotCombinedWithSiblings,
|
||||||
updateEntity,
|
updateEntity,
|
||||||
@ -291,6 +300,7 @@ export const EntityProfile = <T, U>({
|
|||||||
urn,
|
urn,
|
||||||
entityType,
|
entityType,
|
||||||
entityData,
|
entityData,
|
||||||
|
loading,
|
||||||
baseEntity: dataPossiblyCombinedWithSiblings,
|
baseEntity: dataPossiblyCombinedWithSiblings,
|
||||||
dataNotCombinedWithSiblings,
|
dataNotCombinedWithSiblings,
|
||||||
updateEntity,
|
updateEntity,
|
||||||
@ -344,10 +354,7 @@ export const EntityProfile = <T, U>({
|
|||||||
subHeader={subHeader}
|
subHeader={subHeader}
|
||||||
refreshBrowser={refreshBrowser}
|
refreshBrowser={refreshBrowser}
|
||||||
/>
|
/>
|
||||||
<EntityTabs
|
<EntityTabs tabs={visibleTabs} selectedTab={routedTab} />
|
||||||
tabs={[...tabsWithDefaults, ...autoRenderTabs]}
|
|
||||||
selectedTab={routedTab}
|
|
||||||
/>
|
|
||||||
</Header>
|
</Header>
|
||||||
<TabContent>
|
<TabContent>
|
||||||
{routedTab && <routedTab.component properties={routedTab.properties} />}
|
{routedTab && <routedTab.component properties={routedTab.properties} />}
|
||||||
|
@ -25,27 +25,25 @@ const Tab = styled(Tabs.TabPane)`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const EntityTabs = <T,>({ tabs, selectedTab }: Props) => {
|
export const EntityTabs = <T,>({ tabs, selectedTab }: Props) => {
|
||||||
const { entityData } = useEntityData();
|
const { entityData, loading } = useEntityData();
|
||||||
const routeToTab = useRouteToTab();
|
const routeToTab = useRouteToTab();
|
||||||
const baseEntity = useBaseEntity<T>();
|
const baseEntity = useBaseEntity<T>();
|
||||||
|
|
||||||
useEffect(() => {
|
const enabledTabs = tabs.filter((tab) => tab.display?.enabled(entityData, baseEntity));
|
||||||
if (!selectedTab) {
|
|
||||||
if (tabs[0]) {
|
|
||||||
routeToTab({ tabName: tabs[0].name, method: 'replace' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [tabs, selectedTab, routeToTab]);
|
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
<UnborderedTabs
|
<UnborderedTabs
|
||||||
activeKey={selectedTab?.name}
|
activeKey={selectedTab?.name || ''}
|
||||||
size="large"
|
size="large"
|
||||||
onTabClick={(tab: string) => routeToTab({ tabName: tab })}
|
onTabClick={(tab: string) => routeToTab({ tabName: tab })}
|
||||||
>
|
>
|
||||||
{visibleTabs.map((tab) => {
|
{tabs.map((tab) => {
|
||||||
if (!tab.display?.enabled(entityData, baseEntity)) {
|
if (!tab.display?.enabled(entityData, baseEntity)) {
|
||||||
return <Tab tab={tab.name} key={tab.name} disabled />;
|
return <Tab tab={tab.name} key={tab.name} disabled />;
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,7 @@ export type EntityContextType = {
|
|||||||
entityType: EntityType;
|
entityType: EntityType;
|
||||||
dataNotCombinedWithSiblings: any;
|
dataNotCombinedWithSiblings: any;
|
||||||
entityData: GenericEntityProperties | null;
|
entityData: GenericEntityProperties | null;
|
||||||
|
loading: boolean;
|
||||||
baseEntity: any;
|
baseEntity: any;
|
||||||
updateEntity?: UpdateEntityType<any> | null;
|
updateEntity?: UpdateEntityType<any> | null;
|
||||||
routeToTab: (params: { tabName: string; tabParams?: Record<string, any>; method?: 'push' | 'replace' }) => void;
|
routeToTab: (params: { tabName: string; tabParams?: Record<string, any>; method?: 'push' | 'replace' }) => void;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user