Commit c99cfb9f authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski Committed by Karen Konou

[ngramsTable] isEditing prop

This is better than watching whether ngramsParent is Nothing because
subtrees could be edited as well.
parent c6e52231
...@@ -66,7 +66,8 @@ here :: R2.Here ...@@ -66,7 +66,8 @@ here :: R2.Here
here = R2.here "Gargantext.Components.NgramsTable" here = R2.here "Gargantext.Components.NgramsTable"
type TreeEdit = type TreeEdit =
{ ngramsChildren :: List NgramsTerm { isEditing :: Boolean
, ngramsChildren :: List NgramsTerm
-- ^ Root children, as were originally present -- ^ Root children, as were originally present
-- in the table, before editing -- in the table, before editing
, ngramsChildrenDiff :: Map NgramsTerm Boolean , ngramsChildrenDiff :: Map NgramsTerm Boolean
...@@ -85,7 +86,8 @@ type State = ...@@ -85,7 +86,8 @@ type State =
initialTreeEdit :: TreeEdit initialTreeEdit :: TreeEdit
initialTreeEdit = initialTreeEdit =
{ ngramsChildren : List.Nil { isEditing : false
, ngramsChildren : List.Nil
, ngramsChildrenDiff: Map.empty , ngramsChildrenDiff: Map.empty
, ngramsParent : Nothing } , ngramsParent : Nothing }
...@@ -309,6 +311,7 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where ...@@ -309,6 +311,7 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
params'@{ orderBy } <- T.useLive T.unequal params params'@{ orderBy } <- T.useLive T.unequal params
searchQueryFocused <- T.useFocused (_.searchQuery) (\a b -> b { searchQuery = a }) path searchQueryFocused <- T.useFocused (_.searchQuery) (\a b -> b { searchQuery = a }) path
searchQuery <- T.useLive T.unequal searchQueryFocused searchQuery <- T.useLive T.unequal searchQueryFocused
isEditing <- T.useFocused (_.isEditing) (\a b -> b { isEditing = a}) treeEdit.box
let ngramsTable = applyNgramsPatches state' initTable let ngramsTable = applyNgramsPatches state' initTable
rowMap (Tuple ng nre) = rowMap (Tuple ng nre) =
...@@ -359,10 +362,10 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where ...@@ -359,10 +362,10 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
convertRow ngramsElement = convertRow ngramsElement =
{ row: renderNgramsItem { dispatch: performAction { row: renderNgramsItem { dispatch: performAction
, getNgramsChildren , getNgramsChildren
, isEditing
, ngrams: ngramsElement ^. _NgramsElement <<< _ngrams , ngrams: ngramsElement ^. _NgramsElement <<< _ngrams
, ngramsElement , ngramsElement
, ngramsLocalPatch , ngramsLocalPatch
, ngramsParent
, ngramsSelection , ngramsSelection
, ngramsTable } [] , ngramsTable } []
, delete: false , delete: false
...@@ -473,7 +476,8 @@ mkDispatch { filteredRows ...@@ -473,7 +476,8 @@ mkDispatch { filteredRows
performAction ClearTreeEdit = do performAction ClearTreeEdit = do
T.write_ initialTreeEdit treeEdit.box T.write_ initialTreeEdit treeEdit.box
performAction (SetParentResetChildren ngramsParent ngramsChildren) = do performAction (SetParentResetChildren ngramsParent ngramsChildren) = do
T.write_ { ngramsChildren T.write_ { isEditing: true
, ngramsChildren
, ngramsChildrenDiff: Map.empty , ngramsChildrenDiff: Map.empty
, ngramsParent } treeEdit.box , ngramsParent } treeEdit.box
performAction (ToggleChild b c) = do performAction (ToggleChild b c) = do
...@@ -643,13 +647,16 @@ ngramsTreeEdit = R.createElement ngramsTreeEditCpt ...@@ -643,13 +647,16 @@ ngramsTreeEdit = R.createElement ngramsTreeEditCpt
ngramsTreeEditCpt :: R.Component NgramsTreeEditProps ngramsTreeEditCpt :: R.Component NgramsTreeEditProps
ngramsTreeEditCpt = here.component "ngramsTreeEdit" cpt where ngramsTreeEditCpt = here.component "ngramsTreeEdit" cpt where
cpt props@{ box } _ = do cpt props@{ box } _ = do
box' <- T.useLive T.unequal box isEditingFocused <- T.useFocused (_.isEditing) (\a b -> b { isEditing = a }) box
ngramsParentFocused <- T.useFocused (_.ngramsParent) (\a b -> b { ngramsParent = a }) box isEditingFocused' <- T.useLive T.unequal isEditingFocused
ngramsParentFocused <- T.useFocused (_.ngramsParent) (\a b -> b { ngramsParent = a}) box
ngramsParentFocused' <- T.useLive T.unequal ngramsParentFocused ngramsParentFocused' <- T.useLive T.unequal ngramsParentFocused
pure $ case ngramsParentFocused' of pure $ if isEditingFocused'
then case ngramsParentFocused' of
Nothing -> H.div {} [] Nothing -> H.div {} []
Just ngramsParent' -> ngramsTreeEditReal (Record.merge props { ngramsParent' }) [] Just ngramsParent' -> ngramsTreeEditReal (Record.merge props { ngramsParent' }) []
else H.div {} []
type NgramsTreeEditRealProps = type NgramsTreeEditRealProps =
( ngramsParent' :: NgramsTerm ( ngramsParent' :: NgramsTerm
......
...@@ -154,10 +154,10 @@ treeLoadedCpt = here.component "treeLoaded" cpt where ...@@ -154,10 +154,10 @@ treeLoadedCpt = here.component "treeLoaded" cpt where
type RenderNgramsItem = type RenderNgramsItem =
( dispatch :: Action -> Effect Unit ( dispatch :: Action -> Effect Unit
, getNgramsChildren :: NgramsTerm -> Aff (Array NgramsTerm) , getNgramsChildren :: NgramsTerm -> Aff (Array NgramsTerm)
, isEditing :: T.Box Boolean
, ngrams :: NgramsTerm , ngrams :: NgramsTerm
, ngramsElement :: NgramsElement , ngramsElement :: NgramsElement
, ngramsLocalPatch :: NgramsTablePatch , ngramsLocalPatch :: NgramsTablePatch
, ngramsParent :: Maybe NgramsTerm
, ngramsSelection :: Set NgramsTerm , ngramsSelection :: Set NgramsTerm
, ngramsTable :: NgramsTable , ngramsTable :: NgramsTable
) )
...@@ -169,15 +169,14 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt ...@@ -169,15 +169,14 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt
where where
cpt { dispatch cpt { dispatch
--, getNgramsChildren --, getNgramsChildren
, isEditing
, ngrams , ngrams
, ngramsElement , ngramsElement
, ngramsLocalPatch , ngramsLocalPatch
, ngramsParent
, ngramsSelection , ngramsSelection
, ngramsTable , ngramsTable
} _ = do } _ = do
R.useEffect' $ do isEditing' <- T.useLive T.unequal isEditing
here.log2 "[renderNgramsItem] tbl" tbl
pure $ Tbl.makeRow pure $ Tbl.makeRow
[ H.div { className: "ngrams-selector" } [ H.div { className: "ngrams-selector" }
...@@ -188,17 +187,17 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt ...@@ -188,17 +187,17 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt
, checkbox GT.MapTerm , checkbox GT.MapTerm
, checkbox GT.StopTerm , checkbox GT.StopTerm
, H.div {} , H.div {}
( if ngramsParent == Nothing ( if isEditing'
then [ renderNgramsTree { getNgramsChildren: getNgramsChildren' then [ H.a { on: { click: const $ dispatch $ ToggleChild true ngrams } }
[ H.i { className: "fa fa-plus" } [] ]
, R2.buff $ tag [ text $ " " <> ngramsTermText ngramsDepth.ngrams ]
]
else [ renderNgramsTree { getNgramsChildren: getNgramsChildren'
, ngramsClick , ngramsClick
, ngramsDepth , ngramsDepth
, ngramsEdit , ngramsEdit
, ngramsStyle , ngramsStyle
, key: "" } ] , key: "" } ]
else [ H.a { on: { click: const $ dispatch $ ToggleChild true ngrams } }
[ H.i { className: "fa fa-plus" } [] ]
, R2.buff $ tag [ text $ " " <> ngramsTermText ngramsDepth.ngrams ]
]
) )
, H.text $ show (ngramsElement ^. _NgramsElement <<< _occurrences) , H.text $ show (ngramsElement ^. _NgramsElement <<< _occurrences)
] ]
...@@ -215,7 +214,13 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt ...@@ -215,7 +214,13 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt
-- R2.callTrigger toggleSidePanel unit -- R2.callTrigger toggleSidePanel unit
termList = ngramsElement ^. _NgramsElement <<< _list termList = ngramsElement ^. _NgramsElement <<< _list
ngramsStyle = [termStyle termList ngramsOpacity] ngramsStyle = [termStyle termList ngramsOpacity]
ngramsEdit { ngrams } = Just $ dispatch $ SetParentResetChildren (Just ngrams) ngramsChildren ngramsEdit { ngrams: n } =
if n == ngrams then
Just $ dispatch $ SetParentResetChildren (Just ngrams) ngramsChildren
else
Just $ do
here.log2 "[ngramsEdit] n" n
here.log2 "[ngramsEdit] ngrams" ngrams
tbl = applyNgramsPatches { ngramsLocalPatch tbl = applyNgramsPatches { ngramsLocalPatch
, ngramsStagePatch: mempty , ngramsStagePatch: mempty
, ngramsValidPatch: mempty , ngramsValidPatch: mempty
......
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