-
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
Open
severo
wants to merge
23
commits into
refactor-dashboard-logic
Choose a base branch
from
refactor-and-use-entities
base: refactor-dashboard-logic
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b5db8d2
use safer Number.isNaN (no coertion)
severo a5ceede
replace useEffect with (i18n'ed) ErrorBoundary + Suspense + use()
severo d0e37d9
use a theme color (light green) instead of blue
severo d971122
rename
severo e47e5c6
move components to widgets
severo 9d72562
improve promises cache (per API token, and don't cache errors)
severo e6573d1
fix fetch logic and error management
severo 8f9ba3f
adapt data to the new backend format
severo 9e13740
format
severo b17174a
rename get to fetch because it's a promise
severo 06ca01e
move ApiContext from shared to features to later improve types ('meti…
severo fab137c
i18n dashboard header
severo f6817c6
remove type, as typescript infers it better
severo c998fa6
improve type
severo 87542a6
fix types by throwing an error if a taxon is undefined (bug)
severo 7709f65
refactor to extract logic to entities and add type safety
severo 6fb93fc
Potential fix for pull request finding
severo 40906d3
fix logic
severo 38c9676
better message
severo d683c92
remove temporary debug
severo c5386a8
add explanation about 'epf'
severo 812e0dc
epf = eco-potentialité forestière
severo 3991b3a
rename epf to biodiversity index
severo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Tropical Biodiversity Index | ||
|
|
||
| import * as z from "zod"; | ||
|
|
||
| import { ValueAndErrorSchema } from "@entities/dashboard/generic"; | ||
|
|
||
| export const BiodiversityIndexSchema = z.object({ | ||
| bio_idx_deadWood: ValueAndErrorSchema, | ||
| bio_idx_diametric_distribution: ValueAndErrorSchema, | ||
| bio_idx_dominant_height: ValueAndErrorSchema, | ||
| bio_idx_microhabitats: ValueAndErrorSchema, | ||
| bio_idx_spatial_distribution: ValueAndErrorSchema, | ||
| bio_idx_tree_density: ValueAndErrorSchema, | ||
| bio_idx_tree_diversity: ValueAndErrorSchema, | ||
| bio_idx_vertical_distribution: ValueAndErrorSchema, | ||
| }); | ||
|
|
||
| export type BiodiversityIndex = z.infer<typeof BiodiversityIndexSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
webapp/src/shared/contexts/ApiContext.ts → webapp/src/features/contexts/ApiContext.ts
|
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. Why did you move ApiContext and apiClient to the layer 'feature' ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
2 changes: 1 addition & 1 deletion
2
webapp/src/shared/hooks/useApi.ts → webapp/src/features/hooks/useApi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.