From a51c0d5139f2bfdd423cfbaa4ee5e1f656b8b8a2 Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Tue, 25 Feb 2020 15:36:37 -0800 Subject: [PATCH] addressed review comments --- .../condition/components/Criterion.vue | 41 +++++++++++-------- .../condition/criterion/TelemetryCriterion.js | 4 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/plugins/condition/components/Criterion.vue b/src/plugins/condition/components/Criterion.vue index cb2d751163..db45adfb78 100644 --- a/src/plugins/condition/components/Criterion.vue +++ b/src/plugins/condition/components/Criterion.vue @@ -91,21 +91,40 @@ export default { telemetryMetadata: {}, telemetryMetadataOptions: {}, operations: OPERATIONS, - filteredOps: [], inputCount: 0, - rowLabel: '' + rowLabel: '', + operationFormat: '' } }, computed: { setRowLabel: function () { let operator = this.trigger === 'all' ? 'and ': 'or '; return (this.index !== 0 ? operator : '') + 'when'; + }, + filteredOps: function () { + return [...this.operations.filter(op => op.appliesTo.indexOf(this.operationFormat) !== -1)]; } }, mounted() { this.updateMetadataOptions(); }, methods: { + getOperationFormat() { + this.telemetryMetadata.valueMetadatas.forEach((value, index) => { + let valueMetadata = this.telemetryMetadataOptions[index]; + if (valueMetadata.formatString) { + this.operationFormat = 'number'; + } else if (valueMetadata.format) { + if (valueMetadata.format === 'utc') { + this.operationFormat = 'number'; + } else if (valueMetadata.format === 'enum') { + this.operationFormat = 'enum'; + } + } else { + this.operationFormat = 'string'; + } + }); + }, updateMetadataOptions(ev) { if (ev) {this.clearInputs()} if (this.criterion.telemetry) { @@ -121,27 +140,13 @@ export default { }, updateOperations(ev) { if (ev) {this.clearInputs()} - let operationFormat = 'string'; - this.telemetryMetadata.valueMetadatas.forEach((value, index) => { - if (value.key === this.criterion.metadata) { - let valueMetadata = this.telemetryMetadataOptions[index]; - if (valueMetadata.formatString) { - operationFormat = 'number'; - } else if (valueMetadata.format) { - if (valueMetadata.format === 'utc') { - operationFormat = 'number'; - } else if (valueMetadata.format === 'enum') { - operationFormat = 'enum'; - } - } - } - }); - this.filteredOps = [...this.operations.filter(op => op.appliesTo.indexOf(operationFormat) !== -1)]; + this.getOperationFormat(); this.persist(); }, updateOperationInputVisibility(ev) { if (ev) { this.criterion.input = []; + this.inputCount = 0; } for (let i = 0; i < this.filteredOps.length; i++) { if (this.criterion.operation === this.filteredOps[i].name) { diff --git a/src/plugins/condition/criterion/TelemetryCriterion.js b/src/plugins/condition/criterion/TelemetryCriterion.js index 1d35d6bf35..cbbd159e6a 100644 --- a/src/plugins/condition/criterion/TelemetryCriterion.js +++ b/src/plugins/condition/criterion/TelemetryCriterion.js @@ -76,10 +76,8 @@ export default class TelemetryCriterion extends EventEmitter { let params = []; let result = false; params.push(data[this.metadata]); - if (this.input instanceof Array && this.input.length) { + if (this.input.length) { this.input.forEach(input => {params.push(this.input[0])}); - } else if (this.input) { - params.push(this.input); } if (typeof comparator === 'function') { result = comparator(params);