Preview condition styles on selecting that condition or one of it's styles (#2925)

* Preview condition styles on selecting that condition or one of it's styles
* Do not evaluate conditional styles in edit mode

Co-authored-by: charlesh88 <charlesh88@gmail.com>
Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Shefali Joshi
2020-04-30 13:00:43 -07:00
committed by GitHub
parent ff7debfb81
commit 7a906ccf5c
5 changed files with 129 additions and 13 deletions

View File

@@ -23,10 +23,13 @@
import EventEmitter from 'EventEmitter'; import EventEmitter from 'EventEmitter';
export default class StyleRuleManager extends EventEmitter { export default class StyleRuleManager extends EventEmitter {
constructor(styleConfiguration, openmct, callback) { constructor(styleConfiguration, openmct, callback, suppressSubscriptionOnEdit) {
super(); super();
this.openmct = openmct; this.openmct = openmct;
this.callback = callback; this.callback = callback;
if (suppressSubscriptionOnEdit) {
this.openmct.editor.on('isEditing', this.toggleSubscription.bind(this));
}
if (styleConfiguration) { if (styleConfiguration) {
this.initialize(styleConfiguration); this.initialize(styleConfiguration);
if (styleConfiguration.conditionSetIdentifier) { if (styleConfiguration.conditionSetIdentifier) {
@@ -37,9 +40,25 @@ export default class StyleRuleManager extends EventEmitter {
} }
} }
toggleSubscription(isEditing) {
this.isEditing = isEditing;
if (this.isEditing) {
if (this.stopProvidingTelemetry) {
this.stopProvidingTelemetry();
}
if (this.conditionSetIdentifier) {
this.applySelectedConditionStyle();
}
} else if (this.conditionSetIdentifier) {
this.subscribeToConditionSet();
}
}
initialize(styleConfiguration) { initialize(styleConfiguration) {
this.conditionSetIdentifier = styleConfiguration.conditionSetIdentifier; this.conditionSetIdentifier = styleConfiguration.conditionSetIdentifier;
this.staticStyle = styleConfiguration.staticStyle; this.staticStyle = styleConfiguration.staticStyle;
this.selectedConditionId = styleConfiguration.selectedConditionId;
this.defaultConditionId = styleConfiguration.defaultConditionId;
this.updateConditionStylesMap(styleConfiguration.styles || []); this.updateConditionStylesMap(styleConfiguration.styles || []);
} }
@@ -54,7 +73,7 @@ export default class StyleRuleManager extends EventEmitter {
this.handleConditionSetResultUpdated(output[0]); this.handleConditionSetResultUpdated(output[0]);
} }
}); });
this.stopProvidingTelemetry = this.openmct.telemetry.subscribe(conditionSetDomainObject, output => this.handleConditionSetResultUpdated(output)); this.stopProvidingTelemetry = this.openmct.telemetry.subscribe(conditionSetDomainObject, this.handleConditionSetResultUpdated.bind(this));
}); });
} }
@@ -66,12 +85,16 @@ export default class StyleRuleManager extends EventEmitter {
let isNewConditionSet = !this.conditionSetIdentifier || let isNewConditionSet = !this.conditionSetIdentifier ||
!this.openmct.objects.areIdsEqual(this.conditionSetIdentifier, styleConfiguration.conditionSetIdentifier); !this.openmct.objects.areIdsEqual(this.conditionSetIdentifier, styleConfiguration.conditionSetIdentifier);
this.initialize(styleConfiguration); this.initialize(styleConfiguration);
if (this.isEditing) {
this.applySelectedConditionStyle();
} else {
//Only resubscribe if the conditionSet has changed. //Only resubscribe if the conditionSet has changed.
if (isNewConditionSet) { if (isNewConditionSet) {
this.subscribeToConditionSet(); this.subscribeToConditionSet();
} }
} }
} }
}
updateConditionStylesMap(conditionStyles) { updateConditionStylesMap(conditionStyles) {
let conditionStyleMap = {}; let conditionStyleMap = {};
@@ -103,6 +126,16 @@ export default class StyleRuleManager extends EventEmitter {
} }
} }
applySelectedConditionStyle() {
const conditionId = this.selectedConditionId || this.defaultConditionId;
if (!conditionId) {
this.applyStaticStyle();
} else if (this.conditionalStyleMap[conditionId]) {
this.currentStyle = this.conditionalStyleMap[conditionId];
this.updateDomainObjectStyle();
}
}
applyStaticStyle() { applyStaticStyle() {
if (this.staticStyle) { if (this.staticStyle) {
this.currentStyle = this.staticStyle.style; this.currentStyle = this.staticStyle.style;
@@ -123,6 +156,8 @@ export default class StyleRuleManager extends EventEmitter {
} }
delete this.stopProvidingTelemetry; delete this.stopProvidingTelemetry;
this.conditionSetIdentifier = undefined; this.conditionSetIdentifier = undefined;
this.isEditing = undefined;
this.callback = undefined;
} }
} }

