-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(picker-starter): place query and filters logic directly into…
… the picker.config.ts file (#91) * place query and filters functions directly into the picker.config.ts * rename matchItem to matchSearchTerm * apply changes code review
- Loading branch information
1 parent
558bc4b
commit 6870040
Showing
13 changed files
with
72 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './basket/BasketItem' | ||
export * from './basket' | ||
export * from './matchItem' | ||
export * from './matchCategories' | ||
export * from './matchSearchTerm' | ||
export * from './service' | ||
export * from './types' | ||
export * from './setup' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './matchCategories' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { MockItem } from '@/data' | ||
|
||
export const matchCategories = | ||
(categoryNames: string[]) => (items: MockItem) => { | ||
if (categoryNames.length === 0) { | ||
return true | ||
} | ||
return categoryNames.some((categoryName) => items.category === categoryName) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './matchSearchTerm' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,55 @@ | ||
import { getItemFilters, queryItems } from '@/data' | ||
import { defineConfig } from '@/core' | ||
import { categories, items } from '@/data' | ||
import { defineConfig, matchCategories, matchSearchTerm } from '@/core' | ||
import { StoryblokIcon } from './components' | ||
import { getPage } from './utils' | ||
|
||
export default defineConfig((options) => { | ||
return { | ||
title: 'Picker Starter', | ||
icon: StoryblokIcon, | ||
validateOptions: () => { | ||
const { limit } = options | ||
export default defineConfig((options) => ({ | ||
title: 'Picker Starter', | ||
icon: StoryblokIcon, | ||
validateOptions: () => { | ||
const { limit } = options | ||
|
||
const isLimitOptionValid = limit === undefined || Number(limit) > 0 | ||
|
||
if (!isLimitOptionValid) { | ||
return { | ||
isValid: false, | ||
error: `The 'limit' option must be an integer greater than 0`, | ||
} | ||
} | ||
const isLimitOptionValid = limit === undefined || Number(limit) > 0 | ||
|
||
if (!isLimitOptionValid) { | ||
return { | ||
isValid: true, | ||
isValid: false, | ||
error: `The 'limit' option must be an integer greater than 0`, | ||
} | ||
}, | ||
tabs: [ | ||
{ | ||
name: 'items', | ||
label: 'Items', | ||
query: queryItems, | ||
getFilters: getItemFilters, | ||
} | ||
|
||
return { | ||
isValid: true, | ||
} | ||
}, | ||
tabs: [ | ||
{ | ||
name: 'items', | ||
label: 'Items', | ||
query: async ({ searchTerm, page, perPage, filterSelection }) => { | ||
const filteredItems = items | ||
.filter(matchCategories(filterSelection['categoryMulti'] as string[])) | ||
.filter(matchSearchTerm(searchTerm)) | ||
|
||
return { | ||
items: getPage(filteredItems, page, perPage), | ||
pageInfo: { | ||
totalCount: filteredItems.length, | ||
}, | ||
} | ||
}, | ||
], | ||
} | ||
}) | ||
getFilters: async () => [ | ||
{ | ||
type: 'multi', | ||
label: 'Categories', | ||
name: 'categoryMulti', | ||
defaultValue: [], | ||
options: categories.map((category) => ({ | ||
label: category.name, | ||
value: category.name, | ||
})), | ||
}, | ||
], | ||
}, | ||
], | ||
})) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6870040
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
code-block – ./
code-block-git-main-storyblok-com.vercel.app
code-block-storyblok-com.vercel.app
storyblok-code-block.vercel.app