@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.
- package/dist/cjs/index.cjs +88 -113
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +16 -23
- package/dist/esm/components/DataSourcePicker/DataSourcePicker.js +88 -87
- package/dist/esm/components/DataSourcePicker/DataSourcePicker.js.map +1 -1
- package/dist/esm/index.d.ts +16 -23
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/resolvePluginName.js +0 -30
- package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/resolvePluginName.js.map +0 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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:
|
|
383
|
-
value: (current != null ? current : "no name") + " - not found",
|
|
384
|
-
imgUrl: "",
|
|
385
|
-
hideText: hideTextValue
|
|
411
|
+
label: "No datasources found"
|
|
386
412
|
};
|
|
387
413
|
}
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
398
|
-
|
|
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;
|