Skip to content
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
13 changes: 13 additions & 0 deletions src/components/GlassyRecordCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
color: var(--record-title-hover);
}

.glassy-record-card--open .glassy-record-card__button {
grid-template-columns: minmax(0, 1fr);
}

.glassy-record-card__copy,
.glassy-record-card__aside {
min-width: 0;
Expand Down Expand Up @@ -157,12 +161,21 @@
min-height: 1.45em;
max-height: 1.45em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--muted);
font-size: 0.9rem;
line-height: 1.45;
overflow-wrap: anywhere;
}

.glassy-record-card--open .glassy-record-card__summary {
max-height: none;
overflow: visible;
text-overflow: clip;
white-space: normal;
}

.glassy-record-card__association {
align-self: flex-start;
max-width: 100%;
Expand Down
4 changes: 2 additions & 2 deletions src/components/GlassyRecordCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChevronDown } from "lucide-react";
import { Chip } from "@/components/Chip";
import { GlassyCard } from "@/components/GlassyCard";
import { StageChip } from "@/components/StageChip";
import { proposalSummaryPreview } from "@/lib/textPreview";
import { normalizePreviewText } from "@/lib/textPreview";
import { cn } from "@/lib/utils";
import type { Stage } from "@/types/stages";
import "./GlassyRecordCard.css";
Expand Down Expand Up @@ -40,7 +40,7 @@ export function GlassyRecordCard({
title,
}: GlassyRecordCardProps) {
const renderedSummary =
typeof summary === "string" ? proposalSummaryPreview(summary) : summary;
typeof summary === "string" ? normalizePreviewText(summary) : summary;

return (
<GlassyCard
Expand Down
6 changes: 5 additions & 1 deletion src/lib/textPreview.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
export const PROPOSAL_SUMMARY_PREVIEW_MAX = 180;

export function normalizePreviewText(value: string): string {
return value.replace(/\s+/g, " ").trim();
}

export function proposalSummaryPreview(
value: string,
maxLength = PROPOSAL_SUMMARY_PREVIEW_MAX,
): string {
const text = value.replace(/\s+/g, " ").trim();
const text = normalizePreviewText(value);
if (text.length <= maxLength) return text;

const hardCut = text.slice(0, maxLength + 1);
Expand Down
57 changes: 57 additions & 0 deletions tests/unit/glassy-record-card.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { test } from "@rstest/core";
import { renderToStaticMarkup } from "react-dom/server";
import { MemoryRouter } from "react-router";

import { GlassyRecordCard } from "../../src/components/GlassyRecordCard";

test("record cards retain the complete summary for expansion", () => {
const finalSentence = "The complete final sentence remains available.";
const summary = `${"Detailed proposal context. ".repeat(16)}${finalSentence}`;
const html = renderToStaticMarkup(
<MemoryRouter>
<GlassyRecordCard
expanded
onToggle={() => undefined}
stage="pool"
summary={summary}
title="Long proposal"
>
<p>Proposal details</p>
</GlassyRecordCard>
</MemoryRouter>,
);

assert.match(html, /The complete final sentence remains available\./);
assert.match(html, /glassy-record-card--open/);
});

test("record cards use visual ellipsis only while collapsed", () => {
const css = readFileSync(
join(process.cwd(), "src/components/GlassyRecordCard.css"),
"utf8",
);
const collapsedRule = css.match(
/\.glassy-record-card__summary\s*\{([^}]*)\}/,
)?.[1];
const expandedRule = css.match(
/\.glassy-record-card--open \.glassy-record-card__summary\s*\{([^}]*)\}/,
)?.[1];

assert.ok(collapsedRule);
assert.match(collapsedRule, /max-height:\s*1\.45em/);
assert.match(collapsedRule, /text-overflow:\s*ellipsis/);
assert.match(collapsedRule, /white-space:\s*nowrap/);

assert.ok(expandedRule);
assert.match(expandedRule, /max-height:\s*none/);
assert.match(expandedRule, /overflow:\s*visible/);
assert.match(expandedRule, /white-space:\s*normal/);

assert.match(
css,
/\.glassy-record-card--open \.glassy-record-card__button\s*\{[^}]*grid-template-columns:\s*minmax\(0, 1fr\)/s,
);
});
15 changes: 14 additions & 1 deletion tests/unit/text-preview.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { test } from "@rstest/core";
import assert from "node:assert/strict";

import { proposalSummaryPreview } from "../../src/lib/textPreview.ts";
import {
normalizePreviewText,
PROPOSAL_SUMMARY_PREVIEW_MAX,
proposalSummaryPreview,
} from "../../src/lib/textPreview.ts";

test("normalizes preview text without shortening it", () => {
const summary = `A complete summary ${"with substantial detail ".repeat(20)}`;

const normalized = normalizePreviewText(` ${summary}\n\n`);

assert.equal(normalized, summary.trim());
assert.ok(normalized.length > PROPOSAL_SUMMARY_PREVIEW_MAX);
});

test("proposal summary preview caps text without adding ellipsis", () => {
const summary = [
Expand Down
Loading