Skip to content

Commit

Permalink
Merge pull request #1973 from oliver-sanders/toggle-families-in-tree-…
Browse files Browse the repository at this point in the history
…view

tree: add flat option
  • Loading branch information
markgrahamdawson authored Nov 5, 2024
2 parents af3a3f7 + 42b156b commit 8697e72
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes.d/1973.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a button to toggle families on and off in the tree view.
7 changes: 6 additions & 1 deletion src/components/cylc/tree/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
v-for="child of rootChildren"
:key="child.id"
:node="child"
v-bind="{ hoverable, cyclePointsOrderDesc, expandAll, filteredOutNodesCache }"
v-bind="{ hoverable, cyclePointsOrderDesc, expandAll, filteredOutNodesCache, flat }"
/>
</v-container>
</template>
Expand Down Expand Up @@ -82,6 +82,11 @@ export default {
required: false,
default: () => []
},
flat: {
type: Boolean,
required: false,
default: true,
}
},
components: {
Expand Down
7 changes: 6 additions & 1 deletion src/components/cylc/tree/TreeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ export default {
type: Number,
required: false,
},
flat: {
type: Boolean,
requried: false,
default: false,
},
},
data () {
Expand Down Expand Up @@ -268,7 +273,7 @@ export default {
nodeChildren () {
return this.node.type === 'job'
? null
: getNodeChildren(this.node, this.cyclePointsOrderDesc)
: getNodeChildren(this.node, this.cyclePointsOrderDesc, this.flat)
},
nodeStyle () {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/components/cylc/tree/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export function getNodeChildren (node, cyclePointsOrderDesc) {
export function getNodeChildren (node, cyclePointsOrderDesc, flat) {
// returns child nodes folling the family tree and following sort order
if (node.type === 'workflow' && !cyclePointsOrderDesc) {
// a user configuration has configured the sort order for cycle points to
// be reversed
return [...node.children].reverse()
} else if (node.type === 'cycle') {
} else if (node.type === 'cycle' && !flat) {
// display tasks in the inheritance tree
if (node.familyTree?.length) {
const rootFamily = node.familyTree[0]
Expand Down
24 changes: 22 additions & 2 deletions src/views/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<div
class="d-flex flex-nowrap ml-2"
>
<v-btn
@click="flat = !flat"
icon
variant="flat"
size="small"
data-cy="toggle-families"
>
<v-icon size="x-large">
{{ flat? $options.icons.mdiFormatAlignRight : $options.icons.mdiFormatAlignJustify }}
</v-icon>
<v-tooltip>
{{ flat ? "Show Families" : "Hide Families" }}
</v-tooltip>
</v-btn>
<v-btn
@click="expandAll = ['workflow', 'cycle', 'family']"
icon
Expand Down Expand Up @@ -72,6 +86,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
:hoverable="false"
:autoStripTypes="['workflow']"
:node-filter-func="filterNode"
:flat="flat"
v-bind="{ expandAll, filterState }"
ref="treeComponent"
/>
Expand All @@ -83,7 +98,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<script>
import { mapState, mapGetters } from 'vuex'
import { mdiPlus, mdiMinus } from '@mdi/js'
import { mdiPlus, mdiMinus, mdiFormatAlignRight, mdiFormatAlignJustify } from '@mdi/js'
import gql from 'graphql-tag'
import graphqlMixin from '@/mixins/graphql'
import subscriptionComponentMixin from '@/mixins/subscriptionComponent'
Expand Down Expand Up @@ -222,8 +237,11 @@ export default {
*/
const tasksFilter = useInitialOptions('tasksFilter', { props, emit }, { id: null, states: null })
const flat = useInitialOptions('flat', { props, emit }, false)
return {
tasksFilter
tasksFilter,
flat,
}
},
Expand Down Expand Up @@ -301,6 +319,8 @@ export default {
icons: {
mdiPlus,
mdiMinus,
mdiFormatAlignRight,
mdiFormatAlignJustify,
},
}
</script>
9 changes: 9 additions & 0 deletions tests/e2e/specs/tree.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,13 @@ describe('Tree view', () => {
cy.get('[data-cy="filter task state"]')
.contains('.v-select__selection', '(+')
})

describe('Toggle families', () => {
it('Toggles between flat and hierarchical modes', () => {
cy.visit('/#/tree/one')
cy.get('.node-data-family').should('have.length', 3)
cy.get('[data-cy=toggle-families]').click()
cy.get('.node-data-family').should('have.length', 0)
})
})
})

0 comments on commit 8697e72

Please sign in to comment.