-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor and use entities #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: refactor-dashboard-logic
Are you sure you want to change the base?
Changes from all commits
f475291
f740b53
34e7349
eb16ce6
68d2d7c
c6fb82d
00338ed
5185412
6211ab4
4d22865
2d5e0ae
66feeed
f1b496a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // > les epf regroupent tous les indicateurs indirects de biodiversité ("Tropical Biodiversity Index") | ||
| // > epf = eco-potentialité forestière, l'ancien nom de l'indice de biodiversité tropicale | ||
| // TODO: rename epf to something more meaningful? | ||
|
|
||
| import * as z from "zod"; | ||
|
|
||
| import { ValueAndErrorSchema } from "@entities/dashboard/generic"; | ||
|
|
||
| export const EpfDataSchema = z.object({ | ||
| epf_deadWood: ValueAndErrorSchema, | ||
| epf_diameter_distribution: ValueAndErrorSchema, | ||
| epf_dominant_height: ValueAndErrorSchema, | ||
| epf_microhabitats: ValueAndErrorSchema, | ||
| epf_necromass_pied: ValueAndErrorSchema, // needed? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed indeed. I added them in the config.json to help me construct the (very long) formulat for 'epf_deadwoord' but I removed them in #162 |
||
| epf_necromass_sol: ValueAndErrorSchema, // needed? | ||
| epf_spatial_distribution: ValueAndErrorSchema, | ||
| epf_tree_density: ValueAndErrorSchema, | ||
| epf_tree_diversity: ValueAndErrorSchema, | ||
| epf_vertical_distribution: ValueAndErrorSchema, | ||
| }); | ||
|
|
||
| export type EpfData = z.infer<typeof EpfDataSchema>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import * as z from "zod"; | ||
|
|
||
| export const ValueAndErrorSchema = z | ||
| .object({ | ||
| error: z.number().nullable(), | ||
| value: z.number().nullable(), | ||
| }) | ||
| .default(() => ({ | ||
| error: null, | ||
| value: null, | ||
| })); | ||
|
|
||
| const DictionaryDataSchema = z.record(z.string(), ValueAndErrorSchema); | ||
|
|
||
| export type DictionaryData = z.infer<typeof DictionaryDataSchema>; | ||
|
|
||
| const MIN_YEAR = 1900; | ||
| const MAX_YEAR = 2100; | ||
| const YearSchema = z.coerce.number().int().min(MIN_YEAR).max(MAX_YEAR); | ||
|
|
||
| const YearDataSchema = z.object({ | ||
| beneficiary: DictionaryDataSchema, | ||
| control: DictionaryDataSchema, | ||
| }); | ||
|
|
||
| export type YearData = z.infer<typeof YearDataSchema>; | ||
|
|
||
| export const DashboardDataSchema = z.record(YearSchema, YearDataSchema); | ||
|
|
||
| export type DashboardData = z.infer<typeof DashboardDataSchema>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { | ||
| type DashboardData, | ||
| DashboardDataSchema, | ||
| } from "@entities/dashboard/generic"; | ||
|
|
||
| import { fetchJSONWithAuth } from "@shared/api/client"; | ||
|
|
||
| export const createApiClient = (authToken: string | null) => ({ | ||
| // Bases | ||
| fetchDashboardData: async (layerId: string): Promise<DashboardData> => { | ||
| const json = await fetchJSONWithAuth( | ||
| `/maps/dashboard/${layerId}`, | ||
| {}, | ||
| authToken, | ||
| ); | ||
| return DashboardDataSchema.parse(json); | ||
| }, | ||
| }); | ||
|
|
||
| export type ApiClient = ReturnType<typeof createApiClient>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { createContext } from "react"; | ||
|
|
||
| import type { ApiClient } from "@shared/api/client"; | ||
| import type { ApiClient } from "@features/api/client"; | ||
|
|
||
| export const ApiContext = createContext<ApiClient | undefined>(undefined); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ export function cn(...inputs: ClassValue[]) { | |
|
|
||
| export function precise(value?: number | null) { | ||
| if (!value || Number.isNaN(value)) { | ||
| // TODO: missing or erroneous values should not be considered as 0, but rather as null or undefined. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In some cases Cathaline asked us to put "0" for empty values, in other cases "N/A". |
||
| // when displayed, they should be shown as "N/A" or "No data", or the point could be omitted from the chart. | ||
| return "0"; | ||
| } | ||
| if (value > 999) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -244,6 +244,10 @@ const ChartTooltipContent = React.forwardRef< | |
| { | ||
| /* Force a space between item label and value*/ "\xa0" + | ||
| item.value.toLocaleString() | ||
| // ^ TODO: why not using CSS to add a space between the label and the value? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is generated automatically when importing shadcn components, see Shadcn Doc. We might want to tweak this code, but as long as it is not strictly necessary, I would prefer to keep it as is |
||
| // ^ TODO: pass a prop to format the item value (e.g.: no more than 2 decimals, or other formatting rules) | ||
| // ^ TODO: use the current locale to format the item value (e.g.: 1,000.00 in en-US, 1 000,00 in fr-FR, etc.) | ||
| // ^ TODO: add the unit? | ||
| } | ||
| </span> | ||
| )} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.