Commit 5debdac4 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams table] add queryExactMatches to make "add" button work

correctly

It should show if there are search results, but don't match the search
query exactly (modulo normalization).
parent 5472fb06
Pipeline #2360 failed with stage
in 0 seconds
...@@ -19,7 +19,7 @@ import Data.Map as Map ...@@ -19,7 +19,7 @@ import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe, isNothing, maybe) import Data.Maybe (Maybe(..), fromMaybe, isNothing, maybe)
import Data.Monoid.Additive (Additive(..)) import Data.Monoid.Additive (Additive(..))
import Data.Ord.Down (Down(..)) import Data.Ord.Down (Down(..))
import Data.Sequence (Seq, length) as Seq import Data.Sequence as Seq
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
...@@ -38,7 +38,7 @@ import Gargantext.Hooks.Loader (useLoaderBox) ...@@ -38,7 +38,7 @@ import Gargantext.Hooks.Loader (useLoaderBox)
import Gargantext.Routes (SessionRoute(..)) as R import Gargantext.Routes (SessionRoute(..)) as R
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes) import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
import Gargantext.Utils (queryMatchesLabel, toggleSet, sortWith) import Gargantext.Utils (queryExactMatchesLabel, queryMatchesLabel, toggleSet, sortWith)
import Gargantext.Utils.CacheAPI as GUC import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Seq as Seq import Gargantext.Utils.Seq as Seq
...@@ -97,6 +97,7 @@ type TableContainerProps = ...@@ -97,6 +97,7 @@ type TableContainerProps =
, ngramsParent :: Maybe NgramsTerm , ngramsParent :: Maybe NgramsTerm
, ngramsSelection :: Set NgramsTerm , ngramsSelection :: Set NgramsTerm
, ngramsTable :: NgramsTable , ngramsTable :: NgramsTable
, queryExactMatches :: Boolean
, path :: T.Box PageParams , path :: T.Box PageParams
, tabNgramType :: CTabNgramType , tabNgramType :: CTabNgramType
, syncResetButton :: Array R.Element , syncResetButton :: Array R.Element
...@@ -111,6 +112,7 @@ tableContainerCpt { dispatch ...@@ -111,6 +112,7 @@ tableContainerCpt { dispatch
, ngramsSelection , ngramsSelection
, ngramsTable: ngramsTableCache , ngramsTable: ngramsTableCache
, path , path
, queryExactMatches
, tabNgramType , tabNgramType
, syncResetButton , syncResetButton
} = here.component "tableContainer" cpt } = here.component "tableContainer" cpt
...@@ -125,7 +127,7 @@ tableContainerCpt { dispatch ...@@ -125,7 +127,7 @@ tableContainerCpt { dispatch
[ [
R2.row [ H.div {className: "col-md-2", style: {marginTop: "6px"}} R2.row [ H.div {className: "col-md-2", style: {marginTop: "6px"}}
[ H.div {} syncResetButton [ H.div {} syncResetButton
, if 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" H.button { className: "btn btn-primary"
...@@ -336,6 +338,10 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where ...@@ -336,6 +338,10 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
then Just (fromMaybe ng (nre ^. _NgramsRepoElement <<< _root)) then Just (fromMaybe ng (nre ^. _NgramsRepoElement <<< _root))
else Nothing else Nothing
rootsWithMatches = Set.fromFoldable (Seq.mapMaybe rootOfMatch nres) rootsWithMatches = Set.fromFoldable (Seq.mapMaybe rootOfMatch nres)
exactMatches :: Boolean
exactMatches = not $ Seq.null $ Seq.filter fltr nres
where
fltr (Tuple ng _) = queryExactMatchesLabel searchQuery (ngramsTermText ng)
rowsFilter :: NgramsElement -> Maybe NgramsElement rowsFilter :: NgramsElement -> Maybe NgramsElement
rowsFilter ngramsElement = rowsFilter ngramsElement =
if displayRow { ngramsElement if displayRow { ngramsElement
...@@ -411,6 +417,7 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where ...@@ -411,6 +417,7 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
, ngramsSelection , ngramsSelection
, ngramsTable , ngramsTable
, path , path
, queryExactMatches: exactMatches
, syncResetButton: [ syncResetButton ] , syncResetButton: [ syncResetButton ]
, tabNgramType } , tabNgramType }
, params , params
......
...@@ -70,10 +70,14 @@ zeroPad pad num = zeros <> (show num) ...@@ -70,10 +70,14 @@ zeroPad pad num = zeros <> (show num)
zeros' 0 = "" zeros' 0 = ""
zeros' n = "0" <> (zeros' (n - 1)) zeros' n = "0" <> (zeros' (n - 1))
queryNormalize :: String -> String
queryNormalize = S.toLower
queryMatchesLabel :: String -> String -> Boolean queryMatchesLabel :: String -> String -> Boolean
queryMatchesLabel q l = S.contains (S.Pattern $ normalize q) (normalize l) queryMatchesLabel q l = S.contains (S.Pattern $ queryNormalize q) (queryNormalize l)
where
normalize = S.toLower queryExactMatchesLabel :: String -> String -> Boolean
queryExactMatchesLabel q l = queryNormalize q == queryNormalize l
mapLeft :: forall l m r. (l -> m) -> Either l r -> Either m r mapLeft :: forall l m r. (l -> m) -> Either l r -> Either m r
......
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