UNPKG

@grafana/ui

Version:
52 lines (47 loc) 1.86 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var React = require('react'); var data = require('@grafana/data'); var i18n = require('@grafana/i18n'); var Combobox = require('../Combobox/Combobox.cjs'); var utils = require('./utils.cjs'); "use strict"; const FieldNameMatcherEditor = React.memo((props) => { const { data, options, onChange: onChangeFromProps, id, scope = "series" } = props; const names = utils.useFieldDisplayNames(data); const selectOptions = utils.useMatcherSelectOptions(names, options, { scope }); const onChange = React.useCallback( (selection) => { if (!utils.frameHasName(selection.value, names)) { return; } const scope2 = names.scopes.get(selection.value); return onChangeFromProps(selection.value, scope2); }, [names, onChangeFromProps] ); const selectedOption = selectOptions.find((v) => v.value === options); return /* @__PURE__ */ jsxRuntime.jsx( Combobox.Combobox, { value: selectedOption, options: selectOptions, onChange, placeholder: i18n.t("grafana-ui.select.placeholder", "Choose"), id } ); }); FieldNameMatcherEditor.displayName = "FieldNameMatcherEditor"; const getFieldNameMatcherItem = () => ({ id: data.FieldMatcherID.byName, component: FieldNameMatcherEditor, matcher: data.fieldMatchers.get(data.FieldMatcherID.byName), name: i18n.t("grafana-ui.matchers-ui.name-fields-with-name", "Fields with name"), description: i18n.t("grafana-ui.matchers-ui.description-fields-with-name", "Set properties for a specific field"), optionsToLabel: (options) => options }); exports.FieldNameMatcherEditor = FieldNameMatcherEditor; exports.getFieldNameMatcherItem = getFieldNameMatcherItem; //# sourceMappingURL=FieldNameMatcherEditor.cjs.map