-
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.
place query and filters functions directly into the picker.config.ts
- Loading branch information
1 parent
558bc4b
commit b1eeda9
Showing
9 changed files
with
61 additions
and
115 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
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 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 { categoryMockAssets, items } from '@/data' | ||
import { defineConfig, matchCategories, matchItem } 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(matchItem(searchTerm)) | ||
|
||
return { | ||
items: getPage(filteredItems, page, perPage), | ||
pageInfo: { | ||
totalCount: filteredItems.length, | ||
}, | ||
} | ||
}, | ||
], | ||
} | ||
}) | ||
getFilters: async () => [ | ||
{ | ||
type: 'multi', | ||
label: 'Categories', | ||
name: 'categoryMulti', | ||
defaultValue: [], | ||
options: categoryMockAssets.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