-
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.
feature(picker-starter): add picker.config file (#84)
* add picker.config file * return service from defineConfig * make options config to be optional * add simple validation without using Joi * get rid of the option example property in our config schema * make optionsValidate optional * fix type error * fix prettier * only accept limit as option and get rid of selectOnly
- Loading branch information
1 parent
2ffcbb3
commit 027caed
Showing
16 changed files
with
104 additions
and
190 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
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
29 changes: 0 additions & 29 deletions
29
picker-starter/src/components/ModalPage/getItemServices.test.ts
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
picker-starter/src/components/ModalPage/getItemServices.ts
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Component } from 'vue' | ||
import { OptionsParams, PickerPluginParams, TabItem } from './types' | ||
|
||
export type PickerConfig = { | ||
title?: string | ||
icon?: Component | ||
validateOptions?: () => ValidationResult | ||
tabs: TabItem[] | ||
} | ||
|
||
export type ValidationResult = { | ||
isValid: boolean | ||
error?: string | ||
} | ||
|
||
export type PickerConfigFn = (optionsParams: OptionsParams) => PickerConfig | ||
|
||
export type PickerBuilderFn = ( | ||
optionsParams: OptionsParams, | ||
) => PickerPluginParams | ||
|
||
export const defineConfig = | ||
(fn: PickerConfigFn): PickerBuilderFn => | ||
(optionsParams: OptionsParams): PickerPluginParams => { | ||
const { title, icon, tabs, validateOptions } = fn(optionsParams) | ||
|
||
return { | ||
title, | ||
icon, | ||
makeService: () => { | ||
const validation = validateOptions?.() | ||
|
||
if (validation?.isValid === false) { | ||
return { | ||
error: validation.error || 'Unknown error', | ||
} | ||
} | ||
|
||
return { | ||
value: { tabs }, | ||
} | ||
}, | ||
} | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { getProductFilters, queryCategories, queryProducts } from '@/data' | ||
import { defineConfig } from '@/core' | ||
import { StoryblokIcon } from './components' | ||
|
||
export default defineConfig((options) => { | ||
return { | ||
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`, | ||
} | ||
} | ||
|
||
return { | ||
isValid: true, | ||
} | ||
}, | ||
tabs: [ | ||
{ | ||
name: 'product', | ||
label: 'Products', | ||
query: queryProducts, | ||
getFilters: getProductFilters, | ||
}, | ||
{ | ||
name: 'category', | ||
label: 'Categories', | ||
query: queryCategories, | ||
}, | ||
], | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
027caed
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-storyblok-com.vercel.app
code-block-git-main-storyblok-com.vercel.app
storyblok-code-block.vercel.app