Skip to content

Commit

Permalink
feat(schema): added dynamic list component
Browse files Browse the repository at this point in the history
Related to #808
  • Loading branch information
Skaiir committed Dec 12, 2023
1 parent 13f7170 commit e6344b5
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/form-json-schema/src/defs/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@
},
"showOutline": {
"$id": "#/component/showOutline",
"description": "Groups and dynamic lists can have a visual outline.",
"description": "Outlines groups and dynamic lists.",
"type": "boolean"
},
"verticalAlignment": {
"$id": "#/component/verticalAlignment",
"description": "Groups and dynamic lists can be vertical aligned.",
"description": "Sets the alignment of the form field children. This can either be start, center, or end. Defaults to start.",
"type": "string",
"default": "start",
"enum": [
Expand All @@ -209,6 +209,31 @@
"end"
]
},
"isRepeating": {
"$id": "#/component/isRepeating",
"description": "Defines whether the list should currently be repeating its children.",
"type": "boolean"
},
"allowAddRemove": {
"$id": "#/component/allowAddRemove",
"description": "Allow adding and removing items from a list.",
"type": "boolean"
},
"defaultRepetitions": {
"$id": "#/component/defaultRepetitions",
"description": "Default number of repetitions a dynamic list will render with, if no data is provided. Defaults to 1.",
"type": "number"
},
"disableCollapse": {
"$id": "#/component/disableCollapse",
"description": "Disable the ability of a list can be collapsed.",
"type": "boolean"
},
"nonCollapsedItems": {
"$id": "#/component/nonCollapsedItems",
"description": "Number of items that will be rendered when a list is collapsed. Defaults to 5.",
"type": "number"
},
"validate": {
"$id": "#/component/validate",
"$ref": "validate.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,29 @@
}
}
},
{
"if": {
"not": {
"properties": {
"type": {
"const": "dynamiclist"
}
},
"required": [
"type"
]
}
},
"then": {
"properties": {
"isRepeating": false,
"defaultRepetitions": false,
"allowAddRemove": false,
"disableCollapse": false,
"nonCollapsedItems": false
}
}
},
{
"if": {
"not": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

export const form = {
type: 'default',
components: [
{
type: 'group',
path: 'myGroup',
isRepeating: true,
defaultRepetitions: 5,
allowAddRemove: true,
disableCollapse: false,
nonCollapsedItems: 3
}
]
};

export const errors = [
{
'instancePath': '/components/0/isRepeating',
'keyword': 'false schema',
'message': 'boolean schema is false',
'params': {},
'schemaPath': '#/properties/components/items/allOf/1/allOf/15/then/properties/isRepeating/false schema'
},
{
'instancePath': '/components/0/defaultRepetitions',
'keyword': 'false schema',
'message': 'boolean schema is false',
'params': {},
'schemaPath': '#/properties/components/items/allOf/1/allOf/15/then/properties/defaultRepetitions/false schema'
},
{
'instancePath': '/components/0/allowAddRemove',
'keyword': 'false schema',
'message': 'boolean schema is false',
'params': {},
'schemaPath': '#/properties/components/items/allOf/1/allOf/15/then/properties/allowAddRemove/false schema'
},
{
'instancePath': '/components/0/disableCollapse',
'keyword': 'false schema',
'message': 'boolean schema is false',
'params': {},
'schemaPath': '#/properties/components/items/allOf/1/allOf/15/then/properties/disableCollapse/false schema'
},
{
'instancePath': '/components/0/nonCollapsedItems',
'keyword': 'false schema',
'message': 'boolean schema is false',
'params': {},
'schemaPath': '#/properties/components/items/allOf/1/allOf/15/then/properties/nonCollapsedItems/false schema'
},
{
'instancePath': '/components/0',
'keyword': 'if',
'message': 'must match "then" schema',
'params': {
'failingKeyword': 'then'
},
'schemaPath': '#/properties/components/items/allOf/1/allOf/15/if'
}
];
17 changes: 17 additions & 0 deletions packages/form-json-schema/test/fixtures/dynamic-list-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

export const form = {
type: 'default',
components: [
{
type: 'dynamiclist',
path: 'myGroup',
isRepeating: true,
defaultRepetitions: 5,
allowAddRemove: true,
disableCollapse: false,
nonCollapsedItems: 3
}
]
};

export const errors = null;
6 changes: 6 additions & 0 deletions packages/form-json-schema/test/spec/validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ describe('validation', function() {

testForm('rowCount-no-number');


testForm('dynamic-list-properties');


testForm('dynamic-list-properties-not-allowed');

});


Expand Down

0 comments on commit e6344b5

Please sign in to comment.