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(vue-demo): add dynamic breadcrumbs #1369

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

feat(vue-demo): add dynamic breadcrumbs #1369

wants to merge 19 commits into from

Conversation

mdanilowicz
Copy link
Collaborator

@mdanilowicz mdanilowicz commented Oct 17, 2024

Description

This pull request adds a new request to fetch category breadcrumbs. The request is included on the category and product pages, while all other static pages build breadcrumbs with "local" data.

Added getCategoryBreadcrumbs method for fetching backend breadcrumbs in useBreadcrumbs composable
Added buildDynamicBreadcrumbs method for building breadcrumbs structure
Added pushBreadcrumb method to push single breadcrumb at the top of the breadcrumbs list
Added associations option to the search method in useProductSearch composable

closes #139

Type of change

ToDo's

Screenshots (if applicable)

Additional context

Copy link

vercel bot commented Oct 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
frontends-demo 🔄 Building (Inspect) Visit Preview Nov 20, 2024 8:12am
shopware-frontends-docs ❌ Failed (Inspect) Nov 20, 2024 8:12am

Copy link

pkg-pr-new bot commented Oct 17, 2024

Open in Stackblitz

@shopware/api-client

pnpm add https://pkg.pr.new/shopware/frontends/@shopware/api-client@1369

@shopware-pwa/composables-next

pnpm add https://pkg.pr.new/shopware/frontends/@shopware-pwa/composables-next@1369

@shopware/api-gen

pnpm add https://pkg.pr.new/shopware/frontends/@shopware/api-gen@1369

@shopware-pwa/cms-base

pnpm add https://pkg.pr.new/shopware/frontends/@shopware-pwa/cms-base@1369

@shopware-pwa/helpers-next

pnpm add https://pkg.pr.new/shopware/frontends/@shopware-pwa/helpers-next@1369

@shopware-pwa/nuxt3-module

pnpm add https://pkg.pr.new/shopware/frontends/@shopware-pwa/nuxt3-module@1369

commit: 79b20d3

@BrocksiNet
Copy link
Collaborator

@kstala could you test this please 🙌

Copy link
Collaborator

@patzick patzick left a comment

Choose a reason for hiding this comment

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

Good feature incoming! We need to clarify a few things here first :)


useBreadcrumbs(breadcrumbs);
const { buildDynamicBreadcrumbs } = useBreadcrumbs();
buildDynamicBreadcrumbs(props.navigationId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's happening asynchronously, so I have two questions:

  1. how are you assuring it's loaded on Server Side Render?
  2. isn't there a blink on client side? What about showing previous breadcrumbs and replace them when new ones are loaded? Does it make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

true, changed

@@ -48,8 +66,38 @@ export function useBreadcrumbs(
_breadcrumbs.value = [];
};

const getCategoryBreadcrumbs = async (categoryId: string) => {
const response = await apiClient.invoke(
"readBreadcrumb get /breadcrumb/{id}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

this endpoint is not only to load category breadcrumbs, I'm not sure about exposing it here, what is the designed flow here looks like?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This endpoint is only for the category breadcrumbs. For the product entity we will also receive, category breadcrumbs

Copy link
Collaborator

Choose a reason for hiding this comment

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

the endpoint is for both and takes more parameters
image

I just find getCategoryBreadcrumbs misleading as I would search for other types of breadcrumbs

Copy link
Collaborator

Choose a reason for hiding this comment

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

My point is - I would not keep this endpoint in the composable, it does not interfere with the logic and everyone can just use apiClient method for that and pass the data through buildDynamicBreadcrumbs

return response.data;
};

const buildDynamicBreadcrumbs = async (categoryId: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about product breadcrumbs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is the same method, for product we are also getting category breadcrumbs

Comment on lines 92 to 94
} catch (error) {
console.error("Error while fetching breadcrumbs", error);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should not handle errors in composable, it should be thrown to invoking component to handle in the project - analytics/notifications etc. however they need to handle it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

.changeset/funny-hotels-watch.md Show resolved Hide resolved
* @param page
* @returns
*/
export function getCmsBreadcrumbs<
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure about this helper - it's not creating breadcrumbs, just displaying entity translated property, when would that be useful for the users?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are using it to build CMS page breadcrumbs, where we always have 1 level of breadcrumbs

Copy link
Collaborator

@patzick patzick left a comment

Choose a reason for hiding this comment

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

I just have one more hesitation for useBreadcrumbs and I think the rest is in very good shape!

@@ -48,8 +66,38 @@ export function useBreadcrumbs(
_breadcrumbs.value = [];
};

const getCategoryBreadcrumbs = async (categoryId: string) => {
const response = await apiClient.invoke(
"readBreadcrumb get /breadcrumb/{id}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

the endpoint is for both and takes more parameters
image

I just find getCategoryBreadcrumbs misleading as I would search for other types of breadcrumbs

@@ -48,8 +66,38 @@ export function useBreadcrumbs(
_breadcrumbs.value = [];
};

const getCategoryBreadcrumbs = async (categoryId: string) => {
const response = await apiClient.invoke(
"readBreadcrumb get /breadcrumb/{id}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

My point is - I would not keep this endpoint in the composable, it does not interfere with the logic and everyone can just use apiClient method for that and pass the data through buildDynamicBreadcrumbs

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.

[BUG] Category breadcrumbs path is missing
3 participants