diff --git a/ui/src/Common/Select.js b/ui/src/Common/Select.js new file mode 100644 index 000000000..8b9f2555f --- /dev/null +++ b/ui/src/Common/Select.js @@ -0,0 +1,5 @@ +const NewLabelName = (v) => `New label: ${v}`; + +const NewLabelValue = (v) => `New value: ${v}`; + +export { NewLabelName, NewLabelValue }; diff --git a/ui/src/Common/Select.test.js b/ui/src/Common/Select.test.js new file mode 100644 index 000000000..6f6655442 --- /dev/null +++ b/ui/src/Common/Select.test.js @@ -0,0 +1,13 @@ +import { NewLabelName, NewLabelValue } from "./Select"; + +describe("NewLabelName", () => { + it("returns correct text", () => { + expect(NewLabelName("foo")).toBe("New label: foo"); + }); +}); + +describe("NewLabelValue", () => { + it("returns correct text", () => { + expect(NewLabelValue("foo")).toBe("New value: foo"); + }); +}); diff --git a/ui/src/Components/MainModal/Configuration/GridLabelName.js b/ui/src/Components/MainModal/Configuration/GridLabelName.js index dd9f19c2b..4183f3de9 100644 --- a/ui/src/Components/MainModal/Configuration/GridLabelName.js +++ b/ui/src/Components/MainModal/Configuration/GridLabelName.js @@ -7,6 +7,7 @@ import { useFetchGet } from "Hooks/useFetchGet"; import { FormatBackendURI } from "Stores/AlertStore"; import { Settings } from "Stores/Settings"; import { ThemeContext } from "Components/Theme"; +import { NewLabelName } from "Common/Select"; const disabledLabel = "Disable multi-grid"; @@ -28,6 +29,7 @@ const GridLabelName = ({ settingsStore }) => { styles={context.reactSelectStyles} classNamePrefix="react-select" instanceId="configuration-grid-label" + formatCreateLabel={NewLabelName} defaultValue={valueToOption( settingsStore.multiGridConfig.config.gridLabel )} diff --git a/ui/src/Components/MainModal/Configuration/SortLabelName.js b/ui/src/Components/MainModal/Configuration/SortLabelName.js index d61a46c8b..6a65d0fdd 100644 --- a/ui/src/Components/MainModal/Configuration/SortLabelName.js +++ b/ui/src/Components/MainModal/Configuration/SortLabelName.js @@ -8,6 +8,7 @@ import { FormatBackendURI } from "Stores/AlertStore"; import { Settings } from "Stores/Settings"; import { useFetchGet } from "Hooks/useFetchGet"; import { ThemeContext } from "Components/Theme"; +import { NewLabelName } from "Common/Select"; const valueToOption = (v) => ({ label: v, value: v }); @@ -25,6 +26,7 @@ const SortLabelName = ({ settingsStore }) => { styles={context.reactSelectStyles} classNamePrefix="react-select" instanceId="configuration-sort-label" + formatCreateLabel={NewLabelName} defaultValue={valueToOption(settingsStore.gridConfig.config.sortLabel)} options={ response diff --git a/ui/src/Components/SilenceModal/SilenceMatch/LabelNameInput.js b/ui/src/Components/SilenceModal/SilenceMatch/LabelNameInput.js index d99b390f5..d9aba389d 100644 --- a/ui/src/Components/SilenceModal/SilenceMatch/LabelNameInput.js +++ b/ui/src/Components/SilenceModal/SilenceMatch/LabelNameInput.js @@ -8,6 +8,7 @@ import { FormatBackendURI } from "Stores/AlertStore"; import { useFetchGet } from "Hooks/useFetchGet"; import { ValidationError } from "Components/ValidationError"; import { ThemeContext } from "Components/Theme"; +import { NewLabelName } from "Common/Select"; const LabelNameInput = ({ matcher, isValid }) => { const { response } = useFetchGet(FormatBackendURI(`labelNames.json`)); @@ -19,6 +20,7 @@ const LabelNameInput = ({ matcher, isValid }) => { styles={context.reactSelectStyles} classNamePrefix="react-select" instanceId={`silence-input-label-name-${matcher.id}`} + formatCreateLabel={NewLabelName} defaultValue={ matcher.name ? { label: matcher.name, value: matcher.name } : null } diff --git a/ui/src/Components/SilenceModal/SilenceMatch/LabelValueInput.js b/ui/src/Components/SilenceModal/SilenceMatch/LabelValueInput.js index 6716097f6..f92c51cce 100644 --- a/ui/src/Components/SilenceModal/SilenceMatch/LabelValueInput.js +++ b/ui/src/Components/SilenceModal/SilenceMatch/LabelValueInput.js @@ -12,6 +12,7 @@ import { SilenceFormStore } from "Stores/SilenceFormStore"; import { SilenceFormMatcher } from "Models/SilenceForm"; import { useFetchGet } from "Hooks/useFetchGet"; import { hashObject } from "Common/Hash"; +import { NewLabelValue } from "Common/Select"; import { ValidationError } from "Components/ValidationError"; import { ThemeContext } from "Components/Theme"; import { MatchCounter } from "./MatchCounter"; @@ -69,6 +70,7 @@ const LabelValueInput = observer(({ silenceFormStore, matcher, isValid }) => { styles={context.reactSelectStyles} classNamePrefix="react-select" instanceId={`silence-input-label-value-${matcher.id}`} + formatCreateLabel={NewLabelValue} defaultValue={matcher.values} options={ response