Skip to content

Commit

Permalink
Update importer to support sli_specification
Browse files Browse the repository at this point in the history
  • Loading branch information
kaarolch committed May 24, 2024
1 parent 24f007d commit 3a00b85
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/kennel/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Kennel
class Importer
TITLES = [:name, :title].freeze
SORT_ORDER = [*TITLES, :id, :kennel_id, :type, :tags, :query, *Models::Record.subclasses.map { |k| k::TRACKING_FIELDS }, :template_variables].freeze
SORT_ORDER = [*TITLES, :id, :kennel_id, :type, :tags, :query, :sli_specification, *Models::Record.subclasses.map { |k| k::TRACKING_FIELDS }, :template_variables].freeze

def initialize(api)
@api = api
Expand All @@ -19,10 +19,15 @@ def import(resource, id)
raise(ArgumentError, "#{resource} is not supported")

data = @api.show(model.api_resource, id)
# get sli specification before normalization.
sli_specification = data[:sli_specification] || data.dig(:sli_specification, :time_slice)

id = data.fetch(:id) # keep native value
model.normalize({}, data) # removes id
data[:id] = id

data[:sli_specification] = sli_specification if sli_specification

title_field = TITLES.detect { |f| data[f] }
title = data.fetch(title_field)
title.tr!(Kennel::Models::Record::LOCK, "") # avoid double lock icon
Expand Down

0 comments on commit 3a00b85

Please sign in to comment.