lib/eco/api/usecases/graphql/samples/location/command/results.rb in eco-helpers-2.5.5 vs lib/eco/api/usecases/graphql/samples/location/command/results.rb in eco-helpers-2.5.6
- old
+ new
@@ -16,19 +16,23 @@
def request_results_class
Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results
end
+ def tags_remap_class
+ Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap
+ end
+
# Capture results
def results
@results ||= {}
end
# The maps of tags to be used in batch remap tags
# @return [Array<Array>] source/destination pairs of `Array<String>`
def tags_remap_table
- @tags_remap_table ||= []
+ @tags_remap_table ||= tags_remap_class.new
end
# Errors tracking/logging.
# @note it gives feedback on where an error has occurred.
# @param page_results [Eco::API::UseCases::GraphQL::Helpers::Locations::Commands::CommandResults]
@@ -85,32 +89,32 @@
tags_remap_table << [[prev_id], [curr_id]]
when :move
node_id, parent_id = result.command_input_data.values_at(:nodeId, :parentId)
prev_node = previous_tree.node(node_id)
curr_node = current_tree.node(node_id)
- lost_tags = prev_node.path - curr_node.path
- new_tags = curr_node.path - prev_node.path
+ prev_path = prev_node.path.reverse
+ new_path = curr_node.path.reverse
curr_parent = curr_node.parent.top? ? nil : curr_node.parent
unless curr_parent&.id == parent_id
- msg = "Node '#{node_id}' was moved uner '#{parent_id}', "
+ msg = "Node '#{node_id}' was moved under '#{parent_id}', "
msg << "but in current structure has parent '#{curr_parent&.id}'"
log(:warn) { msg }
end
- tags_remap_table << [lost_tags.unshift(node_id), new_tags.unshift(node_id)]
+ tags_remap_table << [prev_path, new_path]
end
end
end
# Generates the final tags remap file
def generate_tags_remap_csv(filename = "cache/remap_tags.csv")
return nil if tags_remap_table.empty?
timestamp_file(filename).tap do |file|
CSV.open(file, 'w') do |csv|
csv << ["source_tags", "destination_tags"]
- tags_remap_table.each do |(src_tags, dst_tags)|
- csv << [src_tags.join('|'), dst_tags.join('|')]
+ tags_remap_table.each do |tags_remap|
+ csv << tags_remap.to_csv_row
end
end
log(:info) { "Generated file '#{file}'" }
end
end