From f1b43681496404013184f7c91fde053b6548e64e Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Fri, 28 May 2021 18:32:20 -0300 Subject: [PATCH] Improved Categories --- framework/bigcommerce/common/get-site-info.ts | 19 ++++++++++++++++--- pages/search.tsx | 5 +---- tsconfig.json | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/framework/bigcommerce/common/get-site-info.ts b/framework/bigcommerce/common/get-site-info.ts index 9d131ec5d..26dc08092 100644 --- a/framework/bigcommerce/common/get-site-info.ts +++ b/framework/bigcommerce/common/get-site-info.ts @@ -4,6 +4,8 @@ import filterEdges from '../api/utils/filter-edges' import { BigcommerceConfig, getConfig } from '../api' import { categoryTreeItemFragment } from '../api/fragments/category-tree' import { Category } from '@commerce/types' +import getSlug from '@lib/get-slug' +import { CategoryTreeItem } from '@framework/schema' // Get 3 levels of categories export const getSiteInfoQuery = /* GraphQL */ ` @@ -49,6 +51,8 @@ export type CategoriesTree = NonNullable< GetSiteInfoQuery['site']['categoryTree'] > +export type CategoryItem = Pick + export type BrandEdge = NonNullable< NonNullable[0] > @@ -57,7 +61,7 @@ export type Brands = BrandEdge[] export type GetSiteInfoResult< T extends { categories: any[]; brands: any[] } = { - categories: CategoriesTree + categories: Category[] brands: Brands } > = T @@ -95,11 +99,20 @@ async function getSiteInfo({ query, { variables } ) - const categories = data.site?.categoryTree + + let categories = data!.site!.categoryTree?.map( + ({ entityId, name, path }: any) => ({ + id: `${entityId}`, + name, + slug: getSlug(path), + path, + }) + ) + const brands = data.site?.brands?.edges return { - categories: (categories as RecursiveRequired) ?? [], + categories: categories ?? [], brands: filterEdges(brands as RecursiveRequired), } } diff --git a/pages/search.tsx b/pages/search.tsx index a52c13f05..9a0330127 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -13,12 +13,9 @@ import useSearch from '@framework/product/use-search' import getAllPages from '@framework/common/get-all-pages' import getSiteInfo from '@framework/common/get-site-info' +import getSlug from '@lib/get-slug' import rangeMap from '@lib/range-map' -// TODO(bc) Remove this. This should come from the API -import getSlug from '@lib/get-slug' - -// TODO (bc) : Remove or standarize this. const SORT = Object.entries({ 'latest-desc': 'Latest arrivals', 'trending-desc': 'Trending', diff --git a/tsconfig.json b/tsconfig.json index 1a6c28831..9e712fb18 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,8 +22,8 @@ "@components/*": ["components/*"], "@commerce": ["framework/commerce"], "@commerce/*": ["framework/commerce/*"], - "@framework": ["framework/vendure"], - "@framework/*": ["framework/vendure/*"] + "@framework": ["framework/bigcommerce"], + "@framework/*": ["framework/bigcommerce/*"] } }, "include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],