Commit 45b2a941 authored by arturo's avatar arturo

[table] automatically sync on ngram addition

* #378
parent a0974175
Pipeline #2837 failed with stage
in 0 seconds
...@@ -26,6 +26,8 @@ import Data.Tuple.Nested ((/\)) ...@@ -26,6 +26,8 @@ import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Components.App.Store (Boxes) import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Bootstrap as B
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, 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)
...@@ -103,6 +105,7 @@ type TableContainerProps = ...@@ -103,6 +105,7 @@ type TableContainerProps =
, path :: T.Box PageParams , path :: T.Box PageParams
, tabNgramType :: CTabNgramType , tabNgramType :: CTabNgramType
, syncResetButton :: Array R.Element , syncResetButton :: Array R.Element
, addCallback :: String -> Effect Unit
) )
tableContainer :: Record TableContainerProps -> Record TT.TableContainerProps -> R.Element tableContainer :: Record TableContainerProps -> Record TT.TableContainerProps -> R.Element
...@@ -117,6 +120,7 @@ tableContainerCpt { dispatch ...@@ -117,6 +120,7 @@ tableContainerCpt { dispatch
, queryExactMatches , queryExactMatches
, tabNgramType , tabNgramType
, syncResetButton , syncResetButton
, addCallback
} = here.component "tableContainer" cpt } = here.component "tableContainer" cpt
where where
cpt props _ = do cpt props _ = do
...@@ -132,13 +136,10 @@ tableContainerCpt { dispatch ...@@ -132,13 +136,10 @@ tableContainerCpt { dispatch
, if (not queryExactMatches || A.null props.tableBody) && searchQuery /= "" then , if (not queryExactMatches || A.null props.tableBody) && searchQuery /= "" then
-- , if (not $ Set.member (normNgram tabNgramType searchQuery) ngramsSelection) && searchQuery /= "" then -- , if (not $ Set.member (normNgram tabNgramType searchQuery) ngramsSelection) && searchQuery /= "" then
H.li { className: "list-group-item" } H.li { className: "list-group-item" }
[ H.button { className: "btn btn-primary" [
, on: { click: const $ dispatch B.button
$ CoreAction { variant: ButtonVariant Primary
$ addNewNgramA , callback: const $ addCallback searchQuery
(normNgram tabNgramType searchQuery)
MapTerm
}
} }
[ H.text ("Add " <> searchQuery) ] [ H.text ("Add " <> searchQuery) ]
] else H.div {} [] ] else H.div {} []
...@@ -379,6 +380,17 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where ...@@ -379,6 +380,17 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
, ngramsLocalPatch , ngramsLocalPatch
, performAction: performAction <<< CoreAction } , performAction: performAction <<< CoreAction }
addCallback searchQuery = do
-- add new ngram as a "Map Term"
performAction
$ CoreAction
$ addNewNgramA (normNgram tabNgramType searchQuery) MapTerm
-- then sync the ngram list
performAction
$ CoreAction
$ Synchronize { afterSync: afterSync' }
-- autoUpdate :: Array R.Element -- autoUpdate :: Array R.Element
-- autoUpdate = if withAutoUpdate then -- autoUpdate = if withAutoUpdate then
-- [ R2.buff -- [ R2.buff
...@@ -410,7 +422,9 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where ...@@ -410,7 +422,9 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
, path , path
, queryExactMatches: exactMatches , queryExactMatches: exactMatches
, syncResetButton: [ syncResetButton ] , syncResetButton: [ syncResetButton ]
, tabNgramType } , tabNgramType
, addCallback
}
, params , params
, rows: filteredConvertedRows , rows: filteredConvertedRows
, syncResetButton: [ syncResetButton ] , syncResetButton: [ syncResetButton ]
......
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