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

feat: make selection node mechanism route based #2659

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

KVV94
Copy link
Contributor

@KVV94 KVV94 commented Feb 4, 2025

Ticket № 2645

closes #2645

Problem:

Currently, the selected node state is managed through application state, making navigation less predictable and hindering the use of standard browser features (like the Back button). We need to make the node selection mechanism route-based.

Solution:

Implemented a route-based node selection mechanism through a new useSelectedNodeFromUrl hook that synchronizes URL state with the selected node state. This makes node selection more predictable and allows for better browser integration

Changes:

  • Added new route for selected node: mainroute/episode/{episode_id}/node/{ref_id}
  • Created useSelectedNodeFromUrl hook for URL state synchronization
  • Created useNodeNavigation hook to handle node navigation
  • Integrated the new mechanism into Graph/index.tsx and other components where node selection occurs
  • Updated existing node selection calls to use the new route-based approach

Testing:

useNodeNavigation tests:

  • Tests URL formation correctness
  • Tests node navigation functionality
  • Tests selected node clearing

useSelectedNodeFromUrl tests:

  • Tests node setting from URL
  • Tests node clearing when URL has no ID
  • Tests invalid ID handling

Notes:

Using replace: true in navigation to prevent unnecessary browser history entries
No state changes occur when node ID from URL is not found
Maintained backward compatibility with existing node selection mechanism
Browser navigation (back/forward) now works seamlessly with node selection

@tomsmith8
Copy link
Contributor

hey @KVV94 any update on the failed tests?

@KVV94 KVV94 changed the title Develop feat: make selection node mechanism route based Feb 5, 2025
@KVV94
Copy link
Contributor Author

KVV94 commented Feb 5, 2025

hey @KVV94 any update on the failed tests?

Just fixed the unit tests. They are passing successfully now.

Copy link
Collaborator

@Rassl Rassl left a comment

Choose a reason for hiding this comment

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

Nice work, please take a look to my comments

import { useModal } from '~/stores/useModalStore'
import { useUserStore } from '~/stores/useUserStore'
import { NodeExtended } from '~/types'
import { executeIfProd, getLSat } from '~/utils'
import { SuccessNotify } from '../common/SuccessToast'
import { useNodeNavigation } from '../Universe/useNodeNavigation'
Copy link
Collaborator

Choose a reason for hiding this comment

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

use absolute path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/components/Universe/useNodeNavigation.ts Show resolved Hide resolved
@@ -7,6 +7,7 @@ import { useDataStore, useNodeTypes } from '~/stores/useDataStore'
import { useGraphStore, useHoveredNode, useSelectedNode } from '~/stores/useGraphStore'
import { NodeExtended } from '~/types'
import { colors } from '~/utils'
import { useNodeNavigation } from '../../useNodeNavigation'
Copy link
Collaborator

Choose a reason for hiding this comment

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

use absolute path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

should not we add routing for non mindset part too ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just added the routing for the non mindset part as well. Thank you for noticing this

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

Successfully merging this pull request may close these issues.

Make selection node mechanism route based
3 participants