Skip to content

Commit 4998df4

Browse files
authored
fix(description-card): handle negative diff in relative date & use SPA navigation for links (#264)
* fix(description-card): handle negative diff in relative date format When updatedAt is slightly in the future relative to now (e.g., due to server clock differences after redirect from edit page), Math.floor of a small negative number produces -1, which displayed as '-1 days ago'. Fix: treat any negative diffDays as 'Today'. Also adds tests for renderField covering text, badge, date, money, link, and address field types. * Format files * fix(description-card): use react-router Link for internal navigation Replace <a href> with react-router <Link to> in LinkFieldRenderer (for internal links) and ReferenceFieldRenderer to enable SPA navigation instead of full page reloads. External links (meta.external: true) still use <a target="_blank">. Also adds reference field tests and improves link field test coverage. * feat(description-card): show minutes/hours in relative date & support future dates - Replace 'Today' with granular 'X minutes ago' / 'X hours ago' - Add future date support: 'In X minutes', 'In X hours', 'Tomorrow', etc. - Add 'Just now' for diffs under 1 minute (past and future) - Add comprehensive tests for all relative date thresholds - Add table-formatted doc comment for formatDate function * feat(description-card): add i18n support for relative date labels - Add i18n.ts with en/ja translations for all relative date strings - Use useDescriptionCardT hook in DateFieldRenderer - formatDate accepts optional t function, falls back to English - Fix circular dependency in tests by reordering imports - Add AppShell context wrapper to DescriptionCard tests * chore: add changeset for description-card fixes
1 parent 70fb128 commit 4998df4

5 files changed

Lines changed: 721 additions & 18 deletions

File tree

.changeset/brave-olives-march.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@tailor-platform/app-shell": patch
3+
---
4+
5+
Fix and improve `DescriptionCard` component:
6+
7+
- Fix relative date formatting producing incorrect output for future dates (negative time diff)
8+
- Add i18n label support for relative date strings
9+
- Use react-router `<Link>` for internal navigation in link and reference fields instead of plain `<a>` tags

packages/core/src/components/description-card/DescriptionCard.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { afterEach, describe, expect, it } from "vitest";
22
import { cleanup, render, screen } from "@testing-library/react";
3+
import { createAppShellWrapper } from "../../../tests/test-utils";
34
import { DescriptionCard } from "./DescriptionCard";
45

6+
const wrapper = createAppShellWrapper();
7+
58
afterEach(() => {
69
cleanup();
710
});
@@ -14,6 +17,7 @@ describe("DescriptionCard", () => {
1417
data={{ status: "NOT_RECEIVED" }}
1518
fields={[{ key: "status", label: "Status", type: "badge" }]}
1619
/>,
20+
{ wrapper },
1721
);
1822

1923
expect(screen.getByText("Not received")).toBeDefined();
@@ -33,6 +37,7 @@ describe("DescriptionCard", () => {
3337
},
3438
]}
3539
/>,
40+
{ wrapper },
3641
);
3742

3843
expect(screen.getByText("NOT_RECEIVED")).toBeDefined();

0 commit comments

Comments
 (0)