Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Mar 4, 2024
1 parent f5ef23d commit a74189f
Show file tree
Hide file tree
Showing 14 changed files with 688 additions and 55 deletions.
17 changes: 17 additions & 0 deletions client/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/styles/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
5 changes: 5 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@json2csv/plainjs": "^6.1.3",
"@loaders.gl/core": "3.3.1",
"@luma.gl/constants": "8.5.18",
"@radix-ui/react-collapsible": "1.0.3",
"@reduxjs/toolkit": "1.8.2",
"@tailwindcss/forms": "0.4.0",
"@tailwindcss/typography": "0.5.0",
Expand All @@ -43,7 +44,9 @@
"autoprefixer": "10.2.5",
"axios": "1.3.4",
"chroma-js": "2.1.2",
"class-variance-authority": "0.7.0",
"classnames": "2.3.1",
"clsx": "^2.1.0",
"d3-array": "3.0.2",
"d3-format": "3.0.1",
"d3-scale": "4.0.2",
Expand All @@ -70,7 +73,9 @@
"recharts": "2.9.0",
"rooks": "7.14.1",
"sharp": "0.32.6",
"tailwind-merge": "2.2.1",
"tailwindcss": "3.3.1",
"tailwindcss-animate": "1.0.7",
"uuid": "8.3.2",
"yup": "0.32.11"
},
Expand Down
9 changes: 9 additions & 0 deletions client/src/components/ui/collapsible.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';

const Collapsible = CollapsiblePrimitive.Root;

const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger;

const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent;

export { Collapsible, CollapsibleTrigger, CollapsibleContent };
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const DeforestationFreeSuppliersBreakdown = () => {
return <div>DeforestationFreeSuppliersBreakdown</div>;
};

export default DeforestationFreeSuppliersBreakdown;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const SuppliersWithDeforestationAlertsBreakdown = () => {
return <div>SuppliersWithDeforestationAlertsBreakdown</div>;
};

export default SuppliersWithDeforestationAlertsBreakdown;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const SuppliersWithNoLocationDataBreakdown = () => {
return <div>SuppliersWithNoLocationData</div>;
};

export default SuppliersWithNoLocationDataBreakdown;
101 changes: 101 additions & 0 deletions client/src/containers/analysis-eudr/category-list/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { useState } from 'react';

import DeforestationFreeSuppliersBreakdown from './breakdown/deforestation-free-suppliers';
import SuppliersWithDeforestationAlertsBreakdown from './breakdown/suppliers-with-deforestation-alerts';
import SuppliersWithNoLocationDataBreakdown from './breakdown/suppliers-with-no-location-data';

import { Button } from '@/components/button';
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
import { formatPercentage } from '@/utils/number-format';

const CATEGORIES = [
{
name: 'Deforestation-free suppliers',
slug: 'deforestation-free-suppliers',
color: 'bg-[#4AB7F3]',
// todo move this value field to the component
value: 0.3,
},
{
name: 'Suppliers with deforestation alerts',
slug: 'suppliers-with-deforestation-alerts',
color: 'bg-[#FFC038]',
// todo move this value field to the component
value: 0.6,
},
{
name: 'Suppliers with no location data',
slug: 'suppliers-with-no-location-data',
color: 'bg-[#8460FF]',
// todo move this value field to the component
value: 0.1,
},
] as const;

type CategoryState = Record<(typeof CATEGORIES)[number]['slug'], boolean>;

export const CategoryList = (): JSX.Element => {
const [categories, toggleCategory] = useState<CategoryState>(
CATEGORIES.reduce(
(acc, category) => ({
...acc,
[category.slug]: false,
}),
{} as CategoryState,
),
);
const categoriesWithValues = CATEGORIES.map((category) => ({
...category,
// todo: calculate value field here
}));

return (
<>
{categoriesWithValues.map((category) => (
<Collapsible
key={category.slug}
className="rounded-xl bg-gray-50 p-5"
onOpenChange={() => {
toggleCategory((prev) => ({
...prev,
[category.slug]: !prev[category.slug],
}));
}}
>
<div className="flex w-full items-center space-x-6">
<div className="flex-1 text-left">{category.name}</div>
<div className="shrink-0 grow-0">
<div>
{formatPercentage(category.value)} <span className="text-xs">of suppliers</span>
</div>
<div className="h-[2px] w-[340px] bg-gray-200">
<div
className={`h-[2px] ${category.color}`}
style={{ width: formatPercentage(category.value) }}
/>
</div>
</div>
<CollapsibleTrigger asChild>
<Button type="button" size="xs" variant="white">
{categories[category.slug] ? 'Close details' : 'View details'}
</Button>
</CollapsibleTrigger>
</div>
<CollapsibleContent>
{category.slug === 'deforestation-free-suppliers' && (
<DeforestationFreeSuppliersBreakdown />
)}
{category.slug === 'suppliers-with-deforestation-alerts' && (
<SuppliersWithDeforestationAlertsBreakdown />
)}
{category.slug === 'suppliers-with-no-location-data' && (
<SuppliersWithNoLocationDataBreakdown />
)}
</CollapsibleContent>
</Collapsible>
))}
</>
);
};

