[Filters] various bugs in telemetry table filters (#2425)

* Update the filters object properly when both checkboxes are deselected. Check composition before loading. Modify logic for mixed filters.

* Get compostion from the global context

* Use Set to store keyStrings

* Rename variables for clarity and add comment. Also add keystring to telemetryKeyStrings when an object is added.

* Use size to get the size of the set instead of length. Remove telemetry keystring from the configuration filters when object is removed from the composition and update the indicator label.
This commit is contained in:
Pegah Sarram 2019-07-02 16:17:15 -07:00 committed by Andrew Henry
parent 262d35804d
commit 9517c1f2cd
3 changed files with 55 additions and 11 deletions

View File

@ -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);
}

View File

@ -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(){

View File

@ -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);
}
}
}
</script>