Skip to content

Commit

Permalink
Merge pull request #6103 from skateman/active-snapshot-select
Browse files Browse the repository at this point in the history
Select active snapshot instead of the last one in the snapshots 🌳

(cherry picked from commit 7de5d52)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1805803
  • Loading branch information
h-kataria authored and simaishi committed Feb 21, 2020
1 parent 5105b81 commit 7dd5016
Showing 1 changed file with 11 additions and 5 deletions.
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 = false, _options = {})
Expand Down

0 comments on commit 7dd5016

Please sign in to comment.