mirror of
https://github.com/Canner/WrenAI.git
synced 2026-09-24 23:29:49 +08:00
fix(wren-ui): fix tests. Remove nil values in view properties when building mdl
This commit is contained in:
@@ -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[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user