Skip to content

Commit

Permalink
Added support for default values in parameter select (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdejong authored Sep 29, 2022
1 parent 66b42b7 commit a344f17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/chart/ParameterSelectionChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const NeoParameterSelectionChart = (props: ChartProps) => {
// In case the components gets (re)loaded with a different/non-existing selected parameter, set the text to the current global parameter value.
if (query && value != currentValue && currentValue != inputText) {
setValue(currentValue);
setInputText(currentValue);
setInputText(value == defaultValue ? "" : currentValue);
setExtraRecords([]);
}

Expand All @@ -63,23 +63,22 @@ const NeoParameterSelectionChart = (props: ChartProps) => {
const settings = (props.settings) ? props.settings : {};
const helperText = settings.helperText;
const clearParameterOnFieldClear = settings.clearParameterOnFieldClear;


const defaultValue = props.settings && props.settings["defaultValue"] && props.settings["defaultValue"].length > 0 ? props.settings["defaultValue"] : "";
return <div>
{type == "Free Text" ?
<div style={{ width: "100%" }}>
<NeoField
key={"freetext"}
label={helperText ? helperText : label + " " + property}
defaultValue={""}
defaultValue={defaultValue}
value={value}
variant="outlined"
placeholder={"Enter text here..."}
style={{ maxWidth: "calc(100% - 30px)", marginLeft: "15px", marginTop: "5px", width: "calc(100% - 80px)" }}
onChange={(newValue) => {
// TODO: i want this to be a proper wait instead of triggering on the first character.
if (newValue == null && clearParameterOnFieldClear) {
setValue("");
setValue(defaultValue);
} else {
setValue(newValue);
}
Expand Down Expand Up @@ -108,6 +107,8 @@ const NeoParameterSelectionChart = (props: ChartProps) => {
}
if (newValue == null && clearParameterOnFieldClear) {
props.setGlobalParameter(parameter, undefined);
} else if (newValue == null) {
props.setGlobalParameter(parameter, defaultValue);
} else {
props.setGlobalParameter(parameter, newValue);
}
Expand Down
5 changes: 5 additions & 0 deletions src/config/ReportConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,11 @@ export const REPORT_TYPES = {
values: [true, false],
default: true
},
"defaultValue": {
label: "Default Value (Override)",
type: SELECTION_TYPES.TEXT,
default: ""
},
"clearParameterOnFieldClear": {
label: "Clear Parameter on Field Reset",
type: SELECTION_TYPES.LIST,
Expand Down

0 comments on commit a344f17

Please sign in to comment.