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

cherry-pick(#7088): [Staleness] Fix staleness on clock change #7112

Merged
merged 1 commit into from
Oct 4, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';

Check warning on line 54 in src/plugins/LADTable/components/LadTable.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTable.vue#L54

Added line #L54 was not covered by tests

export default {
components: {
LadRow
},
mixins: [stalenessMixin],
inject: ['openmct', 'currentView', 'ladTableConfiguration'],
props: {
domainObject: {
Expand All @@ -74,7 +73,6 @@
return {
items: [],
viewContext: {},
staleObjects: [],
configuration: this.ladTableConfiguration.getConfiguration()
};
},
Expand All @@ -96,11 +94,7 @@
return !this.configuration?.hiddenColumns?.type;
},
staleClass() {
if (this.staleObjects.length !== 0) {
return 'is-stale';
}

return '';
return this.isStale ? 'is-stale' : '';

Check warning on line 97 in src/plugins/LADTable/components/LadTable.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTable.vue#L97

Added line #L97 was not covered by tests
},
applyLayoutClass() {
if (this.configuration.isFixedLayout) {
Expand Down Expand Up @@ -133,12 +127,16 @@
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 @@
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 @@
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 @@
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 @@
ladTableObjects: [],
ladTelemetryObjects: {},
viewContext: {},
staleObjects: [],
configuration: this.ladTableConfiguration.getConfiguration()
configuration: this.ladTableConfiguration.getConfiguration(),

Check warning on line 82 in src/plugins/LADTable/components/LadTableSet.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTableSet.vue#L82

Added line #L82 was not covered by tests
subscribedObjects: {}
};
},
computed: {
Expand Down Expand Up @@ -108,11 +111,7 @@
return !this.configuration?.hiddenColumns?.type;
},
staleClass() {
if (this.staleObjects.length !== 0) {
return 'is-stale';
}

return '';
return this.isStale ? 'is-stale' : '';

Check warning on line 114 in src/plugins/LADTable/components/LadTableSet.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTableSet.vue#L114

Added line #L114 was not covered by tests
}
},
created() {
Expand All @@ -125,8 +124,10 @@
this.composition.on('remove', this.removeLadTable);
this.composition.on('reorder', this.reorderLadTables);
this.composition.load();

this.stalenessSubscription = {};
this.setupClockChangedEvent((domainObject) => {
this.triggerUnsubscribeFromStaleness(domainObject);

Check warning on line 128 in src/plugins/LADTable/components/LadTableSet.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTableSet.vue#L127-L128

Added lines #L127 - L128 were not covered by tests
this.subscribeToStaleness(domainObject);
});
},
unmounted() {
this.ladTableConfiguration.off('change', this.handleConfigurationChange);
Expand All @@ -137,11 +138,6 @@
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 @@
);
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]) {

Check warning on line 177 in src/plugins/LADTable/components/LadTableSet.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTableSet.vue#L177

Added line #L177 was not covered by tests
return;
}
let subscribedObject = toRaw(this.subscribedObjects[telemetryKey]);

Check warning on line 180 in src/plugins/LADTable/components/LadTableSet.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTableSet.vue#L180

Added line #L180 was not covered by tests
if (subscribedObject?.count > 1) {
subscribedObject.count -= 1;
} else if (subscribedObject?.count === 1) {

Check warning on line 183 in src/plugins/LADTable/components/LadTableSet.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/LADTable/components/LadTableSet.vue#L183

Added line #L183 was not covered by tests
this.triggerUnsubscribeFromStaleness(subscribedObject.domainObject);
delete this.subscribedObjects[telemetryKey];
}
});

delete this.ladTelemetryObjects[ladTable.key];
Expand All @@ -199,77 +204,35 @@
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