Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/assets/tailwind/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@
box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.input-field:hover:not(:focus) {
.input-field:hover:not(:focus):not(:disabled) {
@apply border-gray-400;
}

.input-field:disabled {
@apply bg-gray-100 text-gray-500;
}

.select-field {
@apply w-full border border-gray-300 rounded-lg text-sm bg-white transition-all duration-200 cursor-pointer;
padding: 0.625rem 2.5rem 0.625rem 0.875rem;
Expand Down
17 changes: 17 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,21 @@ class Provider < ApplicationRecord

validates :name, :provider_type, presence: true
validates :name, uniqueness: true

validate :file_name_prefix_may_be_changed, on: :update, if: :file_name_prefix_changed?

def has_topics?
topics.any?
end

private

def file_name_prefix_may_be_changed
if has_topics?
errors.add(
:file_name_prefix,
"can't be changed as provider has associated topics and so file names are established"
)
end
end
end
46 changes: 45 additions & 1 deletion app/views/providers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
<div class="space-y-6">
<%= render "shared/errors", errors: provider.errors.full_messages, resource_name: provider.class.name %>

<!-- File name prefix uneditable notice -->
<% if @provider.has_topics? %>
<div id="file-name-prefix-uneditable-notice" class="bg-blue-50 border border-blue-200 rounded-lg p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
<div class="ml-3">
<p class="text-sm text-blue-700 m-0">
There are topics associated with this provider, so the file names are established and the file name prefix can't be edited.
</p>
</div>
</div>
</div>
<% end %>


<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">

<!-- Provider Name -->
Expand All @@ -11,7 +30,7 @@
<span class="text-red-500">*</span>
<% end %>
<%= form.text_field :name,
placeholder: "Enter provider name (e.g., Johns Hopkins, Mayo Clinic)",
placeholder: "e.g., Johns Hopkins, Mayo Clinic",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the placeholder here to be consistent with the rest of them. I think it is sufficient to have the placeholder give examples, as our help text says what the input should be

autofocus: true,
class: "input-field bg-gray-50" %>
<p class="help-text">The official name of the healthcare provider or organization.</p>
Expand All @@ -29,6 +48,31 @@
<p class="help-text">The type or category of healthcare provider.</p>
</div>

<!-- File name prefix -->
<% if @provider.has_topics? %>
<div>
<%= form.label :file_name_prefix, class: "input-label" do %>
File name prefix
<% end %>
<%= form.text_field :file_name_prefix,
disabled: true,
value: @provider.file_name_prefix,
class: "input-field bg-gray-50"
%>
<p class="help-text">The prefix to use for this provider's uploads.</p>
</div>
<% else %>
<div>
<%= form.label :file_name_prefix, class: "input-label" do %>
File name prefix
<% end %>
<%= form.text_field :file_name_prefix,
placeholder: "e.g., 123_who_guidelines",
class: "input-field bg-gray-50" %>
<p class="help-text">The prefix to use for this provider's uploads.</p>
</div>
<% end %>

<!-- Regions -->
<div>
<%= form.label :region, class: "input-label" do %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/providers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</div>

<div class="card-body">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">

<div>
<label class="input-label">Provider Name</label>
Expand All @@ -97,7 +97,7 @@
</div>
</div>

<div>
<div class="col-span-full">
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, an overly long file_name_prefix value would overflow its display label on large displays...

Image

The file_name_prefix value overflowing the display label on the previous grid layout

Now, this has been updated so the file_name_prefix display takes up the entire column...

Image

The file_name_prefix value spans its entire column on the new grid layout

<label class="input-label">File Name Prefix</label>
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
<% if @provider.file_name_prefix.present? %>
Expand Down
66 changes: 66 additions & 0 deletions spec/models/provider_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# == Schema Information
#
# Table name: providers
# Database name: primary
#
# id :bigint not null, primary key
# file_name_prefix :string
# name :string
# provider_type :string
# created_at :datetime not null
# updated_at :datetime not null
# old_id :integer
#
# Indexes
#
# index_providers_on_old_id (old_id) UNIQUE
#
require "rails_helper"

RSpec.describe Provider, type: :model do
let(:provider) { create(:provider) }
subject { provider }

describe "validations" do
it { should validate_presence_of(:provider_type) }
it { should validate_presence_of(:name) }
it { should validate_uniqueness_of(:name) }

describe "#file_name_prefix_may_be_changed" do
context "when a provider has topics" do
let!(:topic) { create(:topic, provider: provider) }

it "returns an error" do
provider.file_name_prefix = "updated_prefix"
expect(provider).not_to be_valid
expect(provider.errors[:file_name_prefix]).to match_array(
"can't be changed as provider has associated topics and so file names are established"
)
end
end

context "when a provider has no topics" do
it "does not return an error" do
provider.file_name_prefix = "updated_prefix"
expect(provider).to be_valid
end
end
end
end

describe "#has_topics?" do
context "when a provider has topics" do
let!(:topic) { create(:topic, provider: provider) }

it "returns true" do
expect(provider.has_topics?).to be true
end
end

context "when a provider has no topics" do
it "returns false" do
expect(provider.has_topics?).to be false
end
end
end
end
24 changes: 24 additions & 0 deletions spec/views/providers/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,28 @@
assert_select "input[type='submit'][value='Update Provider']"
end
end

context "when the provider has associated topics" do
before { create(:topic, provider: provider) }

it "tells the user that the File name prefix can't be changed" do
render

assert_select "form[action=?][method=?]", provider_path(provider), "post" do
assert_select "input[name=?][disabled]", "provider[file_name_prefix]"
end

assert_select "div#file-name-prefix-uneditable-notice"
end
end

context "when the provider that has no associated topics" do
it "has the File name prefix field" do
render

assert_select "form[action=?][method=?]", provider_path(provider), "post" do
assert_select "input[name=?]", "provider[file_name_prefix]"
end
end
end
end
1 change: 1 addition & 0 deletions spec/views/providers/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
assert_select "form[action=?][method=?]", providers_path, "post" do
assert_select "input[name=?]", "provider[name]"
assert_select "input[name=?]", "provider[provider_type]"
assert_select "input[name=?]", "provider[file_name_prefix]"
assert_select "input[type='submit'][value='Create Provider']"
end
end
Expand Down
Loading