-
Notifications
You must be signed in to change notification settings - Fork 519
[codex] Show ad title when ad URL is missing #546
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
+54
−4
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,23 @@ | ||
| import { describe, expect, test } from 'bun:test' | ||
|
|
||
| import { getAdDisplayLabel } from '../choice-ad-banner' | ||
|
|
||
| describe('choice ad banner display label', () => { | ||
| test('uses the display domain when the ad has a URL', () => { | ||
| expect( | ||
| getAdDisplayLabel({ | ||
| title: 'Example Sponsor', | ||
| url: 'https://www.example.com/path', | ||
| }), | ||
| ).toEqual({ text: 'example.com', variant: 'domain' }) | ||
| }) | ||
|
|
||
| test('uses the ad title when the ad has no URL', () => { | ||
| expect( | ||
| getAdDisplayLabel({ | ||
| title: 'Example Sponsor', | ||
| url: '', | ||
| }), | ||
| ).toEqual({ text: 'Example Sponsor', variant: 'title' }) | ||
| }) | ||
| }) |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,13 @@ function truncateToLines(text: string, lineWidth: number, maxLines: number): str | |||||
| return text.slice(0, maxChars - 1) + '…' | ||||||
| } | ||||||
|
|
||||||
| const extractDomain = (url: string): string => { | ||||||
| function truncateToWidth(text: string, width: number): string { | ||||||
| if (width <= 0) return '' | ||||||
| if (text.length <= width) return text | ||||||
| return text.slice(0, width - 1) + '…' | ||||||
| } | ||||||
|
|
||||||
| export const extractDomain = (url: string): string => { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: cli/src/components/choice-ad-banner.tsx
Line: 35
Comment:
**Unnecessary export on `extractDomain`**
`extractDomain` is not imported by the test file (only `getAdDisplayLabel` is), so the `export` added here is unneeded. Keeping it private prevents unintended coupling to callers outside this module.
```suggestion
const extractDomain = (url: string): string => {
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| try { | ||||||
| const parsed = new URL(url) | ||||||
| return parsed.hostname.replace(/^www\./, '') | ||||||
|
|
@@ -34,6 +40,17 @@ const extractDomain = (url: string): string => { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| export function getAdDisplayLabel( | ||||||
| ad: Pick<AdResponse, 'title' | 'url'>, | ||||||
| ): { text: string; variant: 'domain' | 'title' } { | ||||||
| const url = ad.url.trim() | ||||||
| if (url) { | ||||||
| return { text: extractDomain(url), variant: 'domain' } | ||||||
| } | ||||||
|
|
||||||
| return { text: ad.title.trim() || 'Sponsored', variant: 'title' } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Calculate evenly distributed column widths that sum exactly to availableWidth. | ||||||
| * Distributes remainder pixels across the first N columns so there's no gap. | ||||||
|
|
@@ -89,8 +106,10 @@ export const ChoiceAdBanner: React.FC<ChoiceAdBannerProps> = ({ ads, onImpressio | |||||
| > | ||||||
| {visibleAds.map((ad, i) => { | ||||||
| const isHovered = hoveredIndex === i | ||||||
| const domain = extractDomain(ad.url) | ||||||
| const ctaText = ad.cta || ad.title || 'Learn more' | ||||||
| const label = getAdDisplayLabel(ad) | ||||||
| const labelMaxWidth = Math.max(0, widths[i] - ctaText.length - 5) | ||||||
| const labelText = truncateToWidth(label.text, labelMaxWidth) | ||||||
|
|
||||||
| return ( | ||||||
| <Button | ||||||
|
|
@@ -130,8 +149,16 @@ export const ChoiceAdBanner: React.FC<ChoiceAdBannerProps> = ({ ads, onImpressio | |||||
| > | ||||||
| {` ${ctaText} `} | ||||||
| </text> | ||||||
| <text style={{ fg: theme.muted, attributes: TextAttributes.UNDERLINE }}> | ||||||
| {domain} | ||||||
| <text | ||||||
| style={{ | ||||||
| fg: theme.muted, | ||||||
| attributes: | ||||||
| label.variant === 'domain' | ||||||
| ? TextAttributes.UNDERLINE | ||||||
| : TextAttributes.DIM, | ||||||
| }} | ||||||
| > | ||||||
| {labelText} | ||||||
| </text> | ||||||
|
|
||||||
| </box> | ||||||
|
|
||||||
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.