Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marlowe Playground Frontend: Separate simulator from marlowe editor #2560

Merged
merged 28 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c292b3a
Created a new view for MarloweEditor
hrajchert Dec 11, 2020
aa11123
Fixed keybinding selector for marlowe editor
hrajchert Dec 15, 2020
9aa0b45
Moved linter, holes and initial marker logic from simulation to marlo…
hrajchert Dec 15, 2020
5ab6c74
Fix double provider information
hrajchert Dec 17, 2020
0b8709a
Renamed Simulation modules
hrajchert Dec 18, 2020
01d7715
Separated simulation bottom panel and actions
hrajchert Dec 21, 2020
0df178e
Fix bottom panel in marlowe editor
hrajchert Dec 22, 2020
b965b65
Fix rebasing problems
hrajchert Dec 22, 2020
f040f8b
Fix simulation language color
hrajchert Dec 24, 2020
7525b68
Make the simulation editor readonly
hrajchert Dec 24, 2020
e4ccd72
Renamed _marloweEditorSlot to _simulatorEditorSlot
hrajchert Dec 24, 2020
22172d9
Remove unused imports
hrajchert Dec 24, 2020
d654ac2
Reimplement workflow buttons
hrajchert Dec 28, 2020
641554f
Move select hole to MarloweEditor
hrajchert Dec 28, 2020
371a512
Fix simulation state on refresh
hrajchert Dec 28, 2020
e83d0a7
Remove unused code from simulation bottom panel
hrajchert Dec 28, 2020
d3c1f67
Remove unused code from Marlowe editor bottom panel
hrajchert Dec 28, 2020
dc7f9ca
redesign simulation right pane
hrajchert Dec 29, 2020
b03037d
Remove obsolete FIXMEs
hrajchert Dec 30, 2020
4d75cb5
Applied PR suggestions
hrajchert Dec 30, 2020
a342fae
Fix rebasing problems
hrajchert Dec 30, 2020
4ebcd1e
Fix file actions not being shown in Marlowe editor
hrajchert Dec 30, 2020
69c951f
Added comment on linter
hrajchert Dec 30, 2020
68a36aa
Remove isValidContract from the simulation as it should always be valid
hrajchert Dec 30, 2020
5acb88e
resolved small fixme
hrajchert Dec 30, 2020
3fafe7b
Applied purty
hrajchert Dec 30, 2020
d3751e7
Fix undo button problem
hrajchert Dec 30, 2020
ab1b119
Improved how we show a slot range
hrajchert Dec 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Renamed _marloweEditorSlot to _simulatorEditorSlot
  • Loading branch information
hrajchert authored and shmish111 committed Jan 5, 2021
commit e4ccd722f87c11965b75e838aafdea122779e87f
7 changes: 3 additions & 4 deletions marlowe-playground-client/src/MainFrame/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ type ChildSlots
, blocklySlot :: H.Slot Blockly.Query Blockly.Message Unit
, actusBlocklySlot :: H.Slot AB.Query AB.Message Unit
, simulationSlot :: H.Slot Simulation.Query Blockly.Message Unit
-- FIXME: Do deeper investigation and merge these two slots together
, marloweEditorSlot :: H.Slot Monaco.Query Monaco.Message Unit
, simulatorEditorSlot :: H.Slot Monaco.Query Monaco.Message Unit
, marloweEditorPageSlot :: H.Slot Monaco.Query Monaco.Message Unit
, walletSlot :: H.Slot Wallet.Query Wallet.Message Unit
)
Expand All @@ -169,8 +168,8 @@ _actusBlocklySlot = SProxy
_simulationSlot :: SProxy "simulationSlot"
_simulationSlot = SProxy

_marloweEditorSlot :: SProxy "marloweEditorSlot"
_marloweEditorSlot = SProxy
_simulatorEditorSlot :: SProxy "simulatorEditorSlot"
_simulatorEditorSlot = SProxy

