Skip to content

Commit

Permalink
refactor(groupe): use isCategory attribute instead of the hardcoded r…
Browse files Browse the repository at this point in the history
…ecord
  • Loading branch information
EmileRolley committed Nov 2, 2023
1 parent f6ad02f commit 81552ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion source/components/publicodesUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ const categoryColorOverride = {
}

export function extractCategories(
rules: any,
rules: NGCRules,
engine: Engine<DottedName>,
valuesFromURL?: any,
parentRule = MODEL_ROOT_RULE_NAME,
Expand Down
67 changes: 34 additions & 33 deletions source/pages/groupe-dashboard/components/VotreEmpreinte.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function VotreEmpreinte({
categoriesFootprints,
membersLength,
}: {
categoriesFootprints?: Record<string, ValueObject> | undefined
categoriesFootprints: Record<string, ValueObject> | undefined
membersLength: number
}) {
return (
Expand All @@ -23,39 +23,40 @@ export default function VotreEmpreinte({

<ul className="mt-6 pl-0 mb-16">
{Object.entries(categoriesFootprints ?? {}).reduce(
(acc, [key, { icon, title, variation, value }]) => {
if (!icon || !title) return acc
return [
...acc,
<li
key={`cat-${key}`}
className="flex items-center justify-between py-4 border-solid border-0 border-b-[1px] last:border-b-0 border-gray-200"
>
<div className="flex items-center">
<div className="flex-shrink-0 text-2xl">
<span>{icon}</span>
</div>
<div className="ml-4">
<div className="text-md font-bold text-gray-900">
{title}
(acc, [key, { icon, title, variation, value, isCategory }]) => {
return title !== undefined && icon !== undefined && isCategory
? [
...acc,
<li
key={`cat-${key}`}
className="flex items-center justify-between py-4 border-solid border-0 border-b-[1px] last:border-b-0 border-gray-200"
>
<div className="flex items-center">
<div className="flex-shrink-0 text-2xl">
<span>{icon}</span>
</div>
<div className="ml-4">
<div className="text-md font-bold text-gray-900">
{title}
</div>
</div>
{membersLength > 1 && (
<PercentageDiff variation={variation ?? 0} />
)}
</div>
</div>
{membersLength > 1 && (
<PercentageDiff variation={variation ?? 0} />
)}
</div>
<div className="flex items-center gap-4">
<div className="text-sm text-primary bg-primaryLight border-solid border-[1px] border-primaryBorder rounded-[5px] p-1">
<strong>
{formatValue(value / 1000, {
precision: 1,
})}
</strong>{' '}
t
</div>
</div>
</li>,
]
<div className="flex items-center gap-4">
<div className="text-sm text-primary bg-primaryLight border-solid border-[1px] border-primaryBorder rounded-[5px] p-1">
<strong>
{formatValue(value / 1000, {
precision: 1,
})}
</strong>{' '}
t
</div>
</div>
</li>,
]
: acc
},
[] as JSX.Element[]
)}
Expand Down

0 comments on commit 81552ad

Please sign in to comment.