Remove color_field input type from profiles (#14239)

* Move brand color validation to Users::Setting

* Fix specs

* Remove color_field as ProfileField input type
This commit is contained in:
Michael Kohl 2021-07-19 18:42:36 +07:00 committed by GitHub
parent bb701c4f78
commit 84a85fe1a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 38 deletions

View file

@ -5,8 +5,7 @@ class ProfileField < ApplicationRecord
enum input_type: {
text_field: 0,
text_area: 1,
check_box: 2,
color_field: 3
check_box: 2
}
enum display_area: {

View file

@ -42,10 +42,6 @@ class ProfileValidator < ActiveModel::Validator
true # checkboxes are always valid
end
def color_field_valid?(_record, _attribute)
true # we do not currently validate color fields here
end
def text_area_valid?(record, attribute)
text = record.public_send(attribute)
text.nil? || text.size <= MAX_TEXT_AREA_LENGTH

View file

@ -107,20 +107,6 @@
<label class="crayons-field__label" for="<%= "profile[#{field.attribute_name}]" %>">
<%= field.label %>
</label>
<% elsif field["input_type"] == "color_field" %>
<label class="crayons-field__label" for="<%= "profile[#{field.attribute_name}]" %>">
<%= field.label %>
</label>
<div class="flex items-center w-100 m:w-50">
<%= f.public_send("text_field", "profile[#{field.attribute_name}]",
value: profile.public_send(field.attribute_name),
placeholder: field["placeholder_text"],
class: "crayons-textfield js-color-field") %>
<%= f.public_send(field["input_type"],
"profile[#{field.attribute_name}]",
value: profile.public_send(field.attribute_name),
class: "crayons-color-selector js-color-field ml-2") %>
</div>
<% else %>
<label class="crayons-field__label" for="<%= "profile[#{field.attribute_name}]" %>">
<%= field.label %>

View file

@ -1,4 +1,4 @@
Full test,text_field,Test,Test field,Basic,header,true
Test name,text_field,John Doe,,Basic,header,false
Test languages,text_area,,Programming languages,Coding,left_sidebar,false
Test color,color_field,#000000,"Used for backgrounds, borders etc.",Branding,settings_only,false
Test languages,text_area,,"Programming languages, frameworks, etc.",Coding,left_sidebar,false

1 Test name Full test text_field John Doe Test Test field Basic header false true
1 Full test text_field Test Test field Basic header true
2 Test name Test name text_field John Doe John Doe Basic header false false
Test languages text_area Programming languages Coding left_sidebar false
3 Test color Test languages color_field text_area #000000 Used for backgrounds, borders etc. Programming languages, frameworks, etc. Branding Coding settings_only left_sidebar false false
4

View file

@ -10,31 +10,29 @@ RSpec.describe ProfileFields::ImportFromCsv do
context "when missing attributes" do
before { described_class.call(file_fixture("profile_fields.csv")) }
it "handles missing descriptions", :aggregate_failures do
field = ProfileField.find_by!(label: "Test name")
it "imports fields" do
field = ProfileField.find_by!(label: "Full test")
expect(field.input_type).to eq "text_field"
expect(field.placeholder_text).to eq "John Doe"
expect(field.description).to be_nil
expect(field.placeholder_text).to eq "Test"
expect(field.description).to eq "Test field"
expect(field.profile_field_group.name).to eq "Basic"
expect(field.display_area).to eq "header"
expect(field.show_in_onboarding).to be true
end
it "handles missing placeholder_texts", :aggregate_failures do
it "handles missing descriptions" do
field = ProfileField.find_by!(label: "Test name")
expect(field.description).to be_nil
end
it "handles missing placeholder_texts" do
field = ProfileField.find_by!(label: "Test languages")
expect(field.input_type).to eq "text_area"
expect(field.placeholder_text).to be_nil
expect(field.description).to eq "Programming languages"
expect(field.profile_field_group.name).to eq "Coding"
expect(field.display_area).to eq "left_sidebar"
end
it "handles commas in correctly quoted fields", :aggregate_failures do
field = ProfileField.find_by!(label: "Test color")
expect(field.input_type).to eq "color_field"
expect(field.placeholder_text).to eq "#000000"
expect(field.description).to eq "Used for backgrounds, borders etc."
expect(field.profile_field_group.name).to eq "Branding"
expect(field.display_area).to eq "settings_only"
it "handles commas in correctly quoted fields" do
field = ProfileField.find_by!(label: "Test languages")
expect(field.description).to eq "Programming languages, frameworks, etc."
end
end
end