Commit ad0d6969 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-use-sequence-instead-of-list-in-table' of...

Merge branch 'dev-use-sequence-instead-of-list-in-table' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev
parents 475a69dc 803fbe8a
...@@ -9,11 +9,11 @@ import Data.Generic.Rep.Show (genericShow) ...@@ -9,11 +9,11 @@ import Data.Generic.Rep.Show (genericShow)
import Data.Lens ((^.)) import Data.Lens ((^.))
import Data.Lens.At (at) import Data.Lens.At (at)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.List as L
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe, isJust) import Data.Maybe (Maybe(..), fromMaybe, isJust)
import Data.Ord.Down (Down(..)) import Data.Ord.Down (Down(..))
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.String as Str import Data.String as Str
...@@ -32,7 +32,7 @@ import Gargantext.Components.Category ...@@ -32,7 +32,7 @@ import Gargantext.Components.Category
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Ends (Frontends, url) import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoaderWithCacheAPI, HashedResponse(..)) import Gargantext.Hooks.Loader (useLoaderWithCacheAPI, HashedResponse(..))
import Gargantext.Utils.List (sortWith) as L import Gargantext.Utils.Seq (sortWith) as Seq
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Routes (SessionRoute(NodeAPI)) import Gargantext.Routes (SessionRoute(NodeAPI))
...@@ -359,7 +359,7 @@ pagePaintCpt = R2.hooksComponent thisModule "pagePaintCpt" cpt where ...@@ -359,7 +359,7 @@ pagePaintCpt = R2.hooksComponent thisModule "pagePaintCpt" cpt where
{ colNames { colNames
, container: T.defaultContainer { title: "Documents" } , container: T.defaultContainer { title: "Documents" }
, params , params
, rows: L.fromFoldable $ rows localCategories , rows: Seq.fromFoldable $ rows localCategories
, totalRecords , totalRecords
, wrapColElts , wrapColElts
} }
...@@ -377,12 +377,12 @@ pagePaintCpt = R2.hooksComponent thisModule "pagePaintCpt" cpt where ...@@ -377,12 +377,12 @@ pagePaintCpt = R2.hooksComponent thisModule "pagePaintCpt" cpt where
getCategory (localCategories /\ _) {_id, category} = fromMaybe category (localCategories ^. at _id) getCategory (localCategories /\ _) {_id, category} = fromMaybe category (localCategories ^. at _id)
orderWith = orderWith =
case convOrderBy (fst params).orderBy of case convOrderBy (fst params).orderBy of
Just DateAsc -> L.sortWith \(DocumentsView { date }) -> date Just DateAsc -> Seq.sortWith \(DocumentsView { date }) -> date
Just DateDesc -> L.sortWith \(DocumentsView { date }) -> Down date Just DateDesc -> Seq.sortWith \(DocumentsView { date }) -> Down date
Just SourceAsc -> L.sortWith \(DocumentsView { source }) -> Str.toLower source Just SourceAsc -> Seq.sortWith \(DocumentsView { source }) -> Str.toLower source
Just SourceDesc -> L.sortWith \(DocumentsView { source }) -> Down $ Str.toLower source Just SourceDesc -> Seq.sortWith \(DocumentsView { source }) -> Down $ Str.toLower source
Just TitleAsc -> L.sortWith \(DocumentsView { title }) -> Str.toLower title Just TitleAsc -> Seq.sortWith \(DocumentsView { title }) -> Str.toLower title
Just TitleDesc -> L.sortWith \(DocumentsView { title }) -> Down $ Str.toLower title Just TitleDesc -> Seq.sortWith \(DocumentsView { title }) -> Down $ Str.toLower title
_ -> identity -- the server ordering is enough here _ -> identity -- the server ordering is enough here
filteredRows = T.filterRows { params: fst params } $ orderWith $ A.toUnfoldable documents filteredRows = T.filterRows { params: fst params } $ orderWith $ A.toUnfoldable documents
rows localCategories = row <$> filteredRows rows localCategories = row <$> filteredRows
......
...@@ -8,11 +8,11 @@ import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyO ...@@ -8,11 +8,11 @@ import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyO
import Data.Array (concat, filter) import Data.Array (concat, filter)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
import Data.List as L
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Sequence as Seq
import Data.Set (Set) import Data.Set (Set)
import Data.String as String
import Data.Set as Set import Data.Set as Set
import Data.String as String
import Data.Tuple (fst, snd) import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
...@@ -323,7 +323,7 @@ pageCpt = R2.hooksComponent thisModule "page" cpt ...@@ -323,7 +323,7 @@ pageCpt = R2.hooksComponent thisModule "page" cpt
documentUrl id = documentUrl id =
url frontends $ Routes.CorpusDocument (sessionId session) nodeId listId id url frontends $ Routes.CorpusDocument (sessionId session) nodeId listId id
comma = H.span {} [ H.text ", " ] comma = H.span {} [ H.text ", " ]
rows = L.fromFoldable $ row <$> filter (not <<< isDeleted) documents rows = Seq.fromFoldable $ row <$> filter (not <<< isDeleted) documents
row dv@(DocumentsView {id, score, title, source, authors, pairs, delete, category}) = row dv@(DocumentsView {id, score, title, source, authors, pairs, delete, category}) =
{ row: { row:
T.makeRow [ T.makeRow [
......
...@@ -11,12 +11,12 @@ import Data.Lens.Common (_Just) ...@@ -11,12 +11,12 @@ import Data.Lens.Common (_Just)
import Data.Lens.Fold (folded) import Data.Lens.Fold (folded)
import Data.Lens.Index (ix) import Data.Lens.Index (ix)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.List (List, mapMaybe, length) as L
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), isNothing, maybe) import Data.Maybe (Maybe(..), 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 as Seq
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
...@@ -44,8 +44,8 @@ import Gargantext.Sessions (Session, get) ...@@ -44,8 +44,8 @@ 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) import Gargantext.Utils (queryMatchesLabel, toggleSet)
import Gargantext.Utils.CacheAPI as GUC import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.List (sortWith) as L
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Seq as Seq
thisModule = "Gargantext.Components.NgramsTable" thisModule = "Gargantext.Components.NgramsTable"
...@@ -119,7 +119,7 @@ setTermListSetA ngramsTable ns new_list = ...@@ -119,7 +119,7 @@ setTermListSetA ngramsTable ns new_list =
addNewNgramA :: NgramsTerm -> Action addNewNgramA :: NgramsTerm -> Action
addNewNgramA ngram = CommitPatch $ addNewNgram ngram CandidateTerm addNewNgramA ngram = CommitPatch $ addNewNgram ngram CandidateTerm
type PreConversionRows = L.List NgramsElement type PreConversionRows = Seq.Seq NgramsElement
type TableContainerProps = type TableContainerProps =
( dispatch :: Dispatch ( dispatch :: Dispatch
...@@ -374,7 +374,7 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt ...@@ -374,7 +374,7 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
setState $ setParentResetChildren Nothing setState $ setParentResetChildren Nothing
commitPatch (Versioned {version: ngramsVersion, data: pt}) (state /\ setState) commitPatch (Versioned {version: ngramsVersion, data: pt}) (state /\ setState)
totalRecords = L.length rows totalRecords = Seq.length rows
filteredConvertedRows :: T.Rows filteredConvertedRows :: T.Rows
filteredConvertedRows = convertRow <$> filteredRows filteredConvertedRows = convertRow <$> filteredRows
filteredRows :: PreConversionRows filteredRows :: PreConversionRows
...@@ -383,9 +383,9 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt ...@@ -383,9 +383,9 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
ng_scores = ngramsTable ^. _NgramsTable <<< _ngrams_scores ng_scores = ngramsTable ^. _NgramsTable <<< _ngrams_scores
rows :: PreConversionRows rows :: PreConversionRows
rows = orderWith ( rows = orderWith (
L.mapMaybe (\(Tuple ng nre) -> Seq.mapMaybe (\(Tuple ng nre) ->
let Additive s = ng_scores ^. at ng <<< _Just in let Additive s = ng_scores ^. at ng <<< _Just in
addOcc <$> rowsFilter (ngramsRepoElementToNgramsElement ng s nre)) $ addOcc <$> rowsFilter (ngramsRepoElementToNgramsElement ng s nre)) $
Map.toUnfoldable (ngramsTable ^. _NgramsTable <<< _ngrams_repo_elements) Map.toUnfoldable (ngramsTable ^. _NgramsTable <<< _ngrams_repo_elements)
) )
rowsFilter :: NgramsElement -> Maybe NgramsElement rowsFilter :: NgramsElement -> Maybe NgramsElement
...@@ -423,10 +423,10 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt ...@@ -423,10 +423,10 @@ loadedNgramsTableCpt = R2.hooksComponent thisModule "loadedNgramsTable" cpt
} }
orderWith = orderWith =
case convOrderBy <$> params.orderBy of case convOrderBy <$> params.orderBy of
Just ScoreAsc -> L.sortWith \x -> x ^. _NgramsElement <<< _occurrences Just ScoreAsc -> Seq.sortWith \x -> x ^. _NgramsElement <<< _occurrences
Just ScoreDesc -> L.sortWith \x -> Down $ x ^. _NgramsElement <<< _occurrences Just ScoreDesc -> Seq.sortWith \x -> Down $ x ^. _NgramsElement <<< _occurrences
Just TermAsc -> L.sortWith \x -> x ^. _NgramsElement <<< _ngrams Just TermAsc -> Seq.sortWith \x -> x ^. _NgramsElement <<< _ngrams
Just TermDesc -> L.sortWith \x -> Down $ x ^. _NgramsElement <<< _ngrams Just TermDesc -> Seq.sortWith \x -> Down $ x ^. _NgramsElement <<< _ngrams
_ -> identity -- the server ordering is enough here _ -> identity -- the server ordering is enough here
colNames = T.ColumnName <$> ["Select", "Map", "Stop", "Terms", "Score"] -- see convOrderBy colNames = T.ColumnName <$> ["Select", "Map", "Stop", "Terms", "Score"] -- see convOrderBy
......
...@@ -3,8 +3,8 @@ module Gargantext.Components.Nodes.Annuaire where ...@@ -3,8 +3,8 @@ module Gargantext.Components.Nodes.Annuaire where
import Prelude (bind, const, identity, pure, show, ($), (<$>), (<>)) import Prelude (bind, const, identity, pure, show, ($), (<$>), (<>))
import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?)) import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?))
import Data.Array as A import Data.Array as A
import Data.List as L
import Data.Maybe (Maybe(..), maybe, fromMaybe) import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Sequence as Seq
import Data.Tuple (fst, snd) import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff_) import Effect.Aff (Aff, launchAff_)
...@@ -156,7 +156,7 @@ pageCpt = R2.hooksComponent thisModule "page" cpt ...@@ -156,7 +156,7 @@ pageCpt = R2.hooksComponent thisModule "page" cpt
, frontends , frontends
, contact: c , contact: c
, session } , session }
, delete: false }) <$> L.fromFoldable docs , delete: false }) <$> Seq.fromFoldable docs
container = T.defaultContainer { title: "Annuaire" } -- TODO container = T.defaultContainer { title: "Annuaire" } -- TODO
colNames = T.ColumnName <$> [ "", "First Name", "Last Name", "Company", "Lab", "Role"] colNames = T.ColumnName <$> [ "", "First Name", "Last Name", "Company", "Lab", "Role"]
wrapColElts = const identity wrapColElts = const identity
......
...@@ -4,8 +4,8 @@ import Prelude ...@@ -4,8 +4,8 @@ import Prelude
import Data.Array as A import Data.Array as A
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
import Data.List as L
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Sequence as Seq
import Data.Tuple (fst, snd) import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
...@@ -29,7 +29,7 @@ type TableContainerProps = ...@@ -29,7 +29,7 @@ type TableContainerProps =
) )
type Row = { row :: R.Element, delete :: Boolean } type Row = { row :: R.Element, delete :: Boolean }
type Rows = L.List Row type Rows = Seq.Seq Row
type OrderBy = Maybe (OrderByDirection ColumnName) type OrderBy = Maybe (OrderByDirection ColumnName)
...@@ -199,10 +199,10 @@ type FilterRowsParams = ...@@ -199,10 +199,10 @@ type FilterRowsParams =
params :: Params params :: Params
) )
filterRows :: forall a. Record FilterRowsParams -> L.List a -> L.List a filterRows :: forall a. Record FilterRowsParams -> Seq.Seq a -> Seq.Seq a
filterRows { params: { limit, offset, orderBy } } rs = newRs filterRows { params: { limit, offset, orderBy } } rs = newRs
where where
newRs = L.take limit $ L.drop offset $ rs newRs = Seq.take limit $ Seq.drop offset $ rs
defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element
defaultContainer {title} props = R.fragment defaultContainer {title} props = R.fragment
......
module Gargantext.Utils.Seq where
import Data.Array as Array
import Data.Maybe
import Data.Sequence
import Data.Tuple
import Gargantext.Prelude
reverse :: forall a. Seq a -> Seq a
reverse s = case uncons s of
Nothing -> empty
Just (Tuple x xs) -> snoc (reverse xs) x
mapMaybe :: forall a b. (a -> Maybe b) -> Seq a -> Seq b
mapMaybe f = go empty
where
go acc s =
case uncons s of
Nothing -> reverse acc
Just (Tuple x xs) ->
case f x of
Nothing -> go acc xs
Just y -> go (cons y acc) xs
-- same as
-- https://github.com/purescript/purescript-arrays/blob/v5.3.1/src/Data/Array.purs#L715-L715
sortWith :: forall a b. Ord b => (a -> b) -> Seq a -> Seq a
sortWith f l = Array.toUnfoldable $ Array.sortBy (comparing f) $ Array.fromFoldable l
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