View File

@@ -79,6 +79,8 @@
<div v-for="(conditionStyle, index) in conditionalStyles" <div v-for="(conditionStyle, index) in conditionalStyles"
:key="index" :key="index"
class="c-inspect-styles__condition" class="c-inspect-styles__condition"
:class="{'is-current': conditionStyle.conditionId === selectedConditionId}"
@click="applySelectedConditionStyle(conditionStyle.conditionId)"
> >
<condition-error :show-label="true" <condition-error :show-label="true"
:condition="getCondition(conditionStyle.conditionId)" :condition="getCondition(conditionStyle.conditionId)"
@@ -126,7 +128,8 @@ export default {
isEditing: this.openmct.editor.isEditing(), isEditing: this.openmct.editor.isEditing(),
conditions: undefined, conditions: undefined,
conditionsLoaded: false, conditionsLoaded: false,
navigateToPath: '' navigateToPath: '',
selectedConditionId: ''
} }
}, },
destroyed() { destroyed() {
@@ -191,6 +194,9 @@ export default {
if (this.stopObservingItems) { if (this.stopObservingItems) {
this.stopObservingItems(); this.stopObservingItems();
} }
if (this.stopProvidingTelemetry) {
this.stopProvidingTelemetry();
}
}, },
initialize(conditionSetDomainObject) { initialize(conditionSetDomainObject) {
//If there are new conditions in the conditionSet we need to set those styles to default //If there are new conditions in the conditionSet we need to set those styles to default
@@ -200,6 +206,13 @@ export default {
}, },
setEditState(isEditing) { setEditState(isEditing) {
this.isEditing = isEditing; this.isEditing = isEditing;
if (this.isEditing) {
if (this.stopProvidingTelemetry) {
this.stopProvidingTelemetry();
}
} else {
this.subscribeToConditionSet();
}
}, },
addConditionSet() { addConditionSet() {
let conditionSetDomainObject; let conditionSetDomainObject;
@@ -270,6 +283,8 @@ export default {
let domainObjectStyles = (this.domainObject.configuration && this.domainObject.configuration.objectStyles) || {}; let domainObjectStyles = (this.domainObject.configuration && this.domainObject.configuration.objectStyles) || {};
if (this.itemId) { if (this.itemId) {
domainObjectStyles[this.itemId].conditionSetIdentifier = undefined; domainObjectStyles[this.itemId].conditionSetIdentifier = undefined;
domainObjectStyles[this.itemId].selectedConditionId = undefined;
domainObjectStyles[this.itemId].defaultConditionId = undefined;
delete domainObjectStyles[this.itemId].conditionSetIdentifier; delete domainObjectStyles[this.itemId].conditionSetIdentifier;
domainObjectStyles[this.itemId].styles = undefined; domainObjectStyles[this.itemId].styles = undefined;
delete domainObjectStyles[this.itemId].styles; delete domainObjectStyles[this.itemId].styles;
@@ -278,6 +293,8 @@ export default {
} }
} else { } else {
domainObjectStyles.conditionSetIdentifier = undefined; domainObjectStyles.conditionSetIdentifier = undefined;
domainObjectStyles.selectedConditionId = undefined;
domainObjectStyles.defaultConditionId = undefined;
delete domainObjectStyles.conditionSetIdentifier; delete domainObjectStyles.conditionSetIdentifier;
domainObjectStyles.styles = undefined; domainObjectStyles.styles = undefined;
delete domainObjectStyles.styles; delete domainObjectStyles.styles;
@@ -287,16 +304,23 @@ export default {
} }
this.persist(domainObjectStyles); this.persist(domainObjectStyles);
if (this.stopProvidingTelemetry) {
this.stopProvidingTelemetry();
}
}, },
updateDomainObjectItemStyles(newItems) { updateDomainObjectItemStyles(newItems) {
//check that all items that have been styles still exist. Otherwise delete those styles //check that all items that have been styles still exist. Otherwise delete those styles
let domainObjectStyles = (this.domainObject.configuration && this.domainObject.configuration.objectStyles) || {}; let domainObjectStyles = (this.domainObject.configuration && this.domainObject.configuration.objectStyles) || {};
let itemsToRemove = []; let itemsToRemove = [];
let keys = Object.keys(domainObjectStyles); let keys = Object.keys(domainObjectStyles);
//TODO: Need an easier way to find which properties are itemIds
keys.forEach((key) => { keys.forEach((key) => {
if ((key !== 'styles') && const keyIsItemId = (key !== 'styles') &&
(key !== 'staticStyle') && (key !== 'staticStyle') &&
(key !== 'conditionSetIdentifier')) { (key !== 'defaultConditionId') &&
(key !== 'selectedConditionId') &&
(key !== 'conditionSetIdentifier');
if (keyIsItemId) {
if (!(newItems.find(item => item.id === key))) { if (!(newItems.find(item => item.id === key))) {
itemsToRemove.push(key); itemsToRemove.push(key);
} }
@@ -324,6 +348,9 @@ export default {
} }
let conditionalStyles = []; let conditionalStyles = [];
this.conditionSetDomainObject.configuration.conditionCollection.forEach((conditionConfiguration, index) => { this.conditionSetDomainObject.configuration.conditionCollection.forEach((conditionConfiguration, index) => {
if (conditionConfiguration.isDefault) {
this.selectedConditionId = conditionConfiguration.id;
}
this.conditions[conditionConfiguration.id] = conditionConfiguration; this.conditions[conditionConfiguration.id] = conditionConfiguration;
let foundStyle = this.findStyleByConditionId(conditionConfiguration.id); let foundStyle = this.findStyleByConditionId(conditionConfiguration.id);
if (foundStyle) { if (foundStyle) {
@@ -339,7 +366,27 @@ export default {
//we're doing this so that we remove styles for any conditions that have been removed from the condition set //we're doing this so that we remove styles for any conditions that have been removed from the condition set
this.conditionalStyles = conditionalStyles; this.conditionalStyles = conditionalStyles;
this.conditionsLoaded = true; this.conditionsLoaded = true;
this.persist(this.getDomainObjectConditionalStyle()); this.persist(this.getDomainObjectConditionalStyle(this.selectedConditionId));
if (!this.isEditing) {
this.subscribeToConditionSet();
}
},
subscribeToConditionSet() {
if (this.stopProvidingTelemetry) {
this.stopProvidingTelemetry();
}
if (this.conditionSetDomainObject) {
this.openmct.telemetry.request(this.conditionSetDomainObject)
.then(output => {
if (output && output.length) {
this.handleConditionSetResultUpdated(output[0]);
}
});
this.stopProvidingTelemetry = this.openmct.telemetry.subscribe(this.conditionSetDomainObject, this.handleConditionSetResultUpdated.bind(this));
}
},
handleConditionSetResultUpdated(resultData) {
this.selectedConditionId = resultData ? resultData.conditionId : '';
}, },
initializeStaticStyle(objectStyles) { initializeStaticStyle(objectStyles) {
let staticStyle = objectStyles && objectStyles.staticStyle; let staticStyle = objectStyles && objectStyles.staticStyle;
@@ -364,14 +411,19 @@ export default {
let found = this.findStyleByConditionId(conditionStyle.conditionId); let found = this.findStyleByConditionId(conditionStyle.conditionId);
if (found) { if (found) {
found.style = conditionStyle.style; found.style = conditionStyle.style;
this.selectedConditionId = found.conditionId;
this.persist(this.getDomainObjectConditionalStyle()); this.persist(this.getDomainObjectConditionalStyle());
} }
}, },
getDomainObjectConditionalStyle() { getDomainObjectConditionalStyle(defaultConditionId) {
let objectStyle = { let objectStyle = {
styles: this.conditionalStyles, styles: this.conditionalStyles,
staticStyle: this.staticStyle staticStyle: this.staticStyle,
selectedConditionId: this.selectedConditionId
}; };
if (defaultConditionId) {
objectStyle.defaultConditionId = defaultConditionId;
}
if (this.conditionSetDomainObject) { if (this.conditionSetDomainObject) {
objectStyle.conditionSetIdentifier = this.conditionSetDomainObject.identifier; objectStyle.conditionSetIdentifier = this.conditionSetDomainObject.identifier;
} }
@@ -393,6 +445,10 @@ export default {
getCondition(id) { getCondition(id) {
return this.conditions ? this.conditions[id] : {}; return this.conditions ? this.conditions[id] : {};
}, },
applySelectedConditionStyle(conditionId) {
this.selectedConditionId = conditionId;
this.persist(this.getDomainObjectConditionalStyle());
},
persist(style) { persist(style) {
this.openmct.objects.mutate(this.domainObject, 'configuration.objectStyles', style); this.openmct.objects.mutate(this.domainObject, 'configuration.objectStyles', style);
} }

View File

@@ -60,6 +60,31 @@
&__condition { &__condition {
@include discreteItem(); @include discreteItem();
border: 1px solid transparent;
pointer-events: none; // Prevent selecting when the object isn't being edited
&.is-current {
$c: $colorBodyFg;
border-color: rgba($c, 0.5);
background: rgba($c, 0.2);
}
.is-editing & {
cursor: pointer;
pointer-events: initial;
transition: $transOut;
&:hover {
background: rgba($colorBodyFg, 0.1);
transition: $transIn;
}
&.is-current {
$c: $editUIColorBg;
border-color: $c;
background: rgba($c, 0.1);
}
}
} }
.c-style { .c-style {

View File

@@ -52,7 +52,7 @@ export default {
}, },
initObjectStyles() { initObjectStyles() {
if (!this.styleRuleManager) { if (!this.styleRuleManager) {
this.styleRuleManager = new StyleRuleManager(this.objectStyle, this.openmct, this.updateStyle.bind(this)); this.styleRuleManager = new StyleRuleManager(this.objectStyle, this.openmct, this.updateStyle.bind(this), true);
} else { } else {
this.styleRuleManager.updateObjectStyleConfig(this.objectStyle); this.styleRuleManager.updateObjectStyleConfig(this.objectStyle);
} }

View File

@@ -201,7 +201,7 @@ export default {
}, },
initObjectStyles() { initObjectStyles() {
if (!this.styleRuleManager) { if (!this.styleRuleManager) {
this.styleRuleManager = new StyleRuleManager((this.currentObject.configuration && this.currentObject.configuration.objectStyles), this.openmct, this.updateStyle.bind(this)); this.styleRuleManager = new StyleRuleManager((this.currentObject.configuration && this.currentObject.configuration.objectStyles), this.openmct, this.updateStyle.bind(this), true);
} else { } else {
this.styleRuleManager.updateObjectStyleConfig(this.currentObject.configuration && this.currentObject.configuration.objectStyles); this.styleRuleManager.updateObjectStyleConfig(this.currentObject.configuration && this.currentObject.configuration.objectStyles);
} }