Context click should add a class to tree item (#3619)

* add ability to pass onDestroy callback to menu api show

* fix lint issues

* remove fdescribe

* rename event and variables to contextClickActive

* rename variable to active

* Sanding and polishing CSS related to context-click visual feedback

- Changed CSS `border` approach to `box-shadow` to avoid jumping;
- Removed unwired code and CSS styles for Folder grid and list views;

Co-authored-by: Jamie V <jamie.j.vigliotta@nasa.gov>
Co-authored-by: charlesh88 <charlesh88@gmail.com>
This commit is contained in:
Deep Tailor
2021-01-04 12:57:18 -08:00
committed by GitHub
parent 26b81345f2
commit 98207a3e0d
6 changed files with 40 additions and 7 deletions

View File

@ -38,7 +38,7 @@ class MenuAPI {
this._showObjectMenu = this._showObjectMenu.bind(this); this._showObjectMenu = this._showObjectMenu.bind(this);
} }
showMenu(x, y, actions) { showMenu(x, y, actions, onDestroy) {
if (this.menuComponent) { if (this.menuComponent) {
this.menuComponent.dismiss(); this.menuComponent.dismiss();
} }
@ -46,7 +46,8 @@ class MenuAPI {
let options = { let options = {
x, x,
y, y,
actions actions,
onDestroy
}; };
this.menuComponent = new Menu(options); this.menuComponent = new Menu(options);

View File

@ -31,6 +31,7 @@ describe ('The Menu API', () => {
let x; let x;
let y; let y;
let result; let result;
let onDestroy;
beforeEach(() => { beforeEach(() => {
openmct = createOpenMct(); openmct = createOpenMct();
@ -73,7 +74,9 @@ describe ('The Menu API', () => {
let vueComponent; let vueComponent;
beforeEach(() => { beforeEach(() => {
menuAPI.showMenu(x, y, actionsArray); onDestroy = jasmine.createSpy('onDestroy');
menuAPI.showMenu(x, y, actionsArray, onDestroy);
vueComponent = menuAPI.menuComponent.component; vueComponent = menuAPI.menuComponent.component;
menuComponent = document.querySelector(".c-menu"); menuComponent = document.querySelector(".c-menu");
@ -120,6 +123,12 @@ describe ('The Menu API', () => {
expect(vueComponent.$destroy).toHaveBeenCalled(); expect(vueComponent.$destroy).toHaveBeenCalled();
}); });
it("invokes the onDestroy callback if passed in", () => {
document.body.click();
expect(onDestroy).toHaveBeenCalled();
});
}); });
}); });
}); });

View File

@ -1,7 +1,9 @@
<template> <template>
<tr <tr
class="c-list-item" class="c-list-item"
:class="{ 'is-alias': item.isAlias === true }" :class="{
'is-alias': item.isAlias === true
}"
@click="navigate" @click="navigate"
> >
<td class="c-list-item__name"> <td class="c-list-item__name">

View File

@ -95,6 +95,10 @@
color: $colorItemTreeSelectedFg; color: $colorItemTreeSelectedFg;
} }
} }
&.is-context-clicked {
box-shadow: inset $colorItemTreeSelectedBg 0 0 0 1px;
}
} }
} }

View File

@ -11,7 +11,8 @@
class="c-tree__item" class="c-tree__item"
:class="{ :class="{
'is-alias': isAlias, 'is-alias': isAlias,
'is-navigated-object': navigated 'is-navigated-object': navigated,
'is-context-clicked': contextClickActive
}" }"
> >
<view-control <view-control
@ -26,6 +27,7 @@
:object-path="node.objectPath" :object-path="node.objectPath"
:navigate-to-path="navigationPath" :navigate-to-path="navigationPath"
:style="{ paddingLeft: leftOffset }" :style="{ paddingLeft: leftOffset }"
@context-click-active="setContextClickActive"
/> />
<view-control <view-control
v-model="expanded" v-model="expanded"
@ -91,7 +93,8 @@ export default {
return { return {
hasComposition: false, hasComposition: false,
navigated: this.isNavigated(), navigated: this.isNavigated(),
expanded: false expanded: false,
contextClickActive: false
}; };
}, },
computed: { computed: {
@ -142,6 +145,9 @@ export default {
}, },
resetTreeHere() { resetTreeHere() {
this.$emit('resetTree', this.node); this.$emit('resetTree', this.node);
},
setContextClickActive(active) {
this.contextClickActive = active;
} }
} }
}; };

View File

@ -8,6 +8,11 @@ export default {
} }
} }
}, },
data() {
return {
contextClickActive: false
};
},
mounted() { mounted() {
//TODO: touch support //TODO: touch support
this.$el.addEventListener('contextmenu', this.showContextMenu); this.$el.addEventListener('contextmenu', this.showContextMenu);
@ -35,7 +40,13 @@ export default {
let actions = actionsCollection.getVisibleActions(); let actions = actionsCollection.getVisibleActions();
let sortedActions = this.openmct.actions._groupAndSortActions(actions); let sortedActions = this.openmct.actions._groupAndSortActions(actions);
this.openmct.menus.showMenu(event.clientX, event.clientY, sortedActions); this.openmct.menus.showMenu(event.clientX, event.clientY, sortedActions, this.onContextMenuDestroyed);
this.contextClickActive = true;
this.$emit('context-click-active', true);
},
onContextMenuDestroyed() {
this.contextClickActive = false;
this.$emit('context-click-active', false);
} }
} }
}; };