From 292209aa47918018e0c8fae6fb5dac853e6114b4 Mon Sep 17 00:00:00 2001 From: Chris Gannon Date: Fri, 13 Oct 2023 13:50:45 +0100 Subject: [PATCH 1/3] remove editable links from submitted notifications --- .../notifications_helper.rb | 213 ++++--------- .../notifications_helper_spec.rb | 282 +++++++++++++----- 2 files changed, 262 insertions(+), 233 deletions(-) diff --git a/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb b/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb index d88b3682ce..d47a817a59 100644 --- a/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb +++ b/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb @@ -26,110 +26,77 @@ def notification_summary_references_rows(notification) ].compact end + def notification_step_action(notification, step) + return {} unless notification.editable? + + { + items: [ + { + href: responsible_person_notification_product_path(notification.responsible_person, notification, step), + text: "Edit", + visuallyHiddenText: step&.to_s&.humanize&.downcase, + classes: ["govuk-link--no-visited-state"], + }, + ], + } + end + + def notification_product_kit_step_action(notification) + return {} unless notification.editable? + + { + items: [ + { + href: new_responsible_person_notification_product_kit_path(notification.responsible_person, notification), + text: "Edit", + visuallyHiddenText: "mixed items", + classes: ["govuk-link--no-visited-state"], + }, + ], + } + end + def notification_summary_product_rows(notification) [ { key: { text: "Product name" }, value: { text: notification.product_name }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :add_product_name), - text: "Edit", - visuallyHiddenText: "product name", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_step_action(notification, :add_product_name), }, if notification.industry_reference.present? { key: { text: "Internal reference number" }, value: { text: notification.industry_reference }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :add_internal_reference), - text: "Edit", - visuallyHiddenText: "internal reference", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_step_action(notification, :add_internal_reference), } end, unless notification.under_three_years.nil? { key: { text: "For children under 3" }, value: { text: notification.under_three_years ? "Yes" : "No" }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :under_three_years), - text: "Edit", - visuallyHiddenText: "under three years", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_step_action(notification, :under_three_years), } end, { key: { text: "Number of items" }, value: { text: notification.components.length }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :single_or_multi_component), - text: "Edit", - visuallyHiddenText: "number of items", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_step_action(notification, :single_or_multi_component), }, { key: { text: "Shades" }, value: { html: display_shades(notification) }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :shades), - text: "Edit", - visuallyHiddenText: "shades", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_step_action(notification, :shades), }, { key: { text: "Label" }, value: { html: render("notifications/product_details_label_images", notification:) }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :add_product_image), - text: "Edit", - visuallyHiddenText: "product image", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_step_action(notification, :add_product_image), }, { key: { text: "Are the items mixed?" }, value: { text: notification.components_are_mixed ? "Yes" : "No" }, - actions: { - items: [ - { - href: new_responsible_person_notification_product_kit_path(notification.responsible_person, notification), - text: "Edit", - visuallyHiddenText: "mixed items", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_product_kit_step_action(notification), }, if can_view_product_ingredients? && notification.ph_min_value.present? { @@ -190,6 +157,21 @@ def notification_summary_search_result_rows(notification) ].compact end + def notification_summary_component_action(component, step) + return {} unless component.notification.editable? + + { + items: [ + { + href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, step), + text: "Edit", + visuallyHiddenText: "#{component.name} category", + classes: ["govuk-link--no-visited-state"], + }, + ], + } + end + def notification_summary_component_rows(component, include_shades: true) cmrs = component.cmrs nano_materials = component.nano_materials @@ -202,16 +184,7 @@ def notification_summary_component_rows(component, include_shades: true) entities_list: component.shades, list_classes: "", list_item_classes: "") }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :number_of_shades), - text: "Edit", - visuallyHiddenText: "#{component.name} category", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_summary_component_action(component, :number_of_shades), } end, { @@ -233,16 +206,7 @@ def notification_summary_component_rows(component, include_shades: true) entities_list: nano_materials_details(nano_materials), list_classes: "", list_item_classes: "") }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :select_nanomaterials), - text: "Edit", - visuallyHiddenText: "select nanomaterials", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_summary_component_action(component, :select_nanomaterials), }, if nano_materials.non_standard.any? { @@ -257,47 +221,20 @@ def notification_summary_component_rows(component, include_shades: true) { key: { text: "Application instruction" }, value: { text: get_exposure_routes_names(component.exposure_routes) }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :add_exposure_routes), - text: "Edit", - visuallyHiddenText: "exposure root", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_summary_component_action(component, :add_exposure_routes), } end, if nano_materials.present? { key: { text: "Exposure condition" }, value: { text: get_exposure_condition_name(component.exposure_condition) }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :add_exposure_condition), - text: "Edit", - visuallyHiddenText: "exposure condition", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_summary_component_action(component, :add_exposure_condition), } end, { key: { text: "Category of product" }, value: { text: get_category_name(component.root_category) }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :select_root_category), - text: "Edit", - visuallyHiddenText: "#{component.name} category", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_summary_component_action(component, :select_root_category), }, { key: { text: "Category of #{get_category_name(component.root_category)&.downcase&.singularize}" }, @@ -310,48 +247,20 @@ def notification_summary_component_rows(component, include_shades: true) { key: { text: "Physical form" }, value: { text: get_physical_form_name(component.physical_form) }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :add_physical_form), - text: "Edit", - visuallyHiddenText: "physical form", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, - + actions: notification_summary_component_action(component, :add_physical_form), }, if can_view_product_ingredients? { key: { text: "Special applicator" }, value: { text: component.special_applicator.present? ? "Yes" : "No" }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :contains_special_applicator), - text: "Edit", - visuallyHiddenText: "contains special applicator", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_summary_component_action(component, :contains_special_applicator), } end, if can_view_product_ingredients? && component.special_applicator.present? { key: { text: "Applicator type" }, value: { text: component_special_applicator_name(component) }, - actions: { - items: [ - { - href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :select_special_applicator_type), - text: "Edit", - visuallyHiddenText: "select special applicator type", - classes: ["govuk-link--no-visited-state"], - }, - ], - }, + actions: notification_summary_component_action(component, :select_special_applicator_type), } end, if can_view_product_ingredients? && component.acute_poisoning_info.present? @@ -535,7 +444,7 @@ def ph_row_text_value(component) end def ph_row_actions(component) - return {} unless component.ph_required? + return {} if !component.ph_required? || !component.notification.editable? { items: [ diff --git a/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb b/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb index f347d9c3b8..e0b4d3c611 100644 --- a/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb +++ b/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb @@ -112,13 +112,13 @@ let(:notification) do build_stubbed(:notification, - :registered, + trait, reference_number: "60162968", product_name: "Product Test", industry_reference: "CPNP-3874065", cpnp_reference: "3796528", cpnp_notification_date: Time.zone.parse("2019-10-04T17:10Z"), - notification_complete_at: Time.zone.parse("2021-05-03T12:08Z")) + notification_complete_at:) end let(:user) { instance_double(SubmitUser, can_view_product_ingredients?: true) } @@ -130,112 +130,232 @@ allow(helper).to receive_messages(render: "", current_user: user) end - it "contains the product name" do - expect(summary_product_rows).to include(hash_including({ key: { text: "Product name" }, value: { text: "Product Test" }, actions: { items: [hash_including({ href: "#{product_href}/add_product_name" })] } })) - end - - it "contains the industry reference number" do - expect(summary_product_rows).to include(hash_including({ key: { text: "Internal reference number" }, value: { text: "CPNP-3874065" }, actions: { items: [hash_including({ href: "#{product_href}/add_internal_reference" })] } })) - end - - it "contains the number of components associated with the notification" do - expect(summary_product_rows).to include(hash_including({ key: { text: "Number of items" }, value: { text: 0 }, actions: { items: [hash_including({ href: "#{product_href}/single_or_multi_component" })] } })) - end + context "for a completed notification" do + let(:notification_complete_at) { Time.zone.parse("2021-10-04T17:10Z") } + let(:trait) { :registered } - it "contains notification shades html" do - allow(helper).to receive(:display_shades).and_return("Shades info") - expect(summary_product_rows).to include(hash_including({ key: { text: "Shades" }, value: { html: "Shades info" }, actions: { items: [hash_including({ href: "#{product_href}/shades" })] } })) - end + it "contains the product name" do + expect(summary_product_rows).to include(hash_including({ key: { text: "Product name" }, value: { text: "Product Test" } })) + end - it "contains info indicating when the notification components are mixed" do - notification.components_are_mixed = true - expect(summary_product_rows).to include(hash_including({ key: { text: "Are the items mixed?" }, value: { text: "Yes" }, actions: { items: [hash_including({ href: "#{notification_href}/product_kit/new" })] } })) - end + it "contains the industry reference number" do + expect(summary_product_rows).to include(hash_including({ key: { text: "Internal reference number" }, value: { text: "CPNP-3874065" } })) + end - it "contains info indicating when the notification components are not mixed" do - notification.components_are_mixed = false - expect(summary_product_rows).to include(hash_including({ key: { text: "Are the items mixed?" }, value: { text: "No" }, actions: { items: [hash_including({ href: "#{notification_href}/product_kit/new" })] } })) - end + it "contains the number of components associated with the notification" do + expect(summary_product_rows).to include(hash_including({ key: { text: "Number of items" }, value: { text: 0 } })) + end - describe "for children under 3" do - it "not included when not available for the notification" do - notification.under_three_years = nil - expect(summary_product_rows).not_to include(hash_including(key: { text: "For children under 3" })) + it "contains notification shades html" do + allow(helper).to receive(:display_shades).and_return("Shades info") + expect(summary_product_rows).to include(hash_including({ key: { text: "Shades" }, value: { html: "Shades info" } })) end - it "included when notification product is for children under 3" do - notification.under_three_years = true - expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "Yes" }, actions: { items: [hash_including({ href: "#{product_href}/under_three_years" })] } })) + it "contains info indicating when the notification components are mixed" do + notification.components_are_mixed = true + expect(summary_product_rows).to include(hash_including({ key: { text: "Are the items mixed?" }, value: { text: "Yes" } })) end - it "included when notification product is not for children under 3" do - notification.under_three_years = false - expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "No" }, actions: { items: [hash_including({ href: "#{product_href}/under_three_years" })] } })) + it "contains info indicating when the notification components are not mixed" do + notification.components_are_mixed = false + expect(summary_product_rows).to include(hash_including({ key: { text: "Are the items mixed?" }, value: { text: "No" } })) end - end - describe "PH information" do - context "when current user can view the product ingredients" do - before { allow(user).to receive(:can_view_product_ingredients?).and_return(true) } + describe "for children under 3" do + it "not included when not available for the notification" do + notification.under_three_years = nil + expect(summary_product_rows).not_to include(hash_including(key: { text: "For children under 3" })) + end - it "contains the product PH minimum value when present" do - notification.ph_min_value = 0.3 - expect(summary_product_rows).to include( - { key: { html: "Minimum pH value" }, value: { text: 0.3 } }, - ) + it "included when notification product is for children under 3" do + notification.under_three_years = true + expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "Yes" } })) end - it "does not contain the product PH minimum value when not present" do - notification.ph_min_value = nil - expect(summary_product_rows).not_to include( - hash_including(key: { html: "Minimum pH value" }), - ) + it "included when notification product is not for children under 3" do + notification.under_three_years = false + expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "No" } })) end + end - it "contains the product PH maximum value when present" do - notification.ph_max_value = 0.7 - expect(summary_product_rows).to include( - { key: { html: "Maximum pH value" }, value: { text: 0.7 } }, - ) + describe "PH information" do + context "when current user can view the product ingredients" do + before { allow(user).to receive(:can_view_product_ingredients?).and_return(true) } + + it "contains the product PH minimum value when present" do + notification.ph_min_value = 0.3 + expect(summary_product_rows).to include( + { key: { html: "Minimum pH value" }, value: { text: 0.3 } }, + ) + end + + it "does not contain the product PH minimum value when not present" do + notification.ph_min_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Minimum pH value" }), + ) + end + + it "contains the product PH maximum value when present" do + notification.ph_max_value = 0.7 + expect(summary_product_rows).to include( + { key: { html: "Maximum pH value" }, value: { text: 0.7 } }, + ) + end + + it "does not contain the product PH maximum value when not present" do + notification.ph_max_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Maximum pH value" }), + ) + end end - it "does not contain the product PH maximum value when not present" do - notification.ph_max_value = nil - expect(summary_product_rows).not_to include( - hash_including(key: { html: "Maximum pH value" }), - ) + context "when the current user cannot view the product ingredients" do + before { allow(user).to receive(:can_view_product_ingredients?).and_return(false) } + + it "does not contain the product PH minimum value even when is available" do + notification.ph_min_value = 0.3 + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Minimum pH value" }), + ) + end + + it "does not contain the product PH minimum value when not available" do + notification.ph_min_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Minimum pH value" }), + ) + end + + it "does not contain the product PH maximum value even when is available" do + notification.ph_max_value = 0.7 + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Maximum pH value" }), + ) + end + + it "does not contain the product PH maximum value when not available" do + notification.ph_max_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Maximum pH value" }), + ) + end end end + end + + context "for a draft notification" do + let(:notification_complete_at) { nil } + let(:trait) { :draft_complete } + + it "contains the product name" do + expect(summary_product_rows).to include(hash_including({ key: { text: "Product name" }, value: { text: "Product Test" }, actions: { items: [hash_including({ href: "#{product_href}/add_product_name" })] } })) + end + + it "contains the industry reference number" do + expect(summary_product_rows).to include(hash_including({ key: { text: "Internal reference number" }, value: { text: "CPNP-3874065" }, actions: { items: [hash_including({ href: "#{product_href}/add_internal_reference" })] } })) + end + + it "contains the number of components associated with the notification" do + expect(summary_product_rows).to include(hash_including({ key: { text: "Number of items" }, value: { text: 0 }, actions: { items: [hash_including({ href: "#{product_href}/single_or_multi_component" })] } })) + end - context "when the current user cannot view the product ingredients" do - before { allow(user).to receive(:can_view_product_ingredients?).and_return(false) } + it "contains notification shades html" do + allow(helper).to receive(:display_shades).and_return("Shades info") + expect(summary_product_rows).to include(hash_including({ key: { text: "Shades" }, value: { html: "Shades info" }, actions: { items: [hash_including({ href: "#{product_href}/shades" })] } })) + end + + it "contains info indicating when the notification components are mixed" do + notification.components_are_mixed = true + expect(summary_product_rows).to include(hash_including({ key: { text: "Are the items mixed?" }, value: { text: "Yes" }, actions: { items: [hash_including({ href: "#{notification_href}/product_kit/new" })] } })) + end + + it "contains info indicating when the notification components are not mixed" do + notification.components_are_mixed = false + expect(summary_product_rows).to include(hash_including({ key: { text: "Are the items mixed?" }, value: { text: "No" }, actions: { items: [hash_including({ href: "#{notification_href}/product_kit/new" })] } })) + end + + describe "for children under 3" do + it "not included when not available for the notification" do + notification.under_three_years = nil + expect(summary_product_rows).not_to include(hash_including(key: { text: "For children under 3" })) + end - it "does not contain the product PH minimum value even when is available" do - notification.ph_min_value = 0.3 - expect(summary_product_rows).not_to include( - hash_including(key: { html: "Minimum pH value" }), - ) + it "included when notification product is for children under 3" do + notification.under_three_years = true + expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "Yes" }, actions: { items: [hash_including({ href: "#{product_href}/under_three_years" })] } })) end - it "does not contain the product PH minimum value when not available" do - notification.ph_min_value = nil - expect(summary_product_rows).not_to include( - hash_including(key: { html: "Minimum pH value" }), - ) + it "included when notification product is not for children under 3" do + notification.under_three_years = false + expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "No" }, actions: { items: [hash_including({ href: "#{product_href}/under_three_years" })] } })) end + end - it "does not contain the product PH maximum value even when is available" do - notification.ph_max_value = 0.7 - expect(summary_product_rows).not_to include( - hash_including(key: { html: "Maximum pH value" }), - ) + describe "PH information" do + context "when current user can view the product ingredients" do + before { allow(user).to receive(:can_view_product_ingredients?).and_return(true) } + + it "contains the product PH minimum value when present" do + notification.ph_min_value = 0.3 + expect(summary_product_rows).to include( + { key: { html: "Minimum pH value" }, value: { text: 0.3 } }, + ) + end + + it "does not contain the product PH minimum value when not present" do + notification.ph_min_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Minimum pH value" }), + ) + end + + it "contains the product PH maximum value when present" do + notification.ph_max_value = 0.7 + expect(summary_product_rows).to include( + { key: { html: "Maximum pH value" }, value: { text: 0.7 } }, + ) + end + + it "does not contain the product PH maximum value when not present" do + notification.ph_max_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Maximum pH value" }), + ) + end end - it "does not contain the product PH maximum value when not available" do - notification.ph_max_value = nil - expect(summary_product_rows).not_to include( - hash_including(key: { html: "Maximum pH value" }), - ) + context "when the current user cannot view the product ingredients" do + before { allow(user).to receive(:can_view_product_ingredients?).and_return(false) } + + it "does not contain the product PH minimum value even when is available" do + notification.ph_min_value = 0.3 + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Minimum pH value" }), + ) + end + + it "does not contain the product PH minimum value when not available" do + notification.ph_min_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Minimum pH value" }), + ) + end + + it "does not contain the product PH maximum value even when is available" do + notification.ph_max_value = 0.7 + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Maximum pH value" }), + ) + end + + it "does not contain the product PH maximum value when not available" do + notification.ph_max_value = nil + expect(summary_product_rows).not_to include( + hash_including(key: { html: "Maximum pH value" }), + ) + end end end end From 3dd76ac1f884ed96c76ecb5dda8c94972c0e4651 Mon Sep 17 00:00:00 2001 From: Chris Gannon Date: Fri, 13 Oct 2023 13:57:30 +0100 Subject: [PATCH 2/3] fix wording for context in specs --- .../helpers/responsible_persons/notifications_helper_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb b/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb index e0b4d3c611..943ba2e31b 100644 --- a/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb +++ b/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb @@ -130,7 +130,7 @@ allow(helper).to receive_messages(render: "", current_user: user) end - context "for a completed notification" do + context "with a completed notification" do let(:notification_complete_at) { Time.zone.parse("2021-10-04T17:10Z") } let(:trait) { :registered } @@ -245,7 +245,7 @@ end end - context "for a draft notification" do + context "with a draft notification" do let(:notification_complete_at) { nil } let(:trait) { :draft_complete } From fa4967332169d8f4019510f911471a813d6e4286 Mon Sep 17 00:00:00 2001 From: Chris Gannon Date: Tue, 17 Oct 2023 12:43:57 +0100 Subject: [PATCH 3/3] remove editable fields for ingredients --- .../notifications/_product_details.html.erb | 72 +++++++++++-------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/cosmetics-web/app/views/responsible_persons/notifications/_product_details.html.erb b/cosmetics-web/app/views/responsible_persons/notifications/_product_details.html.erb index 98f93513ab..c657312a83 100644 --- a/cosmetics-web/app/views/responsible_persons/notifications/_product_details.html.erb +++ b/cosmetics-web/app/views/responsible_persons/notifications/_product_details.html.erb @@ -41,36 +41,50 @@ value: { text: get_notification_type_name(component.notification_type) }, }, if component.predefined? - { - key: { text: "Frame formulation" }, - value: { text: get_frame_formulation_name(component.frame_formulation) }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :add_product_image), - text: "Edit", - visuallyHiddenText: "product image", - classes: ["govuk-link--no-visited-state"] - } - ] - }, - } + if component.notification.editable? + { + key: { text: "Frame formulation" }, + value: { text: get_frame_formulation_name(component.frame_formulation) }, + actions: { + items: [ + { + href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :select_frame_formulation), + text: "Edit", + visuallyHiddenText: "frame formulation", + classes: ["govuk-link--no-visited-state"] + } + ] + }, + } + else + { + key: { text: "Frame formulation" }, + value: { text: get_frame_formulation_name(component.frame_formulation) }, + } + end elsif component.formulation_file.attached? - { - key: { text: "Formulation" }, - value: { html: render("notifications/component_details_formulation_ingredients", - component: component) }, - actions: { - items: [ - { - href: responsible_person_notification_product_path(notification.responsible_person, notification, :add_product_image), - text: "Edit", - visuallyHiddenText: "product image", - classes: ["govuk-link--no-visited-state"] - } - ] - }, - } + if component.notification.editable? + { + key: { text: "Formulation" }, + value: { html: render("notifications/component_details_formulation_ingredients", + component: component) }, + actions: { + items: [ + { + href: responsible_person_notification_component_build_path(component.notification.responsible_person, component.notification, component, :upload_ingredients_file), + text: "Edit", + visuallyHiddenText: "formulation", + classes: ["govuk-link--no-visited-state"] + } + ] + }, + } + else + { + key: { text: "Formulation" }, + value: { html: render("notifications/component_details_formulation_ingredients", component: component) }, + } + end end ].compact ) %>