Skip to content

Commit

Permalink
refactor(productView): simplify, unnecessary hook
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jan 30, 2024
1 parent 7c8f100 commit e15006e
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions src/components/productView/productView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { routerContext } from '../router';
import { ProductViewContext } from './productViewContext';
Expand Down Expand Up @@ -35,63 +35,59 @@ import { translate } from '../i18n/i18n';
const ProductView = ({ t, useRouteDetail: useAliasRouteDetail }) => {
const { firstMatch, productGroup } = useAliasRouteDetail();

const renderProduct = useCallback(() => {
const updated = config => {
const { initialInventoryFilters, initialSubscriptionsInventoryFilters, productId, viewId } = config;
const renderContent = () => {
const { initialInventoryFilters, initialSubscriptionsInventoryFilters, productId, viewId } = firstMatch;

if (!productId || !viewId) {
return null;
}
if (!productId || !viewId) {
return null;
}

return (
<ProductViewContext.Provider value={config} key={`product_${productId}`}>
<PageMessages>
<BannerMessages />
</PageMessages>
<PageToolbar>
<Toolbar />
</PageToolbar>
<PageSection className="curiosity-page-section__graphs">
<GraphCard />
</PageSection>
<PageSection className="curiosity-page-section__tabs">
<InventoryTabs
isDisabled={
(!initialInventoryFilters && !initialSubscriptionsInventoryFilters) || helpers.UI_DISABLED_TABLE
}
>
{!helpers.UI_DISABLED_TABLE_INSTANCES && initialInventoryFilters && (
<InventoryTab
key={`inventory_instances_${productId}`}
title={t('curiosity-inventory.tabInstances', { context: [productId] })}
>
<InventoryCardInstances />
</InventoryTab>
)}
{!helpers.UI_DISABLED_TABLE_SUBSCRIPTIONS && initialSubscriptionsInventoryFilters && (
<InventoryTab
key={`inventory_subs_${productId}`}
title={t('curiosity-inventory.tabSubscriptions', { context: [productId] })}
>
<InventoryCardSubscriptions />
</InventoryTab>
)}
</InventoryTabs>
</PageSection>
</ProductViewContext.Provider>
);
};

return updated(firstMatch);
}, [firstMatch, t]);
return (
<ProductViewContext.Provider value={firstMatch}>
<PageMessages>
<BannerMessages />
</PageMessages>
<PageToolbar>
<Toolbar />
</PageToolbar>
<PageSection className="curiosity-page-section__graphs">
<GraphCard />
</PageSection>
<PageSection className="curiosity-page-section__tabs">
<InventoryTabs
isDisabled={
(!initialInventoryFilters && !initialSubscriptionsInventoryFilters) || helpers.UI_DISABLED_TABLE
}
>
{!helpers.UI_DISABLED_TABLE_INSTANCES && initialInventoryFilters && (
<InventoryTab
key={`inventory_instances_${productId}`}
title={t('curiosity-inventory.tabInstances', { context: [productId] })}
>
<InventoryCardInstances />
</InventoryTab>
)}
{!helpers.UI_DISABLED_TABLE_SUBSCRIPTIONS && initialSubscriptionsInventoryFilters && (
<InventoryTab
key={`inventory_subs_${productId}`}
title={t('curiosity-inventory.tabSubscriptions', { context: [productId] })}
>
<InventoryCardSubscriptions />
</InventoryTab>
)}
</InventoryTabs>
</PageSection>
</ProductViewContext.Provider>
);
};

return (
(productGroup && (
<PageLayout>
<PageHeader productLabel={productGroup}>
{t(`curiosity-view.title`, { appName: helpers.UI_DISPLAY_NAME, context: productGroup })}
</PageHeader>
<PageColumns>{renderProduct()}</PageColumns>
<PageColumns>{renderContent()}</PageColumns>
</PageLayout>
)) ||
null
Expand Down

0 comments on commit e15006e

Please sign in to comment.