Skip to content

Commit 88753e2

Browse files
Merge pull request cylc#1751 from MetRonnie/table-initial-opts
Table view: remember sort & pagination state on navigation
2 parents 10b4a74 + ec54cd6 commit 88753e2

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ creating a new release entry be sure to copy & paste the span tag with the
1010
`actions:bind` attribute, which is used by a regex to find the text to be
1111
updated. Only the first match gets replaced, so it's fine to leave the old
1212
ones in. -->
13+
-------------------------------------------------------------------------------
14+
## __cylc-ui-2.5.0 (<span actions:bind='release-date'>Upcoming</span>)__
15+
16+
### Enhancements
17+
18+
[#1751](https://github.com/cylc/cylc-ui/pull/1751) -
19+
More view options are now remembered & restored when navigating between workflows.
20+
1321
-------------------------------------------------------------------------------
1422
## __cylc-ui-2.4.0 (<span actions:bind='release-date'>Released 2024-04-02</span>)__
1523

src/components/cylc/table/Table.vue

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
:items="tasks"
2222
item-value="task.id"
2323
multi-sort
24-
:sort-by="sortBy"
24+
v-model:sort-by="sortBy"
2525
show-expand
2626
density="compact"
27+
v-model:page="page"
2728
v-model:items-per-page="itemsPerPage"
2829
>
2930
<template v-slot:item.task.name="{ item }">
@@ -100,45 +101,61 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
100101
</template>
101102

102103
<script>
103-
import { ref } from 'vue'
104104
import Task from '@/components/cylc/Task.vue'
105105
import Job from '@/components/cylc/Job.vue'
106106
import { mdiChevronDown } from '@mdi/js'
107107
import { DEFAULT_COMPARATOR } from '@/components/cylc/common/sort'
108108
import { datetimeComparator } from '@/components/cylc/table/sort'
109109
import { dtMean } from '@/utils/tasks'
110110
import { useCyclePointsOrderDesc } from '@/composables/localStorage'
111+
import {
112+
initialOptions,
113+
updateInitialOptionsEvent,
114+
useInitialOptions
115+
} from '@/utils/initialOptions'
111116
112117
export default {
113118
name: 'TableComponent',
114119
120+
emits: [updateInitialOptionsEvent],
121+
115122
props: {
116123
tasks: {
117124
type: Array,
118125
required: true
119-
}
126+
},
127+
initialOptions,
120128
},
121129
122130
components: {
123131
Task,
124132
Job,
125133
},
126134
127-
setup () {
135+
setup (props, { emit }) {
128136
const cyclePointsOrderDesc = useCyclePointsOrderDesc()
129-
return {
130-
itemsPerPage: ref(50),
131-
sortBy: ref([
137+
138+
const sortBy = useInitialOptions(
139+
'sortBy',
140+
{ props, emit },
141+
[
132142
{
133143
key: 'task.tokens.cycle',
134144
order: cyclePointsOrderDesc.value ? 'desc' : 'asc'
135145
},
136-
]),
137-
}
138-
},
146+
]
147+
)
148+
149+
const page = useInitialOptions('page', { props, emit }, 1)
150+
151+
const itemsPerPage = useInitialOptions('itemsPerPage', { props, emit }, 50)
139152
140-
methods: {
141-
dtMean
153+
return {
154+
dtMean,
155+
itemsPerPage,
156+
page,
157+
sortBy,
158+
}
142159
},
143160
144161
headers: [

src/views/Table.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4545
>
4646
<TableComponent
4747
:tasks="filteredTasks"
48+
v-model:initial-options="dataTableOptions"
4849
/>
4950
</v-container>
5051
</v-col>
@@ -60,6 +61,7 @@ import graphqlMixin from '@/mixins/graphql'
6061
import subscriptionComponentMixin from '@/mixins/subscriptionComponent'
6162
import {
6263
initialOptions,
64+
updateInitialOptionsEvent,
6365
useInitialOptions
6466
} from '@/utils/initialOptions'
6567
import { matchNode } from '@/components/cylc/common/filter'
@@ -167,6 +169,8 @@ export default {
167169
}
168170
},
169171
172+
emits: [updateInitialOptionsEvent],
173+
170174
props: {
171175
initialOptions,
172176
},
@@ -178,7 +182,14 @@ export default {
178182
*/
179183
const tasksFilter = useInitialOptions('tasksFilter', { props, emit }, {})
180184
185+
/**
186+
* The Vuetify data table options (sortBy, page etc).
187+
* @type {import('vue').Ref<object>}
188+
*/
189+
const dataTableOptions = useInitialOptions('dataTableOptions', { props, emit })
190+
181191
return {
192+
dataTableOptions,
182193
tasksFilter,
183194
}
184195
},

tests/e2e/specs/table.cy.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,13 @@ function addView (view) {
132132
.should('not.be.exist')
133133
}
134134

135-
describe('Filters save state', () => {
136-
it('remembers job ID and file when switching between workflows', () => {
135+
describe('State saving', () => {
136+
beforeEach(() => {
137137
cy.visit('/#/workspace/one')
138138
addView('Table')
139+
})
140+
141+
it('remembers filters when switching between workflows', () => {
139142
cy.get('.c-treeitem:visible')
140143
cy
141144
.get('.c-table table > tbody > tr')
@@ -163,8 +166,6 @@ describe('Filters save state', () => {
163166
cy.get('.c-dashboard')
164167
// Navigate back
165168
cy.visit('/#/workspace/one')
166-
cy.get('.c-gscan-workflow-name:first')
167-
.click()
168169
cy
169170
.get('.c-table table > tbody > tr')
170171
.should('have.length', 1)
@@ -174,4 +175,36 @@ describe('Filters save state', () => {
174175
.contains('eventually')
175176
.should('be.visible')
176177
})
178+
179+
it('remembers sorting & page options when switching between workflows', () => {
180+
const sortedClass = 'v-data-table__th--sorted'
181+
cy.get('.c-table th')
182+
.contains('Platform')
183+
.closest('th').as('platformCol')
184+
.should('not.have.class', sortedClass)
185+
.click()
186+
.should('have.class', sortedClass)
187+
cy.get('.c-table .v-data-table-footer__items-per-page .v-select')
188+
.as('itemsPerPage')
189+
.find('input')
190+
.should('not.have.value', -1)
191+
.get('@itemsPerPage')
192+
.click()
193+
.get('[role="listbox"] .v-list-item')
194+
.contains('All')
195+
.click()
196+
// Wait for menu to close
197+
.should('not.exist')
198+
.get('@itemsPerPage').find('input')
199+
.should('have.value', -1)
200+
// Navigate away
201+
cy.visit('/#/')
202+
.get('.c-dashboard')
203+
// Navigate back
204+
cy.visit('/#/workspace/one')
205+
cy.get('@platformCol')
206+
.should('have.class', sortedClass)
207+
cy.get('@itemsPerPage').find('input')
208+
.should('have.value', -1)
209+
})
177210
})

0 commit comments

Comments
 (0)