From 1492d482782dbf9d2d97c7adb2589bcd945f79aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 27 Aug 2018 17:05:59 +0100 Subject: [PATCH] fix(ui): remove duplicated code and export functions for testing --- ui/src/Stores/SilenceFormStore.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/ui/src/Stores/SilenceFormStore.js b/ui/src/Stores/SilenceFormStore.js index 6ec4590a1..8ef4d3a31 100644 --- a/ui/src/Stores/SilenceFormStore.js +++ b/ui/src/Stores/SilenceFormStore.js @@ -4,7 +4,7 @@ import uniqueId from "lodash.uniqueid"; import moment from "moment"; -const NewEmptyMatcher = id => { +const NewEmptyMatcher = () => { return { id: uniqueId(), name: "", @@ -17,7 +17,7 @@ const NewEmptyMatcher = id => { }; }; -const ValueToObject = value => ({ label: value, value: value }); +const MatcherValueToObject = value => ({ label: value, value: value }); class SilenceFormStore { // this is used to store modal visibility toggle @@ -75,16 +75,10 @@ class SilenceFormStore { for (const [key, value] of Object.entries( Object.assign({}, group.labels, group.shared.labels) )) { - matchers.push({ - id: uniqueId(), - name: key, - values: [ValueToObject(value)], - suggestions: { - names: [], - values: [] - }, - isRegex: false - }); + const matcher = NewEmptyMatcher(); + matcher.name = key; + matcher.values = [MatcherValueToObject(value)]; + matchers.push(matcher); } // add matchers for all unique labels in this group @@ -101,7 +95,9 @@ class SilenceFormStore { matchers.push({ id: uniqueId(), name: key, - values: [...values].sort().map(value => ValueToObject(value)), + values: [...values] + .sort() + .map(value => MatcherValueToObject(value)), suggestions: { names: [], values: [] @@ -192,4 +188,4 @@ class SilenceFormStore { ); } -export { SilenceFormStore }; +export { SilenceFormStore, NewEmptyMatcher, MatcherValueToObject };