Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide jobs by default in the Tree View #249

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/cylc/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:node="workflow"
:hoverable="hoverable"
:min-depth="minDepth"
:expanded="expanded"
:initialExpanded="expanded"
v-on:tree-item-created="onTreeItemCreated"
v-on:tree-item-expanded="onTreeItemExpanded"
v-on:tree-item-collapsed="onTreeItemCollapsed"
Expand Down
22 changes: 18 additions & 4 deletions src/components/cylc/TreeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
:depth="depth + 1"
:hoverable="hoverable"
:min-depth="minDepth"
:expanded="expanded"
:initialExpanded="initialExpanded"
v-on:tree-item-created="$emit('tree-item-created', $event)"
v-on:tree-item-expanded="$emit('tree-item-expanded', $event)"
v-on:tree-item-collapsed="$emit('tree-item-collapsed', $event)"
Expand Down Expand Up @@ -119,7 +119,7 @@ export default {
default: 0
},
hoverable: Boolean,
expanded: {
initialExpanded: {
type: Boolean,
default: true
}
Expand All @@ -128,7 +128,7 @@ export default {
return {
active: false,
selected: false,
isExpanded: this.expanded,
isExpanded: this.initialExpanded,
leafProperties: [
{
title: 'host id',
Expand Down Expand Up @@ -177,14 +177,28 @@ export default {
})
}
},
beforeMount () {
if (Object.prototype.hasOwnProperty.call(this.node, 'expanded')) {
this.isExpanded = this.node.expand
this.emitExpandCollapseEvent(this.isExpanded)
}
},
methods: {
destroy () {
// $destroy will trigger beforeDestroy and destroyed
this.$destroy(/* destroy from DOM as well */ true)
},
typeClicked () {
this.isExpanded = !this.isExpanded
if (this.isExpanded) {
this.emitExpandCollapseEvent(this.isExpanded)
},
/**
* Emits an event `tree-item-expanded` if `expanded` is true, or emits
* `tree-item-collapsed` if `expanded` is false.
* @param {boolean} expanded whether the node is expanded or not
*/
emitExpandCollapseEvent (expanded) {
if (expanded) {
this.$emit('tree-item-expanded', this)
} else {
this.$emit('tree-item-collapsed', this)
Expand Down
1 change: 1 addition & 0 deletions src/store/workflows.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function _getWorkflowTree (workflows) {
taskProxy.name = taskProxy.task.name
taskProxy.children = []
taskProxy.__type = 'task'
taskProxy.expanded = false
let startedTime = 0
// the GraphQL query is expected to have `jobs(sort: { keys: ["submit_num"], reverse:true }) {`
for (const job of taskProxy.jobs) {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/components/cylc/tree.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const simpleWorkflowTree4Nodes = [
id: 'user/workflow1/20100101T0000Z/foo',
name: 'foo',
state: 'failed',
expanded: false,
children: [
{
__type: 'job',
Expand Down
24 changes: 18 additions & 6 deletions tests/unit/components/cylc/treeitem.vue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,38 @@ describe('TreeItem component', () => {
})
describe('expanded', () => {
// using simpleJobNode as it has only one child so it is easier/quicker to test
it('should display the TreeItem expanded by default', () => {
it('should display the cycle point expanded by default', () => {
const wrapper = mount(TreeItem, {
propsData: {
node: simpleTaskNode,
node: simpleCyclepointNode,
minDepth: 0,
depth: 0
}
})
expect(wrapper.props().expanded).to.equal(true)
expect(wrapper.props().initialExpanded).to.equal(true)
const expandControlElement = wrapper.find('.node-expand-collapse-button')
expect(expandControlElement.text()).to.equal('▽')
})
it('should not display the TreeItem expanded when set expanded=true', () => {
it('should not display the cycle point expanded when set expanded=true', () => {
const wrapper = mount(TreeItem, {
propsData: {
node: simpleTaskNode,
expanded: false
initialExpanded: false
}
})
expect(wrapper.props().initialExpanded).to.equal(false)
const expandControlElement = wrapper.find('.node-expand-collapse-button')
expect(expandControlElement.text()).to.equal('▷')
})
it('should not display the task expanded by default', () => {
const wrapper = mount(TreeItem, {
propsData: {
node: simpleTaskNode,
minDepth: 0,
depth: 0
}
})
expect(wrapper.props().expanded).to.equal(false)
expect(wrapper.props().initialExpanded).to.equal(true)
const expandControlElement = wrapper.find('.node-expand-collapse-button')
expect(expandControlElement.text()).to.equal('▷')
})
Expand Down