Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Simplify Option[Seq[_]] -> Seq[_] once validation for arrays is done for govuk-frontend #32

Open
dabd opened this issue Nov 7, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@dabd
Copy link
Contributor

dabd commented Nov 7, 2019

Once this issue is resolved alphagov/govuk-frontend#1618 (there is branch with a resolution here https://github.com/dorightdigital/govuk-frontend/commits/identify-empty-arrays), we can simplify components that take lists of things Option[Seq[_]] into Seq[_]. This type was introduced to map as a Scala type Javascript's undefined and empty arrays which are respectively falsy and truthy values.
Ex:

The input to govukDateInput becomes:

items: Seq[InputItem]      = Nil,

instead of

items: Option[Seq[InputItem]]      = None,

And the template:

@dateInputItems = @{
  items.getOrElse(Seq(
    InputItem(name = "day", classes = "govuk-input--width-2"),
    InputItem(name = "month", classes = "govuk-input--width-2"),
    InputItem(name = "year", classes = "govuk-input--width-4")
  ))
}

can become

@dateInputItems = @{
  if (items.nonEmpty) items
  else
    (Seq(
      InputItem(name = "day", classes = "govuk-input--width-2"),
      InputItem(name = "month", classes = "govuk-input--width-2"),
      InputItem(name = "year", classes = "govuk-input--width-4")
    ))
}

The same changes should be applied to all the affected components and this will be a breaking change.

@dabd dabd added the enhancement New feature or request label Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant