Skip to content

Commit

Permalink
replace the term product(s) with item(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
demetriusfeijoo committed Dec 11, 2023
1 parent 027caed commit d41b541
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
5 changes: 3 additions & 2 deletions picker-starter/src/components/ItemPicker/ItemPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ export default {
const res = await this.itemService
.query(this.queryState.query)
.catch((error) => error)
if (res instanceof Error) {
this.notify({
title: 'Failed to fetch Products',
description: 'Something went wrong when fetching products.',
title: `Failed to fetch ${this.itemService.label}`,
description: `Something went wrong when fetching ${this.itemService.label}.`,
error: new Error(res),
})
this.dispatch({
Expand Down
4 changes: 0 additions & 4 deletions picker-starter/src/core/basket/BasketItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@ export type BasketItem<Type extends string = string> = {
description: string | undefined
}

export type ProductItem = BasketItem<'product'> & {
sku: string | undefined
}

export type CategoryItem = BasketItem<'category'>
2 changes: 1 addition & 1 deletion picker-starter/src/core/matchItem/matchItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { matchItem } from './matchItem'
import { BasketItem } from '../'

const templateItem: BasketItem = {
type: 'product',
type: 'item',
id: '123',
description: undefined,
image: undefined,
Expand Down
2 changes: 1 addition & 1 deletion picker-starter/src/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './categories'
export * from './products'
export * from './items'
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
FilterList,
FilterItem,
FilterOption,
ProductItem,
matchItem,
BasketItem,
} from '@/core'
import {
compareName,
Expand All @@ -15,15 +15,15 @@ import {
} from '@/utils'
import { categoryMockAssets } from './categories'

export type TmpProduct = {
export type TempItem = {
id: number
filename: string | undefined
description?: string
category: string | undefined
}

// Temporary object, just so that we can save some lines of code
export const tmpAssets: TmpProduct[] = [
export const tmpAssets: TempItem[] = [
{
id: 4997256,
filename:
Expand Down Expand Up @@ -635,28 +635,32 @@ const getNameFromImage = (filename: string): string | undefined => {
return imageName?.split('.')?.[0]?.split('-')?.map(capitalizeWord)?.join(' ')
}

export type MockProduct = ProductItem & {
export type Item = BasketItem<'item'> & {
sku: string | undefined
}

export type MockItem = Item & {
category: string | undefined
}

export const products: MockProduct[] = tmpAssets
.map((mockProduct) => {
const { filename, id, description } = mockProduct
export const items: MockItem[] = tmpAssets
.map((mockItems) => {
const { filename, id, description } = mockItems
const name = filename && getNameFromImage(filename)

return {
type: 'product',
type: 'item',
id: `${id}`,
name: name ?? 'Without image',
image: filename && getImage(filename),
sku: `sku-${id}`,
description,
category: mockProduct.category,
} as MockProduct
category: mockItems.category,
} as MockItem
})
.sort(compareName)

export const getProductFilters: FilterList = async () => {
export const getItemFilters: FilterList = async () => {
const options: FilterOption[] = categoryMockAssets.map<FilterOption>(
(category) => {
return {
Expand All @@ -680,23 +684,20 @@ export const getProductFilters: FilterList = async () => {
return delayed(randomDelay(), response)
}

export const queryProducts: ItemQuery = async ({
export const queryItems: ItemQuery = async ({
searchTerm,
page,
perPage,
filterSelection,
}) => {
const matchCategories =
(categoryNames: string[]) => (product: MockProduct) => {
if (categoryNames.length === 0) {
return true
}
return categoryNames.some(
(categoryName) => product.category === categoryName,
)
const matchCategories = (categoryNames: string[]) => (items: MockItem) => {
if (categoryNames.length === 0) {
return true
}
return categoryNames.some((categoryName) => items.category === categoryName)
}

const allSearchResults = products
const allSearchResults = items
.filter(matchCategories(filterSelection['categoryMulti'] as string[]))
.filter(matchItem(searchTerm))

Expand Down
10 changes: 5 additions & 5 deletions picker-starter/src/picker.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProductFilters, queryCategories, queryProducts } from '@/data'
import { getItemFilters, queryCategories, queryItems } from '@/data'
import { defineConfig } from '@/core'
import { StoryblokIcon } from './components'

Expand All @@ -24,10 +24,10 @@ export default defineConfig((options) => {
},
tabs: [
{
name: 'product',
label: 'Products',
query: queryProducts,
getFilters: getProductFilters,
name: 'items',
label: 'Items',
query: queryItems,
getFilters: getItemFilters,
},
{
name: 'category',
Expand Down

0 comments on commit d41b541

Please sign in to comment.