fix(wren-ui): fix tests. Remove nil values in view properties when building mdl

This commit is contained in:
william chang(張仲威)
2024-05-28 14:38:27 +08:00
parent 4ceb45715a
commit ed39dd643c
2 changed files with 17 additions and 6 deletions
+12 -5
View File
@@ -1,4 +1,4 @@
import { isEmpty } from 'lodash';
import { isEmpty, isNil, pick, pickBy } from 'lodash';
import {
Model,
ModelColumn,
@@ -114,14 +114,21 @@ export class MDLBuilder implements IMDLBuilder {
// if putting properties not string, it will throw error
// filter out properties that have string value
const properties = JSON.parse(view.properties) || {};
// filter out properties that are not null or undefined
// and are in the list of properties that are allowed
const viewProperties = pickBy(properties, (value, key) => {
return (
!isNil(value) &&
['displayName', 'description', 'question', 'summary'].includes(key)
);
});
return {
name: view.name,
statement: view.statement,
properties: {
displayName: properties.displayName,
description: properties.description,
question: properties.question,
summary: properties.summary,
...viewProperties,
// viewId will be passed back in other APIs
// to identify the view
@@ -392,7 +392,11 @@ describe('MDLBuilder', () => {
{
name: 'view',
statement: 'select * from order',
properties: { description: 'foo view', displayName: 'view' },
properties: {
description: 'foo view',
displayName: 'view',
viewId: '1',
},
},
] as ViewMDL[];