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(dashboard): ability to locate new admin route under existing route #10587

Merged
merged 16 commits into from
Dec 19, 2024

Conversation

eugenepro2
Copy link
Contributor

This PR add ability to locate new admin route under existing route in sidebar.

For example, new route Brands
image
image

Screen.Recording.2024-12-12.at.16.41.57.mp4

Copy link

changeset-bot bot commented Dec 12, 2024

⚠️ No Changeset found

Latest commit: 6eb8ed6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 12, 2024

@eugenepro2 is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

@eugenepro2 eugenepro2 marked this pull request as ready for review December 12, 2024 14:45
@eugenepro2 eugenepro2 requested review from a team as code owners December 12, 2024 14:45
@eugenepro2 eugenepro2 changed the title feat: ability to locate new admin route under existing route feat(dashboard): ability to locate new admin route under existing route Dec 12, 2024
Copy link
Contributor

@kasperkristensen kasperkristensen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @eugenepro2! I have added a few comments, but really great addition which we would love to merge once these are addressed.

@@ -117,6 +117,7 @@ export class DashboardExtensionManager {
to: item.path,
icon: item.icon ? <item.icon /> : undefined,
items: [],
nested: item.nested,
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it would be good to log a warning if the item has a nested field
but also has children since they will be ignored.

If you create a nested route for /brand like this:

// /src/admin/routes/brands/page.tsx
import { defineRouteConfig } from "@medusajs/admin-sdk";

const BrandsPage = () => {
  return <div>Brands</div>;
};

export const config = defineRouteConfig({
    label: "Brands",
    nested: "/products",
})

export default BrandsPage;

// src/admin/routes/brands/create/route.tsx
import { defineRouteConfig } from "@medusajs/admin-sdk";

const CreateBrandPage = () => {
  return <div>Create Brand Page</div>;
};

export const config = defineRouteConfig({
    label: "Create Brand", // This would normally generate a nested menu item under "Brands".
})

export default CreateBrandPage;

The nested MenuItem is created, but never used.

So when looping over the items, it would be great to explicitly warn the user why this item is not being used. We need to keep track of items that have a nested field, if we later come across an item which is a child of the item with a nested we should skip it, and warn that we are doing so. A little further up in the function you can see we do something similar for other cases.

Copy link
Contributor Author

@eugenepro2 eugenepro2 Dec 13, 2024

Choose a reason for hiding this comment

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

Good point. But I find out some challange here. The new parameter nested passing only on the first route.
That is means that we cannot check parameter nested on the nested page create. I hope I described it clear)

Possible solution: locate a new route under existing route by path:

// /src/admin/routes/products/brands/page.tsx - located under products route
import { defineRouteConfig } from "@medusajs/admin-sdk";

const BrandsPage = () => {
  return <div>Brands</div>;
};

export const config = defineRouteConfig({
    label: "Brands",
})

export default BrandsPage;

// /src/admin/routes/products/brands/create/page.tsx - will be ignored in sidebar
import { defineRouteConfig } from "@medusajs/admin-sdk";

const CreateBrandPage = () => {
  return <div>Create Brand Page</div>;
};

export const config = defineRouteConfig({
    label: "Create Brand",
})

export default CreateBrandPage;

In this case nested param will be deleted and it would be easy to find parent path.

What do you think about that? Or maybe you have a better solution for that?

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 found a more easy solution. We have menuItems and we can find nested route there. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added warning

Comment on lines 31 to 37
nested?:
| "/orders"
| "/products"
| "/inventory"
| "/customers"
| "/promotions"
| "/price-list"
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to move this to the admin-shared package both as a const:

export const NESTED_ROUTE_POSITIONS = ["/orders", ...] as const

And as a type:

export type NestedRoutePosition = (typeof NESTED_ROUTE_POSITIONS)[number]

We should then use the const to validate that the user has passed a valid nested value in generate-menu-items.ts. And use the type in this file, and in the dashboard project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really good point 🚀. Added type.

Copy link
Contributor

@kasperkristensen kasperkristensen left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes @eugenepro2, only one little thing to update and then this is good to merge 👍

kasperkristensen and others added 2 commits December 17, 2024 11:08
Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
Copy link
Contributor

@kasperkristensen kasperkristensen left a comment

Choose a reason for hiding this comment

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

@eugenepro2 final thing the unit tests are failing because they don't expect the field nested for the route items, so if you could update those then we are good to go

@eugenepro2
Copy link
Contributor Author

@eugenepro2 final thing the unit tests are failing because they don't expect the field nested for the route items, so if you could update those then we are good to go

Yep, I'll do that.

Copy link
Contributor

@kasperkristensen kasperkristensen left a comment

Choose a reason for hiding this comment

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

LGTM thanks @eugenepro2 🚀

@kasperkristensen
Copy link
Contributor

Sorry @eugenepro2, but one more thing, could I get you to remove the changes to the docs, and put those in a separate PR. Otherwise, the changes will go live a soon as we merge this, before the feature is released.

@eugenepro2
Copy link
Contributor Author

Sorry @eugenepro2, but one more thing, could I get you to remove the changes to the docs, and put those in a separate PR. Otherwise, the changes will go live a soon as we merge this, before the feature is released.

@kasperkristensen Of course. Please check this PR. I'll create a new PR with updated docs for this feature.

@kasperkristensen
Copy link
Contributor

Sorry @eugenepro2, but one more thing, could I get you to remove the changes to the docs, and put those in a separate PR. Otherwise, the changes will go live a soon as we merge this, before the feature is released.

@kasperkristensen Of course. Please check this PR. I'll create a new PR with updated docs for this feature.

@eugenepro2 There is still one change in a docs file, which blocks the PR. It's a new line character, if you can remove that then I will make sure this gets merged 👍

@eugenepro2
Copy link
Contributor Author

@kasperkristensen

Sorry @eugenepro2, but one more thing, could I get you to remove the changes to the docs, and put those in a separate PR. Otherwise, the changes will go live a soon as we merge this, before the feature is released.

@kasperkristensen Of course. Please check this PR. I'll create a new PR with updated docs for this feature.

@eugenepro2 There is still one change in a docs file, which blocks the PR. It's a new line character, if you can remove that then I will make sure this gets merged 👍

Oh, Sorry for empty line 😅. Fixed

@kasperkristensen kasperkristensen removed the request for review from a team December 19, 2024 11:59
@kodiakhq kodiakhq bot merged commit 3efd25d into medusajs:develop Dec 19, 2024
14 of 22 checks passed
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.

2 participants