Skip to content

Use child object from sessionStorage JSON as defaultValue in Editor #2218

@MattiasSp

Description

@MattiasSp

Description
When using an attribute with a defaultValue set in the editor, e g

[
  {
    "name": "skapad_av",
    "title": "Skapad av: ",
    "type": "hidden",
    "defaultValue": {
      "type": "sessionStorage",
      "key": "loggedInUser",
      "updateOnEdit": false
    }
  }
]

the value in the session storage variable is used as-is. Often, e g when using the OIDC-plugin, the value of interest is actually a child object within a JSON block.

It would be great if there was a possibility to specify what specific object within a JSON parent object is supposed to be used as the default value.

Describe the solution you'd like
A new defaultValue config parameter: keyType.

By default, the current behaviour is kept - getting the variable that matches key exactly. If set to "json_path", a child object can be referenced with simple dot notation, e g "key": "oidc_user.displayname" in the case of the OIDC-plugin.

[
  {
    "name": "skapad_av",
    "title": "Skapad av: ",
    "type": "hidden",
    "defaultValue": {
      "type": "sessionStorage",
      "key": "oidc_user.displayname",
      "keyType": "json_path",
      "updateOnEdit": false
    }
  }
]

Describe alternatives you've considered
Handling some sort of general or JSON-specific attribute transformation before an attribute is applied could be useful sometimes but would be a more complex solution.

EDIT: Updated the proposed solution to reflect the discussion on the last developer meeting.

Metadata

Metadata

Assignees

Labels

PR acceptedAnyone can write a PR for this issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions