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
adf4c69d
Commit
adf4c69d
authored
Oct 12, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[charts] sync button disabling, some refactoring
parent
5b4d25b2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
14 deletions
+41
-14
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+40
-13
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+1
-1
No files found.
src/Gargantext/Components/NgramsTable.purs
View file @
adf4c69d
...
@@ -22,8 +22,11 @@ import Data.Set as Set
...
@@ -22,8 +22,11 @@ import Data.Set as Set
import Data.Symbol (SProxy(..))
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log)
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import FFI.Simple (delay)
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Unsafe.Coerce (unsafeCoerce)
import Unsafe.Coerce (unsafeCoerce)
...
@@ -301,7 +304,7 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
...
@@ -301,7 +304,7 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
, withAutoUpdate } _ = do
, withAutoUpdate } _ = do
pure $ R.fragment $
pure $ R.fragment $
autoUpdate <>
syncResetButtons
<> [
autoUpdate <>
[syncResetButtons { afterSync, ngramsLocalPatch, performAction }]
<> [
H.h4 {style: {textAlign : "center"}} [
H.h4 {style: {textAlign : "center"}} [
H.span {className: "glyphicon glyphicon-hand-down"} []
H.span {className: "glyphicon glyphicon-hand-down"} []
, H.text "Extracted Terms"
, H.text "Extracted Terms"
...
@@ -324,7 +327,7 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
...
@@ -324,7 +327,7 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
, ngramsSelection
, ngramsSelection
}
}
}
}
] <>
syncResetButtons
] <>
[syncResetButtons { afterSync, ngramsLocalPatch, performAction }]
where
where
autoUpdate :: Array R.Element
autoUpdate :: Array R.Element
autoUpdate = if withAutoUpdate then
autoUpdate = if withAutoUpdate then
...
@@ -333,17 +336,6 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
...
@@ -333,17 +336,6 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
, effect: performAction $ Synchronize { afterSync }
, effect: performAction $ Synchronize { afterSync }
} ]
} ]
else []
else []
resetButton :: Boolean -> R.Element
resetButton active = H.button { className: "btn btn-primary " <> if active then "" else " disabled"
, on: { click: \_ -> performAction ResetPatches } } [ H.text "Reset" ]
syncButton :: R.Element
syncButton = H.button { className: "btn btn-primary"
, on: { click: \_ -> performAction $ Synchronize { afterSync }
}
} [ H.text "Sync" ]
-- I would rather have the two buttons always here and make the reset button inactive when the patch is empty.
syncResetButtons :: Array R.Element
syncResetButtons = [ H.div {} [ resetButton (ngramsLocalPatch /= mempty), syncButton ] ]
setParentResetChildren :: Maybe NgramsTerm -> State -> State
setParentResetChildren :: Maybe NgramsTerm -> State -> State
setParentResetChildren p = _ { ngramsParent = p, ngramsChildren = mempty }
setParentResetChildren p = _ { ngramsParent = p, ngramsChildren = mempty }
...
@@ -452,6 +444,41 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
...
@@ -452,6 +444,41 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
setSearchQuery x = setPath $ _ { searchQuery = x }
setSearchQuery x = setPath $ _ { searchQuery = x }
type SyncResetButtonsProps = (
afterSync :: Unit -> Aff Unit
, ngramsLocalPatch :: NgramsTablePatch
, performAction :: Action -> Effect Unit
)
syncResetButtons :: Record SyncResetButtonsProps -> R.Element
syncResetButtons p = R.createElement syncResetButtonsCpt p []
syncResetButtonsCpt :: R.Component SyncResetButtonsProps
syncResetButtonsCpt = R2.hooksComponent thisModule "syncResetButtons" cpt
where
cpt { afterSync, ngramsLocalPatch, performAction } _ = do
synchronizing@(s /\ _) <- R.useState' false
let hasChanges = ngramsLocalPatch /= mempty
pure $ H.div {} [
H.button { className: "btn btn-danger " <> if hasChanges then "" else " disabled"
, on: { click: \_ -> performAction ResetPatches }
} [ H.text "Reset" ]
, H.button { className: "btn btn-primary " <> (if s || (not hasChanges) then "disabled" else "")
, on: { click: synchronize synchronizing }
} [ H.text "Sync" ]
]
where
synchronize (_ /\ setSynchronizing) _ = delay unit $ \_ -> do
setSynchronizing $ const true
performAction $ Synchronize { afterSync: newAfterSync }
where
newAfterSync x = do
afterSync x
liftEffect $ setSynchronizing $ const false
displayRow :: State -> SearchQuery -> NgramsTable -> Maybe NgramsTerm -> Maybe TermList -> Maybe TermSize -> NgramsElement -> Boolean
displayRow :: State -> SearchQuery -> NgramsTable -> Maybe NgramsTerm -> Maybe TermList -> Maybe TermSize -> NgramsElement -> Boolean
displayRow state@{ ngramsChildren
displayRow state@{ ngramsChildren
, ngramsLocalPatch
, ngramsLocalPatch
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
adf4c69d
...
@@ -884,7 +884,7 @@ syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
...
@@ -884,7 +884,7 @@ syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
let pt = Versioned { data: ngramsPatches, version: ngramsVersion }
let pt = Versioned { data: ngramsPatches, version: ngramsVersion }
launchAff_ $ do
launchAff_ $ do
Versioned { data: newPatch, version: newVersion } <- putNgramsPatches props pt
Versioned { data: newPatch, version: newVersion } <- putNgramsPatches props pt
--
callback unit
callback unit
liftEffect $ do
liftEffect $ do
log2 "[syncPatches] setting state, newVersion" newVersion
log2 "[syncPatches] setting state, newVersion" newVersion
setState $ \s ->
setState $ \s ->
...
...
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