Skip to content

Commit

Permalink
[PH][MIBM-133] fix enum radios (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHodgson authored Oct 13, 2020
1 parent 3ff32a9 commit e47b1ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/Enum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))
Expand All @@ -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)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit e47b1ec

Please sign in to comment.