diff --git a/packages/twenty-front/src/modules/page-layout/widgets/components/WidgetRenderer.tsx b/packages/twenty-front/src/modules/page-layout/widgets/components/WidgetRenderer.tsx index 5e86904391..5766ad54d6 100644 --- a/packages/twenty-front/src/modules/page-layout/widgets/components/WidgetRenderer.tsx +++ b/packages/twenty-front/src/modules/page-layout/widgets/components/WidgetRenderer.tsx @@ -18,6 +18,8 @@ import { getWidgetCardVariant } from '@/page-layout/widgets/utils/getWidgetCardV import { WidgetCard } from '@/page-layout/widgets/widget-card/components/WidgetCard'; import { WidgetCardContent } from '@/page-layout/widgets/widget-card/components/WidgetCardContent'; import { WidgetCardHeader } from '@/page-layout/widgets/widget-card/components/WidgetCardHeader'; +import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext'; +import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile'; import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue'; import { useSetRecoilComponentFamilyState } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentFamilyState'; import { useTheme } from '@emotion/react'; @@ -60,6 +62,8 @@ export const WidgetRenderer = ({ widget }: WidgetRendererProps) => { const { layoutMode } = usePageLayoutContentContext(); const { isInPinnedTab } = useIsInPinnedTab(); + const { isInRightDrawer } = useLayoutRenderingContext(); + const isMobile = useIsMobile(); const { currentPageLayout } = useCurrentPageLayoutOrThrow(); @@ -99,6 +103,8 @@ export const WidgetRenderer = ({ widget }: WidgetRendererProps) => { layoutMode, isInPinnedTab, pageLayoutType: currentPageLayout.type, + isMobile, + isInRightDrawer, }); const actions = useWidgetActions({ widget }); diff --git a/packages/twenty-front/src/modules/page-layout/widgets/components/__stories__/WidgetRenderer.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/components/__stories__/WidgetRenderer.stories.tsx index 6c764ae1fb..bd7c5db3e3 100644 --- a/packages/twenty-front/src/modules/page-layout/widgets/components/__stories__/WidgetRenderer.stories.tsx +++ b/packages/twenty-front/src/modules/page-layout/widgets/components/__stories__/WidgetRenderer.stories.tsx @@ -1195,6 +1195,201 @@ export const WithOneToManyRelationFieldWidget: Story = { }, }; +export const OnMobile: Story = { + parameters: { + viewport: { + defaultViewport: 'mobile1', + }, + docs: { + description: { + story: + 'Widget on mobile viewport should use side-column variant instead of record-page variant.', + }, + }, + }, + render: () => { + const widget: PageLayoutWidget = { + __typename: 'PageLayoutWidget', + id: 'widget-mobile', + pageLayoutTabId: TAB_ID_OVERVIEW, + type: WidgetType.GRAPH, + title: 'Mobile Widget', + objectMetadataId: companyObjectMetadataItem.id, + gridPosition: { + __typename: 'GridPosition', + row: 0, + column: 0, + rowSpan: 2, + columnSpan: 3, + }, + configuration: { + __typename: 'AggregateChartConfiguration', + graphType: GraphType.AGGREGATE, + aggregateOperation: AggregateOperations.COUNT, + aggregateFieldMetadataId: idField.id, + displayDataLabel: true, + }, + 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, + PageLayoutType.RECORD_PAGE, + ); + snapshot.set( + pageLayoutPersistedComponentState.atomFamily({ + instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID, + }), + pageLayoutData, + ); + snapshot.set( + pageLayoutDraftComponentState.atomFamily({ + instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID, + }), + pageLayoutData, + ); + }; + + return ( +