The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix dashboard record table settings context (#25180)
Weiko17cf55103bc1
diff --git a/packages/twenty-front/src/modules/side-panel/pages/page-layout/components/dashboard/SidePanelDashboardRecordTableSettings.tsx b/packages/twenty-front/src/modules/side-panel/pages/page-layout/components/dashboard/SidePanelDashboardRecordTableSettings.tsxindex aee140d2438..394a29b1a33 100644--- a/packages/twenty-front/src/modules/side-panel/pages/page-layout/components/dashboard/SidePanelDashboardRecordTableSettings.tsx+++ b/packages/twenty-front/src/modules/side-panel/pages/page-layout/components/dashboard/SidePanelDashboardRecordTableSettings.tsx@@ -3,7 +3,7 @@ import { CommandMenuItemDropdown } from '@/command-menu/components/CommandMenuItimport { CommandMenuItemNumberInput } from '@/command-menu/components/CommandMenuItemNumberInput';import { CommandMenuItemToggle } from '@/command-menu/components/CommandMenuItemToggle';import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';-import { useCurrentPageLayoutOrThrow } from '@/page-layout/hooks/useCurrentPageLayoutOrThrow';+import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';import { useRecordTableWidgetFieldCallbacks } from '@/page-layout/widgets/record-table/hooks/useRecordTableWidgetFieldCallbacks';import { useRecordTableWidgetLayoutCallbacks } from '@/page-layout/widgets/record-table/hooks/useRecordTableWidgetLayoutCallbacks';import { useRecordTableWidgetViewForDisplay } from '@/page-layout/widgets/record-table/hooks/useRecordTableWidgetViewForDisplay';@@ -31,6 +31,7 @@ import { useWidgetInEditMode } from '@/side-panel/pages/page-layout/hooks/useWidimport { SidePanelSubPages } from '@/side-panel/types/SidePanelSubPages';import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';import { SelectableListItem } from '@/ui/layout/selectable-list/components/SelectableListItem';+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { isDefined } from 'twenty-shared/utils';@@ -69,7 +70,10 @@ export const SidePanelDashboardRecordTableSettings = () => {const { t } = useLingui();const { pageLayoutId } = usePageLayoutIdFromContextStore();- const { currentPageLayout } = useCurrentPageLayoutOrThrow();+ const pageLayoutDraft = useAtomComponentStateValue(+ pageLayoutDraftComponentState,+ pageLayoutId,+ );const { widgetInEditMode } = useWidgetInEditMode(pageLayoutId);const { navigateToSidePanelSubPage } = useSidePanelSubPageHistory();@@ -95,7 +99,7 @@ export const SidePanelDashboardRecordTableSettings = () => {const isUIEditable = getRecordTableWidgetIsUIEditable(configuration,- currentPageLayout.type,+ pageLayoutDraft.type,);const {diff --git a/packages/twenty-front/src/modules/side-panel/pages/page-layout/components/dashboard/__tests__/SidePanelDashboardRecordTableSettings.test.tsx b/packages/twenty-front/src/modules/side-panel/pages/page-layout/components/dashboard/__tests__/SidePanelDashboardRecordTableSettings.test.tsxnew file mode 100644index 00000000000..d0f87ae8851--- /dev/null+++ b/packages/twenty-front/src/modules/side-panel/pages/page-layout/components/dashboard/__tests__/SidePanelDashboardRecordTableSettings.test.tsx@@ -0,0 +1,106 @@+import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { SidePanelDashboardRecordTableSettings } from '@/side-panel/pages/page-layout/components/dashboard/SidePanelDashboardRecordTableSettings';+import { i18n } from '@lingui/core';+import { I18nProvider } from '@lingui/react';+import { render } from '@testing-library/react';+import { createStore, Provider as JotaiProvider } from 'jotai';+import { PageLayoutType } from '~/generated-metadata/graphql';++const PAGE_LAYOUT_ID = 'dashboard-page-layout-id';++jest.mock('@/object-metadata/hooks/useObjectMetadataItems', () => ({+ useObjectMetadataItems: () => ({ objectMetadataItems: [] }),+}));++jest.mock(+ '@/page-layout/widgets/record-table/hooks/useRecordTableWidgetFieldCallbacks',+ () => ({+ useRecordTableWidgetFieldCallbacks: () => ({+ handleFieldUpdated: jest.fn(),+ handleFieldCreated: jest.fn(),+ }),+ }),+);++jest.mock(+ '@/page-layout/widgets/record-table/hooks/useRecordTableWidgetLayoutCallbacks',+ () => ({+ useRecordTableWidgetLayoutCallbacks: () => ({+ handleShouldHideEmptyGroupsChange: jest.fn(),+ }),+ }),+);++jest.mock(+ '@/page-layout/widgets/record-table/hooks/useRecordTableWidgetViewForDisplay',+ () => ({+ useRecordTableWidgetViewForDisplay: () => ({ view: undefined }),+ }),+);++jest.mock('@/side-panel/hooks/useSidePanelSubPageHistory', () => ({+ useSidePanelSubPageHistory: () => ({+ navigateToSidePanelSubPage: jest.fn(),+ }),+}));++jest.mock(+ '@/side-panel/pages/page-layout/hooks/usePageLayoutIdFromContextStore',+ () => ({+ usePageLayoutIdFromContextStore: () => ({ pageLayoutId: PAGE_LAYOUT_ID }),+ }),+);++jest.mock(+ '@/side-panel/pages/page-layout/hooks/useRecordTableSettingsDescriptions',+ () => ({+ useRecordTableSettingsDescriptions: () => ({+ sourceDescription: '',+ fieldsDescription: '',+ filterDescription: '',+ sortDescription: '',+ }),+ }),+);++jest.mock(+ '@/side-panel/pages/page-layout/hooks/useUpdateCurrentWidgetConfig',+ () => ({+ useUpdateCurrentWidgetConfig: () => ({+ updateCurrentWidgetConfig: jest.fn(),+ }),+ }),+);++jest.mock('@/side-panel/pages/page-layout/hooks/useWidgetInEditMode', () => ({+ useWidgetInEditMode: () => ({ widgetInEditMode: undefined }),+}));++describe('SidePanelDashboardRecordTableSettings', () => {+ it('reads the dashboard draft without a page layout component context', () => {+ const store = createStore();++ store.set(+ pageLayoutDraftComponentState.atomFamily({ instanceId: PAGE_LAYOUT_ID }),+ {+ id: PAGE_LAYOUT_ID,+ name: 'Dashboard layout',+ type: PageLayoutType.DASHBOARD,+ objectMetadataId: null,+ tabs: [],+ defaultTabToFocusOnMobileAndSidePanelId: null,+ isFirstTabPinned: true,+ },+ );++ const { container } = render(+ <JotaiProvider store={store}>+ <I18nProvider i18n={i18n}>+ <SidePanelDashboardRecordTableSettings />+ </I18nProvider>+ </JotaiProvider>,+ );++ expect(container).toBeEmptyDOMElement();+ });+});