Skip to content

Commit

Permalink
fix: ensure dynamic list and tables interact safely
Browse files Browse the repository at this point in the history
Closes #1064
  • Loading branch information
Skaiir committed Mar 7, 2024
1 parent 8d01b9a commit d9b8bab
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function Table(props) {
);
const columnKeys = evaluatedColumns.map(({ key }) => key);
const evaluatedDataSource = useExpressionEvaluation(dataSource);
const data = Array.isArray(evaluatedDataSource) ? evaluatedDataSource : [];
const data = Array.isArray(evaluatedDataSource) ? evaluatedDataSource.filter(i => i) : [];
const sortedData =
sortBy === null
? data
Expand Down
56 changes: 56 additions & 0 deletions packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import conditionSchema from './condition.json';
import conditionErrorsSchema from './condition-errors.json';
import conditionErrorsDynamicListSchema from './condition-errors-dynamic-list.json';
import dynamicListVariablesSchema from './dynamic-list-variables.json';
import dynamicListTableFilterInteractionSchema from './dynamic-list-table-filter-interaction.json';
import hiddenFieldsConditionalSchema from './hidden-fields-conditional.json';
import hiddenFieldsExpressionSchema from './hidden-fields-expression.json';
import disabledSchema from './disabled.json';
Expand Down Expand Up @@ -525,6 +526,61 @@ describe('Form', function() {
});


it('should hold proper interaction between table and dynamic list', async function() {

// given
const data = {
'onlyShowRiskAbove': 6,
'riskEntries': [
{
'risk': 3,
'name': 'Alice Johnson',
'date': '2023-03-01'
},
{
'risk': 6,
'name': 'Bob Smith',
'date': '2023-03-05'
},
{
'risk': 9,
'name': 'Carla Gomez',
'date': '2023-03-10'
},
{
'risk': 12,
'name': 'David Lee',
'date': '2023-03-15'
}
]
};

// when
await bootstrapForm({
container,
data,
schema: dynamicListTableFilterInteractionSchema
});

// then
expect(form).to.exist;

const table = container.querySelector('.fjs-form-field-table');
expect(table).to.exist;

const tableEntries = table.querySelectorAll('.fjs-table-td');
expect(tableEntries).to.have.length(6);
expect([ ...tableEntries ].map(e => e.textContent)).to.eql([
'9', 'Carla Gomez', '2023-03-10',
'12', 'David Lee', '2023-03-15'
]);

const groups = container.querySelectorAll('.fjs-form-field-group');
expect(groups).to.have.length(2);

});


const runFocusBlurTest = function(id, index, selector) {

it('focus and blur events should trigger for ' + id, async function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"components": [
{
"label": "Table",
"type": "table",
"dataSource": "=riskEntries",
"rowCount": 3,
"id": "Table_1",
"columns": [
{
"label": "Risk factor",
"key": "risk"
},
{
"label": "Name",
"key": "name"
},
{
"label": "Date",
"key": "date"
}
]
},
{
"label": "Only show risk above",
"type": "number",
"id": "Number_2",
"key": "onlyShowRiskAbove",
"defaultValue": 5
},
{
"components": [
{
"components": [
{
"text": "Risk factor: {{this.risk}}",
"label": "Text view",
"type": "text",
"id": "Field_0kypubr"
},
{
"label": "Risk factor",
"type": "number",
"id": "Number_1",
"key": "risk"
},
{
"label": "Name",
"type": "textfield",
"id": "TextField_1",
"key": "name"
},
{
"label": "Date",
"type": "textfield",
"id": "TextField_2",
"key": "date"
}
],
"showOutline": true,
"label": "Group",
"type": "group",
"id": "Group_1",
"conditional": {
"hide": "=this.risk <= onlyShowRiskAbove"
}
}
],
"showOutline": true,
"isRepeating": true,
"allowAddRemove": true,
"defaultRepetitions": 1,
"label": "Dynamic list",
"type": "dynamiclist",
"id": "Dynamiclist_1",
"path": "riskEntries",
"nonCollapsedItems": null
}
],
"type": "default",
"id": "Form_1je5j4d",
"executionPlatform": "Camunda Cloud",
"executionPlatformVersion": "8.4.0",
"exporter": {
"name": "Camunda Modeler",
"version": "5.20.0"
},
"schemaVersion": 15
}

0 comments on commit d9b8bab

Please sign in to comment.