ui: add isEqual field to Matcher
Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
This commit is contained in:
parent
84dd6ab8d7
commit
740a97345f
File diff suppressed because one or more lines are too long
|
@ -22,6 +22,7 @@ type alias Matcher =
|
|||
{ name : String
|
||||
, value : String
|
||||
, isRegex : Bool
|
||||
, isEqual : Maybe Bool
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,6 +32,7 @@ decoder =
|
|||
|> required "name" Decode.string
|
||||
|> required "value" Decode.string
|
||||
|> required "isRegex" Decode.bool
|
||||
|> optional "isEqual" (Decode.nullable Decode.bool) (Just True)
|
||||
|
||||
|
||||
encoder : Matcher -> Encode.Value
|
||||
|
@ -39,4 +41,5 @@ encoder model =
|
|||
[ ( "name", Encode.string model.name )
|
||||
, ( "value", Encode.string model.value )
|
||||
, ( "isRegex", Encode.bool model.isRegex )
|
||||
, ( "isEqual", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.isEqual) )
|
||||
]
|
||||
|
|
|
@ -35,7 +35,7 @@ nullMatchers =
|
|||
|
||||
nullMatcher : Matcher
|
||||
nullMatcher =
|
||||
Matcher "" "" False
|
||||
Matcher "" "" False (Just True)
|
||||
|
||||
|
||||
stateToString : State -> String
|
||||
|
|
|
@ -142,15 +142,32 @@ type alias Matcher =
|
|||
|
||||
|
||||
convertAPIMatcher : Data.Matcher.Matcher -> Matcher
|
||||
convertAPIMatcher { name, value, isRegex } =
|
||||
convertAPIMatcher { name, value, isRegex, isEqual } =
|
||||
let
|
||||
isEqualValue =
|
||||
case isEqual of
|
||||
Nothing ->
|
||||
True
|
||||
|
||||
Just justIsEqual ->
|
||||
justIsEqual
|
||||
|
||||
op =
|
||||
if not isRegex && isEqualValue then
|
||||
Eq
|
||||
|
||||
else if not isRegex && not isEqualValue then
|
||||
NotEq
|
||||
|
||||
else if isRegex && isEqualValue then
|
||||
RegexMatch
|
||||
|
||||
else
|
||||
NotRegexMatch
|
||||
in
|
||||
{ key = name
|
||||
, value = value
|
||||
, op =
|
||||
if isRegex then
|
||||
RegexMatch
|
||||
|
||||
else
|
||||
Eq
|
||||
, op = op
|
||||
}
|
||||
|
||||
|
||||
|
@ -238,7 +255,8 @@ convertFilterMatcher : Matcher -> Data.Matcher.Matcher
|
|||
convertFilterMatcher { key, op, value } =
|
||||
{ name = key
|
||||
, value = value
|
||||
, isRegex = op == RegexMatch
|
||||
, isRegex = (op == RegexMatch) || (op == NotRegexMatch)
|
||||
, isEqual = Just ((op == Eq) || (op == RegexMatch))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,12 +52,26 @@ replaceIndex index replacement list =
|
|||
mstring : Matcher -> String
|
||||
mstring m =
|
||||
let
|
||||
isEqual =
|
||||
case m.isEqual of
|
||||
Nothing ->
|
||||
True
|
||||
|
||||
Just value ->
|
||||
value
|
||||
|
||||
sep =
|
||||
if m.isRegex then
|
||||
if not m.isRegex && isEqual then
|
||||
"="
|
||||
|
||||
else if not m.isRegex && not isEqual then
|
||||
"!="
|
||||
|
||||
else if m.isRegex && isEqual then
|
||||
"=~"
|
||||
|
||||
else
|
||||
"="
|
||||
"!~"
|
||||
in
|
||||
String.join sep [ m.name, m.value ]
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ type ApiData a
|
|||
|
||||
type alias Matcher =
|
||||
{ isRegex : Bool
|
||||
, isEqual : Maybe Bool
|
||||
, name : String
|
||||
, value : String
|
||||
}
|
||||
|
|
|
@ -39,14 +39,28 @@ newSilenceFromMatchers : List Data.Matcher.Matcher -> String
|
|||
newSilenceFromMatchers matchers =
|
||||
matchers
|
||||
|> List.map
|
||||
(\{ name, value, isRegex } ->
|
||||
(\{ name, value, isRegex, isEqual } ->
|
||||
let
|
||||
isEqualValue =
|
||||
case isEqual of
|
||||
Nothing ->
|
||||
True
|
||||
|
||||
Just justIsEqual ->
|
||||
justIsEqual
|
||||
|
||||
op =
|
||||
if isRegex then
|
||||
if not isRegex && isEqualValue then
|
||||
Utils.Filter.Eq
|
||||
|
||||
else if not isRegex && not isEqualValue then
|
||||
Utils.Filter.NotEq
|
||||
|
||||
else if isRegex && isEqualValue then
|
||||
Utils.Filter.RegexMatch
|
||||
|
||||
else
|
||||
Utils.Filter.Eq
|
||||
Utils.Filter.NotRegexMatch
|
||||
in
|
||||
Utils.Filter.Matcher name op value
|
||||
)
|
||||
|
|
|
@ -62,6 +62,7 @@ type alias MatcherForm =
|
|||
{ name : ValidatedField
|
||||
, value : ValidatedField
|
||||
, isRegex : Bool
|
||||
, isEqual : Maybe Bool
|
||||
}
|
||||
|
||||
|
||||
|
@ -183,10 +184,11 @@ parseEndsAt startsAt endsAt =
|
|||
|
||||
|
||||
validateMatcherForm : MatcherForm -> MatcherForm
|
||||
validateMatcherForm { name, value, isRegex } =
|
||||
validateMatcherForm { name, value, isRegex, isEqual } =
|
||||
{ name = validate stringNotEmpty name
|
||||
, value = value
|
||||
, isRegex = isRegex
|
||||
, isEqual = isEqual
|
||||
}
|
||||
|
||||
|
||||
|
@ -207,6 +209,7 @@ empty =
|
|||
emptyMatcher : MatcherForm
|
||||
emptyMatcher =
|
||||
{ isRegex = False
|
||||
, isEqual = Just True
|
||||
, name = initialField ""
|
||||
, value = initialField ""
|
||||
}
|
||||
|
@ -239,31 +242,33 @@ fromMatchersAndCommentAndTime defaultCreator matchers comment now =
|
|||
|
||||
|
||||
appendMatcher : MatcherForm -> Result String (List Matcher) -> Result String (List Matcher)
|
||||
appendMatcher { isRegex, name, value } =
|
||||
appendMatcher { isRegex, isEqual, name, value } =
|
||||
Result.map2 (::)
|
||||
(Result.map2 (\k v -> Matcher k v isRegex) (stringNotEmpty name.value) (Ok value.value))
|
||||
(Result.map2 (\k v -> Matcher k v isRegex isEqual) (stringNotEmpty name.value) (Ok value.value))
|
||||
|
||||
|
||||
filterMatcherToMatcher : Utils.Filter.Matcher -> Maybe Matcher
|
||||
filterMatcherToMatcher { key, op, value } =
|
||||
Maybe.map (\operator -> Matcher key value operator) <|
|
||||
case op of
|
||||
Utils.Filter.Eq ->
|
||||
Just False
|
||||
case op of
|
||||
Utils.Filter.Eq ->
|
||||
Maybe.map2 (\isRegex isEqual -> Matcher key value isRegex isEqual) (Just False) (Just (Just True))
|
||||
|
||||
Utils.Filter.RegexMatch ->
|
||||
Just True
|
||||
Utils.Filter.RegexMatch ->
|
||||
Maybe.map2 (\isRegex isEqual -> Matcher key value isRegex isEqual) (Just True) (Just (Just True))
|
||||
|
||||
-- we don't support negative matchers
|
||||
_ ->
|
||||
Nothing
|
||||
Utils.Filter.NotRegexMatch ->
|
||||
Maybe.map2 (\isRegex isEqual -> Matcher key value isRegex isEqual) (Just True) (Just (Just False))
|
||||
|
||||
Utils.Filter.NotEq ->
|
||||
Maybe.map2 (\isRegex isEqual -> Matcher key value isRegex isEqual) (Just False) (Just (Just False))
|
||||
|
||||
|
||||
fromMatcher : Matcher -> MatcherForm
|
||||
fromMatcher { name, value, isRegex } =
|
||||
fromMatcher { name, value, isRegex, isEqual } =
|
||||
{ name = initialField name
|
||||
, value = initialField value
|
||||
, isRegex = isRegex
|
||||
, isEqual = isEqual
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -78,12 +78,26 @@ dateView string time =
|
|||
matcherButton : Matcher -> Html Msg
|
||||
matcherButton matcher =
|
||||
let
|
||||
isEqual =
|
||||
case matcher.isEqual of
|
||||
Nothing ->
|
||||
True
|
||||
|
||||
Just value ->
|
||||
value
|
||||
|
||||
op =
|
||||
if matcher.isRegex then
|
||||
if not matcher.isRegex && isEqual then
|
||||
Utils.Filter.Eq
|
||||
|
||||
else if not matcher.isRegex && not isEqual then
|
||||
Utils.Filter.NotEq
|
||||
|
||||
else if matcher.isRegex && isEqual then
|
||||
Utils.Filter.RegexMatch
|
||||
|
||||
else
|
||||
Utils.Filter.Eq
|
||||
Utils.Filter.NotRegexMatch
|
||||
|
||||
msg =
|
||||
FilterBarTypes.AddFilterMatcher False
|
||||
|
|
Loading…
Reference in New Issue