-
Notifications
You must be signed in to change notification settings - Fork 4
Move page header to the same component as the page sidebar #273
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7bf4b6c
Return the handleActionError instead of throwing it
BoraIneviNMI 32c2938
Make the 404 page visually distinct
BoraIneviNMI c6801da
Move ErrorBoundary into its own file called InlineErrorBoundary
BoraIneviNMI 08d1e7f
Add page-specific error boundaries to pages after farm creation
BoraIneviNMI e641841
Fix wrong field name query on the options store
BoraIneviNMI 267246a
Use get in FarmFieldOptionsStore
BoraIneviNMI 3adf677
Delete fertilizer-options.tsx
BoraIneviNMI 290588a
Add error boundaries to farm create pages
BoraIneviNMI ddb99a8
Rename farm-field-options.tsx to farm-field-options.ts
BoraIneviNMI bd2725a
Nitpicks
BoraIneviNMI 5163c17
Remove console.log
BoraIneviNMI ec6c5c0
refactor: Improve the design of the error block to fit better in the …
SvenVw 264ea16
Add automatic header - next phase will be to remove some of the repet…
BoraIneviNMI 7a08934
Remove repeated loading of the same data and add generic header to th…
BoraIneviNMI 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@svenvw/fdm-app": minor | ||
| --- | ||
|
|
||
| Improve the design of the error block to fit better in the page when shown |
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,196 @@ | ||
| import type { ReactNode } from "react" | ||
| import { type UIMatch, useLocation, useMatches, useParams } from "react-router" | ||
| import { useCalendarStore } from "@/app/store/calendar" | ||
| import { useFarmFieldOptionsStore } from "@/app/store/farm-field-options" | ||
| import type { FertilizerOption } from "../farm/farm" | ||
| import { HeaderAtlas } from "./atlas" | ||
| import { HeaderBalance } from "./balance" | ||
| import { Header } from "./base" | ||
| import { HeaderFarmCreate } from "./create-farm" | ||
| import { HeaderFarm, type HeaderFarmOption } from "./farm" | ||
| import { HeaderFertilizer } from "./fertilizer" | ||
| import { HeaderField, type HeaderFieldOption } from "./field" | ||
| import { HeaderNorms } from "./norms" | ||
| import { HeaderNutrientAdvice } from "./nutrient-advice" | ||
|
|
||
| export default function HeaderAutomatic() { | ||
| interface LoaderDataCandidate { | ||
| b_name_farm?: string | ||
| farmOptions?: HeaderFarmOption[] | ||
| fieldOptions?: HeaderFieldOption[] | ||
| fertilizerOptions?: FertilizerOption[] | ||
| } | ||
| const matches = useMatches() as UIMatch<LoaderDataCandidate, unknown>[] | ||
| const params = useParams() | ||
| const location = useLocation() | ||
| const farmFieldOptionsStore = useFarmFieldOptionsStore() | ||
| const storedCalendar = useCalendarStore((s) => s.calendar) | ||
|
|
||
| // Find the farm and field options. | ||
| let farmOptions: HeaderFarmOption[] | undefined | ||
| let fieldOptions: HeaderFieldOption[] | undefined | ||
| let fertilizerOptions: unknown[] | undefined | ||
| let b_name_farm: string | undefined | ||
|
|
||
| for (const match of matches) { | ||
| if (match.loaderData) { | ||
| b_name_farm ??= match.loaderData.b_name_farm | ||
| farmOptions ??= match.loaderData.farmOptions | ||
| fieldOptions ??= match.loaderData.fieldOptions | ||
| fertilizerOptions ??= match.loaderData.fertilizerOptions | ||
| } | ||
| } | ||
|
|
||
| farmOptions ??= farmFieldOptionsStore.farmOptions | ||
| fieldOptions ??= farmFieldOptionsStore.fieldOptions | ||
| b_name_farm ??= | ||
| farmFieldOptionsStore.getFarmById(params.b_id_farm)?.b_name_farm ?? | ||
| undefined | ||
|
|
||
| const calendar = params.calendar ?? storedCalendar | ||
|
|
||
| if (/\/create\//.test(location.pathname)) { | ||
| return ( | ||
| <Header action={undefined}> | ||
| <HeaderFarmCreate b_name_farm={b_name_farm} /> | ||
| </Header> | ||
| ) | ||
| } | ||
|
|
||
| const variants: Record<string, () => ReactNode> = { | ||
| "routes/farm._index": () => ( | ||
| <Header action={undefined}> | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| </Header> | ||
| ), | ||
| "routes/farm.$b_id_farm.settings": () => ( | ||
| <Header | ||
| action={{ | ||
| to: `/farm/${params.b_id_farm}/${calendar}/field`, | ||
| label: "Naar percelen", | ||
| disabled: false, | ||
| }} | ||
| > | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| </Header> | ||
| ), | ||
| "routes/farm.$b_id_farm.$calendar.field.new": () => | ||
| variants["routes/farm.$b_id_farm.$calendar.field._index"](), | ||
| "routes/farm.$b_id_farm.$calendar.field.$b_id": () => | ||
| variants["routes/farm.$b_id_farm.$calendar.field._index"](), | ||
| "routes/farm.$b_id_farm.$calendar.field._index": () => ( | ||
| <Header | ||
| action={{ | ||
| to: `/farm/${params.b_id_farm}`, | ||
| label: "Terug naar bedrijf", | ||
| disabled: false, | ||
| }} | ||
| > | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| <HeaderField | ||
| b_id_farm={params.b_id_farm} | ||
| fieldOptions={ | ||
| /new\/?$/.test(location.pathname) ? [] : fieldOptions | ||
| } | ||
| b_id={params.b_id} | ||
| /> | ||
| </Header> | ||
| ), | ||
| "routes/farm.$b_id_farm.fertilizers": () => ( | ||
| <Header action={undefined}> | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| <HeaderFertilizer | ||
| b_id_farm={params.b_id_farm} | ||
| p_id={params.p_id} | ||
| fertilizerOptions={ | ||
| /\/new(\/|$)/.test(location.pathname) | ||
| ? [] | ||
| : fertilizerOptions | ||
| } | ||
| /> | ||
| </Header> | ||
| ), | ||
| "routes/farm.$b_id_farm.$calendar.atlas": () => { | ||
| const isFieldDetailsPage = | ||
| location.pathname.includes("/atlas/fields/") && | ||
| location.pathname.split("/atlas/fields/")[1]?.includes(",") | ||
| let headerAction: | ||
| | { to: string; label: string; disabled: boolean } | ||
| | undefined | ||
| if (isFieldDetailsPage) { | ||
| headerAction = { | ||
| to: `/farm/${params.b_id_farm}/${calendar}/atlas/fields`, | ||
| label: "Terug", | ||
| disabled: false, | ||
| } | ||
| } | ||
| return ( | ||
| <Header action={headerAction}> | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| <HeaderAtlas b_id_farm={params.b_id_farm} /> | ||
| </Header> | ||
| ) | ||
| }, | ||
| "routes/farm.$b_id_farm.$calendar.balance.nitrogen": () => ( | ||
| <Header action={undefined}> | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| <HeaderBalance | ||
| b_id_farm={params.b_id_farm} | ||
| b_id={params.b_id} | ||
| fieldOptions={fieldOptions} | ||
| /> | ||
| </Header> | ||
| ), | ||
| "routes/farm.$b_id_farm.$calendar.nutrient_advice": () => ( | ||
| <Header action={undefined}> | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| <HeaderNutrientAdvice | ||
| b_id_farm={params.b_id_farm} | ||
| b_id={params.b_id} | ||
| fieldOptions={fieldOptions} | ||
| /> | ||
| </Header> | ||
| ), | ||
| "routes/farm.$b_id_farm.$calendar.norms": () => ( | ||
| <Header action={undefined}> | ||
| <HeaderFarm | ||
| b_id_farm={params.b_id_farm} | ||
| farmOptions={farmOptions} | ||
| /> | ||
| <HeaderNorms b_id_farm={params.b_id_farm} /> | ||
| </Header> | ||
| ), | ||
| } | ||
|
|
||
| let chosenVariant: (() => ReactNode) | undefined | ||
|
|
||
| for (const match of matches) { | ||
| if (match.id in variants) { | ||
| chosenVariant = variants[match.id] | ||
| break | ||
| } | ||
| } | ||
|
|
||
| return chosenVariant ? chosenVariant() : null | ||
| } | ||
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix fertilizer options typing/import and align with HeaderFertilizer.
FertilizerOptionpath looks suspicious and the localfertilizerOptionsis typed asunknown[], butHeaderFertilizerexpects a concrete option shape. This will either break TS or mask bugs.Apply this diff to type things correctly (assuming
HeaderFertilizerOptionis exported from./fertilizer; if not, export it there or declare a local type withp_id/p_name_nl):If
HeaderFertilizerOptionis not exported yet, add this tofdm-app/app/components/blocks/header/fertilizer.tsx:Also applies to: 32-33, 114-122
🤖 Prompt for AI Agents