-
Notifications
You must be signed in to change notification settings - Fork 0
Fix(differentials): route "Compare selected" directly to resolved presentation workflow #883
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
BigSimmo
wants to merge
5
commits into
main
from
codex/fix-restricted-viewport-error-on-compare-hk5lur
+103
−28
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b4f3b95
fix(differentials): wire selected compare to workflow
BigSimmo e0545bc
Merge branch 'main' into codex/fix-restricted-viewport-error-on-compa…
BigSimmo 713ca18
Merge branch 'main' into codex/fix-restricted-viewport-error-on-compa…
cursoragent 78ceaa9
fix(differentials): keep compare href helpers snapshot-free
cursoragent e59b9a1
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * Client-safe differentials href helpers. | ||
| * Keep this module free of `@/lib/differentials` / snapshot imports so the | ||
| * clinical-dashboard client bundle stays fixture-free. | ||
| */ | ||
|
|
||
| export function differentialRouteWithQuery(path: string, query: string, selectedIds?: Iterable<string>) { | ||
| const params = new URLSearchParams(); | ||
| const trimmedQuery = query.trim(); | ||
| if (trimmedQuery) params.set("q", trimmedQuery); | ||
| const ids = selectedIds ? Array.from(selectedIds, (id) => id.trim()).filter(Boolean) : []; | ||
| if (ids.length > 0) params.set("ids", ids.join(",")); | ||
| const suffix = params.toString(); | ||
| return suffix ? `${path}?${suffix}` : path; | ||
| } | ||
|
|
||
| /** | ||
| * Compare-selected CTA href. Resolves the presentation workflow on the server | ||
| * via `/differentials/presentations` (see presentations/route.ts) so the client | ||
| * never loads the differentials snapshot just to build a link. | ||
| */ | ||
| export function differentialSelectedCompareHref(query: string, selectedIds: Iterable<string>) { | ||
| return differentialRouteWithQuery("/differentials/presentations", query, selectedIds); | ||
| } |
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,51 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { NextRequest } from "next/server"; | ||
|
|
||
| import { GET as redirectPresentations } from "@/app/differentials/presentations/route"; | ||
| import { differentialRouteWithQuery, differentialSelectedCompareHref } from "@/lib/differentials-navigation"; | ||
|
|
||
| describe("differentials navigation", () => { | ||
| it("builds same-origin relative query routes", () => { | ||
| expect(differentialRouteWithQuery("/differentials/diagnoses", " acute confusion ")).toBe( | ||
| "/differentials/diagnoses?q=acute+confusion", | ||
| ); | ||
| }); | ||
|
|
||
| it("keeps compare-selected hrefs client-safe and ID-preserving without resolving the workflow locally", () => { | ||
| const href = differentialSelectedCompareHref( | ||
| "Pain", | ||
| new Set(["anorexia-nervosa", "bulimia-nervosa-binge-purge-pattern"]), | ||
| ); | ||
|
|
||
| expect(href).toBe("/differentials/presentations?q=Pain&ids=anorexia-nervosa%2Cbulimia-nervosa-binge-purge-pattern"); | ||
| expect(href).not.toContain("0.0.0.0"); | ||
| expect(href).not.toMatch(/^https?:\/\//); | ||
| }); | ||
|
|
||
| it("does not import the differentials snapshot module from the client-safe navigation helpers", async () => { | ||
| const { readFileSync } = await import("node:fs"); | ||
| const source = readFileSync(new URL("../src/lib/differentials-navigation.ts", import.meta.url), "utf8"); | ||
| expect(source).not.toMatch(/from\s+["']@\/lib\/differentials["']/); | ||
| expect(source).not.toMatch(/differentials-snapshot|loadDifferentialSnapshot/); | ||
| }); | ||
|
|
||
| it("redirects compare selection with a relative Location even when the request host is a bind address", () => { | ||
| const response = redirectPresentations( | ||
| new NextRequest( | ||
| "http://0.0.0.0:4461/differentials/presentations?q=Pain&ids=anorexia-nervosa,bulimia-nervosa-binge-purge-pattern", | ||
| ), | ||
| ); | ||
|
|
||
| expect(response.status).toBe(307); | ||
| const location = response.headers.get("location"); | ||
| expect(location).toMatch(/^\/differentials\/presentations\/[^/?]+/); | ||
| expect(location).toContain("q=Pain"); | ||
| expect(location).not.toContain("0.0.0.0"); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| const parsedUrl = new URL(location!, "http://placeholder.invalid"); | ||
| const idsParam = parsedUrl.searchParams.get("ids"); | ||
| expect(idsParam).toBeTruthy(); | ||
| const parsedIds = idsParam!.split(","); | ||
| expect(parsedIds).toEqual(["anorexia-nervosa", "bulimia-nervosa-binge-purge-pattern"]); | ||
| }); | ||
| }); | ||
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.