Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert the way config elements are mocked to 2.33.0 functionality #265

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Fixes
* [vro-scripting-api] Revert 110 / Mocking for configuration elements is incorrect.

## v2.38.1 - 03 Apr 2024

### Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ namespace vroapi {
* @param key
*/
getAttributeWithKey(key: string): Attribute {
// const attribute = this.attributes.find(a => a.name === key);
const attribute: any = this.attributes != null ? this.attributes.find(a => a.name === key) : [];


const attribute = this.attributes.find(a => a.name === key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do a in-line null check with this.attributes?.find(a => a.name === key)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the fix, the code is from BT 2.33.0, so I assume that this has always been correct.


return typeof attribute === 'undefined' ? null : attribute;
}

Expand All @@ -52,7 +50,6 @@ namespace vroapi {
*/
setAttributeWithKey(key: string, value: any, typeHint?: any): void {
let attr = this.getAttributeWithKey(key);
this._attributes = this._attributes === null ? [] : this._attributes
if (!attr) {
attr = new Attribute();
attr.name = key;
Expand Down
9 changes: 3 additions & 6 deletions typescript/vro-scripting-api/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,13 @@ namespace vroapi {
function getElementAttributes(categoryPath: string, elementName: string): Attribute[] {
const categoryDescriptor = findDescriptorByPath(categoryPath);
if (!categoryDescriptor) {
return null;
return [];
}
const elementDescriptor = categoryDescriptor.elements[elementName];
if (!elementDescriptor || !elementDescriptor.path) {
return null;
return [];
}
const attributeDescriptors = parseJsonFile<AttributeDescriptor[]>(elementDescriptor.path);
if (attributeDescriptors.length === 0) {
return null;
}
return attributeDescriptors.map(attrInfo => {
const attr = new Attribute();
attr.name = attrInfo.name;
Expand All @@ -164,7 +161,7 @@ namespace vroapi {
attr.value = attrInfo.value != null ? convertAttrValue(attrInfo.type, attrInfo.value) : null;
return attr;
});
}
}


function findDescriptorByPath(categoryPath: string): CategoryDescriptor {
Expand Down
Loading