-
Notifications
You must be signed in to change notification settings - Fork 4
feat(search): merged layout in search index #38
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f402ef8
feat(search): consume merged nav layout in search index
platex-rehor-bot bb18ea6
refactor(search): extract DynamicPfIcon, fix parent injection + stale…
platex-rehor-bot 090e37d
fix(common): type DynamicPfIcon state to accept className prop
platex-rehor-bot 19f50a0
fix(search): reflect custom groups and icon overrides in search index
platex-rehor-bot 27a9e5f
fix(search): multi-level nesting for custom groups, PF-aligned guides
Hyperkid123 34249e7
fix(search): preserve parent chain for nested group results
platex-rehor-bot ee5c3f7
fix(search): recompute lazy icon when name prop changes
platex-rehor-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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type { ComponentType } from "react"; | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import { getCachedPfIcon, loadPfIcon } from "./pfIconLoader.js"; | ||
|
|
||
| /** PF icons accept at least className; keep narrow to avoid `any`. */ | ||
| type PfIconComponent = ComponentType<{ className?: string }>; | ||
|
|
||
| interface DynamicPfIconProps { | ||
| /** PascalCase PF icon name, e.g. "CogIcon". */ | ||
| name: string; | ||
| /** Optional className forwarded to the icon wrapper. */ | ||
| className?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Renders a PatternFly icon loaded on demand. | ||
| * | ||
| * Handles async dynamic-import loading internally — consumers just pass the | ||
| * PascalCase icon name and get the rendered icon (or nothing while loading). | ||
| * | ||
| * @example | ||
| * <DynamicPfIcon name="FolderOpenIcon" /> | ||
| */ | ||
| export default function DynamicPfIcon({ name, className }: DynamicPfIconProps) { | ||
| const [Icon, setIcon] = useState<PfIconComponent | null>( | ||
| () => (getCachedPfIcon(name) as PfIconComponent | undefined) ?? null, | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| let active = true; | ||
| const cached = getCachedPfIcon(name) as PfIconComponent | undefined; | ||
| if (cached) { | ||
| setIcon(() => cached); | ||
| return; | ||
| } | ||
| loadPfIcon(name).then((comp) => { | ||
| if (active && comp) setIcon(() => comp as PfIconComponent); | ||
| }); | ||
| return () => { | ||
| active = false; | ||
| }; | ||
| }, [name]); | ||
|
|
||
| if (!Icon) return null; | ||
| return <Icon {...(className ? { className } : {})} />; | ||
| } |
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,60 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| iconNameToFile, | ||
| iconNameToKeywords, | ||
| iconSlugToName, | ||
| } from "../pfIconLoader"; | ||
|
|
||
| describe("iconNameToFile", () => { | ||
| it("converts PascalCase to kebab-case", () => { | ||
| expect(iconNameToFile("CogIcon")).toBe("cog-icon"); | ||
| expect(iconNameToFile("FolderOpenIcon")).toBe("folder-open-icon"); | ||
| expect(iconNameToFile("ShieldAltIcon")).toBe("shield-alt-icon"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("iconNameToKeywords", () => { | ||
| it("extracts search keywords from icon name", () => { | ||
| expect(iconNameToKeywords("FolderOpenIcon")).toEqual(["folder", "open"]); | ||
| expect(iconNameToKeywords("CogIcon")).toEqual(["cog"]); | ||
| expect(iconNameToKeywords("ShieldAltIcon")).toEqual(["shield", "alt"]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("iconSlugToName", () => { | ||
| it("converts kebab-case slug to PascalCase icon name", () => { | ||
| expect(iconSlugToName("cog")).toBe("CogIcon"); | ||
| expect(iconSlugToName("folder-open")).toBe("FolderOpenIcon"); | ||
| expect(iconSlugToName("shield-alt")).toBe("ShieldAltIcon"); | ||
| }); | ||
|
|
||
| it("handles single-word slugs", () => { | ||
| expect(iconSlugToName("cubes")).toBe("CubesIcon"); | ||
| expect(iconSlugToName("globe")).toBe("GlobeIcon"); | ||
| expect(iconSlugToName("key")).toBe("KeyIcon"); | ||
| }); | ||
|
|
||
| it("handles multi-segment slugs", () => { | ||
| expect(iconSlugToName("layer-group")).toBe("LayerGroupIcon"); | ||
| expect(iconSlugToName("puzzle-piece")).toBe("PuzzlePieceIcon"); | ||
| }); | ||
|
|
||
| it("roundtrips with iconNameToFile (minus trailing -icon)", () => { | ||
| const names = [ | ||
| "CogIcon", | ||
| "FolderOpenIcon", | ||
| "CubesIcon", | ||
| "ShieldAltIcon", | ||
| "LayerGroupIcon", | ||
| ]; | ||
| for (const name of names) { | ||
| // iconNameToFile("CogIcon") → "cog-icon" | ||
| // strip trailing "-icon" → "cog" | ||
| // iconSlugToName("cog") → "CogIcon" | ||
| const file = iconNameToFile(name); | ||
| const slug = file.replace(/-icon$/, ""); | ||
| expect(iconSlugToName(slug)).toBe(name); | ||
| } | ||
| }); | ||
| }); |
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
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.
I believe this function already exists somewhere. In the nav editor. Can we deduplicate? Are there any duplications introduced?
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.
Good catch — I searched the codebase and
iconSlugToNameis actually new (no existing duplicate). The closest related functions areiconNameToFileandiconNameToKeywordsin the same file, but they go the opposite direction (PascalCase → kebab/keywords). The nav editor (GroupFormModal,IconGalleryModal) works with PascalCase names directly.Since the function is already in
packages/common/src/pfIconLoader.ts, it's available as a shared utility across all packages.