Skip to content

Commit

Permalink
Added parameter select setting for autopopulating first selector value (
Browse files Browse the repository at this point in the history
#746)

* Added setting for autoselecting first parameter select value

* Sorting returned auto selector values

* Selecting the first value of the suggestions correctly
  • Loading branch information
nielsdejong authored Jan 10, 2024
1 parent ac8eda1 commit f708147
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/chart/parameter/component/NodePropertyParameterSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const NodePropertyParameterSelectComponent = (props: ParameterSelectProps) => {
const helperText = props.settings && props.settings.helperText ? props.settings.helperText : '';
const clearParameterOnFieldClear =
props.settings && props.settings.clearParameterOnFieldClear ? props.settings.clearParameterOnFieldClear : false;
const autoSelectFirstValue =
props.settings && props.settings.autoSelectFirstValue ? props.settings.autoSelectFirstValue : false;

// index of the display value in the resulting extra records retrieved by the component when the user types. equals '1' for NeoDash 2.2.2 and later.
const displayValueRowIndex = props.compatibilityMode
Expand Down Expand Up @@ -190,6 +192,19 @@ const NodePropertyParameterSelectComponent = (props: ParameterSelectProps) => {
debouncedQueryCallback(props.query, { input: `${inputDisplayText}`, ...allParameters }, setExtraRecords);
}
}}
onBlur={() => {
// If the user loses focus of the selector, and nothing is selected
// We may want to auto-select the first value produced by the selector query (`autoSelectFirstValue == true`)
if (autoSelectFirstValue && paramValueDisplayLocal == '') {
debouncedQueryCallback(props.query, { input: '', ...allParameters }, (records) => {
if (records && records.length > 0 && records[0] && records[0]._fields) {
const values = records?.map((r) => r?._fields?.[displayValueRowIndex] || '(no data)').sort();
setExtraRecords(records);
propagateSelection(undefined, values[0]);
}
});
}
}}
value={inputValue || ''}
onChange={propagateSelection}
renderInput={(params) => (
Expand Down
6 changes: 6 additions & 0 deletions src/config/ReportConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,12 @@ const _REPORT_TYPES = {
values: [true, false],
default: false,
},
autoSelectFirstValue: {
label: 'Auto-select first value on no selection',
type: SELECTION_TYPES.LIST,
values: [true, false],
default: false,
},
manualPropertyNameSpecification: {
label: 'Manual Label/Property Name Specification',
type: SELECTION_TYPES.LIST,
Expand Down

0 comments on commit f708147

Please sign in to comment.