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

Use initialOptions to save & restore view state on navigation #7

Closed
wants to merge 5 commits into from

Conversation

MetRonnie
Copy link
Owner

Secondary PR against cylc#1664

The view state (filters, inputs, toggles etc.) can now be saved with the Lumino tab layout by using a prop called initialOptions.

This is only implemented for the log view for now.

Comment on lines +375 to +390
// Watch id & file together:
this.$watch(
() => ({
id: this.id ?? undefined, // (treat null as undefined)
file: this.file ?? undefined
}),
async ({ id }, old) => {
// update the query when the id or file change
this.updateQuery()
// refresh the file list when the id changes
if (id !== old?.id) {
await this.updateLogFileList()
}
},
{ immediate: true }
)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejigged the watchers for file and id to prevent race conditions. The usual order of events now is (for the example of opening the workflow log):

  1. id gets set for the first time to '~user/workflow'. file is nullish.

    • updateQuery() gets called because the id changed, but because file is nullish it doesn't really do anything

      cylc-ui/src/views/Log.vue

      Lines 429 to 431 in 58f5d96

      if (!this.file || !this.id) {
      this.query = null
      return
    • updateLogFileList() gets called because the id changed
  2. file has been set to the default scheduler log by updateLogFileList()

    • updateQuery() gets called again because file changed, and causes the log file to display
    • updateLogFileList() doesn't get called because id is unchanged

Comment on lines -416 to +473
if (this.file && !(this.file in logFiles)) {
if (this.file && !logFiles.includes(this.file)) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x in arr does not do what you think it does!

Comment on lines +51 to +62
export const useInitialOptions = (name, { props, emit }) => {
const _ref = ref(props.initialOptions[name])
watch(
_ref,
(val, old) => emit(
updateInitialOptionsEvent,
{ ...props.initialOptions, [name]: val }
),
{ immediate: true, deep: true }
)
return _ref
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to using a writeable computed property e.g.

computed({
  get: () => props.initialOptions[name],
  set: (val) => emit(
    updateInitialOptionsEvent,
    { ...props.initialOptions, [name]: val }
  )
})

but that seemed to lead to the ref value not updating until the next tick? Maybe the watcher approach works because it is backed up by a concrete ref? Not sure

@MetRonnie
Copy link
Owner Author

Re-opened as cylc#1688

@MetRonnie MetRonnie closed this Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant