Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
3c94362a
Verified
Commit
3c94362a
authored
Jul 14, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[wip] some temp fixes
parent
02129e3d
Pipeline
#4390
failed with stage
in 0 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
122 additions
and
51 deletions
+122
-51
Layout.purs
src/Gargantext/Components/Document/Layout.purs
+99
-40
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+2
-1
AutoSync.purs
src/Gargantext/Components/NgramsTable/AutoSync.purs
+1
-0
SyncResetButton.purs
src/Gargantext/Components/NgramsTable/SyncResetButton.purs
+3
-2
Texts.purs
src/Gargantext/Components/Nodes/Texts.purs
+2
-2
Functions.purs
src/Gargantext/Core/NgramsTable/Functions.purs
+9
-5
Types.purs
src/Gargantext/Core/NgramsTable/Types.purs
+6
-1
No files found.
src/Gargantext/Components/Document/Layout.purs
View file @
3c94362a
...
...
@@ -14,6 +14,7 @@ import Data.Set as Set
import Data.String (length)
import Data.String as String
import Data.Tuple.Nested ((/\))
import Effect.Class (liftEffect)
import Gargantext.Components.Annotation.Field as AnnotatedField
import Gargantext.Components.Annotation.Types as AFT
import Gargantext.Components.AutoUpdate (autoUpdate)
...
...
@@ -25,8 +26,8 @@ import Gargantext.Components.GraphQL.Endpoints (getContextNgrams)
import Gargantext.Components.NgramsTable.AutoSync (useAutoSync)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Config.REST (logRESTError)
import Gargantext.Core.NgramsTable.Functions (addNewNgramA, applyNgramsPatches, coreDispatch, findNgramRoot, setTermListA, computeCache)
import Gargantext.Core.NgramsTable.Types (CoreAction(..), NgramsTable(..), NgramsT
erm, Versioned(..), replac
e)
import Gargantext.Core.NgramsTable.Functions (addNewNgramA, applyNgramsPatches, coreDispatch, findNgramRoot, setTermListA, computeCache
, Cache
)
import Gargantext.Core.NgramsTable.Types (CoreAction(..), NgramsTable(..), NgramsT
ablePatch(..), NgramsTerm, Versioned(..), PatchMap(..), replace, Stat
e)
import Gargantext.Hooks.FirstEffect (useFirstEffect')
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session)
...
...
@@ -69,22 +70,30 @@ layoutCpt :: R.Component Props
layoutCpt = here.component "layout" cpt where
cpt props@{ path: path@{ listIds
, nodeId }
, loaded: loaded@{ ngramsTable: Versioned { data: initTable } }
, reload
, session } _ = do
reload' <- T.useLive T.unequal reload
-- reload' <- T.useLive T.unequal reload
let reload' = 1
state <- T.useBox $ initialState { loaded }
state'@{ ngramsValidPatch } <- T.useLive T.unequal state
ngrams <- T.useBox initTable
ngrams' <- T.useLive T.unequal ngrams
case A.head listIds of
Nothing -> pure $ H.div {} [ H.text "No list supplied!" ]
Just listId ->
useLoader { errorHandler
, loader: \p -> getContextNgrams session p.contextId p.listId
, path: { contextId: nodeId, listId, reload: reload' }
, path: { contextId: nodeId, listId, reload: reload'
, state: state'
}
, render: \contextNgrams ->
layoutWithContextNgrams $ Record.merge props { contextNgrams } }
layoutWithContextNgrams $ Record.merge props { contextNgrams
, ngrams, state
} }
where
errorHandler = logRESTError here "[layout]"
type WithContextNgramsProps =
( contextNgrams :: Array NgramsTerm
, ngrams :: T.Box NgramsTable
, state :: T.Box State
| Props )
layoutWithContextNgrams :: forall r. R2.OptLeaf Options WithContextNgramsProps r
...
...
@@ -93,32 +102,76 @@ layoutWithContextNgramsCpt :: R.Component WithContextNgramsProps
layoutWithContextNgramsCpt = here.component "layoutWithContextNgrams" cpt where
-- Component
cpt { contextNgrams
, ngrams
, path
, reload
, loaded:
loaded@{ ngramsTable: Versioned { data: initTable }
, document: NodePoly { hyperdata: Document doc }
}
, loaded
, sideControlsSlot
, state
} _ = do
-- | States
-- |
reload' <- T.useLive T.unequal reload
--
reload' <- T.useLive T.unequal reload
state'@{ ngramsLocalPatch } /\ state <-
R2.useBox' $ initialState { loaded }
ngrams' <- T.useLive T.unequal ngrams
state'@{ ngramsValidPatch } <- T.useLive T.unequal state
let (NgramsTable { ngrams_scores }) = ngrams'
let cache = computeCache (NgramsTable { ngrams_repo_elements: ngramsValidPatch
, ngrams_scores }) $ Set.fromFoldable contextNgrams
-- let cache = computeCache ngramsValidPatch $ Set.fromFoldable contextNgrams
R.useEffect' $ do
here.log2 "[layoutWithContextNgrams] cache" cache
pure $ layoutWithCache { cache
, ngrams
, path
, loaded
, reload
, sideControlsSlot
, state }
type WithCacheProps =
( cache :: Record Cache
, ngrams :: T.Box NgramsTable
, path :: DocPath
, loaded :: LoadedData
, reload :: T2.ReloadS
, sideControlsSlot :: Maybe R.Element
, state :: T.Box State )
layoutWithCache :: R2.Leaf WithCacheProps
layoutWithCache = R2.leaf layoutWithCacheCpt
layoutWithCacheCpt :: R.Component WithCacheProps
layoutWithCacheCpt = here.component "layoutWithCache" cpt where
-- Component
cpt { cache
, ngrams
, path
, loaded:
loaded@{ ngramsTable: Versioned { data: initTable }
, document: NodePoly { hyperdata: Document doc }
}
, reload
, sideControlsSlot
, state } _ = do
state'@{ ngramsLocalPatch } <- T.useLive T.unequal state
mode' /\ mode <- R2.useBox' AFT.EditionMode
let dispatch = coreDispatch path state
{ onPending, result } <- useAutoSync { state, action: dispatch }
--
{ onPending, result } <- useAutoSync { state, action: dispatch }
onPending' <- R2.useLive' onPending
result' <- R2.useLive' result
--
onPending' <- R2.useLive' onPending
--
result' <- R2.useLive' result
ngrams <- T.useBox initTable
--
ngrams <- T.useBox initTable
ngrams' <- T.useLive T.unequal ngrams
R.useEffect' $ do
here.log2 "[layoutWithCache] state'" state'
here.log2 "[layoutWithCache] ngrams'" ngrams'
-- | Computed
-- |
let
...
...
@@ -127,7 +180,7 @@ layoutWithContextNgramsCpt = here.component "layoutWithContextNgrams" cpt where
-- ngrams = applyNgramsPatches state' initTable
cache = computeCache ngrams' $ Set.fromFoldable contextNgrams
--
cache = computeCache ngrams' $ Set.fromFoldable contextNgrams
setTermListOrAddA ngram Nothing =
addNewNgramA ngram
...
...
@@ -136,14 +189,17 @@ layoutWithContextNgramsCpt = here.component "layoutWithContextNgrams" cpt where
setTermList ngram mOldList termList = do
let root = findNgramRoot ngrams' ngram
--
here.log2 "[setTermList] ngram" ngram
here.log2 "[setTermList] ngram" ngram
-- here.log2 "[setTermList] root" root
let patch = setTermListOrAddA root mOldList termList
--
here.log2 "[setTermList] patch" patch
here.log2 "[setTermList] patch" patch
dispatch patch
T.write_ (applyNgramsPatches state' initTable) ngrams
dispatch $ Synchronize { afterSync: \_ -> pure unit
, afterStateChange: \_ -> do
liftEffect $ T2.reload reload }
-- here.log2 "[setTermList] calling reload" reload'
T2.reload reload
--
T2.reload reload
hasAbstract = maybe false (not String.null) doc.abstract
...
...
@@ -228,7 +284,10 @@ layoutWithContextNgramsCpt = here.component "layoutWithContextNgrams" cpt where
autoUpdate
{ duration: 5000
, effect: dispatch $ Synchronize
{ afterSync: \_ -> pure unit
{ afterSync: \e -> do
liftEffect $ here.log2 "[autoUpdate] synchronized" e
pure unit
, afterStateChange: \_ -> pure unit
}
}
-- @NOTE #386: revert manual for automatic sync
...
...
@@ -244,25 +303,25 @@ layoutWithContextNgramsCpt = here.component "layoutWithContextNgrams" cpt where
{ className: "document-layout__side-controls" }
[
-- Saving informations
H.div
{ className: "document-layout__saving" }
[
R2.when' onPending'
[
B.spinner
{ theme: GrowTheme
, className: "document-layout__saving__spinner"
}
]
,
R2.when (not onPending' && isJust result') $
B.icon
{ name: "check"
, className: "document-layout__saving__icon"
}
]
,
--
H.div
--
{ className: "document-layout__saving" }
--
[
--
R2.when' onPending'
--
[
--
B.spinner
--
{ theme: GrowTheme
--
, className: "document-layout__saving__spinner"
--
}
--
]
--
,
--
R2.when (not onPending' && isJust result') $
--
B.icon
--
{ name: "check"
--
, className: "document-layout__saving__icon"
--
}
--
]
--
,
R2.fromMaybe sideControlsSlot identity
]
]
...
...
src/Gargantext/Components/NgramsTable.purs
View file @
3c94362a
...
...
@@ -599,7 +599,8 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
-- then sync the ngram list
performAction
$ CoreAction
$ Synchronize { afterSync: afterSync' }
$ Synchronize { afterSync: afterSync'
, afterStateChange: \_ -> pure unit }
changePage 1 params
...
...
src/Gargantext/Components/NgramsTable/AutoSync.purs
View file @
3c94362a
...
...
@@ -49,6 +49,7 @@ useAutoSync { state, action } = do
T.write_ Nothing result
action $ Synchronize
{ afterSync: onSuccess
, afterStateChange: \_ -> pure unit
}
onSuccess _ = liftEffect do
...
...
src/Gargantext/Components/NgramsTable/SyncResetButton.purs
View file @
3c94362a
...
...
@@ -49,7 +49,8 @@ syncResetButtonsCpt = here.component "syncResetButtons" cpt
synchronizeClick _ = delay unit $ \_ -> do
T.write_ true synchronizing
performAction $ Synchronize { afterSync: newAfterSync }
performAction $ Synchronize { afterSync: newAfterSync
, afterStateChange: \_ -> pure unit }
performAction ResetPatches
newAfterSync x = do
...
...
@@ -84,5 +85,5 @@ syncResetButtonsCpt = here.component "syncResetButtons" cpt
H.text "Save changes (sync)"
]
]
]
src/Gargantext/Components/Nodes/Texts.purs
View file @
3c94362a
...
...
@@ -75,7 +75,6 @@ textsLayoutCpt = here.component "textsLayout" cpt where
textsLayoutWithKey :: R2.Leaf ( key :: String | Props )
textsLayoutWithKey = R2.leaf textsLayoutWithKeyCpt
textsLayoutWithKeyCpt :: R.Component ( key :: String | Props )
textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt where
cpt { frontends
...
...
@@ -557,7 +556,8 @@ sideTextCpt = here.component "sideText" cpt where
-- here.log2 "[sideText] state'" state'
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
-- reload' <- T.useLive T.unequal reload
let reload' = 1
-- | Computed
-- |
...
...
src/Gargantext/Core/NgramsTable/Functions.purs
View file @
3c94362a
...
...
@@ -414,8 +414,11 @@ putNgramsPatches :: forall s. CoreParams s -> VersionedNgramsPatches -> AffRESTE
putNgramsPatches { listIds, nodeId, session, tabType } = put session putNgrams
where putNgrams = PutNgrams tabType (head listIds) Nothing (Just nodeId)
syncPatches :: forall p s. CoreParams p -> T.Box (CoreState s) -> (Unit -> Aff Unit) -> Effect Unit
syncPatches props state callback = do
syncPatches :: forall p s. CoreParams p
-> T.Box (CoreState s)
-> Record SyncPatchesCallbacks
-> Effect Unit
syncPatches props state { afterSync, afterStateChange } = do
{ ngramsLocalPatch: ngramsLocalPatch@(NgramsTablePatch ngramsPatches)
, ngramsStagePatch
, ngramsVersion } <- T.read state
...
...
@@ -426,7 +429,7 @@ syncPatches props state callback = do
case ePatches of
Left err -> liftEffect $ logRESTError here "[syncPatches]" err
Right (Versioned { data: newPatch, version: newVersion }) -> do
callback
unit
afterSync
unit
liftEffect $ do
here.log2 "[syncPatches] setting state, newVersion" newVersion
T.modify_ (\s ->
...
...
@@ -441,6 +444,7 @@ syncPatches props state callback = do
, ngramsVersion = newVersion
}) state
here.log2 "[syncPatches] ngramsVersion" newVersion
afterStateChange unit
pure unit
{-
...
...
@@ -518,8 +522,8 @@ convOrderBy (T.ASC _) = TermAsc
convOrderBy (T.DESC _) = TermDesc
coreDispatch :: forall p s. CoreParams p -> T.Box State -> CoreDispatch
coreDispatch path state (Synchronize { afterSync }) =
syncPatches path state
afterSync
coreDispatch path state (Synchronize { afterSync
, afterStateChange
}) =
syncPatches path state
{ afterSync, afterStateChange }
coreDispatch _ state (CommitPatch pt) =
commitPatch pt state
coreDispatch _ state ResetPatches =
...
...
src/Gargantext/Core/NgramsTable/Types.purs
View file @
3c94362a
...
...
@@ -521,9 +521,14 @@ type State =
type NgramsListByTabType = Map GT.TabType VersionedNgramsTable
type SyncPatchesCallbacks =
( afterSync :: Unit -> Aff Unit
, afterStateChange :: Unit -> Effect Unit )
data CoreAction
= CommitPatch NgramsTablePatch
| Synchronize
{ afterSync :: Unit -> Aff Unit }
| Synchronize
(Record SyncPatchesCallbacks)
| ResetPatches
data Action
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment