forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7336 create contextstore (twentyhq#7374)
Closes twentyhq#7336 Create 3 states: - `contextStoreCurrentObjectMetadataIdState`: is set when we change object metadata - `contextStoreCurrentViewIdState`: is set when we change view - `contextStoreTargetedRecordIdsState`: is set when we select records inside a table or a board or when a show page is opened. Is reset when we change view.
- Loading branch information
1 parent
800e508
commit 11f68fe
Showing
10 changed files
with
146 additions
and
11 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...twenty-front/src/modules/context-store/states/contextStoreCurrentObjectMetadataIdState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/twenty-front/src/modules/context-store/states/contextStoreCurrentViewIdState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/twenty-front/src/modules/context-store/states/contextStoreTargetedRecordIdsState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
packages/twenty-front/src/modules/views/hooks/useChangeView.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/twenty-front/src/modules/views/hooks/useSetViewInUrl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
export const useSetViewInUrl = () => { | ||
const [, setSearchParams] = useSearchParams(); | ||
|
||
const setViewInUrl = (viewId: string) => { | ||
setSearchParams(() => { | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set('view', viewId); | ||
return searchParams; | ||
}); | ||
}; | ||
|
||
return { setViewInUrl }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/twenty-front/src/pages/object-record/RecordShowPageContextStoreEffect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { contextStoreCurrentObjectMetadataIdState } from '@/context-store/states/contextStoreCurrentObjectMetadataIdState'; | ||
import { contextStoreTargetedRecordIdsState } from '@/context-store/states/contextStoreTargetedRecordIdsState'; | ||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { useEffect } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useSetRecoilState } from 'recoil'; | ||
|
||
export const RecordShowPageContextStoreEffect = ({ | ||
recordId, | ||
}: { | ||
recordId: string; | ||
}) => { | ||
const setContextStoreTargetedRecordIds = useSetRecoilState( | ||
contextStoreTargetedRecordIdsState, | ||
); | ||
|
||
const setContextStoreCurrentObjectMetadataId = useSetRecoilState( | ||
contextStoreCurrentObjectMetadataIdState, | ||
); | ||
|
||
const { objectNameSingular } = useParams(); | ||
|
||
const { objectMetadataItem } = useObjectMetadataItem({ | ||
objectNameSingular: objectNameSingular ?? '', | ||
}); | ||
|
||
useEffect(() => { | ||
setContextStoreTargetedRecordIds([recordId]); | ||
setContextStoreCurrentObjectMetadataId(objectMetadataItem?.id); | ||
|
||
return () => { | ||
setContextStoreTargetedRecordIds([]); | ||
setContextStoreCurrentObjectMetadataId(null); | ||
}; | ||
}, [ | ||
recordId, | ||
setContextStoreTargetedRecordIds, | ||
setContextStoreCurrentObjectMetadataId, | ||
objectMetadataItem?.id, | ||
]); | ||
|
||
return null; | ||
}; |