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

Implement front-end routing #19

Merged
merged 12 commits into from
Aug 20, 2024
Merged

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Jul 31, 2024

Natural forward and back navigation is now supported when interacting with lists & items. Allows resolving the default item URIs generated in #17.

  • Isolate component that renders the router (was getting double toast / confirm popups)
  • Remove trailing slashes from controlled lists routes
  • Move name entry field reset to more logical place

Closes #4

Comment on lines 43 to 64
export const findNodeInTree = (
tree: TreeNode[],
itemId: string,
): {
found: TreeNode | undefined;
path: TreeNode[];
} => {
const path: TreeNode[] = [];

Copy link
Member Author

Choose a reason for hiding this comment

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

This refactor adds the ability to do a lookup in a tree by item id, which wasn't something was needed before (the user was clicking on the tree to navigate to items). We need this for routing to be able to go from a path to somewhere arbitrary in the tree.

Copy link
Contributor

@chrabyrd chrabyrd left a comment

Choose a reason for hiding this comment

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

overall looks good, just a few things 👍

package.json Outdated Show resolved Hide resolved
arches_references/urls.py Outdated Show resolved Hide resolved
displayedRowKey,
) as DisplayedListItemRefAndSetter;
const route = useRoute();
watch(
Copy link
Contributor

Choose a reason for hiding this comment

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

what's going on in this file? Also I don't love the idea of subcomponents being able to navigate, is it possible to abstract this to the main component?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this up one component to <ListTree> where the rest of the list tree state is owned.

What's going on is that the <ListTree> needs to react to route changes:

  • tree rows need to expand and contract
  • tree rows need to be selected

Also I don't love the idea of subcomponents being able to navigate, is it possible to abstract this to the main component?

I guess I wouldn't say that the subcomponent is navigating: it's just reacting and manipulating its own state in response to route changes. I gave it a little thought, and I don't think it makes sense to put the tree expanded and selected keys state on the top-level component. I'd rather adopt a Redux/Pinia store pattern before doing that. The client state management would be a little more compact if we were using Pinia.

You'll notice the main component is in fact where router.push() happens.

Let me know if I can clarify this with variable naming or comments, or if you have other suggestions.

@jacobtylerwalls jacobtylerwalls force-pushed the jtw/front-end-routing branch 2 times, most recently from 2bb753c to 43d07c9 Compare August 9, 2024 20:33
@chrabyrd
Copy link
Contributor

chrabyrd commented Aug 9, 2024

Not that it needs to be answered here, but an interesting question around frontend routing is how to handle it in Lingo. We can assume it will have its own frontend routes, does that place nicely with frontend routing for arches-references? If not, how painful is it to get the two to work together?

Copy link
Contributor

@chrabyrd chrabyrd left a comment

Choose a reason for hiding this comment

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

looks good, save a few minor nits

};

// Navigate on initial load of the tree.
watch(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: at least have the two watches grouped together. Any chance this could be refactored to use onMounted instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Grouped together. Re: onMounted, that's an interesting idea, although I confess to not liking the lifecycle methods as a plan A (feels like pre-react-hooks to me)--but I'd rather explore it as part of a refactor to pull out the functionality that fetches lists and put that state somewhere a little more logical.

arches_references/src/arches_references/constants.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@chrabyrd chrabyrd left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@jacobtylerwalls jacobtylerwalls merged commit d5aee90 into jtw/primevue-4 Aug 20, 2024
5 of 6 checks passed
@jacobtylerwalls jacobtylerwalls deleted the jtw/front-end-routing branch August 20, 2024 17:07
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.

2 participants