From e47b1ec27936065ea8010a19bd585bddc3fb4aed Mon Sep 17 00:00:00 2001 From: Paul Hodgson Date: Tue, 13 Oct 2020 13:21:37 +0100 Subject: [PATCH] [PH][MIBM-133] fix enum radios (#51) --- .../hmrc/merchandiseinbaggagefrontend/model/Enum.scala | 9 +++------ .../model/core/GoodsDestination.scala | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/Enum.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/Enum.scala index 9951147c3..f1d358abd 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/Enum.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/Enum.scala @@ -23,7 +23,6 @@ import play.api.libs.json._ import uk.gov.hmrc.govukfrontend.views.Aliases.Text import uk.gov.hmrc.govukfrontend.views.viewmodels.hint.Hint import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.RadioItem -import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestinations.baseMessageKey trait Enum[A <: EnumEntry] extends PlayEnum[A] { val baseMessageKey: String @@ -44,13 +43,12 @@ object EnumFormat { trait EnumEntryRadioItemSupport { this: EnumEntry => - protected val baseMessageKeyForEntry: String = s"$baseMessageKey.$entryName" protected val maybeHintMessageKey: Option[String] = None - def radioItem(form: Form[_])(implicit messages: Messages): RadioItem = + def radioItem(form: Form[_], baseMessageKey: String)(implicit messages: Messages): RadioItem = RadioItem( value = Some(entryName), - content = Text(messages(s"$baseMessageKeyForEntry")), + content = Text(messages(s"$baseMessageKey.$entryName")), checked = form("value").value.contains(entryName), hint = maybeHintMessageKey.flatMap { messageKey => Some(Hint(content = Text(messages(messageKey)))) @@ -60,9 +58,8 @@ trait EnumEntryRadioItemSupport { trait RadioSupport[A <: EnumEntry with EnumEntryRadioItemSupport] { this: Enum[A] => - def options(form: Form[_])(implicit messages: Messages): Seq[RadioItem] = values.map { value => - value.radioItem(form)(messages) + value.radioItem(form, baseMessageKey)(messages) } } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/GoodsDestination.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/GoodsDestination.scala index fa03ea428..a1be9d16f 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/GoodsDestination.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/GoodsDestination.scala @@ -35,6 +35,6 @@ object GoodsDestinations extends Enum[GoodsDestination] with RadioSupport[GoodsD case object NorthernIreland extends GoodsDestination case object GreatBritain extends GoodsDestination { - override val maybeHintMessageKey: Option[String] = Some(s"$baseMessageKeyForEntry.hint") + override val maybeHintMessageKey: Option[String] = Some(s"$baseMessageKey.$entryName.hint") } }