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

Select active snapshot instead of the last one in the snapshots 🌳 #6103

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Changes from all 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
16 changes: 11 additions & 5 deletions app/presenters/tree_builder_snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ def root_options
}
end

# The tree name is the same for any snapshot tree, so it doesn't make sense to
# load the selected node from the session. This method always selects the last
# node in the tree.
# The tree name is the same for any snapshot tree, so it doesn't make sense to load the selected
# node from the session. This method tries to find the active snapshot based on its suffix.
# FIXME: deciding based on the string is not ideal, it should be evaluated on the node object instead
def active_node_set(tree_nodes)
# Find the last node
stack = [tree_nodes.last]
while stack.any?
node = stack.pop
# If the node's text has an active suffix, return with it
if node.try(:[], :text).try(:ends_with?, " (#{_('Active')})")
active = node
break
end

stack.push(node[:nodes].last) if node[:nodes].try(:any?)
end
# Set it as the active node in the tree state
@tree_state.x_node_set(node[:key], @name)
# If no active snapshot has been found, return with the last node
@tree_state.x_node_set(active.try(:[], :key) || node[:key], @name)
end

def x_get_tree_roots(count_only)
Expand Down