diff --git a/src/plugins/filters/components/FilterObject.vue b/src/plugins/filters/components/FilterObject.vue index af5ed4c31c..e5246724ac 100644 --- a/src/plugins/filters/components/FilterObject.vue +++ b/src/plugins/filters/components/FilterObject.vue @@ -63,7 +63,13 @@ export default { if (filterValue && filterValue[comparator]) { if (value === false) { - filterValue[comparator] = filterValue[comparator].filter(v => v !== valueName); + let filteredValueName = filterValue[comparator].filter(v => v !== valueName); + + if (filteredValueName.length === 0) { + delete this.updatedFilters[key]; + } else { + filterValue[comparator] = filteredValueName; + } } else { filterValue[comparator].push(valueName); } diff --git a/src/plugins/filters/components/FiltersView.vue b/src/plugins/filters/components/FiltersView.vue index 239175ebab..d031925452 100644 --- a/src/plugins/filters/components/FiltersView.vue +++ b/src/plugins/filters/components/FiltersView.vue @@ -59,14 +59,18 @@ export default { removeChildren(identifier) { let keyString = this.openmct.objects.makeKeyString(identifier); this.$delete(this.children, keyString); - this.persistFilters(keyString); + delete this.persistedFilters[keyString]; + this.mutateConfigurationFilters(); }, persistFilters(keyString, userSelects) { this.persistedFilters[keyString] = userSelects; - this.openmct.objects.mutate(this.providedObject, 'configuration.filters', this.persistedFilters); + this.mutateConfigurationFilters(); }, updatePersistedFilters(filters) { this.persistedFilters = filters; + }, + mutateConfigurationFilters() { + this.openmct.objects.mutate(this.providedObject, 'configuration.filters', this.persistedFilters); } }, mounted(){ diff --git a/src/plugins/telemetryTable/components/TelemetryFilterIndicator.vue b/src/plugins/telemetryTable/components/TelemetryFilterIndicator.vue index a2468fdbc5..46291f8703 100644 --- a/src/plugins/telemetryTable/components/TelemetryFilterIndicator.vue +++ b/src/plugins/telemetryTable/components/TelemetryFilterIndicator.vue @@ -64,7 +64,7 @@ data() { return { filterNames: [], - telemetryFilters: {}, + filteredTelemetry: {}, mixed: false, label: '', title: '' @@ -76,12 +76,12 @@ }, setFilterNames() { let names = []; - let composition = this.openmct.composition.get(this.table.configuration.domainObject); - composition.load().then((domainObjects) => { + this.composition && this.composition.load().then((domainObjects) => { domainObjects.forEach(telemetryObject => { let keyString= this.openmct.objects.makeKeyString(telemetryObject.identifier); - let filters = this.telemetryFilters[keyString]; + let filters = this.filteredTelemetry[keyString]; + this.telemetryKeyStrings.add(keyString); if (filters !== undefined) { let metadataValues = this.openmct.telemetry.getMetadata(telemetryObject).values(); @@ -99,19 +99,27 @@ }); }, handleConfigurationChanges(configuration) { - if (!_.eq(this.telemetryFilters, configuration.filters)) { + if (!_.eq(this.filteredTelemetry, configuration.filters)) { this.updateFilters(configuration.filters || {}); } }, checkFiltersForMixedValues() { - let valueToCompare = this.telemetryFilters[Object.keys(this.telemetryFilters)[0]]; + let valueToCompare = this.filteredTelemetry[Object.keys(this.filteredTelemetry)[0]]; let mixed = false; - Object.values(this.telemetryFilters).forEach(value => { + + Object.values(this.filteredTelemetry).forEach(value => { if (!_.isEqual(valueToCompare, value)) { mixed = true; return; } }); + + // If the filtered telemetry is not mixed at this point, check the number of available objects + // with the number of filtered telemetry. If they are not equal, the filters must be mixed. + if (mixed === false && _.size(this.filteredTelemetry) !== this.telemetryKeyStrings.size) { + mixed = true; + } + this.mixed = mixed; }, setLabels() { @@ -124,19 +132,45 @@ } }, updateFilters(filters) { - this.telemetryFilters = JSON.parse(JSON.stringify(filters)); + this.filteredTelemetry = JSON.parse(JSON.stringify(filters)); this.setFilterNames(); + this.updateIndicatorLabel(); + }, + addChildren(child) { + let keyString = this.openmct.objects.makeKeyString(child.identifier); + this.telemetryKeyStrings.add(keyString); + this.updateIndicatorLabel(); + }, + removeChildren(identifier) { + let keyString = this.openmct.objects.makeKeyString(identifier); + this.telemetryKeyStrings.delete(keyString); + this.updateIndicatorLabel(); + }, + updateIndicatorLabel() { this.checkFiltersForMixedValues(); this.setLabels(); } }, mounted() { let filters = this.table.configuration.getConfiguration().filters || {}; + this.telemetryKeyStrings = new Set(); + this.composition = this.openmct.composition.get(this.table.configuration.domainObject); + + if (this.composition) { + this.composition.on('add', this.addChildren); + this.composition.on('remove', this.removeChildren); + } + this.table.configuration.on('change', this.handleConfigurationChanges); this.updateFilters(filters); }, destroyed() { this.table.configuration.off('change', this.handleConfigurationChanges); + + if (this.composition) { + this.composition.off('add', this.addChildren); + this.composition.off('remove', this.removeChildren); + } } }