Skip to content

Commit f33d74a

Browse files
authoredApr 25, 2024
feat(mirinae): add boolean type to jsonSchemaForm (#3608)
* fix(mirinae): fix build error Signed-off-by: sulmo <sulmo@megazone.com> * feat(mirinae): add boolean type to jsonSchemaForm Signed-off-by: sulmo <sulmo@megazone.com> * fix: fix badge setting of text input Signed-off-by: sulmo <sulmo@megazone.com> --------- Signed-off-by: sulmo <sulmo@megazone.com>
1 parent 3960d38 commit f33d74a

File tree

8 files changed

+24
-6
lines changed

8 files changed

+24
-6
lines changed
 

Diff for: ‎packages/mirinae/src/data-display/dynamic/dynamic-layout/templates/item/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</p-heading>
88
<p-definition-table :fields="fields"
99
:data="rootData"
10-
:style-type="options?.styleType"
10+
:style-type="options.styleType"
1111
:loading="loading"
1212
v-on="$listeners"
1313
>

Diff for: ‎packages/mirinae/src/inputs/forms/json-schema-form/PJsonSchemaForm.stories.mdx

+3-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ It internally uses [Ajv JSON schema validator](https://ajv.js.org/) and [ajv-for
101101
|string|ajv|[Text Input](?path=/docs/inputs-input--basic)|
102102
|number|ajv|[Text Input](?path=/docs/inputs-input--basic)|
103103
|integer|ajv|[Text Input](?path=/docs/inputs-input--basic)|
104-
|array|ajv|[Text Input](?path=/docs/inputs-input--basic) or [Filterable Dropdown](?path=/docs/inputs-dropdown-select-dropdown--basic)(with enum keyword)||
105-
|object|self| Json Schema Form ||
104+
|array|ajv|[Text Input](?path=/docs/inputs-input--basic) or [Filterable Dropdown](?path=/docs/inputs-dropdown-select-dropdown--basic)(with enum keyword)|
105+
|boolean|ajv|[Toggle](?path=/docs/inputs-buttons-toggle-button--toggle-button-basic)|
106+
|object|self| Json Schema Form |
106107

107108
### Formats
108109
**string type only**

Diff for: ‎packages/mirinae/src/inputs/forms/json-schema-form/PJsonSchemaForm.vue

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@
117117
/>
118118
</template>
119119
</p-select-dropdown>
120+
<p-toggle-button v-else-if="schemaProperty.componentName === 'PToggleButton'"
121+
:key="`PToggleButton-${schemaProperty.propertyName}`"
122+
:value="rawFormData[schemaProperty.propertyName]"
123+
:disabled="schemaProperty.disabled"
124+
class="input-form"
125+
@update:value="handleUpdateFormValue(schemaProperty, propertyIdx, ...arguments)"
126+
/>
120127
<template v-else>
121128
<p-text-input :key="`PTextInput-${schemaProperty.propertyName}`"
122129
:value="schemaProperty.multiInputMode ? undefined : rawFormData[schemaProperty.propertyName]"
@@ -159,6 +166,7 @@ import addFormats from 'ajv-formats';
159166
import { isEqual } from 'lodash';
160167
161168
import PMarkdown from '@/data-display/markdown/PMarkdown.vue';
169+
import PToggleButton from '@/inputs/buttons/toggle-button/PToggleButton.vue';
162170
import PSelectDropdown from '@/inputs/dropdown/select-dropdown/PSelectDropdown.vue';
163171
import PFieldGroup from '@/inputs/forms/field-group/PFieldGroup.vue';
164172
import GenerateIdFormat from '@/inputs/forms/json-schema-form/components/GenerateIdFormat.vue';
@@ -200,6 +208,7 @@ export default defineComponent<JsonSchemaFormProps>({
200208
PMarkdown,
201209
PFieldGroup,
202210
PTextInput,
211+
PToggleButton,
203212
},
204213
props: {
205214
schema: {

Diff for: ‎packages/mirinae/src/inputs/forms/json-schema-form/helpers/form-data-refine-helper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const refineValueByProperty = (schema: JsonSchema, val?: any): any => {
3434
}
3535
}
3636
if (typeof val === 'string') return val?.trim() || undefined;
37+
if (typeof val === 'boolean') return val;
3738
return undefined;
3839
};
3940

Diff for: ‎packages/mirinae/src/inputs/forms/json-schema-form/helpers/inner-schema-helper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const getComponentNameBySchemaProperty = (schemaProperty: JsonSchema): Co
4747
if (schemaProperty.type === 'object') return 'PJsonSchemaForm';
4848
if (Array.isArray(schemaProperty.enum) && schemaProperty.type === 'string') return 'PSelectDropdown';
4949
if (isStrictArraySelectMode(schemaProperty)) return 'PFilterableDropdown';
50+
if (schemaProperty.type === 'boolean') return 'PToggleButton';
5051
return 'PTextInput';
5152
};
5253

Diff for: ‎packages/mirinae/src/inputs/forms/json-schema-form/mock.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export const getDefaultSchema = () => ({
3333
format: 'generate_id',
3434
markdown: '[How to generate ID?](https://www.google.com)',
3535
},
36+
is_that_true: {
37+
type: 'boolean',
38+
title: 'Is that true?',
39+
default: true,
40+
},
3641
password: {
3742
title: 'Password',
3843
minLength: 8,
@@ -178,7 +183,7 @@ G6aFKaqQfOXKCyWoUiVknQJAXsssyFFci/2ueKlIE1QqIiLSZ8V8OlpFLRnb1pzI
178183
},
179184
},
180185
required: ['user_id', 'password', 'user_name', 'age', 'homepage', 'phone', 'additional', 'emails', 'colors', 'provider', 'friends', 'pem_key'],
181-
order: ['user_id', 'password', 'user_name', 'user_nickname', 'country_code', 'provider', 'age', 'phone', 'homepage', 'additional', 'colors', 'foods', 'food', 'pem_key'],
186+
order: ['user_id', 'is_that_true', 'password', 'user_name', 'user_nickname', 'country_code', 'provider', 'age', 'phone', 'homepage', 'additional', 'colors', 'foods', 'food', 'pem_key'],
182187
});
183188

