Skip to content

Commit

Permalink
[web] Use early return
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Nov 15, 2023
1 parent 0e6c2fd commit e5e7510
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions web/src/components/product/ProductSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,27 @@ import React from "react";
import { Card, CardBody, Radio } from "@patternfly/react-core";

import { _ } from "~/i18n";
import { If } from "~/components/core";
import { noop } from "~/utils";

export default function ProductSelector({ value, products = [], onChange = noop }) {
if (products.length === 0) return <p>{_("No products available for selection")}</p>;

const isSelected = (product) => product.id === value;

return (
<If
condition={products.length === 0}
then={<p>{_("No products available for selection")}</p>}
else={
products.map((p) => (
<Card key={p.id} className={isSelected(p) && "selected-product"}>
<CardBody>
<Radio
id={p.id}
name="product"
label={p.name}
description={p.description}
isChecked={isSelected(p)}
onClick={() => onChange(p.id)}
/>
</CardBody>
</Card>
))
}
/>
products.map((p) => (
<Card key={p.id} className={isSelected(p) && "selected-product"}>
<CardBody>
<Radio
id={p.id}
name="product"
label={p.name}
description={p.description}
isChecked={isSelected(p)}
onClick={() => onChange(p.id)}
/>
</CardBody>
</Card>
))
);
}

0 comments on commit e5e7510

Please sign in to comment.