Skip to content

Commit

Permalink
feat: allow to pass search criteria to loadNavigationElements of useN…
Browse files Browse the repository at this point in the history
…avigation (#1540)
  • Loading branch information
kasztof authored Dec 20, 2024
1 parent d2b967b commit 3778061
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-snakes-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-pwa/composables-next": minor
---

Allow to pass full seach criteria according to loadNavigationElements method of useNavigation composable
17 changes: 17 additions & 0 deletions packages/composables/src/useNavigation/useNavigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@ describe("useNavigation", () => {
);
expect(vm.navigationElements).toStrictEqual([]);
});

it("should pass criteria to the api call", async () => {
const { vm, injections } = useSetup(useNavigation);
injections.apiClient.invoke.mockResolvedValue({ data: undefined });
vi.spyOn(injections.apiClient, "invoke").mockImplementation(() => {});

await vm.loadNavigationElements({
depth: 2,
includes: { category: ["name"] },
});
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
expect.stringContaining("readNavigation"),
expect.objectContaining({
body: { depth: 2, includes: { category: ["name"] } },
}),
);
});
});
16 changes: 8 additions & 8 deletions packages/composables/src/useNavigation/useNavigation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, inject, provide, ref } from "vue";
import type { ComputedRef, Ref } from "vue";
import { useShopwareContext } from "#imports";
import type { Schemas } from "#shopware";
import type { Schemas, operations } from "#shopware";

/**
*
Expand All @@ -15,9 +15,9 @@ export type UseNavigationReturn = {
/**
* Load navigation elements
*/
loadNavigationElements(params: {
depth: number;
}): Promise<Schemas["NavigationRouteResponse"]>;
loadNavigationElements(
params: operations["readNavigation post /navigation/{activeId}/{rootId}"]["body"],
): Promise<Schemas["NavigationRouteResponse"]>;
};

/**
Expand Down Expand Up @@ -49,7 +49,9 @@ export function useNavigation(params?: {

const navigationElements = computed(() => sharedElements.value);

async function loadNavigationElements({ depth }: { depth: number }) {
async function loadNavigationElements(
params: operations["readNavigation post /navigation/{activeId}/{rootId}"]["body"],
) {
try {
const navigationResponse = await apiClient.invoke(
"readNavigation post /navigation/{activeId}/{rootId}",
Expand All @@ -61,9 +63,7 @@ export function useNavigation(params?: {
activeId: type,
rootId: type,
},
body: {
depth,
},
body: params,
},
);

Expand Down

0 comments on commit 3778061

Please # to comment.