Skip to content

Commit

Permalink
feat(TextResources): add support for defaultValue in variables in tex… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelrss authored Sep 14, 2023
1 parent b2db236 commit 465a036
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions schemas/json/text-resources/text-resources.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
{ "$ref": "#/definitions/dataSource-instanceContext" },
{ "$ref": "#/definitions/dataSource-applicationSettings" }
]
},
"defaultValue": {
"type": "string",
"title": "Default value of a variable",
"description": "The default value that you want to display if there is no value in the data model for the variable."
}
},
"required": [
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/useLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ function replaceVariables(text: string, variables: IVariable[], dataSources: Tex
value = applicationSettings && variable.key in applicationSettings ? applicationSettings[variable.key] : value;
}

if (value === variable.key) {
/*
By returning value if variable.defaultValue is null, we ensure
that we are returning the dataModel path string instead of blank
value. If app developers want to return blank value, they should
set defaultValue to a blank space.
*/
value = variable.defaultValue || value;
}

out = out.replaceAll(`{${idx}}`, value);
}

Expand Down
1 change: 1 addition & 0 deletions src/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export interface ITextResource {
export interface IVariable {
key: string;
dataSource: string;
defaultValue?: string;
}

export interface IAttachmentGrouping {
Expand Down

0 comments on commit 465a036

Please sign in to comment.