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