[ENG - 506] Add support for custom links in the left sidebar#16472
[ENG - 506] Add support for custom links in the left sidebar#16472yash-learner wants to merge 10 commits into
Conversation
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds a ChangesCustom Navigation Links Pipeline
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Deploying care-preview with
|
| Latest commit: |
8a17625
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://40085126.care-preview-a7w.pages.dev |
| Branch Preview URL: | https://eng-506-support-for-insertin.care-preview-a7w.pages.dev |
There was a problem hiding this comment.
Pull request overview
Adds a new configuration surface for injecting custom navigation links into the left sidebar (via REACT_CUSTOM_NAV_LINKS and plugin manifests), including optional icons, placement scoping, and external/new-tab behavior.
Changes:
- Introduces
CustomNavLinkzod schema/types and wiresREACT_CUSTOM_NAV_LINKSthrough env typing, validation, andcareConfig. - Adds
useCustomNavLinks+CustomNavLinksto resolve and render configured links per sidebar context. - Updates
NavMainto support external/new-tab links by rendering anchors (instead of only ravigerActiveLink) and filtering unsafe external URLs.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vite-env.d.ts | Adds REACT_CUSTOM_NAV_LINKS to Vite env typings. |
| src/Utils/utils.ts | Adds isSafeExternalUrl() helper for http(s)-only external URL checks. |
| src/types/nav/customNavLink.ts | New zod schema/types for custom sidebar links + placement scopes. |
| src/pluginTypes.ts | Extends plugin manifest type to allow plugins to contribute customNavLinks. |
| src/hooks/useCustomNavLinks.tsx | New hook to merge env + plugin links, filter, and map to NavigationLink. |
| src/components/ui/sidebar/nav-main.tsx | Adds support for rendering anchors for external/new-tab links + URL filtering. |
| src/components/ui/sidebar/custom-nav-links.tsx | New component to render resolved custom links via NavMain. |
| src/components/ui/sidebar/app-sidebar.tsx | Computes current nav scope and mounts CustomNavLinks in the sidebar. |
| scripts/validate-env.ts | Adds parsing/validation for REACT_CUSTOM_NAV_LINKS. |
| care.config.ts | Adds customNavLinks to runtime config from REACT_CUSTOM_NAV_LINKS. |
| .example.env | Documents REACT_CUSTOM_NAV_LINKS format and examples. |
🎭 Playwright Test ResultsStatus: ✅ Passed
📊 Detailed results are available in the playwright-final-report artifact. Run: #9719 |
which is causing complex code and more review comments from copilot
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/ui/sidebar/nav-main.tsx`:
- Around line 78-90: The anchor element that renders when isExternal or
link.openInNewTab is true lacks accessibility information for screen readers.
Add an aria-label attribute to the <a> tag that indicates the link opens in a
new tab or a new window. The aria-label should combine the link's purpose with a
clear indication that it opens externally, using the openInNewTab variable to
conditionally include this text when a new tab will be opened. This ensures
assistive technology users are informed about the navigation behavior before
activating the link.
In `@src/hooks/useCustomNavLinks.tsx`:
- Around line 78-104: The useCustomNavLinks hook returns a new array reference
on every render due to the filter and map operations, causing unnecessary
re-renders of consuming components. Wrap the entire computation (from the
envLinks and pluginLinks declaration through the final return statement with all
the filter and map operations) in a useMemo hook, and include the appropriate
dependencies: t from useTranslation, careApps from useCareApps, and
careConfig.customNavLinks to ensure the memoized value is recalculated only when
these dependencies change.
In `@src/Utils/url.ts`:
- Around line 14-21: The isSafeExternalUrl function has a security vulnerability
where protocol-relative URLs like "//evil.com" are accepted in browser contexts
because they inherit the page protocol. To fix this, add an explicit check at
the beginning of the isSafeExternalUrl function to reject any URLs that start
with "//" (protocol-relative URLs) by returning false before attempting to parse
with new URL(). This ensures that protocol-relative URLs are blocked regardless
of runtime context.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 33a5ad17-c8f8-42ce-a016-cacff3a77d64
📒 Files selected for processing (11)
.example.envcare.config.tsscripts/validate-env.tssrc/Utils/url.tssrc/components/ui/sidebar/app-sidebar.tsxsrc/components/ui/sidebar/custom-nav-links.tsxsrc/components/ui/sidebar/nav-main.tsxsrc/hooks/useCustomNavLinks.tsxsrc/pluginTypes.tssrc/types/nav/customNavLink.tssrc/vite-env.d.ts
Greptile SummaryThis PR adds support for custom navigation links in the left sidebar, sourced from the
Confidence Score: 5/5Safe to merge — the URL safety checks are layered correctly, no data mutations or auth boundaries are touched, and the feature is purely additive to the sidebar. The change is well-contained: new files introduce URL predicates, a Zod schema, a hook, and a thin wrapper component. Existing sidebar code is refactored only to replace ActiveLink with renderNavLink, which preserves the same rendering for internal paths. No files require special attention; the minor t-import concern in nav-main.tsx is isolated to screen-reader text. Important Files Changed
Reviews (3): Last reviewed commit: "Merge branch 'develop' into ENG-506-supp..." | Re-trigger Greptile |
Proposed Changes
Fixes https://openhealthcarenetwork.atlassian.net/browse/ENG-506
Demo_.Add.custom.links.to.sidebar.mp4
Add support for custom links in the left sidebar
Lets deployments and plugins inject custom navigation links into the sidebar, scoped per nav context, with build-time and runtime URL safety.
How it's implemented
Config & schema
CustomNavLinkschema:title,url, optionalicon,external,openInNewTab, andplacement[](which nav contexts it appears in; defaults to["all"]).REACT_CUSTOM_NAV_LINKS(parsed in care.config.ts →careConfig.customNavLinks) and plugin manifests (customNavLinksin pluginTypes.ts). Env format documented in .example.env; typed via vite-env.d.ts.Resolution (useCustomNavLinks.tsx)
useCustomNavLinks(scope)concatenates env + plugin links, filters byplacement(matchingscopeor"all") and by nav-URL safety, then maps toNavigationLink[].iconMapallow-list (not arbitrary strings) to keep the bundle bounded and avoid injection.Rendering (sidebar)
<CustomNavLinks scope>) feeds resolved links intoNavMain; app-sidebar.tsx mounts it with the active scope.nav-main.tsxrenderNavLinkreturns a DOM element directly (for RadixasChild): internal links → ravigerActiveLink(same-tab SPA nav); external / new-tab links → sanitized<a target="_blank" rel="noopener noreferrer">.isRenderableNavLinkdrops anything failing URL safety.URL safety (url.ts)
isSafeExternalUrl(absolutehttp(s)only),isInternalNavPath(/…but not protocol-relative//), andisSafeNavUrl.superRefineonREACT_CUSTOM_NAV_LINKSso a misconfigured/unsafe URL fails the build instead of silently rendering.i18n — link titles are translated; English keys added to en.json.
Notes
Tagging: @ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit
REACT_CUSTOM_NAV_LINKSconfiguration