Skip to content

Commit

Permalink
Fix Filtered index view infinite re-render (twentyhq#5286)
Browse files Browse the repository at this point in the history
The whole viewBar component was re-rendered on view changes which was
introducing performance issue. The need was to compute page title, this
should be done in a lower level component
  • Loading branch information
charlesBochet authored and i-am-chitti committed May 4, 2024
1 parent fa88c03 commit 1db3aae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
13 changes: 2 additions & 11 deletions packages/twenty-front/src/modules/views/components/ViewBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import { ObjectFilterDropdownButton } from '@/object-record/object-filter-dropdo
import { FiltersHotkeyScope } from '@/object-record/object-filter-dropdown/types/FiltersHotkeyScope';
import { ObjectSortDropdownButton } from '@/object-record/object-sort-dropdown/components/ObjectSortDropdownButton';
import { TopBar } from '@/ui/layout/top-bar/TopBar';
import { PageTitle } from '@/ui/utilities/page-title/PageTitle';
import { QueryParamsFiltersEffect } from '@/views/components/QueryParamsFiltersEffect';
import { QueryParamsViewIdEffect } from '@/views/components/QueryParamsViewIdEffect';
import { ViewBarEffect } from '@/views/components/ViewBarEffect';
import { ViewBarFilterEffect } from '@/views/components/ViewBarFilterEffect';
import { ViewBarPageTitle } from '@/views/components/ViewBarPageTitle';
import { ViewBarSortEffect } from '@/views/components/ViewBarSortEffect';
import { useGetCurrentView } from '@/views/hooks/useGetCurrentView';
import { ViewScope } from '@/views/scopes/ViewScope';
import { GraphQLView } from '@/views/types/GraphQLView';
import { ViewPickerDropdown } from '@/views/view-picker/components/ViewPickerDropdown';
import { capitalize } from '~/utils/string/capitalize';

import { ViewsHotkeyScope } from '../types/ViewsHotkeyScope';

Expand All @@ -37,20 +35,13 @@ export const ViewBar = ({
}: ViewBarProps) => {
const { objectNamePlural } = useParams();

const { currentViewWithCombinedFiltersAndSorts: currentView } =
useGetCurrentView(viewBarId);

const filterDropdownId = 'view-filter';
const sortDropdownId = 'view-sort';

if (!objectNamePlural) {
return;
}

const pageTitle = currentView?.name
? `${currentView?.name} - ${capitalize(objectNamePlural)}`
: capitalize(objectNamePlural);

return (
<ViewScope
viewScopeId={viewBarId}
Expand All @@ -62,7 +53,7 @@ export const ViewBar = ({
<QueryParamsFiltersEffect />
<QueryParamsViewIdEffect />

<PageTitle title={pageTitle} />
<ViewBarPageTitle viewBarId={viewBarId} />
<TopBar
className={className}
leftComponent={
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useParams } from 'react-router-dom';

import { PageTitle } from '@/ui/utilities/page-title/PageTitle';
import { useGetCurrentView } from '@/views/hooks/useGetCurrentView';
import { capitalize } from '~/utils/string/capitalize';

export type ViewBarPageTitleProps = {
viewBarId: string;
};

export const ViewBarPageTitle = ({ viewBarId }: ViewBarPageTitleProps) => {
const { objectNamePlural } = useParams();

const { currentViewWithCombinedFiltersAndSorts: currentView } =
useGetCurrentView(viewBarId);

if (!objectNamePlural) {
return;
}

const pageTitle = currentView?.name
? `${currentView?.name} - ${capitalize(objectNamePlural)}`
: capitalize(objectNamePlural);

return <PageTitle title={pageTitle} />;
};

0 comments on commit 1db3aae

Please sign in to comment.