mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
fix(ui): remove duplicated code and export functions for testing
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user