_marloweEditorPageSlot :: SProxy "marloweEditorPageSlot"
_marloweEditorPageSlot = SProxy
Expand Down
10 changes: 5 additions & 5 deletions marlowe-playground-client/src/SimulationPage/State.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Foreign.JSON (parseJSON)
import Halogen (HalogenM, get, modify_, query)
import Halogen.Monaco (Message(..), Query(..)) as Monaco
import LocalStorage as LocalStorage
import MainFrame.Types (ChildSlots, _hasUnsavedChanges', _marloweEditorSlot)
import MainFrame.Types (ChildSlots, _hasUnsavedChanges', _simulatorEditorSlot)
import Marlowe (SPParams_)
import Marlowe as Server
import Marlowe.Holes (fromTerm)
Expand Down Expand Up @@ -285,16 +285,16 @@ scrollHelpPanel =
_, _ -> pure unit

editorSetTheme :: forall state action msg m. HalogenM state action ChildSlots msg m Unit
editorSetTheme = void $ query _marloweEditorSlot unit (Monaco.SetTheme MM.daylightTheme.name unit)
editorSetTheme = void $ query _simulatorEditorSlot unit (Monaco.SetTheme MM.daylightTheme.name unit)

editorResize :: forall state action msg m. HalogenM state action ChildSlots msg m Unit
editorResize = void $ query _marloweEditorSlot unit (Monaco.Resize unit)
editorResize = void $ query _simulatorEditorSlot unit (Monaco.Resize unit)

editorSetValue :: forall state action msg m. String -> HalogenM state action ChildSlots msg m Unit
editorSetValue contents = void $ query _marloweEditorSlot unit (Monaco.SetText contents unit)
editorSetValue contents = void $ query _simulatorEditorSlot unit (Monaco.SetText contents unit)

editorGetValue :: forall state action msg m. HalogenM state action ChildSlots msg m (Maybe String)
editorGetValue = query _marloweEditorSlot unit (Monaco.GetText identity)
editorGetValue = query _simulatorEditorSlot unit (Monaco.GetText identity)

saveInitialState :: forall m. MonadEffect m => HalogenM State Action ChildSlots Void m Unit
saveInitialState = do
Expand Down
75 changes: 16 additions & 59 deletions marlowe-playground-client/src/SimulationPage/View.purs
Original file line number Diff line number Diff line change
@@ -1,85 +1,42 @@
module SimulationPage.View where

import Control.Alternative (map, void, when, (<*>), (<|>))
import Control.Monad.Except (ExceptT, runExceptT, runExcept)
import Control.Monad.Reader (runReaderT)
import Data.Array (delete, filter, intercalate, snoc, sortWith)
import Control.Alternative (map, (<|>))
import Data.Array (intercalate, sortWith)
import Data.Array as Array
import Data.BigInteger (BigInteger, fromString, fromInt)
import Data.Decimal (truncated, fromNumber)
import Data.Decimal as Decimal
import Data.Either (Either(..), hush)
import Data.Enum (toEnum, upFromIncluding)
import Data.EuclideanRing ((*))
import Data.HeytingAlgebra (not, (&&))
import Data.Lens (assign, has, modifying, only, over, preview, set, to, use, view, (^.))
import Data.Lens.Extra (peruse)
import Data.Lens.Index (ix)
import Data.Lens (has, only, to, view, (^.))
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.NonEmptyList (_Head)
import Data.List.NonEmpty as NEL
import Data.List.Types (List(..), NonEmptyList)
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Newtype (wrap)
import Data.NonEmptyList.Extra (tailIfNotEmpty)
import Data.RawJson (RawJson(..))
import Data.String (codePointFromChar)
import Data.String as String
import Data.Traversable (for_, traverse)
import Data.Tuple (Tuple(..), snd)
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Console (log)
import FileEvents (readFileFromDragEvent)
import FileEvents as FileEvents
import Foreign.Generic (ForeignError, decode)
import Foreign.JSON (parseJSON)
import Halogen (HalogenM, RefLabel(..), get, modify_, query)
import Effect.Aff.Class (class MonadAff)
import Effect.Class (liftEffect)
import Halogen (RefLabel(..))
import Halogen.Classes (aHorizontal, bold, closeDrawerIcon, codeEditor, expanded, fullHeight, group, infoIcon, noMargins, panelSubHeaderSide, plusBtn, pointer, scroll, sidebarComposer, smallBtn, spanText, textSecondaryColor, uppercase)
import Halogen.Classes as Classes
import Halogen.HTML (ClassName(..), ComponentHTML, HTML, a, article, aside, b_, br_, button, div, em_, h6, h6_, img, input, li, option, p, p_, section, select, slot, small, strong_, text, ul, ul_)
import Halogen.HTML.Events (onClick, onSelectedIndexChange, onValueChange)
import Halogen.HTML (ClassName(..), ComponentHTML, HTML, a, article, aside, b_, br_, button, div, em_, h6, h6_, img, input, li, p, p_, section, slot, small, strong_, text, ul, ul_)
import Halogen.HTML.Events (onClick, onValueChange)
import Halogen.HTML.Properties (InputType(..), alt, class_, classes, enabled, placeholder, src, type_, value)
import Halogen.HTML.Properties as HTML
import Halogen.Monaco (Message(..), Query(..)) as Monaco
import Halogen.Monaco (Settings, monacoComponent)
import Help (HelpContext(..), toHTML)
import LocalStorage as LocalStorage
import MainFrame.Types (ChildSlots, _hasUnsavedChanges', _marloweEditorSlot)
import Marlowe (SPParams_)
import Marlowe as Server
import Marlowe.Holes (fromTerm)
import Marlowe.Linter as Linter
import Marlowe.Monaco (daylightTheme, documentFormattingEditProvider, languageExtensionPoint, updateAdditionalContext)
import MainFrame.Types (ChildSlots, _simulatorEditorSlot)
import Marlowe.Monaco (daylightTheme, languageExtensionPoint)
import Marlowe.Monaco as MM
import Marlowe.Parser (parseContract)
import Marlowe.Semantics (AccountId, Bound(..), ChoiceId(..), Input(..), Party(..), PubKey, Token, emptyState, inBounds)
import Marlowe.Symbolic.Types.Request as MSReq
import Monaco (Editor, IMarker, isError, isWarning)
import Marlowe.Semantics (AccountId, Bound(..), ChoiceId(..), Input(..), Party(..), PubKey, Token, inBounds)
import Monaco (Editor)
import Monaco (getModel, getMonaco, setTheme, setValue, setReadOnly) as Monaco
import Network.RemoteData (RemoteData(..))
import Network.RemoteData as RemoteData
import Prelude (class Show, Unit, Void, bind, bottom, const, discard, eq, flip, identity, mempty, pure, show, unit, zero, ($), (-), (/=), (<), (<$>), (<<<), (<>), (=<<), (==), (>=))
import Prelude (class Show, Unit, bind, const, discard, show, unit, ($), (<<<), (<>), (==))
import Pretty (renderPrettyParty, renderPrettyToken, showPrettyMoney)
import Prim.TypeError (class Warn, Text)
import Projects.Types (Lang(..))
import Servant.PureScript.Ajax (AjaxError, errorToString)
import Servant.PureScript.Settings (SPSettings_)
import SimulationPage.BottomPanel (bottomPanel)
import SimulationPage.Types (Action(..), ActionInput(..), ActionInputId(..), ExecutionState(..), Parties(..), State, _SimulationNotStarted, _SimulationRunning, _bottomPanelView, _contract, _currentContract, _currentMarloweState, _editorErrors, _editorKeybindings, _editorWarnings, _executionState, _helpContext, _initialSlot, _marloweState, _moveToAction, _oldContract, _pendingInputs, _possibleActions, _selectedHole, _showBottomPanel, _showRightPanel, _slot, _source, emptyExecutionStateWithSlot, emptyMarloweState, isContractValid, mapPartiesActionInput, otherActionsParty)
import Simulator (applyInput, getAsMuchStateAsPossible, hasHistory, inFuture, moveToSignificantSlot, moveToSlot, nextSignificantSlot, updateContractInState, updateMarloweState)
import StaticData (marloweBufferLocalStorageKey)
import SimulationPage.Types (Action(..), ActionInput(..), ActionInputId, ExecutionState(..), State, _SimulationRunning, _currentMarloweState, _editorErrors, _executionState, _helpContext, _marloweState, _possibleActions, _showBottomPanel, _showRightPanel, _slot, _source, isContractValid, otherActionsParty)
import Simulator (hasHistory, inFuture)
import StaticData as StaticData
import Text.Pretty (genericPretty, pretty)
import Web.DOM.Document as D
import Web.DOM.Element (setScrollTop)
import Web.DOM.Element as E
import Web.DOM.HTMLCollection as WC
import Web.HTML as Web
import Web.HTML.HTMLDocument (toDocument)
import Web.HTML.Window as W

render ::
forall m.
Expand Down Expand Up @@ -157,7 +114,7 @@ marloweEditor ::
MonadAff m =>
State ->
ComponentHTML Action ChildSlots m
marloweEditor state = slot _marloweEditorSlot unit component unit (const Nothing)
marloweEditor state = slot _simulatorEditorSlot unit component unit (const Nothing)
where
-- FIXME: probably dont use local storage nor empty ?contract... see what a good default should be
setup editor = do
Expand Down
6 changes: 3 additions & 3 deletions marlowe-playground-client/src/StaticAnalysis/StaticTools.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.Tuple.Nested (type (/\), (/\))
import Effect.Aff.Class (class MonadAff)
import Halogen (HalogenM, query)
import Halogen.Monaco as Monaco
import MainFrame.Types (ChildSlots, _marloweEditorSlot)
import MainFrame.Types (ChildSlots, _simulatorEditorSlot)
import Marlowe (SPParams_)
import Marlowe as Server
import Marlowe.Semantics (Case(..), Contract(..), Observation(..))
Expand Down Expand Up @@ -286,5 +286,5 @@ stepAnalysis problemDef settings isCounterExample rad =
pure result
where
refreshEditor = do
mContent <- query _marloweEditorSlot unit (Monaco.GetText identity)
for_ mContent (\content -> void $ query _marloweEditorSlot unit $ Monaco.SetText content unit)
mContent <- query _simulatorEditorSlot unit (Monaco.GetText identity)
for_ mContent (\content -> void $ query _simulatorEditorSlot unit $ Monaco.SetText content unit)