diff --git a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationCard.tsx b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationCard.tsx index 62428e5a60..bc419984c8 100644 --- a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationCard.tsx +++ b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationCard.tsx @@ -20,15 +20,7 @@ import { generateFieldWidgetInstanceId } from '@/page-layout/widgets/field/utils import { useCurrentWidget } from '@/page-layout/widgets/hooks/useCurrentWidget'; import { useTargetRecord } from '@/ui/layout/contexts/useTargetRecord'; import { RightDrawerProvider } from '@/ui/layout/right-drawer/contexts/RightDrawerContext'; -import { t } from '@lingui/core/macro'; import { isDefined } from 'twenty-shared/utils'; -import { - AnimatedPlaceholder, - AnimatedPlaceholderEmptyContainer, - AnimatedPlaceholderEmptyTextContainer, - AnimatedPlaceholderEmptyTitle, - EMPTY_PLACEHOLDER_TRANSITION_PROPS, -} from 'twenty-ui/layout'; type FieldWidgetMorphRelationCardProps = { fieldDefinition: FieldDefinition; @@ -115,21 +107,7 @@ export const FieldWidgetMorphRelationCard = ({ ); if (validRecords.length === 0) { - return ( - - - - - - {t`No related records`} - - - - - ); + return null; } return ( diff --git a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationField.tsx b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationField.tsx index dd6b3510ed..f9b381eb56 100644 --- a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationField.tsx +++ b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetMorphRelationField.tsx @@ -4,14 +4,6 @@ import { type FieldDefinition } from '@/object-record/record-field/ui/types/Fiel import { type FieldMorphRelationMetadata } from '@/object-record/record-field/ui/types/FieldMetadata'; import { RightDrawerProvider } from '@/ui/layout/right-drawer/contexts/RightDrawerContext'; import styled from '@emotion/styled'; -import { t } from '@lingui/core/macro'; -import { - AnimatedPlaceholder, - AnimatedPlaceholderEmptyContainer, - AnimatedPlaceholderEmptyTextContainer, - AnimatedPlaceholderEmptyTitle, - EMPTY_PLACEHOLDER_TRANSITION_PROPS, -} from 'twenty-ui/layout'; const StyledContainer = styled.div` box-sizing: border-box; @@ -44,38 +36,22 @@ export const FieldWidgetMorphRelationField = ({ morphRelations: fieldMetadata.morphRelations, }); - if (recordsWithObjectNameSingular.length > 0) { - return ( - - - - {recordsWithObjectNameSingular.map((morphItem, index) => ( - - ))} - - - - ); + if (recordsWithObjectNameSingular.length === 0) { + return null; } return ( - - - - - {t`No related records`} - - - + + {recordsWithObjectNameSingular.map((morphItem, index) => ( + + ))} + ); diff --git a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationCard.tsx b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationCard.tsx index 3f0ca8b0ba..95375a8eac 100644 --- a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationCard.tsx +++ b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationCard.tsx @@ -18,15 +18,7 @@ import { generateFieldWidgetInstanceId } from '@/page-layout/widgets/field/utils import { useCurrentWidget } from '@/page-layout/widgets/hooks/useCurrentWidget'; import { useTargetRecord } from '@/ui/layout/contexts/useTargetRecord'; import { RightDrawerProvider } from '@/ui/layout/right-drawer/contexts/RightDrawerContext'; -import { t } from '@lingui/core/macro'; import { isDefined } from 'twenty-shared/utils'; -import { - AnimatedPlaceholder, - AnimatedPlaceholderEmptyContainer, - AnimatedPlaceholderEmptyTextContainer, - AnimatedPlaceholderEmptyTitle, - EMPTY_PLACEHOLDER_TRANSITION_PROPS, -} from 'twenty-ui/layout'; type FieldWidgetRelationCardProps = { fieldDefinition: FieldDefinition; @@ -112,21 +104,7 @@ export const FieldWidgetRelationCard = ({ : []; if (records.length === 0) { - return ( - - - - - - {t`No related records`} - - - - - ); + return null; } return ( diff --git a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationField.tsx b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationField.tsx index 503301d227..842e9bb9ea 100644 --- a/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationField.tsx +++ b/packages/twenty-front/src/modules/page-layout/widgets/field/components/FieldWidgetRelationField.tsx @@ -3,15 +3,7 @@ import { type FieldDefinition } from '@/object-record/record-field/ui/types/Fiel import { type FieldRelationMetadata } from '@/object-record/record-field/ui/types/FieldMetadata'; import { RightDrawerProvider } from '@/ui/layout/right-drawer/contexts/RightDrawerContext'; import styled from '@emotion/styled'; -import { t } from '@lingui/core/macro'; import { isDefined } from 'twenty-shared/utils'; -import { - AnimatedPlaceholder, - AnimatedPlaceholderEmptyContainer, - AnimatedPlaceholderEmptyTextContainer, - AnimatedPlaceholderEmptyTitle, - EMPTY_PLACEHOLDER_TRANSITION_PROPS, -} from 'twenty-ui/layout'; const StyledContainer = styled.div` box-sizing: border-box; @@ -41,7 +33,15 @@ export const FieldWidgetRelationField = ({ const relationObjectNameSingular = fieldMetadata.relationObjectMetadataNameSingular; - if (isOneToMany && Array.isArray(relationValue)) { + if (isOneToMany && !Array.isArray(relationValue)) { + return null; + } + + if (!isOneToMany && !isDefined(relationValue)) { + return null; + } + + if (isOneToMany) { return ( @@ -59,35 +59,15 @@ export const FieldWidgetRelationField = ({ ); } - if (!isOneToMany && isDefined(relationValue)) { - return ( - - - - - - - - ); - } - return ( - - - - - {t`No related records`} - - - + + + ); diff --git a/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsx index ecdc5b927d..17236cecbf 100644 --- a/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsx +++ b/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsx @@ -1762,103 +1762,6 @@ export const OneToManyRelationCardWidget: Story = { }, }; -export const ManyToOneRelationCardWidgetEmpty: Story = { - render: () => { - const widget: PageLayoutWidget = { - __typename: 'PageLayoutWidget', - id: 'widget-relation-card-empty', - pageLayoutTabId: TAB_ID_OVERVIEW, - type: WidgetType.FIELD, - title: 'Account Owner', - objectMetadataId: companyObjectMetadataItem.id, - gridPosition: { - __typename: 'GridPosition', - row: 4, - column: 0, - rowSpan: 1, - columnSpan: 2, - }, - configuration: { - __typename: 'FieldConfiguration', - configurationType: WidgetConfigurationType.FIELD, - fieldMetadataId: accountOwnerField.id, - layout: 'CARD', - }, - createdAt: '2024-01-01T00:00:00Z', - updatedAt: '2024-01-01T00:00:00Z', - deletedAt: null, - }; - - const initializeState = (snapshot: MutableSnapshot) => { - snapshot.set(objectMetadataItemsState, generatedMockObjectMetadataItems); - snapshot.set(shouldAppBeLoadingState, false); - const pageLayoutData = createPageLayoutWithWidget( - widget, - companyObjectMetadataItem.id, - ); - snapshot.set( - pageLayoutPersistedComponentState.atomFamily({ - instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID, - }), - pageLayoutData, - ); - snapshot.set( - pageLayoutDraftComponentState.atomFamily({ - instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID, - }), - pageLayoutData, - ); - snapshot.set(recordStoreFamilyState(TEST_RECORD_ID), { - ...mockCompanyRecord, - accountOwner: null, - }); - }; - - return ( -
- - - - - - - - - - - - - -
- ); - }, - play: async ({ canvasElement }) => { - const canvas = within(canvasElement); - - await waitFor(() => { - const emptyPlaceholder = canvas.queryByText('No related records'); - expect(emptyPlaceholder).toBeInTheDocument(); - }); - }, -}; - export const TimelineActivityRelationCardWidget: Story = { render: () => { const widget: PageLayoutWidget = { @@ -1966,101 +1869,3 @@ export const TimelineActivityRelationCardWidget: Story = { }); }, }; - -export const TimelineActivityRelationCardWidgetEmpty: Story = { - render: () => { - const widget: PageLayoutWidget = { - __typename: 'PageLayoutWidget', - id: 'widget-timeline-activity-relation-card-empty', - pageLayoutTabId: TAB_ID_OVERVIEW, - type: WidgetType.FIELD, - title: 'Workspace Member', - objectMetadataId: timelineActivityObjectMetadataItem.id, - gridPosition: { - __typename: 'GridPosition', - row: 12, - column: 0, - rowSpan: 1, - columnSpan: 2, - }, - configuration: { - __typename: 'FieldConfiguration', - configurationType: WidgetConfigurationType.FIELD, - fieldMetadataId: timelineActivityWorkspaceMemberField.id, - layout: 'CARD', - }, - createdAt: '2024-01-01T00:00:00Z', - updatedAt: '2024-01-01T00:00:00Z', - deletedAt: null, - }; - - const initializeState = (snapshot: MutableSnapshot) => { - snapshot.set(objectMetadataItemsState, generatedMockObjectMetadataItems); - snapshot.set(shouldAppBeLoadingState, false); - const pageLayoutData = createPageLayoutWithWidget( - widget, - timelineActivityObjectMetadataItem.id, - ); - snapshot.set( - pageLayoutPersistedComponentState.atomFamily({ - instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID, - }), - pageLayoutData, - ); - snapshot.set( - pageLayoutDraftComponentState.atomFamily({ - instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID, - }), - pageLayoutData, - ); - snapshot.set(recordStoreFamilyState(TEST_TIMELINE_ACTIVITY_RECORD_ID), { - ...mockTimelineActivityRecord, - workspaceMember: null, - }); - }; - - return ( -
- - - - - - - - - - - - - -
- ); - }, - play: async ({ canvasElement }) => { - const canvas = within(canvasElement); - - const emptyPlaceholder = await canvas.findByText('No related records'); - - await waitFor(() => { - expect(emptyPlaceholder).toBeVisible(); - }); - }, -};