From cc33849a76acb102ad77be522ee43a389dbe8e8b Mon Sep 17 00:00:00 2001 From: Fiona Mclaren Date: Thu, 7 May 2026 12:35:35 +0100 Subject: [PATCH] Set provider prefix on creation and when editing a provider with no topics Resolves #607 Each provider has a `file_name_prefix`. This value is added to the file name when the provider uploads a file. This `file_name_prefix` is necessary to coordinate between our file storage and Azure's. However, if a provider was to change their `file_name_prefix` when they had uploaded files, it would break management of those existing uploaded files. Before, we got around this by simply removing the field from the provider's form. This meant that users could not set the value of `file_name_prefix` when making a new provider or when editing a provider who had no uploaded files. This PR adds the ability to set the `file_name_prefix` value on the provider form. The field will show on the form when the provider is... - A new instance - One who has no topics, and no uploaded files --- app/views/providers/_form.html.erb | 15 ++++++++++++++- spec/views/providers/edit.html.erb_spec.rb | 22 ++++++++++++++++++++++ spec/views/providers/new.html.erb_spec.rb | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/views/providers/_form.html.erb b/app/views/providers/_form.html.erb index ee97b2f2..bed63361 100644 --- a/app/views/providers/_form.html.erb +++ b/app/views/providers/_form.html.erb @@ -11,7 +11,7 @@ * <% end %> <%= form.text_field :name, - placeholder: "Enter provider name (e.g., Johns Hopkins, Mayo Clinic)", + placeholder: "e.g., Johns Hopkins, Mayo Clinic", autofocus: true, class: "input-field bg-gray-50" %>

The official name of the healthcare provider or organization.

@@ -29,6 +29,19 @@

The type or category of healthcare provider.

+ + <% unless @provider&.topics.any? %> +
+ <%= 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" %> +

The prefix to use for this provider's uploads.

+
+ <% end %> +
<%= form.label :region, class: "input-label" do %> diff --git a/spec/views/providers/edit.html.erb_spec.rb b/spec/views/providers/edit.html.erb_spec.rb index fc4bf133..6a7b972e 100644 --- a/spec/views/providers/edit.html.erb_spec.rb +++ b/spec/views/providers/edit.html.erb_spec.rb @@ -16,4 +16,26 @@ assert_select "input[type='submit'][value='Update Provider']" end end + + context "when the provider has associated topics" do + before { create(:topic, provider: provider) } + + it "does not have 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]", false + end + 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 diff --git a/spec/views/providers/new.html.erb_spec.rb b/spec/views/providers/new.html.erb_spec.rb index 0088e81e..ab48436a 100644 --- a/spec/views/providers/new.html.erb_spec.rb +++ b/spec/views/providers/new.html.erb_spec.rb @@ -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