Skip to content

Commit

Permalink
Merge branch 'branches/rudder/8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins CI committed Sep 28, 2023
2 parents 4ec3755 + 2dde68e commit 5216806
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module NodeProperties.DataTypes exposing (..)

import Http exposing (Error)
import Dict exposing (Dict)
import Json.Encode exposing (Value)
--
-- All our data types
--
Expand All @@ -21,20 +22,12 @@ type ValueFormat = JsonFormat | StringFormat

type alias Property =
{ name : String
, value : JsonValue
, value : Value
, provider : Maybe String
, hierarchy : Maybe String
, origval : Maybe JsonValue
, origval : Maybe Value
}

type JsonValue
= JsonString String
| JsonInt Int
| JsonFloat Float
| JsonBoolean Bool
| JsonArray (List JsonValue)
| JsonObject (Dict String JsonValue)
| JsonNull

type SortOrder = Asc | Desc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,15 @@ decodeSaveProperties =
decodeSaveGroupProperties =
at [ "data", "groups" ] (index 0 decodeProperties)


decodeProperties =
at [ "properties" ] (list decodeProperty)

decodePropertyValue : Decoder JsonValue
decodePropertyValue =
oneOf
[ map JsonString string
, map JsonInt int
, map JsonFloat float
, map JsonBoolean bool
, list (lazy (\_ -> decodePropertyValue)) |> map JsonArray
, dict (lazy (\_ -> decodePropertyValue)) |> map JsonObject
, null JsonNull
]

decodeProperty : Decoder Property
decodeProperty =
succeed Property
|> required "name" string
|> required "value" decodePropertyValue
|> required "value" value
|> optional "provider" (map Just string) Nothing
|> optional "hierarchy" (map Just string) Nothing
|> optional "origval" (map Just decodePropertyValue) Nothing

decodeValue : Decoder JsonValue
decodeValue =
oneOf
[ map JsonString string
, map JsonInt int
, map JsonFloat float
, map JsonBoolean bool
, list (lazy (\_ -> decodePropertyValue)) |> map JsonArray
, dict (lazy (\_ -> decodePropertyValue)) |> map JsonObject
, null JsonNull
]
|> optional "origval" (map Just value) Nothing

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module NodeProperties.ViewUtils exposing (..)
import Html exposing (..)
import Html.Attributes exposing (id, class, href, type_, attribute, disabled, for, checked, selected, value, title, placeholder, style, tabindex )
import Html.Events exposing (onClick, onInput)
import Json.Decode exposing (decodeValue)
import Maybe.Extra exposing (isJust)
import Dict exposing (Dict)
import Json.Encode exposing (..)
Expand Down Expand Up @@ -50,21 +51,35 @@ sortTable tableFilters sortBy =
else
{ tableFilters | sortBy = sortBy, sortOrder = Asc}


getFormat : Property -> ValueFormat
getFormat pr =
case decodeValue Json.Decode.string pr.value of
Ok _ -> StringFormat
Err _ -> JsonFormat

getFormatTxt : ValueFormat -> String
getFormatTxt format =
case format of
StringFormat -> "String"
JsonFormat -> "JSON"

getSortFunction : Model -> Property -> Property -> Order
getSortFunction model p1 p2 =
let
order = case model.ui.filters.sortBy of
Name -> N.compare p1.name p2.name
Format ->
let
getFormat pr = case pr.value of
JsonString s -> "String"
_ -> "JSON"
formatP1 = getFormat p1
formatP2 = getFormat p2
in
N.compare formatP1 formatP2
Value -> N.compare p1.name p2.name
case (formatP1,formatP2) of
(StringFormat,StringFormat) -> EQ
(JsonFormat, JsonFormat) -> EQ
(StringFormat, JsonFormat) -> GT
(JsonFormat, StringFormat) -> LT
Value -> N.compare (Json.Encode.encode 0 p1.value) (Json.Encode.encode 0 p2.value)
in
if model.ui.filters.sortOrder == Asc then
order
Expand All @@ -77,7 +92,7 @@ getSortFunction model p1 p2 =
searchField : Property -> List String
searchField property =
[ property.name
, (displayJsonValue property.value)
, (Json.Encode.encode 0 property.value)
]

checkUsedName : String -> List Property -> Bool
Expand All @@ -88,22 +103,9 @@ checkUsedName name properties =
Nothing -> p.name == name
)

displayJsonValue : JsonValue -> String
displayJsonValue value =
case value of
JsonString s -> s
_ -> encode 2 (encodeJsonValue value)

encodeJsonValue : JsonValue -> Value
encodeJsonValue value =
case value of
JsonString s -> string s
JsonInt i -> int i
JsonFloat f -> float f
JsonBoolean b -> bool b
JsonNull -> null
JsonArray a -> list encodeJsonValue a
JsonObject o -> (dict identity encodeJsonValue o)
displayJsonValue : Value -> String
displayJsonValue value =
encode 2 value

displayNodePropertyRow : Model -> List (Html Msg)
displayNodePropertyRow model =
Expand All @@ -117,10 +119,8 @@ displayNodePropertyRow model =
propertyRow : Property -> Html Msg
propertyRow p =
let
(format, formatTxt) = case p.value of
JsonString s -> (StringFormat, "String")
_ -> (JsonFormat, "JSON")

format = getFormat p
formatTxt = getFormatTxt format
defaultEditProperty = EditProperty p.name (displayJsonValue p.value) format True True False

editedProperty = Dict.get p.name model.ui.editedProperties
Expand All @@ -144,7 +144,7 @@ displayNodePropertyRow model =
)
Nothing -> (text "", True)

isTooLong : JsonValue -> Bool
isTooLong : Value -> Bool
isTooLong value =
let
str = displayJsonValue value
Expand Down

0 comments on commit 5216806

Please sign in to comment.