- Now uses Watch instead of Update to handle changes from containing AppLayout.vue component.

- Code cleanup, console.log removals.
This commit is contained in:
Charles Hacskaylo 2024-09-19 16:33:57 -07:00 committed by David Tsay
parent bea6d9b264
commit b0a892c9b5
2 changed files with 31 additions and 34 deletions

View File

@ -40,8 +40,8 @@
<CreateButton class="l-shell__create-button" />
<GrandSearch ref="grand-search" />
<StatusIndicators
:listen-for-overflow="!indicatorsMultiline"
:content-updated="headExpanded || indicatorsMultiline"
:head-expanded="headExpanded"
:indicators-multiline="indicatorsMultiline"
@indicators-overflowing="indicatorsOverflowUpdate"
/>
<button
@ -282,13 +282,13 @@ export default {
},
toggleShellHead() {
this.headExpanded = !this.headExpanded;
this.setLocalStorage();
this.setLocalStorageShellHead();
},
toggleIndicatorsMultiline() {
this.indicatorsMultiline = !this.indicatorsMultiline;
this.setLocalStorage();
this.setLocalStorageShellHead();
},
setLocalStorage() {
setLocalStorageShellHead() {
window.localStorage.setItem(
'openmct-shell-head',
JSON.stringify({
@ -346,7 +346,6 @@ export default {
this.disableClearButton = isDisabled;
},
indicatorsOverflowUpdate(isOverflowing) {
console.log('indicatorsOverflowUpdate', isOverflowing);
this.indicatorsOverflowing = isOverflowing;
}
}

View File

@ -33,16 +33,13 @@ import { shallowRef } from 'vue';
export default {
inject: ['openmct'],
props: {
contentUpdated: {
type: String,
headExpanded: {
type: Boolean,
required: true
},
listenForOverflow: {
indicatorsMultiline: {
type: Boolean,
required: false,
default() {
return false;
}
required: true
}
},
emits: ['indicators-overflowing'],
@ -60,34 +57,30 @@ export default {
return [...this.indicators].sort((a, b) => b.value.priority - a.value.priority);
}
},
// watch: {
// contentUpdated() {
// console.log('content updated');
// this.checkOverflow();
// }
// },
watch: {
headExpanded() {
this.checkOverflowNextTick();
},
indicatorsMultiline() {
if (!this.indicatorsMultiline) {
window.addEventListener('resize', this.checkOverflow);
} else {
window.removeEventListener('resize', this.checkOverflow);
}
this.checkOverflowNextTick();
}
},
mounted() {
if (this.listenForOverflow) {
if (!this.indicatorsMultiline) {
// `load` listener is necessary because the width of the Indicators has to be eval'd after other components have loaded.
window.addEventListener('load', this.checkOverflow);
window.addEventListener('resize', this.checkOverflow);
}
},
beforeUnmount() {
this.openmct.indicators.off('addIndicator', this.addIndicator);
if (this.listenForOverflow) {
window.removeEventListener('load', this.checkOverflow);
window.removeEventListener('resize', this.checkOverflow);
}
},
updated() {
// console.log('updated');
if (this.listenForOverflow) {
window.addEventListener('resize', this.checkOverflow);
this.checkOverflow();
} else {
window.removeEventListener('resize', this.checkOverflow);
this.checkOverflow();
}
window.removeEventListener('load', this.checkOverflow);
window.removeEventListener('resize', this.checkOverflow);
},
created() {
this.openmct.indicators.on('addIndicator', this.addIndicator);
@ -99,6 +92,11 @@ export default {
checkOverflow() {
const element = this.$refs.indicators;
this.$emit('indicators-overflowing', element.scrollWidth > element.clientWidth);
},
checkOverflowNextTick() {
this.$nextTick(() => {
this.checkOverflow();
});
}
}
};