Skip to content

Commit 9f59363

Browse files
pkp/pkp-lib#9527 Add FieldControlledVocab to storybook
1 parent a062b70 commit 9f59363

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

.storybook/preview.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const pinia = createPinia();
3737

3838
// Initialize MSW
3939
initialize({
40+
onUnhandledRequest: 'bypass',
4041
/** To be migrated to msw2 if neede */
4142
/*onUnhandledRequest: ({method, url}) => {
4243
if (url.pathname.includes('://mock/')) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Primary, Controls, Stories, Meta, ArgTypes} from '@storybook/blocks';
2+
3+
import * as FieldControlledVocabStories from './FieldControlledVocab.stories.js';
4+
5+
<Meta of={FieldControlledVocabStories} />
6+
7+
# FieldControlledVocab
8+
9+
## Usage
10+
11+
This is an implementation of [FieldBaseAutosuggest](#/component/Form/fields/FieldBaseAutosuggest). Used for example for keywords, where it fetches list of keywords from the api, but allow to add additional keywords as well.
12+
13+
<Primary />
14+
<Controls />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import {http, HttpResponse} from 'msw';
2+
import FieldControlledVocab from './FieldControlledVocab.vue';
3+
import FieldBaseMock from '../mocks/field-base';
4+
import FieldBaseAutosuggest from '../mocks/field-autosuggest';
5+
6+
import KeywordsMock from '@/mocks/keywords.json';
7+
8+
export default {
9+
title: 'Forms/FieldControlledVocab',
10+
component: FieldControlledVocab,
11+
render: (args) => ({
12+
components: {FieldControlledVocab},
13+
setup() {
14+
function change(name, prop, newValue, localeKey) {
15+
if (localeKey) {
16+
args[prop][localeKey] = newValue;
17+
} else {
18+
args[prop] = newValue;
19+
}
20+
}
21+
22+
return {args, change};
23+
},
24+
template: `
25+
<FieldControlledVocab v-bind="args" @change="change" />
26+
`,
27+
}),
28+
};
29+
30+
export const Base = {
31+
args: {
32+
...FieldBaseMock,
33+
...FieldBaseAutosuggest,
34+
label: 'Keywords',
35+
/*selected: [
36+
{value: 'keyword1', label: 'keyword1'},
37+
{value: 'keyword2', label: 'keyword2'},
38+
],
39+
40+
//value: ['keyword1', 'keyword2'],
41+
value: ['keyword1', 'keyword2'],*/
42+
43+
// multi
44+
value: {en: ['keyword1', 'keyword2']},
45+
selected: {
46+
en: [
47+
{value: 'keyword1', label: 'keyword1'},
48+
{value: 'keyword2', label: 'keyword2'},
49+
],
50+
},
51+
isMultilingual: true,
52+
localeKey: 'en',
53+
54+
apiUrl:
55+
'https://mock/index.php/publicknowledge/api/v1/vocabs?vocab=submissionKeyword&locale=en',
56+
/*selected: [
57+
{
58+
value: 1,
59+
label: 'Articles',
60+
},
61+
],*/
62+
},
63+
parameters: {
64+
docs: {
65+
story: {
66+
height: '300px',
67+
},
68+
},
69+
msw: {
70+
handlers: [
71+
http.get(
72+
'https://mock/index.php/publicknowledge/api/v1/vocabs?vocab=submissionKeyword&locale=en',
73+
async () => {
74+
return HttpResponse.json(KeywordsMock);
75+
},
76+
),
77+
],
78+
},
79+
},
80+
};

src/mocks/keywords.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[
2+
"21st Century",
3+
"Alberta",
4+
"cattle",
5+
"citizenship",
6+
"Common pool resource",
7+
"common property",
8+
"Computer Skills",
9+
"Culture",
10+
"Development",
11+
"Diversity",
12+
"education",
13+
"Egalitarianism",
14+
"employees",
15+
"engineering education",
16+
"food security",
17+
"Gender",
18+
"Goverance",
19+
"Integrating Technology",
20+
"intellectual developments",
21+
"Language",
22+
"Multi-Level Institutions",
23+
"Multiethnic",
24+
"Multilingual",
25+
"National",
26+
"Participatory Pedagogy",
27+
"pigs",
28+
"Professional Development",
29+
"Provincial",
30+
"Self-Organization",
31+
"service learning",
32+
"Social Transformation",
33+
"survey",
34+
"Survey",
35+
"sustainability",
36+
"Test keyword 1",
37+
"Test keyword 2",
38+
"water"
39+
]

0 commit comments

Comments
 (0)