The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix currency and date display in cards (#28657)
Raphaël Bosif6d23b95366a
diff --git a/packages/twenty-front/src/modules/object-record/record-inline-cell/components/__stories__/RecordInlineCellDisplayMode.stories.tsx b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/__stories__/RecordInlineCellDisplayMode.stories.tsxindex 6ef1194af79..c408a28d938 100644--- a/packages/twenty-front/src/modules/object-record/record-inline-cell/components/__stories__/RecordInlineCellDisplayMode.stories.tsx+++ b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/__stories__/RecordInlineCellDisplayMode.stories.tsx@@ -5,13 +5,16 @@ import {} from '@storybook/react-vite';import { expect, fn, userEvent, waitFor, within } from 'storybook/test';+import { RecordCardBodyContainer } from '@/object-record/record-card/components/RecordCardBodyContainer';import { FieldDisplay } from '@/object-record/record-field/ui/components/FieldDisplay';+import { FieldFocusStaticFocusedProvider } from '@/object-record/record-field/ui/contexts/FieldFocusContextProvider';+import { RecordInlineCellContainer } from '@/object-record/record-inline-cell/components/RecordInlineCellContainer';import {RecordInlineCellContext,type RecordInlineCellContextProps,} from '@/object-record/record-inline-cell/components/RecordInlineCellContext';import { RecordInlineCellDisplayMode } from '@/object-record/record-inline-cell/components/RecordInlineCellDisplayMode';-import { IconPencil } from 'twenty-ui/icon';+import { IconCalendar, IconCurrencyDollar, IconPencil } from 'twenty-ui/icon';import { ComponentDecorator } from 'twenty-ui/testing';import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';import { ToastDecorator } from '~/testing/decorators/ToastDecorator';@@ -36,6 +39,14 @@ const spyOnClipboard = () => {return writeText;};+const renderCardField = () => (+ <RecordCardBodyContainer>+ <FieldFocusStaticFocusedProvider>+ <RecordInlineCellContainer />+ </FieldFocusStaticFocusedProvider>+ </RecordCardBodyContainer>+);+const meta: Meta<typeof RecordInlineCellDisplayMode> = {title: 'Modules/ObjectRecord/RecordInlineCell/RecordInlineCellDisplayMode',component: RecordInlineCellDisplayMode,@@ -140,3 +151,76 @@ export const CopiesLinkUrl: Story = {);},};++export const CurrencyStaysOnOneLine: Story = {+ render: renderCardField,+ decorators: [+ getFieldDecorator('company', 'annualRecurringRevenue', {+ amountMicros: 100000000,+ currencyCode: 'USD',+ }),+ getInlineCellContextDecorator({+ IconLabel: IconCurrencyDollar,+ label: 'Amount',+ isDisplayModeFixHeight: true,+ }),+ ],+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const currencyDisplay = await canvas.findByText('100');+ const amountRange = document.createRange();++ amountRange.setStart(+ currencyDisplay,+ currencyDisplay.childNodes.length - 1,+ );+ amountRange.setEnd(currencyDisplay, currencyDisplay.childNodes.length);++ const amountBounds = amountRange.getBoundingClientRect();+ const displayBounds = currencyDisplay.getBoundingClientRect();++ expect(amountBounds.width).toBeGreaterThan(0);+ expect(amountBounds.top).toBeGreaterThanOrEqual(displayBounds.top);+ expect(amountBounds.bottom).toBeLessThanOrEqual(displayBounds.bottom);++ const [fieldIcon, currencyIcon] = canvasElement.querySelectorAll('svg');+ const fieldIconBounds = fieldIcon.getBoundingClientRect();+ const currencyIconBounds = currencyIcon.getBoundingClientRect();+ const amountCenter = amountBounds.top + amountBounds.height / 2;+ const fieldIconCenter = fieldIconBounds.top + fieldIconBounds.height / 2;+ const currencyIconCenter =+ currencyIconBounds.top + currencyIconBounds.height / 2;++ expect(Math.abs(amountCenter - fieldIconCenter)).toBeLessThanOrEqual(1);+ expect(Math.abs(amountCenter - currencyIconCenter)).toBeLessThanOrEqual(1);+ },+};++export const DateTimeVerticallyCentered: Story = {+ render: renderCardField,+ decorators: [+ getFieldDecorator('task', 'dueAt', '2026-11-19T07:24:00.000Z'),+ getInlineCellContextDecorator({+ IconLabel: IconCalendar,+ label: 'Date',+ isDisplayModeFixHeight: true,+ }),+ ],+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const dateDisplay = await canvas.findByText(/2026/);+ const dateRange = document.createRange();++ dateRange.setStart(dateDisplay, 0);+ dateRange.setEnd(dateDisplay, 1);++ const dateBounds = dateRange.getBoundingClientRect();+ const [fieldIcon] = canvasElement.querySelectorAll('svg');+ const fieldIconBounds = fieldIcon.getBoundingClientRect();+ const dateCenter = dateBounds.top + dateBounds.height / 2;+ const fieldIconCenter = fieldIconBounds.top + fieldIconBounds.height / 2;++ expect(dateBounds.width).toBeGreaterThan(0);+ expect(Math.abs(dateCenter - fieldIconCenter)).toBeLessThanOrEqual(1);+ },+};diff --git a/packages/twenty-front/src/modules/ui/field/display/components/CurrencyDisplay.tsx b/packages/twenty-front/src/modules/ui/field/display/components/CurrencyDisplay.tsxindex e71f1363086..a1eba9562e2 100644--- a/packages/twenty-front/src/modules/ui/field/display/components/CurrencyDisplay.tsx+++ b/packages/twenty-front/src/modules/ui/field/display/components/CurrencyDisplay.tsx@@ -19,7 +19,8 @@ import { DEFAULT_DECIMAL_VALUE } from '@/localization/utils/formatNumber';const StyledCurrencyIconContainer = styled.span`align-items: center;- display: flex;+ display: inline-flex;+ vertical-align: text-bottom;`;type CurrencyDisplayProps = {diff --git a/packages/twenty-front/src/modules/ui/field/display/components/__stories__/DateDisplay.stories.tsx b/packages/twenty-front/src/modules/ui/field/display/components/__stories__/DateDisplay.stories.tsxindex 30cd0fe0000..eccaeaa1021 100644--- a/packages/twenty-front/src/modules/ui/field/display/components/__stories__/DateDisplay.stories.tsx+++ b/packages/twenty-front/src/modules/ui/field/display/components/__stories__/DateDisplay.stories.tsx@@ -39,5 +39,16 @@ export const Default: Story = {const canvas = within(canvasElement);const dateElement = await canvas.findByText('1 May, 2025');expect(dateElement).toBeInTheDocument();++ const dateRange = document.createRange();++ dateRange.selectNodeContents(dateElement);++ const textBounds = dateRange.getBoundingClientRect();+ const displayBounds = dateElement.getBoundingClientRect();+ const textCenter = textBounds.top + textBounds.height / 2;+ const displayCenter = displayBounds.top + displayBounds.height / 2;++ expect(Math.abs(textCenter - displayCenter)).toBeLessThanOrEqual(1);},};diff --git a/packages/twenty-front/src/modules/ui/field/display/components/internal/EllipsisDisplay/EllipsisDisplay.tsx b/packages/twenty-front/src/modules/ui/field/display/components/internal/EllipsisDisplay/EllipsisDisplay.tsxindex 28889b60f67..7320ca9b6b7 100644--- a/packages/twenty-front/src/modules/ui/field/display/components/internal/EllipsisDisplay/EllipsisDisplay.tsx+++ b/packages/twenty-front/src/modules/ui/field/display/components/internal/EllipsisDisplay/EllipsisDisplay.tsx@@ -1,11 +1,13 @@import { css } from '@linaria/core';import { clsx } from 'clsx';import { Text } from 'twenty-ui/primitives/typography';+import { themeCssVariables } from 'twenty-ui/theme';import { isDefined } from 'twenty-shared/utils';const styles = {ellipsis: css`- height: 20px;+ height: ${themeCssVariables.spacing[5]};+ line-height: ${themeCssVariables.spacing[5]};max-width: 100%;width: 100%;`,