Skip to content
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

Adding support for default values in parameter select reports #200

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1182,6 +1182,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