-
Notifications
You must be signed in to change notification settings - Fork 3k
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
reset main context store viewId and current view type on settings page #11206
reset main context store viewId and current view type on settings page #11206
Conversation
…store-on-settings-page
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.
PR Summary
This PR implements a reset mechanism for the main context store when navigating to settings pages, ensuring proper state management and view type handling across the application.
- Added new
MainContextStoreSettingsSideEffect
component to reset viewId and set view type to 'Settings' - Modified
useContextStoreObjectMetadataItemOrThrow
to prevent errors on settings pages when metadata is undefined - Added 'Settings' to
ContextStoreViewType
enum and updatedgetActionViewType
to return null for settings views - Updated
MainContextStoreProvider
to conditionally render settings-specific components - Consider adding validation or warning for undefined
objectMetadataItem
in settings pages to prevent potential issues
5 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
// not sure what should happen here, should we return null when page name and object metadata item are not defined as it was before? | ||
// or should we return the provider with the default/reset values? -- ie like one of settings side effect? | ||
|
||
// if ( | ||
// !isDefined(pageName) || | ||
// !isDefined(objectMetadataItem) || | ||
// isSettingsPage | ||
// ) { | ||
// return <MainContextStoreSettingsSideEffect />; | ||
// } |
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.
logic: This commented code block contains an unresolved question about behavior. Need to make a clear decision on whether to return null or reset values before merging.
...ges/twenty-front/src/modules/context-store/hooks/useContextStoreObjectMetadataItemOrThrow.ts
Outdated
Show resolved
Hide resolved
...ges/twenty-front/src/modules/context-store/components/MainContextStoreSettingsSideEffect.tsx
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/context-store/components/MainContextStoreProvider.tsx
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/context-store/types/ContextStoreViewType.ts
Outdated
Show resolved
Hide resolved
const { objectMetadataItem } = useObjectMetadataItemById({ | ||
objectId: objectMetadataItemId ?? '', | ||
}); | ||
|
||
if (!objectMetadataItem) { | ||
if (!objectMetadataItem && !isSettingsPage) { |
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.
no, this useContextStoreObjectMetadataItemOrThrow.ts should not be loaded if we are on a settings page. The higher the edge cases are treated in the hieararchy, the happier we are :)
packages/twenty-front/src/modules/action-menu/actions/utils/getActionViewType.ts
Outdated
Show resolved
Hide resolved
...ges/twenty-front/src/modules/context-store/components/MainContextStoreSettingsSideEffect.tsx
Outdated
Show resolved
Hide resolved
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.
Thanks @ehconitin, see comments :)
…store-on-settings-page
@charlesBochet 2025-03-27.14-42-37.mov |
…store-on-settings-page
@ehconitin, I feel we should unmount the CommandMenu in the Settings for now :) Edit: let's keep it :p |
@@ -67,7 +69,10 @@ export const MainContextStoreProvider = () => { | |||
|
|||
const viewId = getViewId(viewIdQueryParam, indexViewId, lastVisitedViewId); | |||
|
|||
if (!isDefined(pageName) || !isDefined(objectMetadataItem)) { | |||
if ( | |||
!isSettingsPage && |
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.
I would make pageName = 'settings' in case we are on a settingsPage, and remove this condition here
packages/twenty-front/src/modules/context-store/components/MainContextStoreProviderEffect.tsx
Show resolved
Hide resolved
@ehconitin I think Thomas actually wants it with the page shortcuts only. Previously, we assumed that the command menu was always loaded in a context with objectMetadataItem set. |
@@ -42,8 +43,12 @@ export const CommandMenu = () => { | |||
'command-menu-previous', | |||
); | |||
|
|||
const { objectMetadataItem: currentObjectMetadataItem } = | |||
useContextStoreObjectMetadataItemOrThrow(); | |||
const objectMetadataItemId = useRecoilComponentValueV2( |
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.
@ehconitin here
viewId, | ||
]); | ||
|
||
useEffect(() => { |
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.
splitting the effects to keep the logic simple and atomic
Thanks @ehconitin for your contribution! |
closes twentyhq/core-team-issues#588