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
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Grégoire Locqueville
purescript-gargantext
Commits
4c644592
Unverified
Commit
4c644592
authored
Feb 04, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NGRAMS-TABLE] Basic support for arbitrary patches and versions from the server
parent
1ec62fb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+19
-16
No files found.
src/Gargantext/Components/NgramsTable.purs
View file @
4c644592
...
...
@@ -357,6 +357,7 @@ applyNgramsTablePatch p (NgramsTable m) =
type State =
{ ngramsTablePatch :: NgramsTablePatch
, ngramsVersion :: Version
, ngramsParent :: Maybe NgramsTerm -- Nothing means we are not currently grouping terms
, ngramsChildren :: Map NgramsTerm Boolean
-- ^ Used only when grouping.
...
...
@@ -370,9 +371,11 @@ type State =
_ngramsChildren = prop (SProxy :: SProxy "ngramsChildren")
initialState :: forall props. props -> State
initialState _ =
initialState :: forall props. { loaded :: VersionedNgramsTable | props }
-> State
initialState {loaded: Versioned {version}} =
{ ngramsTablePatch: mempty
, ngramsVersion: version
, ngramsParent: Nothing
, ngramsChildren: mempty
, searchQuery: ""
...
...
@@ -484,14 +487,14 @@ tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable
putTable :: {nodeId :: Int, tabType :: TabType} -> Versioned NgramsTablePatch -> Aff (Versioned NgramsTablePatch)
putTable {nodeId, tabType} = put (toUrl Back (PutNgrams tabType Nothing) $ Just nodeId)
commitPatch :: {nodeId :: Int, tabType :: TabType} -> NgramsTablePatch -> StateCoTransformer State Unit
commitPatch props pt = do
Versioned {version
, data: new_patch} <- lift $ putTable props $ Versioned {version: 1, data: pt}
when (version /= 1) $
throwError $ error "commitPatch: expected version 1 only"
when (not $ isEmptyPatchMap new_patch) $
throwError $ error "commitPatch: expected empty patch only"
modifyState_ $ \s -> s { ngramsTablePatch = pt <> s.ngramsTablePatch }
commitPatch :: {nodeId :: Int, tabType :: TabType} ->
Versioned
NgramsTablePatch -> StateCoTransformer State Unit
commitPatch props pt
@(Versioned {data: tablePatch})
= do
Versioned {version
: newVersion, data: newPatch} <- lift $ putTable props pt
modifyState_ $ \s ->
s { ngramsVersion = newVersion
, ngramsTablePatch = newPatch <> tablePatch <> s.ngramsTablePatch
}
-- TODO: check that pt.version == s.ngramsTablePatch.version
toggleMap :: forall a. a -> Maybe a -> Maybe a
toggleMap _ (Just _) = Nothing
...
...
@@ -511,7 +514,8 @@ ngramsTableSpec = simpleSpec performAction render
modifyState_ $ setParentResetChildren p
performAction (ToggleChild b c) _ _ =
modifyState_ $ _ngramsChildren <<< at c %~ toggleMap b
performAction (SetTermListItem n pl) {path: {nodeId, tabType}} _ = commitPatch {nodeId, tabType} pt
performAction (SetTermListItem n pl) {path: {nodeId, tabType}} {ngramsVersion} =
commitPatch {nodeId, tabType} (Versioned {version: ngramsVersion, data: pt})
where
pe = NgramsPatch { patch_list: pl, patch_children: mempty }
pt = PatchMap $ Map.singleton n pe
...
...
@@ -521,9 +525,10 @@ ngramsTableSpec = simpleSpec performAction render
performAction AddTermChildren {path: {nodeId, tabType}}
{ ngramsParent: Just parent
, ngramsChildren
, ngramsVersion
} = do
modifyState_ $ setParentResetChildren Nothing
commitPatch {nodeId, tabType}
pt
commitPatch {nodeId, tabType}
(Versioned {version: ngramsVersion, data: pt})
where
pc = patchSetFromMap ngramsChildren
pe = NgramsPatch { patch_list: mempty, patch_children: pc }
...
...
@@ -533,12 +538,10 @@ ngramsTableSpec = simpleSpec performAction render
render :: Render State Props' Action
render dispatch { path: {nodeId, tabType}
, loaded: Versioned {
version,
data: initTable }
, loaded: Versioned { data: initTable }
, dispatch: loaderDispatch }
{ ngramsTablePatch, ngramsParent, ngramsChildren, searchQuery }
_reactChildren
| version /= 1 = [ p [] [text "Invalid version"] ]
| otherwise =
_reactChildren =
[ T.tableElt
{ rows
, setParams: \params -> loaderDispatch (Loader.SetPath {nodeId, params, tabType})
...
...
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