Skip to content

Commit

Permalink
feat: all regions & dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNumericite committed Feb 2, 2024
1 parent a70cfa0 commit fd0be4c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 26 deletions.
107 changes: 88 additions & 19 deletions webapp-next/components/filters/Regions.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,113 @@
import { Cm2dContext } from '@/utils/cm2d-provider';
import { ChevronDownIcon, StarIcon } from '@chakra-ui/icons';
import {
Button,
Flex,
Menu,
MenuButton,
MenuItem,
MenuList
} from '@chakra-ui/react';
import { ChevronDownIcon } from '@chakra-ui/icons';
import { Flex, Menu, MenuButton, MenuItem, MenuList } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import { useContext, useEffect, useState } from 'react';

type Props = {};

export const RegionFilter = (props: Props) => {
const context = useContext(Cm2dContext);
const router = useRouter();
const { mode } = router.query;

if (!context) {
throw new Error('Menu must be used within a Cm2dProvider');
}

const { filters, setFilters } = context;

const [selectedFilter, setSelectedFilter] = useState<number[]>(
const [selectedFilter, setSelectedFilter] = useState<string[]>(
filters.region_departments
);

console.log(filters);
console.log(selectedFilter);

const regionFilters: { label: string; value: number[] }[] = [
{ label: 'Ile-de-France', value: [75, 77, 78, 91, 92, 93, 94, 95] },
{ label: 'Normandie', value: [14, 27, 50, 61, 76] },
let regionFilters: { label: string; value: string[] }[] = [
{
label: 'Ile-de-France',
value: ['75', '77', '78', '91', '92', '93', '94', '95']
},
{ label: 'Normandie', value: ['14', '27', '50', '61', '76'] },
{
label: 'Nouvelle-Aquitaine',
value: [16, 17, 19, 23, 24, 33, 40, 47, 64, 79, 86, 87]
value: [
'16',
'17',
'19',
'23',
'24',
'33',
'40',
'47',
'64',
'79',
'86',
'87'
]
},
{ label: 'Hauts-de-France', value: [2, 59, 60, 62, 80] }
{ label: 'Hauts-de-France', value: ['2', '59', '60', '62', '80'] }
];

const getLabelFromValue = (value: number[]): string => {
if (mode === 'dev') {
regionFilters = [
...regionFilters,
{
label: 'Auvergne-Rhône-Alpes',
value: [
'1',
'3',
'7',
'15',
'26',
'38',
'42',
'43',
'63',
'69',
'73',
'74'
]
},
{
label: 'Bourgogne-Franche-Comté',
value: ['21', '25', '39', '58', '70', '71', '89', '90']
},
{ label: 'Bretagne', value: ['22', '29', '35', '56'] },
{
label: 'Centre-Val de Loire',
value: ['18', '28', '36', '37', '41', '45']
},
{ label: 'Corse', value: ['2A', '2B'] },
{
label: 'Grand Est',
value: ['8', '10', '51', '52', '54', '55', '57', '67', '68', '88']
},
{
label: 'Occitanie',
value: [
'9',
'11',
'12',
'30',
'31',
'32',
'34',
'46',
'48',
'65',
'66',
'81',
'82'
]
},
{ label: 'Pays de la Loire', value: ['44', '49', '53', '72', '85'] },
{
label: "Provence-Alpes-Côte d'Azur",
value: ['4', '5', '6', '13', '83', '84']
}
];
}

const getLabelFromValue = (value: string[]) => {
return (
regionFilters.find(
df => JSON.stringify(df.value) === JSON.stringify(value)
Expand Down
4 changes: 2 additions & 2 deletions webapp-next/utils/cm2d-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type Filters = {
}[];
sex: string[];
department: string[];
region_departments: number[];
region_departments: string[];
start_date?: string;
end_date?: string;
};
Expand Down Expand Up @@ -69,7 +69,7 @@ export const baseFilters: Filters = {
age: [],
sex: [],
department: [],
region_departments: [75, 77, 78, 91, 92, 93, 94, 95]
region_departments: ['75', '77', '78', '91', '92', '93', '94', '95']
};
export const baseAggregation = {
aggregated_date: {
Expand Down
10 changes: 5 additions & 5 deletions webapp-next/utils/map/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MapConfig } from './type';
export const getMapProps = (
id: string,
datasets: { hits: any[]; total?: number }[],
departments: number[],
departments: string[],
saveAggregateX?: string
): {
config?: MapConfig;
Expand Down Expand Up @@ -67,21 +67,21 @@ export const getMapProps = (
}
};

const getCountFromKey = (key: number): number => {
const getCountFromKey = (key: string): number => {
const hit = hits.find(h => h.key === key);
// return hit ? (isNC(hit.doc_count) ? 'NC' : hit.doc_count) : 0;
return hit ? hit.doc_count : 0;
};

const getPercentage = (key: number): string => {
const getPercentage = (key: string): string => {
const hit = hits.find(h => h.key === key);
if (!hit || !total) return '0%';
// if (isNC(hit.doc_count)) return 'NC';
return `${Math.round((hit.doc_count / total) * 10000) / 100}%`;
};

const getColorFromPercentage = (
key: number,
key: string,
kind: 'initial' | 'hover'
): string => {
const hit = hits.find(h => h.key === key);
Expand All @@ -94,7 +94,7 @@ export const getMapProps = (
return stateColors.RED[kind];
};

const getFullDescription = (key: number): string => {
const getFullDescription = (key: string): string => {
const hit = hits.find(h => h.key === key);
if (!hit) return '';

Expand Down

0 comments on commit fd0be4c

Please sign in to comment.