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

Analysis view: use initialOptions to save & restore view state on navigation #1744

Merged
merged 17 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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 changes.d/1717.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
More view options are now remembered & restored when navigating between workflows.
1 change: 1 addition & 0 deletions changes.d/1744.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
More view options are now remembered & restored when navigating between workflows.
41 changes: 36 additions & 5 deletions src/components/cylc/analysis/AnalysisTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<v-data-table
:headers="shownHeaders"
:items="tasks"
:sort-by="sortBy"
v-model:sort-by="sortBy"
density="compact"
v-model:page="page"
v-model:items-per-page="itemsPerPage"
>
<!-- Use custom format for values in columns that have a specified formatter: -->
Expand All @@ -56,10 +57,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<script>
import { upperFirst } from 'lodash'
import { formatDuration } from '@/utils/tasks'
import {
initialOptions,
updateInitialOptionsEvent,
useInitialOptions
} from '@/utils/initialOptions'

export default {
name: 'AnalysisTableComponent',

emits: [updateInitialOptionsEvent],

props: {
tasks: {
type: Array,
Expand All @@ -68,15 +76,38 @@ export default {
timingOption: {
type: String,
required: true
},
initialOptions,
},

setup (props, { emit }) {
/**
* The number of tasks displayed per page.
* @type {import('vue').Ref<number>}
*/
const itemsPerPage = useInitialOptions('tasksFilter', { props, emit }, 50)

/**
* The 'sort by' state.
* @type {import('vue').Ref<array>}
*/
const sortBy = useInitialOptions('sortBy', { props, emit }, [{ key: 'name', order: 'asc' }])

/**
* The page number state.
* @type {import('vue').Ref<number>}
*/
const page = useInitialOptions('page', { props, emit }, 1)

return {
itemsPerPage,
sortBy,
page
}
},

data () {
return {
itemsPerPage: 50,
sortBy: [
{ key: 'name', order: 'asc' }
],
headers: [
{
title: 'Task',
Expand Down
44 changes: 33 additions & 11 deletions src/components/cylc/analysis/BoxPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<template>
<Teleport
v-if="sortInputTeleportTarget"
:to="sortInputTeleportTarget"
:to="`#${sortInputTeleportTarget}`"
>
<div class="d-flex flex-grow-1 col-gap-1">
<v-select
data-cy="box-plot-sort-select"
:items="sortChoices"
v-model="sortBy"
label="Sort by"
Expand Down Expand Up @@ -66,6 +67,11 @@ import {
import { upperFirst } from 'lodash'
import { formatDuration } from '@/utils/tasks'
import { useReducedAnimation } from '@/composables/localStorage'
import {
initialOptions,
updateInitialOptionsEvent,
useInitialOptions
} from '@/utils/initialOptions'

export default {
name: 'BoxPlot',
Expand All @@ -74,6 +80,8 @@ export default {
VueApexCharts,
},

emits: [updateInitialOptionsEvent],

props: {
tasks: {
type: Array,
Expand All @@ -83,6 +91,7 @@ export default {
type: String,
required: true,
},
initialOptions,
itemsPerPage: {
type: Number,
default: 20,
Expand All @@ -91,14 +100,32 @@ export default {
type: Boolean,
default: true,
},
/** Where to teleport the sorting input (or don't render if null) */
/** ID of element to teleport the sorting input (or don't render if null) */
sortInputTeleportTarget: {
type: String,
default: null,
},
},

setup (props) {
setup (props, { emit }) {
/**
* The 'sort by' state.
* @type {import('vue').Ref<string>}
*/
const sortBy = useInitialOptions('sortBy', { props, emit }, 'name')

/**
* The page number state.
* @type {import('vue').Ref<number>}
*/
const page = useInitialOptions('page', { props, emit }, 1)

/**
* The sort descending/sscending state.
* @type {import('vue').Ref<boolean>}
*/
const sortDesc = useInitialOptions('sortDesc', { props, emit }, false)

const reducedAnimation = useReducedAnimation()

const chartOptions = computed(() => ({
Expand Down Expand Up @@ -163,18 +190,13 @@ export default {
}))

return {
sortBy,
page,
sortDesc,
chartOptions,
}
},

data () {
return {
page: 1,
sortBy: 'name',
sortDesc: false,
}
},

errorCaptured (err, instance, info) {
if (err.name === 'TypeError' && instance.type === 'boxPlot') {
// Suppress bogus error https://github.com/apexcharts/vue3-apexcharts/issues/79
Expand Down
58 changes: 51 additions & 7 deletions src/views/Analysis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</v-col>
</v-row>
<div
ref="toolbar"
id="analysis-toolbar"
class="d-flex align-center flex-wrap my-2 col-gap-2 row-gap-4"
>
Expand Down Expand Up @@ -106,25 +107,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
v-if="table"
:tasks="filteredTasks"
:timing-option="timingOption"
v-model:initial-options="dataTableOptions"
/>
<BoxPlot
v-else
:tasks="filteredTasks"
:timing-option="timingOption"
sort-input-teleport-target="#analysis-toolbar"
:sort-input-teleport-target="toolbar?.id"
v-model:initial-options="boxPlotOptions"
/>
</v-container>
</div>
</template>

<script>
import { ref } from 'vue'
import {
debounce,
pick,
} from 'lodash'
import gql from 'graphql-tag'
import { getPageTitle } from '@/utils/index'
import graphqlMixin from '@/mixins/graphql'
import {
initialOptions,
updateInitialOptionsEvent,
useInitialOptions
} from '@/utils/initialOptions'
import AnalysisTable from '@/components/cylc/analysis/AnalysisTable.vue'
import BoxPlot from '@/components/cylc/analysis/BoxPlot.vue'
import {
Expand Down Expand Up @@ -227,18 +236,53 @@ export default {
this.historicalQuery()
},

emits: [updateInitialOptionsEvent],

props: { initialOptions },

setup (props, { emit }) {
/**
* The task name, timing option and platform filter state.
* @type {import('vue').Ref<object>}
*/
const tasksFilter = useInitialOptions('tasksFilter', { props, emit }, { name: '', timingOption: 'totalTimes', platformOption: -1 })

/**
* If true the analysis will be shown in table format
* @type {import('vue').Ref<boolean>}
*/
const table = useInitialOptions('table', { props, emit }, true)

/** @type {import('vue').Ref<HTMLElement>} template ref */
const toolbar = ref(null)

/**
* The Vuetify data table options (sortBy, page etc).
* @type {import('vue').Ref<object>}
*/
const dataTableOptions = useInitialOptions('dataTableOptions', { props, emit })
markgrahamdawson marked this conversation as resolved.
Show resolved Hide resolved

/**
* The Vuetify box and whisker plot options (sortBy, page etc).
* @type {import('vue').Ref<object>}
*/
const boxPlotOptions = useInitialOptions('boxPlotOptions', { props, emit })

return {
tasksFilter,
table,
toolbar,
dataTableOptions,
boxPlotOptions
}
},

data () {
const tasks = []
return {
callback: new AnalysisCallback(tasks),
/** Object containing all of the tasks added by the callback */
tasks,
tasksFilter: {
name: '',
timingOption: 'totalTimes',
platformOption: -1,
},
table: true,
}
},

Expand Down
Loading
Loading