Skip to content

Commit

Permalink
fix(inventoryTabs): allow any child component (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jul 26, 2021
1 parent 8bad6e8 commit ae64e86
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"cardHeading": "Current systems",
"tabHeading": "Inventory listing",
"tabHeading_plural": "Inventory listings",
"tabSubHeading": "Tab {{count}}",
"tabHosts": "Current systems",
"tabHosts_noInstances_OpenShift-dedicated-metrics": "Current instances",
"tabHosts_OpenShift-dedicated-metrics": "{{count}} instance",
Expand Down
4 changes: 4 additions & 0 deletions src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ Array [
Object {
"file": "./src/components/inventoryTabs/inventoryTabs.js",
"keys": Array [
Object {
"key": "curiosity-inventory.tabSubHeading",
"match": "t('curiosity-inventory.tabSubHeading', { count: index })",
},
Object {
"key": "curiosity-inventory.tabHeading",
"match": "t('curiosity-inventory.tabHeading', { count: updatedChildren.length })",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`InventoryTabs Component should render a non-connected component: non-co
className="sr-only"
headingLevel="h2"
>
t(curiosity-inventory.tabHeading, {"count":2})
t(curiosity-inventory.tabHeading, {"count":3})
</Title>
<Tabs
activeTab={0}
Expand All @@ -39,6 +39,11 @@ exports[`InventoryTabs Component should render a non-connected component: non-co
"content": "amet",
"title": "sit",
},
Object {
"active": false,
"content": <GenericComponent />,
"title": "t(curiosity-inventory.tabSubHeading, {\\"count\\":2})",
},
]
}
/>
Expand Down
9 changes: 8 additions & 1 deletion src/components/inventoryTabs/__tests__/inventoryTabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ describe('InventoryTabs Component', () => {
});

it('should render a non-connected component', () => {
const GenericComponent = () => (
<div>
<strong>world</strong>
</div>
);

const props = {
productId: 'lorem',
children: [
Expand All @@ -23,7 +29,8 @@ describe('InventoryTabs Component', () => {
</InventoryTab>,
<InventoryTab key="sit" title="sit">
amet
</InventoryTab>
</InventoryTab>,
<GenericComponent key="hello" />
]
};

Expand Down
14 changes: 9 additions & 5 deletions src/components/inventoryTabs/inventoryTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ class InventoryTabs extends React.Component {
return null;
}

const updatedChildren = React.Children.toArray(children).map(({ props = {} }) => ({
active: props.active || false,
content: props.children,
title: props.title
}));
const updatedChildren = React.Children.toArray(children).map((child, index) => {
const { props = {} } = child;

return {
active: props.active || false,
content: props.children || child,
title: props.title || t('curiosity-inventory.tabSubHeading', { count: index })
};
});

return (
<React.Fragment>
Expand Down

0 comments on commit ae64e86

Please sign in to comment.