Refactor state code that runs upon entering a view
When we want to change the view, we typically need to do the following:
- Set new view state in model
- Set new URL
- Depending on which view we are entering, fire some commands and make some tweaks the model
StateHelpers.updateViewState
does the first two of these things; State.setProjectView
does the third.
setProjectView
currently does the following:
- Calls
StateHelpers.updateViewState
to set new view state and URL - Model changes:
- If entering server list view or server detail view, resets Cockpit statuses
- If already on create server view, enforces quota (ensure server count is compatible with flavor chosen)
- When firing a command that requires setting something in the model to "loading", sets that in the model
- Commands, which are only fired if first entering view:
- for image list view:
- request images
- for server list view:
- request servers and floating IPs
- for server detail view:
- request server
- request flavors
- request images
- request volumes
- instantiate clipboard.js
- for server creation view:
- request flavors
- request keypairs
- request networks
- generate random server name
- request compute quota
- request volume quota
- for volume list view:
- request volumes
- instantiate clipboard.js
- for quota usage view:
- request compute quota
- request volume quota
- for attach volume view:
- request servers
- request volumes
- for create volume view:
- request volume quota
- for image list view:
Sometimes we call the update function recursively, which feels like a hack:
-
init
does this when initial view (set by URL entered) is a project-specific view, to ensure that appropriate commands are fired when entering view-
ReceiveCreateVolume
and ReceiveDetachVolume
do this to SetProjectView
to ListProjectVolumes
- ReceiveAttachVolume
does this to SetProjectView
to MountVolInstructions
Consider doing the following:
-
Calling State.setProjectView
instead of calling entire update function recursively - Breaking out the "commands to fire on first entering view" to its own function, sort of like how we break out the code to set URL to its own function
- Check if we, e.g., have a fairly recent list of images before firing command to get images
- When we fire some commands, we need to set the resource as loading in the model. Maybe we should have more functions to set resources as loading (like
setServersLoading
). Maybe there should be a function to both fire the command and set as loading, which prevents us from forgetting to set resource as loading when we start loading it.
Edited by Chris Martin