Commit 41ab6da4 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[CodeEditor] hashes added, trying to solve the move up/down problem

parent b9cfd213
...@@ -5,7 +5,8 @@ import Data.Argonaut.Parser (jsonParser) ...@@ -5,7 +5,8 @@ import Data.Argonaut.Parser (jsonParser)
import Data.Array as A import Data.Array as A
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..), fst) import Data.Sequence as Seq
import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
...@@ -25,6 +26,7 @@ import Gargantext.Hooks.Loader (useLoader) ...@@ -25,6 +26,7 @@ import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(NodeAPI, Children)) import Gargantext.Routes (SessionRoute(NodeAPI, Children))
import Gargantext.Sessions (Session, get, put) import Gargantext.Sessions (Session, get, put)
import Gargantext.Types (NodeType(..), AffTableResult) import Gargantext.Types (NodeType(..), AffTableResult)
import Gargantext.Utils.Crypto as GUC
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
type Props = ( type Props = (
...@@ -75,7 +77,9 @@ corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt ...@@ -75,7 +77,9 @@ corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt
H.span { className: "glyphicon glyphicon-save" } [ ] H.span { className: "glyphicon glyphicon-save" } [ ]
] ]
] ]
, H.div {} [ fieldsCodeEditor {nodeId, session, fields: fieldsS} ] , H.div {} [ fieldsCodeEditor { fields: fieldsS
, nodeId
, session } ]
, H.div { className: "row" } [ , H.div { className: "row" } [
H.div { className: "btn btn-default" H.div { className: "btn btn-default"
, on: { click: onClickAdd fieldsS } , on: { click: onClickAdd fieldsS }
...@@ -118,10 +122,11 @@ fieldsCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldsCodeEditorCpt" cpt ...@@ -118,10 +122,11 @@ fieldsCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldsCodeEditorCpt" cpt
where where
cpt {nodeId, fields: fS@(fields /\ _), session} _ = do cpt {nodeId, fields: fS@(fields /\ _), session} _ = do
pure $ H.div {} $ pure $ H.div {} $
(\(Tuple idx field) -> (\idxField@(Tuple idx field) ->
fieldCodeEditorWrapper { canMoveDown: idx < (A.length fields - 1) fieldCodeEditorWrapper { canMoveDown: idx < (A.length fields - 1)
, canMoveUp: idx > 0 , canMoveUp: idx > 0
, field , field
, hash: hash idxField
, onChange: onChange fS idx , onChange: onChange fS idx
, onMoveDown: onMoveDown fS idx , onMoveDown: onMoveDown fS idx
, onMoveUp: onMoveUp fS idx , onMoveUp: onMoveUp fS idx
...@@ -161,11 +166,15 @@ fieldsCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldsCodeEditorCpt" cpt ...@@ -161,11 +166,15 @@ fieldsCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldsCodeEditorCpt" cpt
recomputeIndices :: Array FTFieldWithIndex -> Array FTFieldWithIndex recomputeIndices :: Array FTFieldWithIndex -> Array FTFieldWithIndex
recomputeIndices = A.mapWithIndex $ \idx -> \(Tuple _ t) -> Tuple idx t recomputeIndices = A.mapWithIndex $ \idx -> \(Tuple _ t) -> Tuple idx t
hash :: FTFieldWithIndex -> Hash
hash (Tuple idx f) = GUC.md5 $ "--idx--" <> (show idx) <> "--field--" <> (show f)
type FieldCodeEditorProps = type FieldCodeEditorProps =
( (
canMoveDown :: Boolean canMoveDown :: Boolean
, canMoveUp :: Boolean , canMoveUp :: Boolean
, field :: FTField , field :: FTField
, hash :: Hash
, onChange :: FieldType -> Effect Unit , onChange :: FieldType -> Effect Unit
, onMoveDown :: Unit -> Effect Unit , onMoveDown :: Unit -> Effect Unit
, onMoveUp :: Unit -> Effect Unit , onMoveUp :: Unit -> Effect Unit
...@@ -179,8 +188,8 @@ fieldCodeEditorWrapper props = R.createElement fieldCodeEditorWrapperCpt props [ ...@@ -179,8 +188,8 @@ fieldCodeEditorWrapper props = R.createElement fieldCodeEditorWrapperCpt props [
fieldCodeEditorWrapperCpt :: R.Component FieldCodeEditorProps fieldCodeEditorWrapperCpt :: R.Component FieldCodeEditorProps
fieldCodeEditorWrapperCpt = R.hooksComponent "G.C.N.C.fieldCodeEditorWrapperCpt" cpt fieldCodeEditorWrapperCpt = R.hooksComponent "G.C.N.C.fieldCodeEditorWrapperCpt" cpt
where where
cpt props@{canMoveDown, canMoveUp, field: Field {name, typ}, onMoveDown, onMoveUp, onRemove, onRename} _ = do cpt props@{canMoveDown, canMoveUp, field: Field {name, typ}, hash, onMoveDown, onMoveUp, onRemove, onRename} _ = do
pure $ H.div { className: "row panel panel-default" } [ pure $ H.div { className: "row panel panel-default hash-" <> hash } [
H.div { className: "panel-heading" } [ H.div { className: "panel-heading" } [
H.div { className: "code-editor-heading" } [ H.div { className: "code-editor-heading" } [
renameable {onRename, text: name} renameable {onRename, text: name}
...@@ -232,18 +241,18 @@ renameableCpt = R.hooksComponent "G.C.N.C.renameableCpt" cpt ...@@ -232,18 +241,18 @@ renameableCpt = R.hooksComponent "G.C.N.C.renameableCpt" cpt
state <- R.useState' text state <- R.useState' text
pure $ H.div { className: "renameable" } [ pure $ H.div { className: "renameable" } [
textCpt isEditing onRename state textCpt isEditing state
] ]
where
textCpt :: R.State Boolean -> (String -> Effect Unit) -> R.State String -> R.Element textCpt :: R.State Boolean -> R.State String -> R.Element
textCpt (false /\ setIsEditing) _ (text /\ _) = H.div {} [ textCpt (false /\ setIsEditing) (text /\ _) = H.div {} [
H.span { className: "text" } [ H.text text ] H.span { className: "text" } [ H.text text ]
, H.span { className: "btn btn-default" , H.span { className: "btn btn-default"
, on: { click: \_ -> setIsEditing $ const true } } [ , on: { click: \_ -> setIsEditing $ const true } } [
H.span { className: "glyphicon glyphicon-pencil" } [] H.span { className: "glyphicon glyphicon-pencil" } []
] ]
] ]
textCpt (true /\ setIsEditing) onRename (text /\ setText) = H.div {} [ textCpt (true /\ setIsEditing) (text /\ setText) = H.div {} [
H.input { defaultValue: text H.input { defaultValue: text
, className: "form-control text" , className: "form-control text"
, on: { change: \e -> setText $ const $ R2.unsafeEventValue e } } , on: { change: \e -> setText $ const $ R2.unsafeEventValue e } }
......
...@@ -4,6 +4,7 @@ import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, (.:), (.:? ...@@ -4,6 +4,7 @@ import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, (.:), (.:?
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq) import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Gargantext.Prelude import Gargantext.Prelude
...@@ -17,6 +18,7 @@ type Tag = String ...@@ -17,6 +18,7 @@ type Tag = String
type Title = String type Title = String
type HaskellCode = String type HaskellCode = String
type MarkdownText = String type MarkdownText = String
type Hash = String
newtype Hyperdata = newtype Hyperdata =
Hyperdata Hyperdata
...@@ -41,6 +43,8 @@ type FTField = Field FieldType ...@@ -41,6 +43,8 @@ type FTField = Field FieldType
derive instance genericFTField :: Generic (Field FieldType) _ derive instance genericFTField :: Generic (Field FieldType) _
instance eqFTField :: Eq (Field FieldType) where instance eqFTField :: Eq (Field FieldType) where
eq = genericEq eq = genericEq
instance showFTField :: Show (Field FieldType) where
show = genericShow
data FieldType = data FieldType =
Haskell { Haskell {
...@@ -61,6 +65,8 @@ data FieldType = ...@@ -61,6 +65,8 @@ data FieldType =
derive instance genericFieldType :: Generic FieldType _ derive instance genericFieldType :: Generic FieldType _
instance eqFieldType :: Eq FieldType where instance eqFieldType :: Eq FieldType where
eq = genericEq eq = genericEq
instance showFieldType :: Show FieldType where
show = genericShow
instance decodeFTField :: DecodeJson (Field FieldType) where instance decodeFTField :: DecodeJson (Field FieldType) where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
......
...@@ -58,3 +58,6 @@ swap i j arr = DA.updateAtIndices updates arr ...@@ -58,3 +58,6 @@ swap i j arr = DA.updateAtIndices updates arr
Just iEl -> case DA.index arr j of Just iEl -> case DA.index arr j of
Nothing -> [] Nothing -> []
Just jEl -> [ Tuple i jEl, Tuple j iEl ] Just jEl -> [ Tuple i jEl, Tuple j iEl ]
swapSeq :: forall a. Int -> Int -> Seq.Seq a -> Seq.Seq a
swapSeq i j seq = Seq.fromFoldable $ swap i j $ Seq.toFoldable seq
...@@ -6,8 +6,9 @@ import Data.Foldable (all) ...@@ -6,8 +6,9 @@ import Data.Foldable (all)
import Data.Maybe (Maybe(..), isJust) import Data.Maybe (Maybe(..), isJust)
import Data.String (drop, stripPrefix, Pattern(..)) import Data.String (drop, stripPrefix, Pattern(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Utils as U import Gargantext.Utils as GU
import Gargantext.Utils.Math as UM import Gargantext.Utils.Crypto as GUC
import Gargantext.Utils.Math as GUM
-- import Test.QuickCheck ((===), (/==), (<?>), Result(..)) -- import Test.QuickCheck ((===), (/==), (<?>), Result(..))
import Test.Spec (Spec, describe, it) import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual) import Test.Spec.Assertions (shouldEqual)
...@@ -17,21 +18,25 @@ spec :: Spec Unit ...@@ -17,21 +18,25 @@ spec :: Spec Unit
spec = spec =
describe "G.Utils" do describe "G.Utils" do
it "zeroPad 1 works" do it "zeroPad 1 works" do
U.zeroPad 1 0 `shouldEqual` "0" GU.zeroPad 1 0 `shouldEqual` "0"
U.zeroPad 1 1 `shouldEqual` "1" GU.zeroPad 1 1 `shouldEqual` "1"
U.zeroPad 1 10 `shouldEqual` "10" GU.zeroPad 1 10 `shouldEqual` "10"
it "zeroPad 2 works" do it "zeroPad 2 works" do
U.zeroPad 2 0 `shouldEqual` "00" GU.zeroPad 2 0 `shouldEqual` "00"
U.zeroPad 2 1 `shouldEqual` "01" GU.zeroPad 2 1 `shouldEqual` "01"
U.zeroPad 2 10 `shouldEqual` "10" GU.zeroPad 2 10 `shouldEqual` "10"
U.zeroPad 2 100 `shouldEqual` "100" GU.zeroPad 2 100 `shouldEqual` "100"
it "zeroPad 3 works" do it "zeroPad 3 works" do
U.zeroPad 3 0 `shouldEqual` "000" GU.zeroPad 3 0 `shouldEqual` "000"
U.zeroPad 3 1 `shouldEqual` "001" GU.zeroPad 3 1 `shouldEqual` "001"
U.zeroPad 3 10 `shouldEqual` "010" GU.zeroPad 3 10 `shouldEqual` "010"
U.zeroPad 3 99 `shouldEqual` "099" GU.zeroPad 3 99 `shouldEqual` "099"
U.zeroPad 3 100 `shouldEqual` "100" GU.zeroPad 3 100 `shouldEqual` "100"
U.zeroPad 3 101 `shouldEqual` "101" GU.zeroPad 3 101 `shouldEqual` "101"
U.zeroPad 3 1000 `shouldEqual` "1000" GU.zeroPad 3 1000 `shouldEqual` "1000"
it "log10 10" do it "log10 10" do
UM.log10 10.0 `shouldEqual` 1.0 GUM.log10 10.0 `shouldEqual` 1.0
it "md5 works" do
let text = "The quick brown fox jumps over the lazy dog"
let textMd5 = "9e107d9d372bb6826bd81d3542a419d6"
GUC.md5 text `shouldEqual` textMd5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment