Skip to content
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

Fix: More sensible handling of headline and subhead in wires list #165

Merged
merged 3 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 18 additions & 1 deletion newswires/client/src/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
EuiSpacer,
EuiSplitPanel,
EuiSwitch,
EuiText,
EuiTitle,
useGeneratedHtmlId,
} from '@elastic/eui';
Expand All @@ -19,6 +20,20 @@
import { paramsToQuerystring } from './urlState';
import { WireDetail } from './WireDetail';

function decideTitleContentForItem(wire: WireData) {
const { slug, headline } = wire.content;

if (headline && headline.length > 0) {
return (
<>
{slug && <EuiText size={'xs'}>{slug}</EuiText>} {headline}
</>
);
}

return <>{slug ?? 'No title'}</>;
}

export const Item = ({ id }: { id: string }) => {
const { handleDeselectItem, config } = useSearch();

Expand Down Expand Up @@ -71,7 +86,7 @@
: 'unknown error',
);
});
}, [id]);

Check warning on line 89 in newswires/client/src/Item.tsx

View workflow job for this annotation

GitHub Actions / Build and upload to riffraff

React Hook useEffect has a missing dependency: 'maybeSearchParams'. Either include it or remove the dependency array

return (
<EuiSplitPanel.Outer>
Expand All @@ -97,7 +112,9 @@
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={true}>
<EuiTitle size="xs">
<h2 id={pushedFlyoutTitleId}>{itemData.content.headline}</h2>
<h2 id={pushedFlyoutTitleId}>
{decideTitleContentForItem(itemData)}
</h2>
</EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
38 changes: 35 additions & 3 deletions newswires/client/src/WireItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ export const WireItemList = ({
);
};

function decideMainHeadingContent({
headline,
slug,
}: WireData['content']): string {
if (headline && headline.length > 0) {
return headline;
}
if (slug && slug.length > 0) {
return slug;
}
return 'No headline';
}

function decideSecondaryCardContent({
headline,
subhead,
bodyText,
}: WireData['content']): string | undefined {
if (subhead && subhead !== headline) {
return subhead;
}
const maybeBodyTextPreview = bodyText
? sanitizeHtml(bodyText, { allowedTags: [], allowedAttributes: {} }).slice(
0,
100,
)
: undefined;
if (maybeBodyTextPreview && maybeBodyTextPreview !== headline) {
return maybeBodyTextPreview;
}
}

const WirePreviewCard = ({
id,
supplier,
Expand Down Expand Up @@ -116,9 +148,9 @@ const WirePreviewCard = ({
const supplierLabel = supplierInfo?.label ?? supplier;
const supplierColour = supplierInfo?.colour ?? theme.euiTheme.colors.text;

const hasSlug = content.slug && content.slug.length > 0;
const mainHeadingContent = decideMainHeadingContent(content);

const mainHeadingContent = hasSlug ? content.slug : content.headline;
const maybeSecondaryCardContent = decideSecondaryCardContent(content);

const cardGrid = css`
display: grid;
Expand Down Expand Up @@ -175,7 +207,7 @@ const WirePreviewCard = ({
grid-area: content;
`}
>
{hasSlug && <p>{content.headline}</p>}
{maybeSecondaryCardContent && <p>{maybeSecondaryCardContent}</p>}
{highlight && highlight.trim().length > 0 && (
<EuiText
size="xs"
Expand Down
Loading