Skip to content

Commit

Permalink
Merge pull request #1079 from KindsonTheGenius/bugfixes
Browse files Browse the repository at this point in the history
Fixed bugs from IR -> Distribution migration
  • Loading branch information
AttilaMihaly authored Jul 18, 2023
2 parents 8f34ae5 + 684b75f commit 576c63c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
17 changes: 8 additions & 9 deletions cli/src/Morphir/Web/Editor.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Element
import Html exposing (Html)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
import Morphir.IR as IR exposing (IR)
import Morphir.IR.Distribution exposing (Distribution)
import Morphir.IR.Distribution.Codec exposing (decodeVersionedDistribution)
import Morphir.IR.FQName as FQName exposing (FQName)
Expand All @@ -25,7 +24,7 @@ type alias Model =


type alias ModelState =
{ ir : IR
{ ir : Distribution
, theme : Theme
, valueType : Type ()
, editorState : ValueEditor.EditorState
Expand Down Expand Up @@ -60,24 +59,24 @@ init flags =
tpe =
Type.Reference () flag.entryPoint []

ir : IR
ir =
IR.fromDistribution flag.distribution
distro : Distribution
distro =
flag.distribution

initEditorState : ValueEditor.EditorState
initEditorState =
ValueEditor.initEditorState ir tpe flag.initialValue
ValueEditor.initEditorState distro tpe flag.initialValue

encoderResult : Result String (RawValue -> Result String Encode.Value)
encoderResult =
DataCodec.encodeData ir tpe
DataCodec.encodeData distro tpe

model : Model
model =
encoderResult
|> Result.map
(\encoder ->
{ ir = ir
{ ir = distro
, theme = Theme.fromConfig Nothing
, valueType = tpe
, editorState = initEditorState
Expand Down Expand Up @@ -200,7 +199,7 @@ decodeFlag =
in
Decode.field "initialValue"
(Decode.maybe
(decodeData (IR.fromDistribution distribution) tpe
(decodeData distribution tpe
|> decodeResultToFailure
)
)
Expand Down
50 changes: 22 additions & 28 deletions cli/src/Morphir/Web/InsightTestApp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import Html exposing (Html)
import Http
import Morphir.Correctness.Codec exposing (decodeTestSuite)
import Morphir.Correctness.Test exposing (TestCases, TestSuite)
import Morphir.IR as IR exposing (IR)
import Morphir.IR.Distribution exposing (Distribution(..))
import Morphir.IR.Distribution as Distribution exposing (Distribution(..))
import Morphir.IR.Distribution.Codec as DistributionCodec
import Morphir.IR.FQName exposing (FQName)
import Morphir.IR.Name as Name exposing (Name)
Expand All @@ -39,8 +38,8 @@ type alias Flags =

type Model
= LoadingDistribution
| LoadingTests Distribution IR
| Initialized Distribution IR TestSuite
| LoadingTests Distribution
| Initialized Distribution TestSuite
| Errored String


Expand Down Expand Up @@ -76,7 +75,7 @@ httpGetDistribution =
}


httpGetTestModel : IR -> Cmd Msg
httpGetTestModel : Distribution -> Cmd Msg
httpGetTestModel ir =
Http.get
{ url = "/server/morphir-tests.json"
Expand All @@ -103,19 +102,15 @@ update msg model =
_ ->
case ( model, msg ) of
( LoadingDistribution, HttpGetDistributionResponse distro ) ->
let
ir =
IR.fromDistribution distro
in
( LoadingTests distro ir, httpGetTestModel ir )
( LoadingTests distro, httpGetTestModel distro )

( LoadingDistribution, HttpError error ) ->
( Errored "Error while loading distribution", Cmd.none )

( LoadingTests distro ir, HttpGetTestsResponse testSuite ) ->
( Initialized distro ir testSuite, Cmd.none )
( LoadingTests distro, HttpGetTestsResponse testSuite ) ->
( Initialized distro testSuite, Cmd.none )

( LoadingTests distro ir, HttpError error ) ->
( LoadingTests distro, HttpError error ) ->
( Errored "Error while loading tests", Cmd.none )

_ ->
Expand Down Expand Up @@ -146,35 +141,34 @@ viewModel model =
LoadingDistribution ->
text "Loading distribution ..."

LoadingTests _ _ ->
LoadingTests _ ->
text "Loading tests ..."

Initialized distro ir testSuite ->
viewInitialized distro ir testSuite
Initialized distro testSuite ->
viewInitialized distro testSuite

Errored string ->
text string


viewInitialized : Distribution -> IR -> TestSuite -> Element Msg
viewInitialized distro ir testSuite =
viewInitialized : Distribution -> TestSuite -> Element Msg
viewInitialized distro testSuite =
testSuite
|> Dict.toList
|> List.filterMap
(\( fqn, testCases ) ->
ir
|> IR.lookupValueDefinition fqn
distro
|> Distribution.lookupValueDefinition fqn
|> Maybe.map
(\valueDef ->
viewValue ir fqn valueDef testCases
viewValue distro fqn valueDef testCases
)
)
|> column [ spacing 10 ]



viewValue : IR -> FQName -> Value.Definition () (Type ()) -> TestCases -> Element Msg
viewValue ir (( _, moduleName, localName ) as fqn) valueDefinition testCases =
viewValue : Distribution -> FQName -> Value.Definition () (Type ()) -> TestCases -> Element Msg
viewValue distro (( _, moduleName, localName ) as fqn) valueDefinition testCases =
let
cardColor : Element.Color
cardColor =
Expand Down Expand Up @@ -205,7 +199,7 @@ viewValue ir (( _, moduleName, localName ) as fqn) valueDefinition testCases =
, padding 10
, Background.color (rgb 1 1 1)
]
(viewInsight ir
(viewInsight distro
fqn
valueDefinition
inputs
Expand Down Expand Up @@ -245,8 +239,8 @@ viewValue ir (( _, moduleName, localName ) as fqn) valueDefinition testCases =
viewCases


viewInsight : IR -> FQName -> Value.Definition () (Type ()) -> List (Maybe RawValue) -> Element Msg
viewInsight ir fqn valueDef argValues =
viewInsight : Distribution -> FQName -> Value.Definition () (Type ()) -> List (Maybe RawValue) -> Element Msg
viewInsight distro fqn valueDef argValues =
let
variables : Dict Name RawValue
variables =
Expand All @@ -261,7 +255,7 @@ viewInsight ir fqn valueDef argValues =
|> Dict.fromList

config =
{ ir = ir
{ ir = distro
, nativeFunctions = SDK.nativeFunctions
, state =
{ drillDownFunctions = DrillDownFunctions Dict.empty
Expand Down

0 comments on commit 576c63c

Please sign in to comment.