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

[ngramstable] WIP

parent a1b4c82f
...@@ -33,7 +33,7 @@ import Gargantext.Components.App.Store (Boxes) ...@@ -33,7 +33,7 @@ import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Bootstrap as B import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), Variant(..)) import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), Variant(..))
import Gargantext.Components.NgramsTable.Components as NTC import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Core (Action(..), CoreAction(..), CoreState, Dispatch, NgramsElement(..), NgramsPatch(..), NgramsTable, NgramsTerm, PageParams, PatchMap(..), Versioned(..), VersionedNgramsTable, VersionedWithCountNgramsTable, _NgramsElement, _NgramsRepoElement, _NgramsTable, _children, _list, _ngrams, _ngrams_repo_elements, _ngrams_scores, _occurrences, _root, addNewNgramA, applyNgramsPatches, applyPatchSet, chartsAfterSync, commitPatch, convOrderBy, coreDispatch, filterTermSize, fromNgramsPatches, ngramsRepoElementToNgramsElement, ngramsTermText, normNgram, patchSetFromMap, replace, setTermListA, singletonNgramsTablePatch, syncResetButtons, toVersioned) import Gargantext.Components.NgramsTable.Core (Action(..), CoreAction(..), CoreState, Dispatch, NgramsClick, NgramsDepth, NgramsElement(..), NgramsPatch(..), NgramsTable, NgramsTerm, PageParams, PatchMap(..), Versioned(..), VersionedNgramsTable, VersionedWithCountNgramsTable, _NgramsElement, _NgramsRepoElement, _NgramsTable, _children, _list, _ngrams, _ngrams_repo_elements, _ngrams_scores, _occurrences, _root, addNewNgramA, applyNgramsPatches, applyPatchSet, chartsAfterSync, commitPatch, convOrderBy, coreDispatch, filterTermSize, fromNgramsPatches, ngramsRepoElementToNgramsElement, ngramsTermText, normNgram, patchSetFromMap, replace, setTermListA, singletonNgramsTablePatch, syncResetButtons, toVersioned)
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI) import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
import Gargantext.Components.Nodes.Lists.Types as NT import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as TT import Gargantext.Components.Table as TT
...@@ -591,7 +591,9 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt ...@@ -591,7 +591,9 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
cpt props@{ cacheState, path } _ = do cpt props@{ cacheState, path } _ = do
searchQuery <- T.useFocused (_.searchQuery) (\a b -> b { searchQuery = a }) path searchQuery <- T.useFocused (_.searchQuery) (\a b -> b { searchQuery = a }) path
cacheState' <- T.useLive T.unequal cacheState cacheState' <- T.useLive T.unequal cacheState
onSave <- T.useBox Nothing onCancelRef <- R.useRef Nothing
onNgramsClickRef <- R.useRef Nothing
onSaveRef <- R.useRef Nothing
treeEdit <- T.useBox initialTreeEdit treeEdit <- T.useBox initialTreeEdit
-- let path = initialPageParams session nodeId [defaultListId] tabType -- let path = initialPageParams session nodeId [defaultListId] tabType
...@@ -605,58 +607,78 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt ...@@ -605,58 +607,78 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
NT.CacheOff -> pure $ R.fragment NT.CacheOff -> pure $ R.fragment
[ [
loadedNgramsTableHeader { searchQuery } [] loadedNgramsTableHeader { searchQuery } []
, ngramsTreeEdit { onSave, treeEdit } [] , ngramsTreeEdit { treeEdit } []
, mainNgramsTableCacheOff (props { treeEdit = treeEdit }) [] , mainNgramsTableCacheOff (props { onCancelRef = onCancelRef
, onNgramsClickRef = onNgramsClickRef
, onSaveRef = onSaveRef
, treeEdit = treeEdit }) []
] ]
type NgramsTreeEditProps = type NgramsTreeEditProps =
( onSave :: T.Box (Maybe (Effect Unit)) ( onCancelRef :: R.Ref (Maybe (Unit -> Effect Unit))
, treeEdit :: T.Box TreeEdit ) , onNgramsClickRef :: R.Ref (Maybe NgramsClick)
, onSaveRef :: R.Ref (Maybe (Unit -> Effect Unit))
, treeEdit :: T.Box TreeEdit )
ngramsTreeEdit :: R2.Component NgramsTreeEditProps ngramsTreeEdit :: R2.Component NgramsTreeEditProps
ngramsTreeEdit = R.createElement ngramsTreeEditCpt 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 { onSave, treeEdit } _ = do cpt props@{ treeEdit } _ = do
{ ngramsParent } <- T.useLive T.unequal treeEdit { ngramsParent } <- T.useLive T.unequal treeEdit
pure $ if ngramsParent == Nothing pure $ if ngramsParent == Nothing
then then
H.div {} [] H.div {} []
else else
ngramsTreeEditReal { onSave, treeEdit } [] ngramsTreeEditReal props []
ngramsTreeEditReal :: R2.Component NgramsTreeEditProps ngramsTreeEditReal :: R2.Component NgramsTreeEditProps
ngramsTreeEditReal = R.createElement ngramsTreeEditRealCpt ngramsTreeEditReal = R.createElement ngramsTreeEditRealCpt
ngramsTreeEditRealCpt :: R.Component NgramsTreeEditProps ngramsTreeEditRealCpt :: R.Component NgramsTreeEditProps
ngramsTreeEditRealCpt = here.component "ngramsTreeEditReal" cpt where ngramsTreeEditRealCpt = here.component "ngramsTreeEditReal" cpt where
cpt { treeEdit } _ = do cpt { onCancelRef, onNgramsClickRef, onSaveRef, treeEdit } _ = do
pure $ H.div {} [ H.text "ngramsTreeEditReal" ] -- pure $ H.div {} [ H.text "ngramsTreeEditReal" ]
-- pure $ H.div {}
-- [ H.p {} { ngramsChildren, ngramsChildrenDiff, ngramsParent } <- T.useLive T.unequal treeEdit
-- [ H.text $ "Editing " <> ngramsTermText ngrams ]
-- , NTC.renderNgramsTree { ngramsClick --let ngramsTable = applyPatchSet (patchSetFromMap ngramsChildrenDiff) ngramsChildren
-- , ngramsDepth let ngramsDepth = { depth: 1, ngrams: ngramsParent }
-- , ngramsEdit
-- , ngramsStyle: [] pure $ H.div {}
-- , ngramsTable [ H.p {}
-- } [ H.text $ "Editing " <> ngramsTermText ngramsDepth.ngrams ]
-- , H.button { className: "btn btn-primary" , NTC.renderNgramsTree { ngramsChildren: applyPatchSet (patchSetFromMap ngramsChildrenDiff) $ Set.toUnfoldable ngramsChildren
-- , on: {click: (const $ dispatch AddTermChildren)} , ngramsClick
-- } [H.text "Save"] , ngramsDepth
-- , H.button { className: "btn btn-primary" , ngramsEdit
-- , on: {click: (const $ dispatch ClearTreeEdit)} , ngramsStyle: []
-- } [H.text "Cancel"] }
-- ] , H.button { className: "btn btn-primary"
-- where , on: {click: onSaveClick} --(const $ dispatch AddTermChildren)}
-- ngramsTable = ngramsTableCache # at ngrams } [H.text "Save"]
-- <<< _Just , H.button { className: "btn btn-primary"
-- <<< _NgramsRepoElement , on: {click: onCancelClick } --(const $ dispatch ClearTreeEdit)}
-- <<< _children } [H.text "Cancel"]
-- %~ applyPatchSet (patchSetFromMap ngramsChildrenDiff) ]
-- ngramsClick {depth: 1, ngrams: child} = Just $ dispatch $ ToggleChild false child where
-- ngramsClick _ = Nothing -- ngramsTable = ngramsTableCache # at ngrams
-- ngramsEdit _ = Nothing -- <<< _Just
-- <<< _NgramsRepoElement
-- <<< _children
-- %~ applyPatchSet (patchSetFromMap ngramsChildrenDiff)
--ngramsClick {depth: 1, ngrams: child} = Just $ dispatch $ ToggleChild false child
--ngramsClick _ = Nothing
ngramsClick nd = case R.readRef onNgramsClickRef of
Nothing -> Nothing
Just ngc -> ngc nd
ngramsEdit _ = Nothing
onCancelClick _ = case R.readRef onCancelRef of
Nothing -> Nothing
Just onCancel -> onCancel unit
onSaveClick _ = case R.readRef onSaveRef of
Nothing -> Nothing
Just onSave -> onSave unit
mainNgramsTableCacheOn :: R2.Component MainNgramsTableProps mainNgramsTableCacheOn :: R2.Component MainNgramsTableProps
mainNgramsTableCacheOn = R.createElement mainNgramsTableCacheOnCpt mainNgramsTableCacheOn = R.createElement mainNgramsTableCacheOnCpt
......
...@@ -12,7 +12,7 @@ import Data.Set (Set) ...@@ -12,7 +12,7 @@ import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Effect (Effect) import Effect (Effect)
import FFI.Simple (delay) import FFI.Simple (delay)
import Gargantext.Components.NgramsTable.Core (Action(..), Dispatch, NgramsElement, NgramsTable, NgramsTablePatch, NgramsTerm, _NgramsElement, _NgramsRepoElement, _PatchMap, _children, _list, _ngrams, _occurrences, ngramsTermText, replace, setTermListA) import Gargantext.Components.NgramsTable.Core (Action(..), Dispatch, NgramsClick, NgramsDepth, NgramsElement, NgramsTable, NgramsTablePatch, NgramsTerm, _NgramsElement, _NgramsRepoElement, _PatchMap, _children, _list, _ngrams, _occurrences, ngramsTermText, replace, setTermListA)
import Gargantext.Components.Table as Tbl import Gargantext.Components.Table as Tbl
import Gargantext.Prelude (Unit, bind, const, discard, map, not, otherwise, pure, show, unit, ($), (+), (/=), (<<<), (<>), (==), (>), (||)) import Gargantext.Prelude (Unit, bind, const, discard, map, not, otherwise, pure, show, unit, ($), (+), (/=), (<<<), (<>), (==), (>), (||))
import Gargantext.Types as GT import Gargantext.Types as GT
...@@ -146,9 +146,6 @@ renderNgramsTreeCpt = here.component "renderNgramsTree" cpt ...@@ -146,9 +146,6 @@ renderNgramsTreeCpt = here.component "renderNgramsTree" cpt
] ]
type NgramsDepth = { ngrams :: NgramsTerm, depth :: Int }
type NgramsClick = NgramsDepth -> Maybe (Effect Unit)
type TagProps = type TagProps =
( ngramsClick :: NgramsClick ( ngramsClick :: NgramsClick
, ngramsDepth :: NgramsDepth , ngramsDepth :: NgramsDepth
......
...@@ -77,6 +77,9 @@ module Gargantext.Components.NgramsTable.Core ...@@ -77,6 +77,9 @@ module Gargantext.Components.NgramsTable.Core
, syncResetButtons , syncResetButtons
, chartsAfterSync , chartsAfterSync
, useAutoSync , useAutoSync
, NgramsDepth
, NgramsClick
) )
where where
...@@ -1190,3 +1193,7 @@ postNgramsChartsAsync { listIds, nodeId, session, tabType } = do ...@@ -1190,3 +1193,7 @@ postNgramsChartsAsync { listIds, nodeId, session, tabType } = do
acu = AsyncNgramsChartsUpdate { listId: head listIds acu = AsyncNgramsChartsUpdate { listId: head listIds
, tabType } , tabType }
putNgramsAsync = PostNgramsChartsAsync (Just nodeId) putNgramsAsync = PostNgramsChartsAsync (Just nodeId)
type NgramsDepth = { ngrams :: NgramsTerm, depth :: Int }
type NgramsClick = NgramsDepth -> Maybe (Effect Unit)
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