cherry pick retain styles on url change

This commit is contained in:
David Tsay 2023-05-02 13:38:13 -07:00
parent d80819634b
commit 23310f85ae
5 changed files with 49 additions and 69 deletions

View File

@ -21,15 +21,18 @@
*****************************************************************************/ *****************************************************************************/
<template> <template>
<component <div
:is="urlDefined ? 'a' : 'span'" ref="conditionWidgetElement"
class="c-condition-widget u-style-receiver js-style-receiver" class="c-condition-widget u-style-receiver js-style-receiver"
:href="url"
> >
<div class="c-condition-widget__label"> <component
{{ label }} :is="urlDefined ? 'a' : 'div'"
</div> class="c-condition-widget__label-wrapper"
</component> :href="url"
>
<div class="c-condition-widget__label">{{ label }}</div>
</component>
</div>
</template> </template>
<script> <script>
@ -39,19 +42,26 @@ export default {
inject: ['openmct', 'domainObject'], inject: ['openmct', 'domainObject'],
data: function () { data: function () {
return { return {
conditionalLabel: '', conditionalLabel: ''
conditionSetIdentifier: null,
domainObjectLabel: '',
url: null,
urlDefined: false,
useConditionSetOutputAsLabel: false
}; };
}, },
computed: { computed: {
urlDefined() {
return this.domainObject.url?.length > 0;
},
url() {
return this.urlDefined ? sanitizeUrl(this.domainObject.url) : null;
},
useConditionSetOutputAsLabel() {
return this.conditionSetIdentifier && this.domainObject.configuration.useConditionSetOutputAsLabel;
},
conditionSetIdentifier() {
return this.domainObject.configuration?.objectStyles?.conditionSetIdentifier;
},
label() { label() {
return this.useConditionSetOutputAsLabel return this.useConditionSetOutputAsLabel
? this.conditionalLabel ? this.conditionalLabel
: this.domainObjectLabel : this.domainObject.label
; ;
} }
}, },
@ -68,20 +78,11 @@ export default {
} }
}, },
mounted() { mounted() {
this.unlisten = this.openmct.objects.observe(this.domainObject, '*', this.updateDomainObject);
if (this.domainObject) { if (this.domainObject) {
this.updateDomainObject(this.domainObject);
this.listenToConditionSetChanges(); this.listenToConditionSetChanges();
} }
}, },
beforeDestroy() { beforeDestroy() {
this.conditionSetIdentifier = null;
if (this.unlisten) {
this.unlisten();
}
this.stopListeningToConditionSetChanges(); this.stopListeningToConditionSetChanges();
}, },
methods: { methods: {
@ -120,31 +121,6 @@ export default {
} }
this.conditionalLabel = latestDatum.output || ''; this.conditionalLabel = latestDatum.output || '';
},
updateDomainObject(domainObject) {
if (this.domainObjectLabel !== domainObject.label) {
this.domainObjectLabel = domainObject.label;
}
const urlDefined = domainObject.url && domainObject.url.length > 0;
if (this.urlDefined !== urlDefined) {
this.urlDefined = urlDefined;
}
const url = this.urlDefined ? sanitizeUrl(domainObject.url) : null;
if (this.url !== url) {
this.url = url;
}
const conditionSetIdentifier = domainObject.configuration?.objectStyles?.conditionSetIdentifier;
if (conditionSetIdentifier && this.conditionSetIdentifier !== conditionSetIdentifier) {
this.conditionSetIdentifier = conditionSetIdentifier;
}
const useConditionSetOutputAsLabel = this.conditionSetIdentifier && domainObject.configuration.useConditionSetOutputAsLabel;
if (this.useConditionSetOutputAsLabel !== useConditionSetOutputAsLabel) {
this.useConditionSetOutputAsLabel = useConditionSetOutputAsLabel;
}
} }
} }
}; };

View File