184189
export const getDefaultFormData = () => ({

Diff for: ‎packages/mirinae/src/inputs/forms/json-schema-form/type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { SupportLanguage } from '@/translations';
55
const TEXT_INPUT_TYPES = ['password', 'text', 'number'] as const;
66
export type TextInputType = typeof TEXT_INPUT_TYPES[number];
77

8-
const COMPONENTS = ['PTextInput', 'GenerateIdFormat', 'PJsonSchemaForm', 'PSelectDropdown', 'PFilterableDropdown', 'PEMKeyFormat'] as const;
8+
const COMPONENTS = ['PTextInput', 'GenerateIdFormat', 'PJsonSchemaForm', 'PSelectDropdown', 'PFilterableDropdown', 'PEMKeyFormat', 'PToggleButton'] as const;
99
export type ComponentName = typeof COMPONENTS[number];
1010

1111
interface Reference {

Diff for: ‎packages/mirinae/src/inputs/input/text-input/PTextInput.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
>
3030
{{ proxySelected[0].label || proxySelected[0].name }}
3131
<p-badge v-if="proxySelected.length > 1"
32+
badge-type="subtle"
3233
:style-type="disabled ? 'gray200' : 'blue200'"
3334
>
3435
+{{ proxySelected.length - 1 }}
@@ -544,7 +545,7 @@ export default defineComponent<TextInputProps>({
544545
@apply w-full;
545546
}
546547
> .input-container {
547-
@apply inline-flex border bg-white text-gray-900 rounded items-center;
548+
@apply inline-flex border border-gray-300 bg-white text-gray-900 rounded items-center;
548549
width: inherit;
549550
min-height: 2rem;
550551
height: auto;

0 commit comments

Comments
 (0)