@grafana/plugin-ui 0.17.10 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,10 +8,11 @@ var data = require('@grafana/data');
8
8
  var Calendar = require('react-calendar');
9
9
  var css = require('@emotion/css');
10
10
  var e2eSelectors = require('@grafana/e2e-selectors');
11
- var runtime = require('@grafana/runtime');
11
+ var datasources = require('@grafana/plugin-compat/datasources');
12
12
  var reactUse = require('react-use');
13
13
  var ui$1 = require('@react-awesome-query-builder/ui');
14
14
  var uuid = require('uuid');
15
+ var runtime = require('@grafana/runtime');
15
16
  var lodash = require('lodash');
16
17
  var AutoSizer = require('react-virtualized-auto-sizer');
17
18
  var sqlFormatter = require('sql-formatter');
@@ -338,99 +339,100 @@ function getSignatureDisplayModel(signature) {
338
339
  }
339
340
  PluginSignatureBadge.displayName = "PluginSignatureBadge";
340
341
 
341
- var __defProp$6 = Object.defineProperty;
342
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
343
- var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
344
- class DataSourcePicker extends React.PureComponent {
345
- constructor(props) {
346
- super(props);
347
- __publicField$6(this, "dataSourceSrv", runtime.getDataSourceSrv());
348
- __publicField$6(this, "state", {});
349
- __publicField$6(this, "onChange", (item) => {
350
- const dsSettings = this.dataSourceSrv.getInstanceSettings(item.value);
351
- if (dsSettings) {
352
- this.props.onChange(dsSettings);
353
- this.setState({ error: void 0 });
342
+ function DataSourcePicker({
343
+ onChange,
344
+ current: currentProp,
345
+ hideTextValue,
346
+ onBlur,
347
+ autoFocus = false,
348
+ openMenuOnFocus = false,
349
+ placeholder = "Select datasource",
350
+ noDefault
351
+ }) {
352
+ const current = currentProp != null ? currentProp : null;
353
+ const showNoDatasources = !current && !!noDefault;
354
+ const { items, isLoading: isListLoading, error: listError } = datasources.useDataSourceInstanceList();
355
+ const currentResult = datasources.useDataSourceInstanceListItem(current);
356
+ const selected = currentResult.item;
357
+ const isCurrentLoading = !showNoDatasources && currentResult.isLoading;
358
+ const isLoading = isListLoading || isCurrentLoading;
359
+ const notFound = !selected && !isCurrentLoading && !showNoDatasources;
360
+ const handleChange = (option) => {
361
+ const item = items.find((ds) => ds.uid === option.value);
362
+ if (item) {
363
+ onChange(item);
364
+ }
365
+ };
366
+ const options = items.map((ds) => ({
367
+ value: ds.uid,
368
+ label: ds.name,
369
+ imgUrl: ds.meta.info.logos.small,
370
+ meta: ds.meta
371
+ }));
372
+ const value = getCurrentValue({ current, selected, notFound, showNoDatasources, hideTextValue });
373
+ const invalid = !!listError || notFound;
374
+ return /* @__PURE__ */ React__default.default.createElement("div", { "aria-label": e2eSelectors.selectors.components.DataSourcePicker.container }, /* @__PURE__ */ React__default.default.createElement(
375
+ ui.Select,
376
+ {
377
+ className: "ds-picker select-container",
378
+ isMulti: false,
379
+ isClearable: false,
380
+ backspaceRemovesValue: false,
381
+ onChange: handleChange,
382
+ options,
383
+ isLoading,
384
+ autoFocus,
385
+ onBlur,
386
+ openMenuOnFocus,
387
+ maxMenuHeight: 500,
388
+ placeholder,
389
+ noOptionsMessage: listError ? "Could not load data sources" : "No datasources found",
390
+ value,
391
+ invalid,
392
+ "aria-invalid": invalid,
393
+ getOptionLabel: (o) => {
394
+ if (o.meta && isUnsignedPluginSignature(o.meta.signature) && o !== value) {
395
+ return /* @__PURE__ */ React__default.default.createElement(ui.Stack, { alignItems: "center", justifyContent: "space-between" }, /* @__PURE__ */ React__default.default.createElement("span", null, o.label), " ", /* @__PURE__ */ React__default.default.createElement(PluginSignatureBadge, { status: o.meta.signature }));
396
+ }
397
+ return o.label || "";
354
398
  }
355
- });
356
- }
357
- componentDidMount() {
358
- const { current } = this.props;
359
- const dsSettings = this.dataSourceSrv.getInstanceSettings(current);
360
- if (!dsSettings) {
361
- this.setState({ error: "Could not find data source " + current });
362
- }
363
- }
364
- getCurrentValue() {
365
- const { current, hideTextValue, noDefault } = this.props;
366
- if (!current && noDefault) {
367
- return {
368
- label: "No datasources found"
369
- };
370
- }
371
- const ds = this.dataSourceSrv.getInstanceSettings(current);
372
- if (ds) {
373
- return {
374
- label: ds.name.substr(0, 37),
375
- value: ds.name,
376
- imgUrl: ds.meta.info.logos.small,
377
- hideText: hideTextValue,
378
- meta: ds.meta
379
- };
380
399
  }
400
+ ));
401
+ }
402
+ function getCurrentValue({
403
+ current,
404
+ selected,
405
+ notFound,
406
+ showNoDatasources,
407
+ hideTextValue
408
+ }) {
409
+ if (showNoDatasources) {
381
410
  return {
382
- label: (current != null ? current : "no name") + " - not found",
383
- value: (current != null ? current : "no name") + " - not found",
384
- imgUrl: "",
385
- hideText: hideTextValue
411
+ label: "No datasources found"
386
412
  };
387
413
  }
388
- getDataSourceOptions() {
389
- const options = this.dataSourceSrv.getList().map((ds) => ({
390
- value: ds.uid,
391
- label: ds.name,
392
- imgUrl: ds.meta.info.logos.small,
393
- meta: ds.meta
394
- }));
395
- return options;
414
+ if (selected) {
415
+ return toOption$1(selected, hideTextValue);
396
416
  }
397
- render() {
398
- const { autoFocus, onBlur, openMenuOnFocus, placeholder } = this.props;
399
- const { error } = this.state;
400
- const options = this.getDataSourceOptions();
401
- const value = this.getCurrentValue();
402
- return /* @__PURE__ */ React__default.default.createElement("div", { "aria-label": e2eSelectors.selectors.components.DataSourcePicker.container }, /* @__PURE__ */ React__default.default.createElement(
403
- ui.Select,
404
- {
405
- className: "ds-picker select-container",
406
- isMulti: false,
407
- isClearable: false,
408
- backspaceRemovesValue: false,
409
- onChange: this.onChange,
410
- options,
411
- autoFocus,
412
- onBlur,
413
- openMenuOnFocus,
414
- maxMenuHeight: 500,
415
- placeholder,
416
- noOptionsMessage: "No datasources found",
417
- value,
418
- invalid: !!error,
419
- getOptionLabel: (o) => {
420
- if (o.meta && isUnsignedPluginSignature(o.meta.signature) && o !== value) {
421
- return /* @__PURE__ */ React__default.default.createElement(ui.Stack, { alignItems: "center", justifyContent: "space-between" }, /* @__PURE__ */ React__default.default.createElement("span", null, o.label), " ", /* @__PURE__ */ React__default.default.createElement(PluginSignatureBadge, { status: o.meta.signature }));
422
- }
423
- return o.label || "";
424
- }
425
- }
426
- ));
417
+ if (!notFound) {
418
+ return void 0;
427
419
  }
420
+ return {
421
+ label: (current != null ? current : "no name") + " - not found",
422
+ value: (current != null ? current : "no name") + " - not found",
423
+ imgUrl: "",
424
+ hideText: hideTextValue
425
+ };
426
+ }
427
+ function toOption$1(ds, hideTextValue) {
428
+ return {
429
+ label: ds.name.substr(0, 37),
430
+ value: ds.name,
431
+ imgUrl: ds.meta.info.logos.small,
432
+ hideText: hideTextValue,
433
+ meta: ds.meta
434
+ };
428
435
  }
429
- __publicField$6(DataSourcePicker, "defaultProps", {
430
- autoFocus: false,
431
- openMenuOnFocus: false,
432
- placeholder: "Select datasource"
433
- });
434
436
 
435
437
  const { FormField, Switch } = ui.LegacyForms;
436
438
  const getStyles$u = ui.stylesFactory(() => ({
@@ -24700,32 +24702,6 @@ function useHealthChecks() {
24700
24702
  return { healthMap, checkUids, retry };
24701
24703
  }
24702
24704
 
24703
- let pluginNameCache = null;
24704
- function buildPluginNameCache() {
24705
- var _a;
24706
- if (pluginNameCache) {
24707
- return pluginNameCache;
24708
- }
24709
- const map = /* @__PURE__ */ new Map();
24710
- try {
24711
- const list = runtime.getDataSourceSrv().getList();
24712
- for (const ds of list) {
24713
- if (((_a = ds.meta) == null ? void 0 : _a.name) && ds.type && !map.has(ds.type)) {
24714
- map.set(ds.type, ds.meta.name);
24715
- }
24716
- }
24717
- } catch (ex) {
24718
- console.error(ex);
24719
- }
24720
- pluginNameCache = map;
24721
- return map;
24722
- }
24723
- function resolvePluginName(pluginType) {
24724
- var _a;
24725
- const cache = buildPluginNameCache();
24726
- return (_a = cache.get(pluginType)) != null ? _a : pluginType;
24727
- }
24728
-
24729
24705
  function useDatasourceSchema(pluginType) {
24730
24706
  const [schema, setSchema] = React.useState(null);
24731
24707
  const [loading, setLoading] = React.useState(false);
@@ -26588,7 +26564,6 @@ exports.isValidCelExpression = isValidCelExpression;
26588
26564
  exports.parseDependsOn = parseDependsOn;
26589
26565
  exports.resolveActiveOverride = resolveActiveOverride;
26590
26566
  exports.resolveGroups = resolveGroups;
26591
- exports.resolvePluginName = resolvePluginName;
26592
26567
  exports.resolveRequiredFieldsGroup = resolveRequiredFieldsGroup;
26593
26568
  exports.toOption = toOption;
26594
26569
  exports.useDatasourceSchema = useDatasourceSchema;