Altinn / Altinn/app-frontend-react

Properly support `null | type` values in options

Open
#1,790 4 comments 0 reactions 0 assignees View on GitHub
kind/feature-request
Dominant language
TypeScript
Stars
21
Forks
33
Avg merge
6d 23h
Merged PRs (30d)
3

Description

After JsonPatch support was implemented, our data models got support for non-string values, along with `null`, `number` and `boolean`. After support for non-string values in options was implemented in the backend (https://github.com/Altinn/app-lib-dotnet/issues/413), some issues have been uncovered:

**Support for `oneOf`/`anyOf` in data model schema**
Our current solution that resolves data model bindings in the JsonSchema to get the 'real' data type, and validate it, seems to not like more complex types, like the following:
```json
{
"Months": {
"oneOf": [
{ "type": "integer" },
{ "const": null }
]
}
}
```
When a component is bound to `Months` in this data model, it fails to render, saying the bound type is unsupported. Investigate what Studio creates, and support variants of this and `{ "type": "null" }`.

**Cast types with option-value restrictions**
Currently, we cast all options to strings in the `castOptionsToStrings()` function, so all option-components can assume their values are strings. However, there's a difference between `null` and `"null"`, so we should take care not to lose that distinction when casting the values back to their *real* counterparts. In `src/features/formData/convertData.ts` the form data system will try to cast the given value back to something that 'fits' in the data model, and it should possibly be the responsibility of `useGetOptions()` to cast option values before sending them to the form data system.

Contributor guide

Open the contributing guide

Research direction

Start by investigating how Studio-created schemas with oneOf, anyOf, and null types are resolved for component bindings. Then trace castOptionsToStrings() and useGetOptions(), including src/features/formData/convertData.ts, to preserve the distinction between null and "null". Done means supported nullable option types render and option values are cast correctly for the data model.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.