Skip to content

Variables in text. Empty variables in will display path to datasource. #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tracked by #339 ...
tronberg opened this issue Dec 15, 2022 · 5 comments
Closed
Tracked by #339 ...
Labels
fe-v4 Issues to be solved before v4 goes gold kind/breaking-change Issue/pull request containing a breaking change kind/bug Something isn't working org/dsb org/ssb Issues relevant for Statistisk sentralbyrå.

Comments

@tronberg
Copy link

Description of the bug

If a variable's datasource is empty, the path to the datasource will be displayed.

ra0182-01-01

ra0182-02-02

Steps To Reproduce

Clone and run app ra0182.

Additional Information

No response

@tronberg tronberg added the kind/bug Something isn't working label Dec 15, 2022
@nkylstad nkylstad transferred this issue from Altinn/altinn-studio Dec 15, 2022
@FinnurO FinnurO added the org/ssb Issues relevant for Statistisk sentralbyrå. label Dec 16, 2022
@olemartinorg olemartinorg added the kind/breaking-change Issue/pull request containing a breaking change label Dec 19, 2022
@olemartinorg
Copy link
Contributor

olemartinorg commented Dec 19, 2022

In the long term, we hope to replace these variables with dynamic expressions. With expressions, it's possible to control what gets displayed if the value is empty. Right now (even in your screenshot example), there is no proper default. Displaying an empty string is a bit better - but it's still not optimal. We could, of course, figure out that the field is formatted as a number (or uses a number type in the data model) and assume 0 is a good default - but at that point, implementing expressions instead is probably easier.

You can fix this in your app at when using the latest main (which will be released as a proper version today or tomorrow), by controlling this using expressions in the text resource bindings themselves.

@olemartinorg
Copy link
Contributor

As an easier quick-fix, I believe we should support a default parameter (in plain text, or possibly other text keys - if easy to implement).

{
  "id": "entityInfoBusinessId",
  "value": "Business ID: {0}",
  "variables": [
    {
      "key": "EntityInfo.BusinessId",
      "dataSource": "dataModel.default",
      "default": "(missing value)" // <--------- New parameter
    }
  ]
},

This might have consequences for Studio, so we should make sure Studio doesn't clean these up for us. It's also relevant for the possible future language file format, where references to the data model will change at some point (@mjulstein @mijohansen @TomasEng @andrealouisestanderen).

@FinnurO
Copy link

FinnurO commented Feb 15, 2023

Kunne man brukt shortname brukt i validering, eller samme mønster, for å sette inn default tekst? Eller bruke teksten på feltet man skal hente verdien fra? @olemartinorg

@olemartinorg
Copy link
Contributor

olemartinorg commented Feb 16, 2023

Tekstnøklene har ikke en 1-1-relasjon med komponentene, så det blir ikke naturlig å putte shortName eller lignende som default-verdi for et oppslag som feiler i disse variablene. Med det sagt, vi har en god workaround for dette problemet på plass nå, som er mer fleksibel enn det jeg foreslo 13. januar.

Vi støtter nå dynamiske uttrykk på alle verdiene i textResourceBindings. Så for å gjenbruke eksempelet vi har over:

[
  {
    "id": "entityInfoBusinessId",
    "value": "Business ID: {0}",
    "variables": [
      {
        "key": "EntityInfo.BusinessId",
        "dataSource": "dataModel.default"
      }
    ]
  },
  {
    "id": "entityInfoBusinessIdNotFound" // <--- Lagt til
    "value": "Business ID not found",
  }
]

Og i layout-fila:

{
  "id": "abc123",
  "type": "Header",
  "textResourceBindings": {
    "title": [
      "if"
      ["equals", ["dataModel", "EntityInfo.BusinessId"], null]
      "entityInfoBusinessIdNotFound",
      "else",
      "entityInfoBusinessId"
    ]
  }
}

Med andre ord, man kan nå bruke uttrykk for å bytte mellom forskjellige tekstressurser, avhengig av f.eks. verdien som ligger i datamodellen. En manglende verdi vil være lik null i uttrykk-språket.

@olemartinorg olemartinorg moved this to 🧪 Test in Team Apps Oct 24, 2023
@HanneLauritsen1967 HanneLauritsen1967 moved this from 🧪 Test to ✅ Done in Team Apps Oct 25, 2023
@RonnyB71 RonnyB71 mentioned this issue Nov 22, 2023
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fe-v4 Issues to be solved before v4 goes gold kind/breaking-change Issue/pull request containing a breaking change kind/bug Something isn't working org/dsb org/ssb Issues relevant for Statistisk sentralbyrå.
Projects
Archived in project
Development

No branches or pull requests

4 participants