kennel 2.26.0 → 2.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kennel/api.rb +35 -23
- data/lib/kennel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8a2ad2ca075e3372bf8240fcfd2311690549cac696f6f40c37739a624b0787e
|
|
4
|
+
data.tar.gz: 5a46c7a1daf6c9d5d26ed580c5f5b8ca9e26922d5d5dfcc945a278f5029bc361
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ec316eaa442ddb2ffaf3f1ec233e1cfcb40c23d245d1c062f3d812d7fa7a658aa24475b811627c2abaf6ac6642b4509eef647fce645afa7e8d5e95ef94bb77e
|
|
7
|
+
data.tar.gz: 9875b2bc7f779c8983bf98eb43071d693cb100b23e8d68df7c86819d35d4d6b46209a6911f5c7b9438d12cf965000b6a64ad4604636f2d4d437a0ee279d7d15f
|
data/lib/kennel/api.rb
CHANGED
|
@@ -90,37 +90,49 @@ module Kennel
|
|
|
90
90
|
|
|
91
91
|
# keep widget + tab ids stable so stored dashboard urls that point at a widget or tab do not break on every update
|
|
92
92
|
# ids are dropped when diffing since storing them would be ugly, so restore the previous ids by matching widget titles
|
|
93
|
+
# groups and widgets use separate id pools since tabs reference groups and should not end up pointing at a widget
|
|
93
94
|
def restore_widget_ids(id, attributes)
|
|
94
95
|
return unless (widgets = attributes[:widgets])
|
|
95
96
|
return unless (current = show("dashboard", id, {}, ignore_404: true))
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
next unless (id = widget_title_to_id[title])
|
|
102
|
-
widget[:id] ||= id # do not set nil, that breaks updates
|
|
103
|
-
end
|
|
98
|
+
old_groups, old_widgets = partition_groups(current[:widgets])
|
|
99
|
+
new_groups, new_widgets = partition_groups(widgets)
|
|
100
|
+
reuse_ids(old_groups, new_groups)
|
|
101
|
+
reuse_ids(old_widgets, new_widgets)
|
|
104
102
|
|
|
105
103
|
return unless (tabs = attributes[:tabs])
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
old_tabs = (current[:tabs] || []).map { |t| [t[:name], t] }
|
|
106
|
+
new_tabs = tabs.map { |t| [t[:name], t] }
|
|
107
|
+
reuse_ids(old_tabs, new_tabs)
|
|
108
|
+
|
|
109
|
+
# new tabs get a fake id since the api requires one
|
|
110
|
+
tabs.each { |tab| tab[:id] ||= SecureRandom.uuid }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# split all widgets including nested ones into [key, widget] pairs of groups and non-groups
|
|
114
|
+
def partition_groups(widgets)
|
|
115
|
+
pairs = []
|
|
116
|
+
each_widget_with_title(widgets) { |key, widget| pairs << [key, widget] }
|
|
117
|
+
pairs.partition { |_, widget| widget.dig(:definition, :type) == "group" }
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# assign old ids to new items: exact key matches first, then leftover ids in order to reuse as many ids as possible
|
|
121
|
+
# not setting nils so we get the proper `{"errors":["Required parameter 'id' is missing"]}` error
|
|
122
|
+
def reuse_ids(old_pairs, new_pairs)
|
|
123
|
+
# [[key, item{id}]] -> {key -> [id]}
|
|
124
|
+
pool = old_pairs.group_by(&:first).transform_values { |pairs| pairs.map { |_, item| item[:id] } }
|
|
125
|
+
|
|
126
|
+
unmatched = new_pairs.filter_map do |key, item|
|
|
127
|
+
next item unless (id = pool[key]&.shift)
|
|
128
|
+
item[:id] = id
|
|
129
|
+
nil
|
|
121
130
|
end
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
|
|
132
|
+
leftover = pool.values.flatten
|
|
133
|
+
unmatched.each do |item|
|
|
134
|
+
break unless (id = leftover.shift)
|
|
135
|
+
item[:id] = id
|
|
124
136
|
end
|
|
125
137
|
end
|
|
126
138
|
|
data/lib/kennel/version.rb
CHANGED