@ -26,31 +26,35 @@
background-color: rgba($colorBodyFg, 0.1); // Give a little presence if the user hasn't defined a fill color background-color: rgba($colorBodyFg, 0.1); // Give a little presence if the user hasn't defined a fill color
border-radius: $basicCr; border-radius: $basicCr;
border: 1px solid transparent; border: 1px solid transparent;
display: inline-block; display: block;
padding: $interiorMarginLg $interiorMarginLg * 2; max-width: max-content;
a {
display: block;
color: inherit;
}
} }
.c-condition-widget__label { .c-condition-widget__label {
padding: $interiorMargin; // Either a <div> or an <a> tag
padding: $interiorMargin $interiorMargin * 1.5;
text-align: center; text-align: center;
white-space: normal; white-space: normal;
} }
a.c-condition-widget {
// Widget is conditionally made into a <a> when URL property has been defined
cursor: pointer !important;
pointer-events: inherit;
}
// Make Condition Widget expand when in a hidden frame Layout context // Make Condition Widget expand when in a hidden frame Layout context
// For both static and Flexible Layouts // For both static and Flexible Layouts
.c-so-view--conditionWidget.c-so-view--no-frame { .c-so-view--conditionWidget.c-so-view--no-frame {
.c-condition-widget { .c-condition-widget {
@include abs(); @include abs();
display: flex; max-width: unset;
align-items: center;
justify-content: center; &__label-wrapper {
padding: 0; @include abs();
display: flex;
align-items: center;
justify-content: center;
}
} }
.c-so-view__frame-controls { display: none; } .c-so-view__frame-controls { display: none; }

View File

@ -36,6 +36,7 @@ export default function plugin() {
domainObject.configuration = {}; domainObject.configuration = {};
domainObject.label = 'Condition Widget'; domainObject.label = 'Condition Widget';
domainObject.conditionalLabel = ''; domainObject.conditionalLabel = '';
domainObject.url = '';
}, },
form: [ form: [
{ {

View File

@ -19,7 +19,7 @@
class="c-icon-button c-button--menu icon-font" class="c-icon-button c-button--menu icon-font"
@click.prevent.stop="showFontMenu" @click.prevent.stop="showFontMenu"
> >
<span class="c-button__label">{{ fontTypeLable }}</span> <span class="c-button__label">{{ fontTypeLabel }}</span>
</button> </button>
</div> </div>
</div> </div>
@ -43,7 +43,7 @@ export default {
} }
}, },
computed: { computed: {
fontTypeLable() { fontTypeLabel() {
const fontType = FONTS.find(f => f.value === this.fontStyle.font); const fontType = FONTS.find(f => f.value === this.fontStyle.font);
if (!fontType) { if (!fontType) {
return '??'; return '??';

View File

@ -74,7 +74,7 @@ export default {
return this.domainObject && (this.currentObjectPath || this.objectPath); return this.domainObject && (this.currentObjectPath || this.objectPath);
}, },
objectFontStyle() { objectFontStyle() {
return this.domainObject && this.domainObject.configuration && this.domainObject.configuration.fontStyle; return this.domainObject?.configuration?.fontStyle;
}, },
fontSize() { fontSize() {
return this.objectFontStyle ? this.objectFontStyle.fontSize : this.layoutFontSize; return this.objectFontStyle ? this.objectFontStyle.fontSize : this.layoutFontSize;
@ -287,6 +287,8 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.updateStyle(this.styleRuleManager?.currentStyle); this.updateStyle(this.styleRuleManager?.currentStyle);
this.setFontSize(this.fontSize);
this.setFont(this.font);
this.getActionCollection(); this.getActionCollection();
}); });
}, },
@ -329,9 +331,9 @@ export default {
}, },
initObjectStyles() { initObjectStyles() {
if (!this.styleRuleManager) { if (!this.styleRuleManager) {
this.styleRuleManager = new StyleRuleManager((this.domainObject.configuration && this.domainObject.configuration.objectStyles), this.openmct, this.updateStyle.bind(this), true); this.styleRuleManager = new StyleRuleManager((this.domainObject.configuration?.objectStyles), this.openmct, this.updateStyle.bind(this), true);
} else { } else {
this.styleRuleManager.updateObjectStyleConfig(this.domainObject.configuration && this.domainObject.configuration.objectStyles); this.styleRuleManager.updateObjectStyleConfig(this.domainObject.configuration?.objectStyles);
} }
if (this.stopListeningStyles) { if (this.stopListeningStyles) {
@ -343,9 +345,6 @@ export default {
this.styleRuleManager.updateObjectStyleConfig(newObjectStyle); this.styleRuleManager.updateObjectStyleConfig(newObjectStyle);
}); });
this.setFontSize(this.fontSize);
this.setFont(this.font);
this.stopListeningFontStyles = this.openmct.objects.observe(this.domainObject, 'configuration.fontStyle', (newFontStyle) => { this.stopListeningFontStyles = this.openmct.objects.observe(this.domainObject, 'configuration.fontStyle', (newFontStyle) => {
this.setFontSize(newFontStyle.fontSize); this.setFontSize(newFontStyle.fontSize);
this.setFont(newFontStyle.font); this.setFont(newFontStyle.font);