-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7336 create contextstore #7374
7336 create contextstore #7374
Changes from 9 commits
0fa87af
fdd4028
7b96e35
d84ccd8
b24fa66
ad6947e
dd5b1be
5cf71b3
1f329d2
b63a896
afdfa97
667306b
c73d393
5b0b536
e396202
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { | ||
useLocation, | ||
useNavigate, | ||
useParams, | ||
useSearchParams, | ||
} from 'react-router-dom'; | ||
import { useRecoilValue, useSetRecoilState } from 'recoil'; | ||
import { IconCheckbox } from 'twenty-ui'; | ||
|
||
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer'; | ||
|
@@ -12,6 +17,10 @@ import { useRequestFreshCaptchaToken } from '@/captcha/hooks/useRequestFreshCapt | |
import { isCaptchaScriptLoadedState } from '@/captcha/states/isCaptchaScriptLoadedState'; | ||
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; | ||
import { CommandType } from '@/command-menu/types/Command'; | ||
import { contextStoreCurrentObjectMetadataIdState } from '@/context-store/states/contextStoreCurrentObjectMetadataIdState'; | ||
import { contextStoreCurrentViewIdState } from '@/context-store/states/contextStoreCurrentViewIdState'; | ||
import { contextStoreTargetedRecordIdsState } from '@/context-store/states/contextStoreTargetedRecordIdsState'; | ||
import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector'; | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkeyScope'; | ||
import { AppBasePath } from '@/types/AppBasePath'; | ||
|
@@ -49,6 +58,29 @@ export const PageChangeEffect = () => { | |
activityObjectNameSingular: CoreObjectNameSingular.Task, | ||
}); | ||
|
||
const [searchParams] = useSearchParams(); | ||
const { objectNameSingular, objectNamePlural } = useParams(); | ||
|
||
const objectMetadataItem = useRecoilValue( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. every page |
||
objectMetadataItemFamilySelector( | ||
objectNameSingular | ||
? { objectName: objectNameSingular, objectNameType: 'singular' } | ||
: objectNamePlural | ||
? { objectName: objectNamePlural, objectNameType: 'plural' } | ||
: { objectName: '', objectNameType: 'singular' }, | ||
), | ||
); | ||
|
||
const setContextStoreCurrentViewId = useSetRecoilState( | ||
contextStoreCurrentViewIdState, | ||
); | ||
const setContextStoreCurrentObjectMetadataId = useSetRecoilState( | ||
contextStoreCurrentObjectMetadataIdState, | ||
); | ||
const setContextStoreTargetedRecordIds = useSetRecoilState( | ||
contextStoreTargetedRecordIdsState, | ||
); | ||
|
||
useEffect(() => { | ||
cleanRecoilState(); | ||
}, [cleanRecoilState]); | ||
|
@@ -67,6 +99,20 @@ export const PageChangeEffect = () => { | |
} | ||
}, [navigate, pageChangeEffectNavigateLocation]); | ||
|
||
useEffect(() => { | ||
const viewId = searchParams.get('view'); | ||
setContextStoreCurrentViewId(viewId); | ||
setContextStoreTargetedRecordIds([]); | ||
}, [ | ||
searchParams, | ||
setContextStoreCurrentViewId, | ||
setContextStoreTargetedRecordIds, | ||
]); | ||
|
||
useEffect(() => { | ||
setContextStoreCurrentObjectMetadataId(objectMetadataItem?.id ?? null); | ||
}, [objectMetadataItem, setContextStoreCurrentObjectMetadataId]); | ||
|
||
useEffect(() => { | ||
switch (true) { | ||
case isMatchingLocation(AppPath.RecordIndexPage): { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createState } from 'twenty-ui'; | ||
|
||
export const contextStoreCurrentObjectMetadataIdState = createState< | ||
string | null | ||
>({ | ||
key: 'contextStoreCurrentObjectMetadataIdState', | ||
defaultValue: null, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createState } from 'twenty-ui'; | ||
|
||
export const contextStoreCurrentViewIdState = createState<string | null>({ | ||
key: 'contextStoreCurrentViewIdState', | ||
defaultValue: null, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createState } from 'twenty-ui'; | ||
|
||
export const contextStoreTargetedRecordIdsState = createState<string[]>({ | ||
key: 'contextStoreTargetedRecordIdsState', | ||
defaultValue: [], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilte | |
import { useRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentStateV2'; | ||
import { useViewFromQueryParams } from '@/views/hooks/internal/useViewFromQueryParams'; | ||
import { useGetCurrentView } from '@/views/hooks/useGetCurrentView'; | ||
import { useSetViewInUrl } from '@/views/hooks/useSetViewInUrl'; | ||
import { currentViewIdComponentState } from '@/views/states/currentViewIdComponentState'; | ||
import { isUndefined } from '@sniptt/guards'; | ||
import { useEffect } from 'react'; | ||
|
@@ -37,6 +38,7 @@ export const QueryParamsViewIdEffect = () => { | |
objectMetadataItemId?.id, | ||
lastVisitedObjectMetadataItemId, | ||
); | ||
const { setViewInUrl } = useSetViewInUrl(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should push the viewId from there |
||
|
||
// // TODO: scope view bar per view id if possible | ||
// const { resetCurrentView } = useResetCurrentView(); | ||
|
@@ -59,6 +61,7 @@ export const QueryParamsViewIdEffect = () => { | |
}); | ||
} | ||
setCurrentViewId(lastVisitedViewId); | ||
setViewInUrl(lastVisitedViewId); | ||
return; | ||
} | ||
|
||
|
@@ -99,6 +102,7 @@ export const QueryParamsViewIdEffect = () => { | |
setCurrentViewId, | ||
setLastVisitedObjectMetadataItem, | ||
setLastVisitedView, | ||
setViewInUrl, | ||
viewIdQueryParam, | ||
viewsOnCurrentObject, | ||
]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
export const useSetViewInUrl = () => { | ||
bosiraphael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const [, setSearchParams] = useSearchParams(); | ||
|
||
const setViewInUrl = (viewId: string) => { | ||
setSearchParams(() => { | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set('view', viewId); | ||
return searchParams; | ||
}); | ||
bosiraphael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
return { setViewInUrl }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { contextStoreTargetedRecordIdsState } from '@/context-store/states/contextStoreTargetedRecordIdsState'; | ||
import { useEffect } from 'react'; | ||
import { useSetRecoilState } from 'recoil'; | ||
|
||
export const RecordShowPageEffect = ({ recordId }: { recordId: string }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RecordShowPageContextStoreEffect |
||
const setContextStoreTargetedRecordIds = useSetRecoilState( | ||
contextStoreTargetedRecordIdsState, | ||
); | ||
|
||
useEffect(() => { | ||
setContextStoreTargetedRecordIds([recordId]); | ||
}, [recordId, setContextStoreTargetedRecordIds]); | ||
|
||
return null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract this to another ComponentEffect: ContextStorePageChangeEffect.tsx