Variables: Extend option pickers to accept custom onChange callback (#30913)

* Rename DashboardPicker props

* Extend variable option pickers to allow providing custom onchage callback

* Update public/app/features/variables/pickers/OptionsPicker/actions.ts

Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>

* Update public/app/features/variables/pickers/OptionsPicker/actions.ts

Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>

* Update public/app/features/variables/pickers/OptionsPicker/actions.ts

Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>

* Update public/app/features/variables/textbox/TextBoxVariablePicker.tsx

Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>

* Codeformat

Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>
This commit is contained in:
Alex Khomenko
2021-02-12 16:00:12 +02:00
committed by GitHub
parent 8c35ed4014
commit 6f1a38cbe2
5 changed files with 30 additions and 19 deletions

View File

@@ -7,8 +7,8 @@ import { DashboardSearchHit } from 'app/features/search/types';
import { DashboardDTO } from 'app/types';
export interface Props {
onSelected: (dashboard: DashboardDTO) => void;
currentDashboard?: SelectableValue;
onChange: (dashboard: DashboardDTO) => void;
value?: SelectableValue;
width?: number;
isClearable?: boolean;
invalid?: boolean;
@@ -26,14 +26,7 @@ const getDashboards = (query = '') => {
});
};
export const DashboardPicker: FC<Props> = ({
onSelected,
currentDashboard,
width,
isClearable = false,
invalid,
disabled,
}) => {
export const DashboardPicker: FC<Props> = ({ onChange, value, width, isClearable = false, invalid, disabled }) => {
const debouncedSearch = debounce(getDashboards, 300);
return (
@@ -42,10 +35,10 @@ export const DashboardPicker: FC<Props> = ({
isClearable={isClearable}
defaultOptions={true}
loadOptions={debouncedSearch}
onChange={onSelected}
onChange={onChange}
placeholder="Select dashboard"
noOptionsMessage="No dashboards found"
value={currentDashboard}
value={value}
invalid={invalid}
disabled={disabled}
/>