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

TreeView: Use initialOptions prop to save view state #1705

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Aaron Cole <aaron@epiphron.co.nz>
Jamie Allen <jamie.allen@metoffice.gov.uk> JAllen42 <jrallen42@gmail.com>
Jamie Allen <69790602+JAllen42@users.noreply.github.com>
Christopher Bennett <christopher.bennett@metoffice.gov.uk> ChrisPaulBennett
Mark Dawson <mark.dawson@metoffice.gov.uk> Mark Dawson <mark.dawson@metoffice.gov.ukpython>
markgrahamdawson marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ ones in. -->

### Enhancements

[#1705](https://github.com/cylc/cylc-ui/pull/1705) -
Tree view options remembered & restored when navigating between workflows.
[#1688](https://github.com/cylc/cylc-ui/pull/1688) -
Log view options remembered & restored when navigating between workflows.
markgrahamdawson marked this conversation as resolved.
Show resolved Hide resolved

[#1664](https://github.com/cylc/cylc-ui/pull/1664) -
Workspace tab layout is now remembered & restored when navigating between workflows.

Expand Down
23 changes: 19 additions & 4 deletions src/views/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ import gql from 'graphql-tag'
import { getPageTitle } from '@/utils/index'
import graphqlMixin from '@/mixins/graphql'
import subscriptionComponentMixin from '@/mixins/subscriptionComponent'
import {
initialOptions,
useInitialOptions
} from '@/utils/initialOptions'
import SubscriptionQuery from '@/model/SubscriptionQuery.model'
import TaskFilter from '@/components/cylc/TaskFilter.vue'
import TreeComponent from '@/components/cylc/tree/Tree.vue'
import { matchID, matchState } from '@/components/cylc/common/filter'
import { ref } from 'vue'

const QUERY = gql`
subscription Workflow ($workflowId: ID) {
Expand Down Expand Up @@ -216,12 +221,22 @@ export default {
}
},

props: { initialOptions },

setup (props, { emit }) {
/**
* The job id input and selected task filter state.
* @type {import('vue').Ref<Object>}
*/
const tasksFilter = useInitialOptions('tasksFilter', { props, emit }, ref({ id: null, states: null }))

return {
tasksFilter
}
},

data: () => ({
expandAll: null,
tasksFilter: {
id: null,
states: null,
},
}),

computed: {
Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/specs/tree.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@ describe('Tree view', () => {
.should('have.length', 1)
.contains('retrying')
})
it('remembers job ID and file when switching between workflows', () => {
cy.visit('/#/workspace/one')
cy
.get('.node-data-task')
.contains('failed')
.should('be.visible')
cy
.get('[data-cy=filter-id]')
.type('i')
cy
.get('[data-cy="filter task state"]')
.click()
.get('.v-list-item')
.contains(TaskState.WAITING.name)
.click({ force: true })
// Navigate away
cy.visit('/#/')
cy.title().should('eq', 'Cylc UI | Dashboard')
markgrahamdawson marked this conversation as resolved.
Show resolved Hide resolved
// Navigate back
cy.visit('/#/workspace/one')
.get('.node-data-task:visible')
.should('have.length', 1)
.contains('retrying')
})
})

describe('Expand/collapse all buttons', () => {
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/views/tree.vue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */

import { nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { createStore } from 'vuex'
import { createVuetify } from 'vuetify'
Expand Down Expand Up @@ -123,7 +124,8 @@ describe('Tree view', () => {
{ tasksFilter: { id: 'asdf', states: ['failed'] }, filteredOut: true },
])('filters by $tasksFilter', async ({ tasksFilter, filteredOut }) => {
const wrapper = mountFunction()
await wrapper.setData({ tasksFilter })
wrapper.vm.tasksFilter = tasksFilter
await nextTick()
expect(wrapper.vm.filterState).toMatchObject(tasksFilter)
const filteredOutNodesCache = new Map()
expect(wrapper.vm.filterNode(workflowNode, filteredOutNodesCache)).toEqual(!filteredOut)
Expand Down