Add viewId to recordIndexId (#9647)
Before the `recordIndexId` was the name plural. This caused problems because the component states were the same for every view of an object. When we switched from one view to another, some states weren't reset. This PR fixes this by: - Creating an effect at the same level of page change effect to set the `currentViewId` inside the object `contextStore` - Adding the `currentViewId` to the `recordIndexId` Follow ups: - We need to get rid of `packages/twenty-front/src/modules/views/states/currentViewIdComponentState.ts` and use the context store instead
This commit is contained in:
@ -4,6 +4,7 @@ import { useParams } from 'react-router-dom';
|
||||
import { ActionMenuComponentInstanceContext } from '@/action-menu/states/contexts/ActionMenuComponentInstanceContext';
|
||||
import { getActionMenuIdFromRecordIndexId } from '@/action-menu/utils/getActionMenuIdFromRecordIndexId';
|
||||
import { MainContextStoreComponentInstanceIdSetterEffect } from '@/context-store/components/MainContextStoreComponentInstanceIdSetterEffect';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural';
|
||||
@ -17,9 +18,11 @@ import { useHandleIndexIdentifierClick } from '@/object-record/record-index/hook
|
||||
import { PageBody } from '@/ui/layout/page/components/PageBody';
|
||||
import { PageContainer } from '@/ui/layout/page/components/PageContainer';
|
||||
import { PageTitle } from '@/ui/utilities/page-title/components/PageTitle';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { ViewComponentInstanceContext } from '@/views/states/contexts/ViewComponentInstanceContext';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
|
||||
const StyledIndexContainer = styled.div`
|
||||
display: flex;
|
||||
@ -30,7 +33,12 @@ const StyledIndexContainer = styled.div`
|
||||
export const RecordIndexPage = () => {
|
||||
const objectNamePlural = useParams().objectNamePlural ?? '';
|
||||
|
||||
const recordIndexId = objectNamePlural ?? '';
|
||||
const contextStoreCurrentViewId = useRecoilComponentValueV2(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
objectNamePlural,
|
||||
);
|
||||
|
||||
const recordIndexId = `${objectNamePlural}-${contextStoreCurrentViewId}`;
|
||||
|
||||
const { objectNameSingular } = useObjectNameSingularFromPlural({
|
||||
objectNamePlural,
|
||||
@ -54,6 +62,10 @@ export const RecordIndexPage = () => {
|
||||
[],
|
||||
);
|
||||
|
||||
if (!isDefined(contextStoreCurrentViewId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<RecordIndexContextProvider
|
||||
|
||||
Reference in New Issue
Block a user