-
Notifications
You must be signed in to change notification settings - Fork 287
fix: stabilize command palette search results #2052
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
DonKoko
merged 14 commits into
main
from
codex/implement-core-command-palette-functionality-lintkk
Sep 29, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
31751e7
fix: stabilize command palette search results
carlosvirreira 6b98493
Merge branch 'main' into codex/implement-core-command-palette-functio…
DonKoko 96f5072
feat: expand command palette with universal search across kits, booki…
DonKoko a09a08e
fix: guard CommandPaletteButton against missing provider
DonKoko 700d82e
fix: implement comprehensive security hardening for command palette s…
DonKoko 52a2374
fixing styling of buttom
DonKoko 949d0a4
mend
DonKoko 2cd5a03
fixing styling of buttom
DonKoko 18acb07
fix: exclude bookings and team members from personal workspace comman…
DonKoko c26fca9
Merge branch 'main' into codex/implement-core-command-palette-functio…
DonKoko 8968427
feat: implement comprehensive role-based access control for command p…
DonKoko 9fc3748
ui and text fixes
DonKoko 467ee74
feat: enhance command palette asset search with direct getAssets inte…
DonKoko ac73430
improving search results for quick find
DonKoko 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
86 changes: 86 additions & 0 deletions
86
app/components/layout/command-palette/command-palette-button.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,86 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { useMatches } from "@remix-run/react"; | ||
| import { SearchIcon } from "lucide-react"; | ||
|
|
||
| import { Button } from "~/components/shared/button"; | ||
| import type { RouteHandleWithName } from "~/modules/types"; | ||
| import { tw } from "~/utils/tw"; | ||
| import { useCommandPaletteSafe } from "./command-palette-context"; | ||
|
|
||
| type CommandPaletteButtonVariant = "default" | "icon"; | ||
|
|
||
| function useShortcutLabel() { | ||
| const [label, setLabel] = useState("⌘K"); | ||
|
|
||
| useEffect(() => { | ||
| if (typeof navigator === "undefined") { | ||
| return; | ||
| } | ||
|
|
||
| const isAppleDevice = /Mac|iPhone|iPad|iPod/i.test(navigator.platform); | ||
| setLabel(isAppleDevice ? "⌘K" : "Ctrl K"); | ||
| }, []); | ||
|
|
||
| return label; | ||
| } | ||
|
|
||
| export function CommandPaletteButton({ | ||
| className, | ||
| variant = "default", | ||
| }: { | ||
| className?: string; | ||
| variant?: CommandPaletteButtonVariant; | ||
| }) { | ||
| const matches = useMatches(); | ||
| const currentRoute: RouteHandleWithName = matches[matches.length - 1]; | ||
| const shouldRenderButton = !["bookings.$bookingId.overview"].includes( | ||
| // on the user bookings page we dont want to show the custodian filter becuase they are alreayd filtered for that user | ||
| currentRoute?.handle?.name | ||
| ); | ||
| const context = useCommandPaletteSafe(); | ||
| const shortcut = useShortcutLabel(); | ||
|
|
||
| // Don't render if the command palette provider is not available | ||
| if (!context || !shouldRenderButton) { | ||
| return null; | ||
| } | ||
|
|
||
| const { setOpen } = context; | ||
|
|
||
| if (variant === "icon") { | ||
| return ( | ||
| <Button | ||
| type="button" | ||
| onClick={() => setOpen(true)} | ||
| aria-label="Open command palette" | ||
| variant={"secondary"} | ||
| className={tw( | ||
| "flex items-center justify-center rounded border-0 bg-white px-2 py-[2px] text-gray-600 transition hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 md:border-gray-200", | ||
| className | ||
| )} | ||
| > | ||
| <SearchIcon className="size-5" /> | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Button | ||
| type="button" | ||
| onClick={() => setOpen(true)} | ||
| variant={"secondary"} | ||
| className={tw( | ||
| "flex w-full items-center gap-2 rounded bg-white py-2 text-sm text-gray-600 transition hover:border-gray-300 hover:text-gray-800 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 md:w-64 md:border md:border-gray-200", | ||
| className | ||
| )} | ||
| > | ||
| <div className="flex w-full items-center gap-2"> | ||
| <span className="hidden sm:inline">Quick find</span> | ||
| <span className="sm:hidden">Quick find...</span> | ||
| <span className="ml-auto hidden items-center gap-1 rounded bg-gray-50 px-1 text-[10px] font-medium text-gray-500 md:inline-flex md:border md:border-gray-200"> | ||
| {shortcut} | ||
| </span> | ||
| </div> | ||
| </Button> | ||
| ); | ||
| } | ||
51 changes: 51 additions & 0 deletions
51
app/components/layout/command-palette/command-palette-context.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,51 @@ | ||
| import { createContext, useContext, useMemo, useState } from "react"; | ||
|
|
||
| interface CommandPaletteContextValue { | ||
| open: boolean; | ||
| setOpen: (value: boolean) => void; | ||
| toggle: () => void; | ||
| } | ||
|
|
||
| const CommandPaletteContext = createContext<CommandPaletteContextValue | null>( | ||
| null | ||
| ); | ||
|
|
||
| export function useCommandPalette() { | ||
| const context = useContext(CommandPaletteContext); | ||
|
|
||
| if (!context) { | ||
| throw new Error( | ||
| "useCommandPalette must be used within a CommandPaletteProvider" | ||
| ); | ||
| } | ||
|
|
||
| return context; | ||
| } | ||
|
|
||
| export function useCommandPaletteSafe() { | ||
| const context = useContext(CommandPaletteContext); | ||
| return context; | ||
| } | ||
|
|
||
| export function CommandPaletteProvider({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) { | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| const value = useMemo( | ||
| () => ({ | ||
| open, | ||
| setOpen, | ||
| toggle: () => setOpen((previous) => !previous), | ||
| }), | ||
| [open] | ||
| ); | ||
|
|
||
| return ( | ||
| <CommandPaletteContext.Provider value={value}> | ||
| {children} | ||
| </CommandPaletteContext.Provider> | ||
| ); | ||
| } |
180 changes: 180 additions & 0 deletions
180
app/components/layout/command-palette/command-palette.test.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,180 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| getAssetCommandValue, | ||
| getBookingCommandValue, | ||
| getKitCommandValue, | ||
| getLocationCommandValue, | ||
| getTeamMemberCommandValue, | ||
| type AssetSearchResult, | ||
| type BookingSearchResult, | ||
| type KitSearchResult, | ||
| type LocationSearchResult, | ||
| type TeamMemberSearchResult, | ||
| } from "./command-palette"; | ||
|
|
||
| describe("getAssetCommandValue", () => { | ||
| const baseAsset: AssetSearchResult = { | ||
| id: "asset-123", | ||
| title: "4K Camera", | ||
| sequentialId: "AS-100", | ||
| mainImage: null, | ||
| mainImageExpiration: null, | ||
| locationName: "Studio", | ||
| description: null, | ||
| qrCodes: [], | ||
| categoryName: null, | ||
| tagNames: [], | ||
| custodianName: null, | ||
| custodianUserName: null, | ||
| barcodes: [], | ||
| customFieldValues: [], | ||
| }; | ||
|
|
||
| it("includes the primary searchable fields", () => { | ||
| const value = getAssetCommandValue(baseAsset); | ||
|
|
||
| expect(value).toContain("asset-123"); | ||
| expect(value).toContain("4K Camera"); | ||
| expect(value).toContain("AS-100"); | ||
| expect(value).toContain("Studio"); | ||
| }); | ||
|
|
||
| it("falls back gracefully when optional fields are missing", () => { | ||
| const value = getAssetCommandValue({ | ||
| ...baseAsset, | ||
| sequentialId: null, | ||
| locationName: null, | ||
| }); | ||
|
|
||
| expect(value).toContain("asset-123"); | ||
| expect(value).toContain("4K Camera"); | ||
| expect(value).not.toContain("null"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getKitCommandValue", () => { | ||
| const baseKit: KitSearchResult = { | ||
| id: "kit-456", | ||
| name: "Camera Kit", | ||
| description: "Professional camera equipment", | ||
| status: "AVAILABLE", | ||
| assetCount: 5, | ||
| }; | ||
|
|
||
| it("includes the primary searchable fields", () => { | ||
| const value = getKitCommandValue(baseKit); | ||
|
|
||
| expect(value).toContain("kit-456"); | ||
| expect(value).toContain("Camera Kit"); | ||
| expect(value).toContain("Professional camera equipment"); | ||
| }); | ||
|
|
||
| it("falls back gracefully when optional fields are missing", () => { | ||
| const value = getKitCommandValue({ | ||
| ...baseKit, | ||
| description: null, | ||
| }); | ||
|
|
||
| expect(value).toContain("kit-456"); | ||
| expect(value).toContain("Camera Kit"); | ||
| expect(value).not.toContain("null"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getBookingCommandValue", () => { | ||
| const baseBooking: BookingSearchResult = { | ||
| id: "booking-789", | ||
| name: "Photo Shoot", | ||
| description: "Wedding photography session", | ||
| status: "RESERVED", | ||
| custodianName: "John Doe", | ||
| from: "2024-01-15T10:00:00Z", | ||
| to: "2024-01-15T18:00:00Z", | ||
| }; | ||
|
|
||
| it("includes the primary searchable fields", () => { | ||
| const value = getBookingCommandValue(baseBooking); | ||
|
|
||
| expect(value).toContain("booking-789"); | ||
| expect(value).toContain("Photo Shoot"); | ||
| expect(value).toContain("Wedding photography session"); | ||
| expect(value).toContain("John Doe"); | ||
| }); | ||
|
|
||
| it("falls back gracefully when optional fields are missing", () => { | ||
| const value = getBookingCommandValue({ | ||
| ...baseBooking, | ||
| description: null, | ||
| custodianName: null, | ||
| }); | ||
|
|
||
| expect(value).toContain("booking-789"); | ||
| expect(value).toContain("Photo Shoot"); | ||
| expect(value).not.toContain("null"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getLocationCommandValue", () => { | ||
| const baseLocation: LocationSearchResult = { | ||
| id: "location-101", | ||
| name: "Main Studio", | ||
| description: "Primary photography studio", | ||
| address: "123 Main St, City", | ||
| assetCount: 12, | ||
| }; | ||
|
|
||
| it("includes the primary searchable fields", () => { | ||
| const value = getLocationCommandValue(baseLocation); | ||
|
|
||
| expect(value).toContain("location-101"); | ||
| expect(value).toContain("Main Studio"); | ||
| expect(value).toContain("Primary photography studio"); | ||
| expect(value).toContain("123 Main St, City"); | ||
| }); | ||
|
|
||
| it("falls back gracefully when optional fields are missing", () => { | ||
| const value = getLocationCommandValue({ | ||
| ...baseLocation, | ||
| description: null, | ||
| address: null, | ||
| }); | ||
|
|
||
| expect(value).toContain("location-101"); | ||
| expect(value).toContain("Main Studio"); | ||
| expect(value).not.toContain("null"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getTeamMemberCommandValue", () => { | ||
| const baseMember: TeamMemberSearchResult = { | ||
| id: "member-202", | ||
| name: "Jane Smith", | ||
| email: "jane@example.com", | ||
| firstName: "Jane", | ||
| lastName: "Smith", | ||
| }; | ||
|
|
||
| it("includes the primary searchable fields", () => { | ||
| const value = getTeamMemberCommandValue(baseMember); | ||
|
|
||
| expect(value).toContain("member-202"); | ||
| expect(value).toContain("Jane Smith"); | ||
| expect(value).toContain("jane@example.com"); | ||
| expect(value).toContain("Jane"); | ||
| expect(value).toContain("Smith"); | ||
| }); | ||
|
|
||
| it("falls back gracefully when optional fields are missing", () => { | ||
| const value = getTeamMemberCommandValue({ | ||
| ...baseMember, | ||
| email: null, | ||
| firstName: null, | ||
| lastName: null, | ||
| }); | ||
|
|
||
| expect(value).toContain("member-202"); | ||
| expect(value).toContain("Jane Smith"); | ||
| expect(value).not.toContain("null"); | ||
| }); | ||
| }); |
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.