- 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
parent 2094521f20
commit e494bee1ff
2 changed files with 31 additions and 34 deletions

View File

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

View File

@ -33,16 +33,13 @@ import { shallowRef } from 'vue';
export default { export default {
inject: ['openmct'], inject: ['openmct'],
props: { props: {
contentUpdated: { headExpanded: {
type: String, type: Boolean,
required: true required: true
}, },
listenForOverflow: { indicatorsMultiline: {
type: Boolean, type: Boolean,
required: false, required: true
default() {
return false;
}
} }
}, },
emits: ['indicators-overflowing'], emits: ['indicators-overflowing'],
@ -60,34 +57,30 @@ export default {
return [...this.indicators].sort((a, b) => b.value.priority - a.value.priority); return [...this.indicators].sort((a, b) => b.value.priority - a.value.priority);
} }
}, },
// watch: { watch: {
// contentUpdated() { headExpanded() {
// console.log('content updated'); this.checkOverflowNextTick();
// this.checkOverflow(); },
// } indicatorsMultiline() {
// }, if (!this.indicatorsMultiline) {
window.addEventListener('resize', this.checkOverflow);
} else {
window.removeEventListener('resize', this.checkOverflow);
}
this.checkOverflowNextTick();
}
},
mounted() { 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('load', this.checkOverflow);
window.addEventListener('resize', this.checkOverflow); window.addEventListener('resize', this.checkOverflow);
} }
}, },
beforeUnmount() { beforeUnmount() {
this.openmct.indicators.off('addIndicator', this.addIndicator); this.openmct.indicators.off('addIndicator', this.addIndicator);
if (this.listenForOverflow) { window.removeEventListener('load', this.checkOverflow);
window.removeEventListener('load', this.checkOverflow); window.removeEventListener('resize', 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();
}
}, },
created() { created() {
this.openmct.indicators.on('addIndicator', this.addIndicator); this.openmct.indicators.on('addIndicator', this.addIndicator);
@ -99,6 +92,11 @@ export default {
checkOverflow() { checkOverflow() {
const element = this.$refs.indicators; const element = this.$refs.indicators;
this.$emit('indicators-overflowing', element.scrollWidth > element.clientWidth); this.$emit('indicators-overflowing', element.scrollWidth > element.clientWidth);
},
checkOverflowNextTick() {
this.$nextTick(() => {
this.checkOverflow();
});
} }
} }
}; };