Skip to content
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

Conversation

ehconitin
Copy link
Contributor

@ehconitin ehconitin commented Mar 26, 2025

@ehconitin ehconitin requested a review from bosiraphael March 26, 2025 18:01
@ehconitin ehconitin self-assigned this Mar 26, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 updated getActionViewType 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

Comment on lines 77 to 86
// 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 />;
// }
Copy link
Contributor

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.

const { objectMetadataItem } = useObjectMetadataItemById({
objectId: objectMetadataItemId ?? '',
});

if (!objectMetadataItem) {
if (!objectMetadataItem && !isSettingsPage) {
Copy link
Member

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 :)

Copy link
Member

@charlesBochet charlesBochet left a 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 :)

@ehconitin
Copy link
Contributor Author

ehconitin commented Mar 27, 2025

@charlesBochet
Regarding handling edge cases higher in the hierarchy: #11206 (comment)
I've run into an issue where the CommandMenu component throws an error on settings pages because it unconditionally calls useContextStoreObjectMetadataItemOrThrow.
Should we add a CommandMenuSettingsPage component and a Settings option to the CommandMenuPages enum? I've tried this approach, and while the context is set correctly when navigating from another page to settings, we still get an error when opening the command menu directly on a settings page.
Any guidance on how specialized command menu pages are typically set based on the current route? I don't see any effects or logic that would automatically set the appropriate command menu page based on the current route for other specialized pages.
Or would an even simpler solution be to add a check in the CommandMenu component itself? Though this doesn't seem to align with the existing code patterns and your feedback about handling edge cases higher in the hierarchy.

2025-03-27.14-42-37.mov

@charlesBochet
Copy link
Member

charlesBochet commented Mar 28, 2025

@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 &&
Copy link
Member

@charlesBochet charlesBochet Mar 28, 2025

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

@charlesBochet
Copy link
Member

@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.
Changing this hypothesis, we need to authorize both. Here it's quite easy to fix by stopping throwing and do the work manually. If it would get too complex, I would push to split the components at CommandMenuRouter level and introduce SettingsCommandMenu alongside with the existing CommandMenu

@@ -42,8 +43,12 @@ export const CommandMenu = () => {
'command-menu-previous',
);

const { objectMetadataItem: currentObjectMetadataItem } =
useContextStoreObjectMetadataItemOrThrow();
const objectMetadataItemId = useRecoilComponentValueV2(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehconitin here

viewId,
]);

useEffect(() => {
Copy link
Member

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

@charlesBochet charlesBochet merged commit c294d96 into twentyhq:main Mar 28, 2025
45 checks passed
Copy link
Contributor

Thanks @ehconitin for your contribution!
This marks your 122nd PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Actions from last visited view are visible inside the command menu on the settings page
2 participants