export default CategoryList;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Label,
} from 'recharts';

import { Button } from '@/components/button';
import CategoryList from '@/containers/analysis-eudr/category-list';

const data = [
{
Expand Down Expand Up @@ -121,62 +121,81 @@ const SuppliersStackedBar = () => {
type="category"
width={200}
/>
<Tooltip />
<Tooltip cursor={{ fill: 'transparent' }} />
<Bar dataKey="pv" stackId="a" fill="#4AB7F3" shapeRendering="crispEdges" />
<Bar dataKey="uv" stackId="a" fill="#FFC038" shapeRendering="crispEdges" />
<Bar dataKey="amt" stackId="a" fill="#8460FF" shapeRendering="crispEdges" />
</BarChart>
</ResponsiveContainer>
</div>
<div className="space-y-1">
<div className="flex items-center space-x-6 rounded-xl bg-gray-50 p-5">
<div className="flex-1">Deforestation-free suppliers</div>
<div className="shrink-0 grow-0">
<div>
31% <span className="text-xs">of suppliers</span>
<CategoryList />
{/* <Collapsible className="rounded-xl bg-gray-50 p-5">
<CollapsibleTrigger className="w-full">
<div className="flex w-full items-center space-x-6">
<div className="flex-1 text-left">Deforestation-free suppliers</div>
<div className="shrink-0 grow-0">
<div>
31% <span className="text-xs">of suppliers</span>
</div>
<div className="h-[2px] w-[340px] bg-gray-200">
<div className="h-[2px] bg-[#4AB7F3]" style={{ width: '31%' }} />
</div>
</div>
<Button type="button" size="xs" variant="white">
View details
</Button>
</div>
<div className="h-[2px] w-[340px] bg-gray-200">
<div className="h-[2px] bg-[#4AB7F3]" style={{ width: '31%' }} />
</CollapsibleTrigger>
<CollapsibleContent>
<div>test</div>
</CollapsibleContent>
</Collapsible>
<Collapsible className="rounded-xl bg-gray-50 p-5">
<CollapsibleTrigger className="w-full">
<div className="flex w-full items-center space-x-6">
<div className="flex-1 text-left">Suppliers with deforestation alerts</div>
<div className="shrink-0 grow-0">
<div>
36% <span className="text-xs">of suppliers</span>
</div>
<div className="h-[2px] w-[340px] bg-gray-200">
<div className="h-[2px] bg-[#FFC038]" style={{ width: '31%' }} />
</div>
</div>
<Button type="button" size="xs" variant="white">
View details
</Button>
</div>
</div>
<div>
<Button type="button" size="xs" variant="white">
View details
</Button>
</div>
</div>
<div className="flex items-center space-x-6 rounded-xl bg-gray-50 p-5">
<div className="flex-1">Suppliers with deforestation alerts</div>
<div className="shrink-0 grow-0">
<div>
36% <span className="text-xs">of suppliers</span>
</CollapsibleTrigger>
<CollapsibleContent>
<div>test</div>
</CollapsibleContent>
</Collapsible>
<Collapsible className="rounded-xl bg-gray-50 p-5">
<CollapsibleTrigger className="w-full">
<div className="flex w-full items-center space-x-6">
<div className="flex-1">Suppliers with no location data</div>
<div className="shrink-0 grow-0">
<div>
33% <span className="text-xs">of suppliers</span>
</div>
<div className="h-[2px] w-[340px] bg-gray-200">
<div className="h-[2px] bg-[#8460FF]" style={{ width: '31%' }} />
</div>
</div>
<div>
<Button type="button" size="xs" variant="white">
View details
</Button>
</div>
</div>
<div className="h-[2px] w-[340px] bg-gray-200">
<div className="h-[2px] bg-[#FFC038]" style={{ width: '31%' }} />
</div>
</div>
<div>
<Button type="button" size="xs" variant="white">
View details
</Button>
</div>
</div>
<div className="flex items-center space-x-6 rounded-xl bg-gray-50 p-5">
<div className="flex-1">Suppliers with no location data</div>
<div className="shrink-0 grow-0">
<div>
33% <span className="text-xs">of suppliers</span>
</div>
<div className="h-[2px] w-[340px] bg-gray-200">
<div className="h-[2px] bg-[#8460FF]" style={{ width: '31%' }} />
</div>
</div>
<div>
<Button type="button" size="xs" variant="white">
View details
</Button>
</div>
</div>
</CollapsibleTrigger>
<CollapsibleContent>
<div>test</div>
</CollapsibleContent>
</Collapsible> */}
</div>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions client/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Loading

0 comments on commit a74189f

Please sign in to comment.