-
Notifications
You must be signed in to change notification settings - Fork 7
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
Open
trangdoan982
wants to merge
11
commits into
eng-2189-reorganize-roam-settings-replace-the-personalglobal-split
from
eng-2186-grammar-nodes-drill-down-and-settings-navigation-primitive
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
153faf2
ENG-2186 Grammar › Nodes drill-down and settings navigation primitive
trangdoan982 d858e53
Flush pending debounced writes when navigating away
trangdoan982 c55399a
Show the template under Suggestive mode behind a collapsed toggle
trangdoan982 fdc2150
Use the toggle as the template's only header
trangdoan982 756ad07
ENG-2186 Commit deferred setting writes once, from one place
trangdoan982 fe002bf
ENG-2186 Cover the settings navigation reducer and tab aliases
trangdoan982 9a7b1b4
ENG-2186 Let settingsTabs say what is and is not a tab id
trangdoan982 de6c4f0
ENG-2186 Regroup the node page and simplify the drill-down header
trangdoan982 84358c1
ENG-2186 Attributes last on the node page
trangdoan982 92a4176
ENG-2186 Open up the space between node page groups
trangdoan982 9dba941
ENG-2186 Restore the brace a merge dropped from settingsStyles.css
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
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,76 @@ | ||
| import React, { useEffect } from "react"; | ||
| import { OnloadArgs } from "roamjs-components/types"; | ||
| import getDiscourseNodes, { | ||
| excludeDefaultNodes, | ||
| } from "~/utils/getDiscourseNodes"; | ||
| import { formatHexColor } from "./DiscourseNodeCanvasSettings"; | ||
| import { nodeConfigSegmentIds } from "./utils/settingsNavigation"; | ||
| import { useSettingsNav } from "./navigation/SettingsNavContext"; | ||
| import SettingsPageHeader from "./navigation/SettingsPageHeader"; | ||
| import DiscourseNodeConfigPanel from "./DiscourseNodeConfigPanel"; | ||
| import NodeConfig from "./NodeConfig"; | ||
| import NodeIndexPage from "./NodeIndexPage"; | ||
| import NodeTemplatePage from "./NodeTemplatePage"; | ||
|
|
||
| const NODES_ANCESTOR_LABELS = ["Grammar"] as const; | ||
|
|
||
| const SUB_PAGE_LABELS: Record<string, string | undefined> = { | ||
| [nodeConfigSegmentIds.index]: "Index", | ||
| [nodeConfigSegmentIds.template]: "Template", | ||
| }; | ||
|
|
||
| const GrammarNodesRoute = ({ | ||
| onloadArgs, | ||
| }: { | ||
| onloadArgs: OnloadArgs; | ||
| }): JSX.Element => { | ||
| const { segments, goToDepth } = useSettingsNav(); | ||
| const nodes = getDiscourseNodes().filter(excludeDefaultNodes); | ||
|
|
||
| const [nodeTypeUid, subPage] = 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, segmentIndex: number): string => | ||
| segmentIndex === 0 | ||
| ? (nodes.find((n) => n.type === segment)?.text ?? segment) | ||
| : (SUB_PAGE_LABELS[segment] ?? segment); | ||
|
|
||
| // Sub-pages fall through to the stylesheet's default dot colour. | ||
| const dotColor = subPage | ||
| ? undefined | ||
| : formatHexColor(node?.canvasSettings?.color ?? "") || undefined; | ||
|
|
||
| return ( | ||
| <div className="dg-settings-route"> | ||
| <SettingsPageHeader | ||
| ancestorLabels={NODES_ANCESTOR_LABELS} | ||
| rootLabel="Nodes" | ||
| resolveLabel={resolveLabel} | ||
| dotColor={dotColor} | ||
| /> | ||
| <div className="dg-settings-route__body"> | ||
| {!node ? ( | ||
| <div className="p-1"> | ||
| <DiscourseNodeConfigPanel /> | ||
| </div> | ||
| ) : subPage === nodeConfigSegmentIds.index ? ( | ||
| <NodeIndexPage node={node} onloadArgs={onloadArgs} /> | ||
| ) : subPage === nodeConfigSegmentIds.template ? ( | ||
| <NodeTemplatePage node={node} /> | ||
| ) : ( | ||
| <NodeConfig node={node} /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default GrammarNodesRoute; | ||
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.