Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions src/client/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const Editor: FC<EditorProps> = ({
<DropdownMenuTrigger className="flex w-fit min-w-[140px] cursor-pointer items-center justify-between rounded-md border bg-surface-primary px-2 py-1.5 text-content-secondary transition-colors hover:text-content-primary data-[state=open]:text-content-primary">
<div className="flex items-center justify-center gap-2">
Copy link
Member

@Parkreiner Parkreiner Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to check the generated HTML. If the trigger is producing a button, the resulting markup is going to fail to pass from an HTML validator
#50 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggers do generate a button, so I've changed the divs to spans

<ZapIcon width={18} height={18} />
<p className="text-xs">Snippets</p>
<span className="text-xs">Snippets</span>
</div>
<PlusIcon width={18} height={18} />
</DropdownMenuTrigger>
Expand All @@ -108,7 +108,7 @@ export const Editor: FC<EditorProps> = ({
{snippets.map(
({ name, label, icon: Icon, snippet }, index) => (
<DropdownMenuItem
key={index}
key={`${label}-${index}`}
onClick={() => onAddSnippet(name, snippet)}
>
<Icon size={24} />
Expand All @@ -124,28 +124,33 @@ export const Editor: FC<EditorProps> = ({
<DropdownMenuTrigger className="flex w-fit min-w-[140px] cursor-pointer items-center justify-between rounded-md border bg-surface-primary px-2 py-1.5 text-content-secondary transition-colors hover:text-content-primary data-[state=open]:text-content-primary">
<div className="flex items-center justify-center gap-2">
<NotebookPenIcon width={18} height={18} />
<p className="text-xs">Examples</p>
<span className="text-xs">Examples</span>
</div>
<ChevronDownIcon width={18} height={18} />
</DropdownMenuTrigger>

<DropdownMenuPortal>
<DropdownMenuContent>
{Object.entries(examples).map(([slug, title]) => {
const href = `${window.location.origin}/parameters/example/${slug}`;
return (
<DropdownMenuItem key={slug} asChild={true}>
<a href={href} target="_blank" rel="noreferrer">
<span className="sr-only">
{" "}
(link opens in new tab)
</span>
<ExternalLinkIcon />
{title}
</a>
</DropdownMenuItem>
);
})}
{Object.entries(examples)
.sort()
Copy link
Member

@Parkreiner Parkreiner Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last change: because we didn't give a callback, .sort is going to stringify each entry array and then compare them. I'm guessing that you could get away with value1.localeCompare(value2), where each value is the second element of each entry?

.map(([slug, title], index) => {
Copy link
Member

@Parkreiner Parkreiner Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code was right before. I'm curious to know why this was changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to add .sort based on this comment from the old PR.

const href = `${window.location.origin}/parameters/example/${slug}`;
return (
<DropdownMenuItem
key={`${slug}-${index}`}
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using index in the key after sorting may cause React reconciliation issues. Since slug appears to be unique, consider using just key={slug} instead of including the index.

Suggested change
key={`${slug}-${index}`}
key={slug}

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code was right. index shouldn't be here

asChild={true}
>
<a href={href} target="_blank" rel="noreferrer">
<span className="sr-only">
{" "}
(link opens in new tab)
</span>
<ExternalLinkIcon />
{title}
</a>
</DropdownMenuItem>
);
})}
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenu>
Expand Down