mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
feat: implement YMM filters
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
16
lib/utils.ts
16
lib/utils.ts
@@ -1,6 +1,7 @@
|
||||
import clsx, { ClassValue } from 'clsx';
|
||||
import { ReadonlyURLSearchParams } from 'next/navigation';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
import { Menu } from './shopify/types';
|
||||
|
||||
export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyURLSearchParams) => {
|
||||
const paramsString = params.toString();
|
||||
@@ -55,3 +56,18 @@ export const parseMetaFieldValue = <T>(field: { value: string } | null): T | nul
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const findParentCollection = (menu: Menu[], collection: string): Menu | null => {
|
||||
let parentCollection: Menu | null = null;
|
||||
for (const item of menu) {
|
||||
if (item.items.length) {
|
||||
const hasParent = item.items.some((subItem) => subItem.path.includes(collection));
|
||||
if (hasParent) {
|
||||
return item;
|
||||
} else {
|
||||
parentCollection = findParentCollection(item.items, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
return parentCollection;
|
||||
};
|
||||
|
Reference in New Issue
Block a user