Skip to content

Commit

Permalink
[Staleness] Fix staleness on clock change (#7088)
Browse files Browse the repository at this point in the history
* Update staleness mixin
* Fix listeners and add guard
* Add check to make sure staleness only shows for correct clock
* Add guard for time api
* Cleanup the setting of isStale in ObjectView
* Cleanup use of combinedKey on LadTableSet
  • Loading branch information
khalidadil authored Oct 4, 2023
1 parent 5eed5de commit 734a8dd
Show file tree
Hide file tree
Showing 18 changed files with 347 additions and 399 deletions.
67 changes: 12 additions & 55 deletions src/plugins/LADTable/components/LadTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@

<script>
import Vue, { toRaw } from 'vue';
import StalenessUtils from '@/utils/staleness';
import LadRow from './LadRow.vue';
import stalenessMixin from '@/ui/mixins/staleness-mixin';
export default {
components: {
LadRow
},
mixins: [stalenessMixin],
inject: ['openmct', 'currentView', 'ladTableConfiguration'],
props: {
domainObject: {
Expand All @@ -74,7 +73,6 @@ export default {
return {
items: [],
viewContext: {},
staleObjects: [],
configuration: this.ladTableConfiguration.getConfiguration()
};
},
Expand All @@ -96,11 +94,7 @@ export default {
return !this.configuration?.hiddenColumns?.type;
},
staleClass() {
if (this.staleObjects.length !== 0) {
return 'is-stale';
}
return '';
return this.isStale ? 'is-stale' : '';
},
applyLayoutClass() {
if (this.configuration.isFixedLayout) {
Expand Down Expand Up @@ -133,12 +127,16 @@ export default {
this.composition.on('remove', this.removeItem);
this.composition.on('reorder', this.reorder);
this.composition.load();
this.stalenessSubscription = {};
await Vue.nextTick();
this.viewActionsCollection = this.openmct.actions.getActionsCollection(
this.objectPath,
this.currentView
);
this.setupClockChangedEvent((domainObject) => {
this.triggerUnsubscribeFromStaleness(domainObject);
this.subscribeToStaleness(domainObject);
});
this.initializeViewActions();
},
unmounted() {
Expand All @@ -147,11 +145,6 @@ export default {
this.composition.off('add', this.addItem);
this.composition.off('remove', this.removeItem);
this.composition.off('reorder', this.reorder);
Object.values(this.stalenessSubscription).forEach((stalenessSubscription) => {
stalenessSubscription.unsubscribe();
stalenessSubscription.stalenessUtils.destroy();
});
},
methods: {
addItem(domainObject) {
Expand All @@ -160,35 +153,16 @@ export default {
item.key = this.openmct.objects.makeKeyString(domainObject.identifier);
this.items.push(item);
this.stalenessSubscription[item.key] = {};
this.stalenessSubscription[item.key].stalenessUtils = new StalenessUtils(
this.openmct,
domainObject
);
this.openmct.telemetry.isStale(domainObject).then((stalenessResponse) => {
if (stalenessResponse !== undefined) {
this.handleStaleness(item.key, stalenessResponse);
}
});
const stalenessSubscription = this.openmct.telemetry.subscribeToStaleness(
domainObject,
(stalenessResponse) => {
this.handleStaleness(item.key, stalenessResponse);
}
);
this.stalenessSubscription[item.key].unsubscribe = stalenessSubscription;
this.subscribeToStaleness(domainObject);
},
removeItem(identifier) {
const SKIP_CHECK = true;
const keystring = this.openmct.objects.makeKeyString(identifier);
const index = this.items.findIndex((item) => keystring === item.key);
const index = this.items.findIndex((item) => keystring === item.key);
this.items.splice(index, 1);
this.stalenessSubscription[keystring].unsubscribe();
this.handleStaleness(keystring, { isStale: false }, SKIP_CHECK);
const domainObject = this.openmct.objects.get(keystring);
this.triggerUnsubscribeFromStaleness(domainObject);
},
reorder(reorderPlan) {
const oldItems = this.items.slice();
Expand All @@ -204,23 +178,6 @@ export default {
handleConfigurationChange(configuration) {
this.configuration = configuration;
},
handleStaleness(id, stalenessResponse, skipCheck = false) {
if (
skipCheck ||
this.stalenessSubscription[id].stalenessUtils.shouldUpdateStaleness(stalenessResponse)
) {
const index = this.staleObjects.indexOf(id);
if (stalenessResponse.isStale) {
if (index === -1) {
this.staleObjects.push(id);
}
} else {
if (index !== -1) {
this.staleObjects.splice(index, 1);
}
}
}
},
updateViewContext(rowContext) {
this.viewContext.row = rowContext;
},
Expand Down
99 changes: 31 additions & 68 deletions src/plugins/LADTable/components/LadTableSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
:domain-object="ladRow.domainObject"
:path-to-table="ladTable.objectPath"
:has-units="hasUnits"
:is-stale="staleObjects.includes(combineKeys(ladTable.key, ladRow.key))"
:is-stale="staleObjects.includes(ladRow.key)"
:configuration="configuration"
@rowContextClick="updateViewContext"
@row-context-click="updateViewContext"
/>
</template>
</tbody>
Expand All @@ -56,14 +56,17 @@
</template>

<script>
import StalenessUtils from '@/utils/staleness';
import { toRaw } from 'vue';
import stalenessMixin from '@/ui/mixins/staleness-mixin';
import LadRow from './LadRow.vue';
export default {
components: {
LadRow
},
mixins: [stalenessMixin],
inject: ['openmct', 'objectPath', 'currentView', 'ladTableConfiguration'],
props: {
domainObject: {
Expand All @@ -76,8 +79,8 @@ export default {
ladTableObjects: [],
ladTelemetryObjects: {},
viewContext: {},
staleObjects: [],
configuration: this.ladTableConfiguration.getConfiguration()
configuration: this.ladTableConfiguration.getConfiguration(),
subscribedObjects: {}
};
},
computed: {
Expand Down Expand Up @@ -108,11 +111,7 @@ export default {
return !this.configuration?.hiddenColumns?.type;
},
staleClass() {
if (this.staleObjects.length !== 0) {
return 'is-stale';
}
return '';
return this.isStale ? 'is-stale' : '';
}
},
created() {
Expand All @@ -125,8 +124,10 @@ export default {
this.composition.on('remove', this.removeLadTable);
this.composition.on('reorder', this.reorderLadTables);
this.composition.load();
this.stalenessSubscription = {};
this.setupClockChangedEvent((domainObject) => {
this.triggerUnsubscribeFromStaleness(domainObject);
this.subscribeToStaleness(domainObject);
});
},
unmounted() {
this.ladTableConfiguration.off('change', this.handleConfigurationChange);
Expand All @@ -137,11 +138,6 @@ export default {
c.composition.off('add', c.addCallback);
c.composition.off('remove', c.removeCallback);
});
Object.values(this.stalenessSubscription).forEach((stalenessSubscription) => {
stalenessSubscription.unsubscribe();
stalenessSubscription.stalenessUtils.destroy();
});
},
methods: {
addLadTable(domainObject) {
Expand Down Expand Up @@ -176,9 +172,18 @@ export default {
);
let ladTable = this.ladTableObjects[index];
this.ladTelemetryObjects[ladTable.key].forEach((telemetryObject) => {
let combinedKey = this.combineKeys(ladTable.key, telemetryObject.key);
this.unwatchStaleness(combinedKey);
ladTable?.domainObject?.composition.forEach((telemetryObject) => {
const telemetryKey = this.openmct.objects.makeKeyString(telemetryObject);
if (!this.subscribedObjects?.[telemetryKey]) {
return;
}
let subscribedObject = toRaw(this.subscribedObjects[telemetryKey]);
if (subscribedObject?.count > 1) {
subscribedObject.count -= 1;
} else if (subscribedObject?.count === 1) {
this.triggerUnsubscribeFromStaleness(subscribedObject.domainObject);
delete this.subscribedObjects[telemetryKey];
}
});
delete this.ladTelemetryObjects[ladTable.key];
Expand All @@ -199,77 +204,35 @@ export default {
let telemetryObject = {};
telemetryObject.key = this.openmct.objects.makeKeyString(domainObject.identifier);
telemetryObject.domainObject = domainObject;
const combinedKey = this.combineKeys(ladTable.key, telemetryObject.key);
const telemetryObjects = this.ladTelemetryObjects[ladTable.key];
telemetryObjects.push(telemetryObject);
this.ladTelemetryObjects[ladTable.key] = telemetryObjects;
this.stalenessSubscription[combinedKey] = {};
this.stalenessSubscription[combinedKey].stalenessUtils = new StalenessUtils(
this.openmct,
domainObject
);
this.openmct.telemetry.isStale(domainObject).then((stalenessResponse) => {
if (stalenessResponse !== undefined) {
this.handleStaleness(combinedKey, stalenessResponse);
}
});
const stalenessSubscription = this.openmct.telemetry.subscribeToStaleness(
domainObject,
(stalenessResponse) => {
this.handleStaleness(combinedKey, stalenessResponse);
}
);
this.stalenessSubscription[combinedKey].unsubscribe = stalenessSubscription;
if (!this.subscribedObjects[telemetryObject?.key]) {
this.subscribeToStaleness(domainObject);
this.subscribedObjects[telemetryObject?.key] = { count: 1, domainObject };
} else if (this.subscribedObjects?.[telemetryObject?.key]?.count) {
this.subscribedObjects[telemetryObject?.key].count += 1;
}
};
},
removeTelemetryObject(ladTable) {
return (identifier) => {
const keystring = this.openmct.objects.makeKeyString(identifier);
const telemetryObjects = this.ladTelemetryObjects[ladTable.key];
const combinedKey = this.combineKeys(ladTable.key, keystring);
let index = telemetryObjects.findIndex(
(telemetryObject) => keystring === telemetryObject.key
);
this.unwatchStaleness(combinedKey);
telemetryObjects.splice(index, 1);
this.ladTelemetryObjects[ladTable.key] = telemetryObjects;
};
},
unwatchStaleness(combinedKey) {
const SKIP_CHECK = true;
this.stalenessSubscription[combinedKey].unsubscribe();
this.stalenessSubscription[combinedKey].stalenessUtils.destroy();
this.handleStaleness(combinedKey, { isStale: false }, SKIP_CHECK);
delete this.stalenessSubscription[combinedKey];
},
handleConfigurationChange(configuration) {
this.configuration = configuration;
},
handleStaleness(combinedKey, stalenessResponse, skipCheck = false) {
if (
skipCheck ||
this.stalenessSubscription[combinedKey].stalenessUtils.shouldUpdateStaleness(
stalenessResponse
)
) {
const index = this.staleObjects.indexOf(combinedKey);
const foundStaleObject = index > -1;
if (stalenessResponse.isStale && !foundStaleObject) {
this.staleObjects.push(combinedKey);
} else if (!stalenessResponse.isStale && foundStaleObject) {
this.staleObjects.splice(index, 1);
}
}
},
updateViewContext(rowContext) {
this.viewContext.row = rowContext;
},
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/condition/ConditionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ describe('The condition', function () {
mockTimeSystems = {
key: 'utc'
};
openmct.time = jasmine.createSpyObj('time', ['getAllTimeSystems']);
openmct.time = jasmine.createSpyObj('time', ['getAllTimeSystems', 'on', 'off']);
openmct.time.getAllTimeSystems.and.returnValue([mockTimeSystems]);
openmct.time.on.and.returnValue(() => {});
openmct.time.off.and.returnValue(() => {});

testConditionDefinition = {
id: '123-456',
Expand Down
Loading

0 comments on commit 734a8dd

Please sign in to comment.