UNPKG

@grafana/ui

Version:
1 lines 3.39 kB
{"version":3,"file":"FieldNameMatcherEditor.cjs","sources":["../../../../src/components/MatchersUI/FieldNameMatcherEditor.tsx"],"sourcesContent":["import { memo, useCallback } from 'react';\n\nimport { FieldMatcherID, fieldMatchers } from '@grafana/data';\nimport { t } from '@grafana/i18n';\n\nimport { Combobox } from '../Combobox/Combobox';\nimport { type ComboboxOption } from '../Combobox/types';\n\nimport { type FieldMatcherUIRegistryItem, type MatcherUIProps } from './types';\nimport { frameHasName, useFieldDisplayNames, useMatcherSelectOptions } from './utils';\n\nexport const FieldNameMatcherEditor = memo<MatcherUIProps<string>>((props) => {\n const { data, options, onChange: onChangeFromProps, id, scope = 'series' } = props;\n const names = useFieldDisplayNames(data);\n const selectOptions = useMatcherSelectOptions(names, options, { scope });\n\n const onChange = useCallback(\n (selection: ComboboxOption) => {\n if (!frameHasName(selection.value, names)) {\n return;\n }\n\n const scope = names.scopes.get(selection.value!);\n return onChangeFromProps(selection.value!, scope);\n },\n [names, onChangeFromProps]\n );\n\n const selectedOption = selectOptions.find((v) => v.value === options);\n return (\n <Combobox\n value={selectedOption}\n options={selectOptions}\n onChange={onChange}\n placeholder={t('grafana-ui.select.placeholder', 'Choose')}\n id={id}\n />\n );\n});\nFieldNameMatcherEditor.displayName = 'FieldNameMatcherEditor';\n\nexport const getFieldNameMatcherItem: () => FieldMatcherUIRegistryItem<string> = () => ({\n id: FieldMatcherID.byName,\n component: FieldNameMatcherEditor,\n matcher: fieldMatchers.get(FieldMatcherID.byName),\n name: t('grafana-ui.matchers-ui.name-fields-with-name', 'Fields with name'),\n description: t('grafana-ui.matchers-ui.description-fields-with-name', 'Set properties for a specific field'),\n optionsToLabel: (options) => options,\n});\n"],"names":["memo","useFieldDisplayNames","useMatcherSelectOptions","useCallback","frameHasName","scope","jsx","Combobox","t","FieldMatcherID","fieldMatchers"],"mappings":";;;;;;;;;;;;AAWO,MAAM,sBAAA,GAAyBA,UAAA,CAA6B,CAAC,KA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