Repository navigation
ENG-2186 Grammar › Nodes drill-down and settings navigation primitive #1375
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
Merged
trangdoan982
merged 8 commits into
roam-setting-overhaul
from
eng-2186-grammar-nodes-drill-down-and-settings-navigation-primitive
Sep 28, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e22179
ENG-2186 Grammar › Nodes drill-down and settings navigation primitive
trangdoan982 3ec5b41
ENG-2186 Deferred commits always return a promise; format the stylesheet
trangdoan982 48ae50f
ENG-2186 Drop the colour dot from the drill-down header
trangdoan982 4a8a1ed
ENG-2186 Style the settings route and page header with Tailwind
trangdoan982 f0e3267
ENG-2186 Use the ~ alias for the settings navigation imports
trangdoan982 0b72a7a
ENG-2186 Remove the pending-write registry and Roam write tracking
trangdoan982 6d00db3
ENG-2186 Remove the settings-write changes from this PR
trangdoan982 d54edbc
ENG-2186 Remove a stray file committed by accident
trangdoan982 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
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,55 @@ | ||
| import React, { useEffect } from "react"; | ||
| import { OnloadArgs } from "roamjs-components/types"; | ||
| import getDiscourseNodes, { | ||
| excludeDefaultNodes, | ||
| } from "~/utils/getDiscourseNodes"; | ||
| import { useSettingsNav } from "./navigation/SettingsNavContext"; | ||
| import SettingsPageHeader from "./navigation/SettingsPageHeader"; | ||
| import DiscourseNodeConfigPanel from "./DiscourseNodeConfigPanel"; | ||
| import NodeConfig from "./NodeConfig"; | ||
|
|
||
| const NODES_ANCESTOR_LABELS = ["Grammar"] as const; | ||
|
|
||
| const GrammarNodesRoute = ({ | ||
| onloadArgs, | ||
| }: { | ||
| onloadArgs: OnloadArgs; | ||
| }): JSX.Element => { | ||
| const { segments, goToDepth } = useSettingsNav(); | ||
| const nodes = getDiscourseNodes().filter(excludeDefaultNodes); | ||
|
|
||
| const [nodeTypeUid] = segments; | ||
| const node = nodeTypeUid | ||
| ? nodes.find((n) => n.type === nodeTypeUid) | ||
| : undefined; | ||
|
|
||
| // A deleted node type or stale deep link resolves to nothing; return to the list. | ||
| const isStalePath = Boolean(nodeTypeUid) && !node; | ||
| useEffect(() => { | ||
| if (isStalePath) goToDepth(0); | ||
| }, [isStalePath, goToDepth]); | ||
|
|
||
| const resolveLabel = (segment: string): string => | ||
| nodes.find((n) => n.type === segment)?.text ?? segment; | ||
|
|
||
| return ( | ||
| <div className="flex h-full flex-col"> | ||
| <SettingsPageHeader | ||
| ancestorLabels={NODES_ANCESTOR_LABELS} | ||
| rootLabel="Nodes" | ||
| resolveLabel={resolveLabel} | ||
| /> | ||
| <div className="min-h-0 flex-auto overflow-y-auto"> | ||
| {node ? ( | ||
| <NodeConfig node={node} onloadArgs={onloadArgs} /> | ||
| ) : ( | ||
| <div className="p-1"> | ||
| <DiscourseNodeConfigPanel /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default GrammarNodesRoute; | ||
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
53 changes: 53 additions & 0 deletions
53
apps/roam/src/components/settings/navigation/SettingsNavContext.tsx
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,53 @@ | ||
| import React, { createContext, useContext, useMemo } from "react"; | ||
| import { | ||
| depthOf, | ||
| segmentsOf, | ||
| type SettingsNavAction, | ||
| type SettingsPath, | ||
| } from "~/components/settings/utils/settingsNavigation"; | ||
|
|
||
| export type SettingsNavValue = { | ||
| path: SettingsPath; | ||
| depth: number; | ||
| segments: readonly string[]; | ||
| push: (segment: string) => void; | ||
| pop: () => void; | ||
| goToDepth: (depth: number) => void; | ||
| }; | ||
|
|
||
| const SettingsNavContext = createContext<SettingsNavValue | null>(null); | ||
|
|
||
| export const SettingsNavProvider = ({ | ||
| path, | ||
| dispatch, | ||
| children, | ||
| }: { | ||
| path: SettingsPath; | ||
| dispatch: React.Dispatch<SettingsNavAction>; | ||
| children: React.ReactNode; | ||
| }): JSX.Element => { | ||
| const value = useMemo<SettingsNavValue>( | ||
| () => ({ | ||
| path, | ||
| depth: depthOf(path), | ||
| segments: segmentsOf(path), | ||
| push: (segment) => dispatch({ type: "push", segment }), | ||
| pop: () => dispatch({ type: "pop" }), | ||
| goToDepth: (depth) => dispatch({ type: "truncate", depth }), | ||
| }), | ||
| [path, dispatch], | ||
| ); | ||
| return ( | ||
| <SettingsNavContext.Provider value={value}> | ||
| {children} | ||
| </SettingsNavContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export const useSettingsNav = (): SettingsNavValue => { | ||
| const context = useContext(SettingsNavContext); | ||
| if (!context) { | ||
| throw new Error("useSettingsNav must be used within a SettingsNavProvider"); | ||
| } | ||
| return context; | ||
| }; |
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.
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.
The path outlives this panel —
renderActiveTabPanelOnlyunmounts and remounts it on every tab switch — so it can point at a node type deleted in the meantime, or arrive stale from a saved link.goToDepth(0)rather thanpop()so a depth-2 stale path converges in one dispatch instead of two.