Merge pull request #2791 from basecamp/fix-export-column-colors
Fix export/import losing custom column colors
This commit is contained in:
@@ -65,7 +65,7 @@ class Account::DataTransfer::RecordSet
|
||||
end
|
||||
|
||||
def export_record(record)
|
||||
zip.add_file "data/#{model_dir}/#{record.id}.json", record.to_json
|
||||
zip.add_file "data/#{model_dir}/#{record.id}.json", record.attributes.slice(*attributes).to_json
|
||||
end
|
||||
|
||||
def files
|
||||
|
||||
+15
-1
@@ -2,9 +2,23 @@ Color = Struct.new(:name, :value)
|
||||
|
||||
class Color
|
||||
class << self
|
||||
# Finds a Color by its CSS value (e.g. "var(--color-card-4)").
|
||||
# Falls back to extracting the value from legacy export formats where
|
||||
# the Color struct was serialized instead of the raw CSS string.
|
||||
def for_value(value)
|
||||
COLORS.find { |it| it.value == value }
|
||||
COLORS.find { |it| it.value == value } ||
|
||||
extract_from_legacy_export(value)
|
||||
end
|
||||
|
||||
private
|
||||
# Broken exports serialized Color structs instead of raw CSS values,
|
||||
# producing JSON like {"name":"Lime","value":"var(--color-card-4)"}.
|
||||
# Parse it and extract the value.
|
||||
def extract_from_legacy_export(value)
|
||||
parsed = value.is_a?(String) && JSON.parse(value)
|
||||
COLORS.find { |it| it.value == parsed["value"] } if parsed.is_a?(Hash)
|
||||
rescue JSON::ParserError
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
||||
@@ -226,6 +226,7 @@ class Account::ImportTest < ActiveSupport::TestCase
|
||||
name: account.name,
|
||||
board_count: Board.where(account: account).count,
|
||||
column_count: Column.where(account: account).count,
|
||||
column_colors: Column.where(account: account).order(:id).pluck(:color),
|
||||
card_count: Card.where(account: account).count,
|
||||
comment_count: Comment.where(account: account).count,
|
||||
tag_count: Tag.where(account: account).count
|
||||
|
||||
@@ -7,6 +7,14 @@ class Column::ColoredTest < ActiveSupport::TestCase
|
||||
assert_equal Column::Colored::DEFAULT_COLOR, column.color
|
||||
end
|
||||
|
||||
test "reads color from legacy export format" do
|
||||
column = columns(:writebook_triage)
|
||||
# Broken exports serialized Color structs as JSON
|
||||
column.update_column(:color, { "name" => "Lime", "value" => "var(--color-card-4)" }.to_json)
|
||||
|
||||
assert_equal Color.for_value("var(--color-card-4)"), column.reload.color
|
||||
end
|
||||
|
||||
test "update the column color" do
|
||||
columns(:writebook_triage).update!(color: "var(--color-card-3)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user