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
d8729444
Commit
d8729444
authored
Oct 26, 2020
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a better and more general sortWith
parent
9c4f2849
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
33 deletions
+34
-33
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+7
-7
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+5
-5
Utils.purs
src/Gargantext/Utils.purs
+17
-1
Seq.purs
src/Gargantext/Utils/Seq.purs
+5
-20
No files found.
src/Gargantext/Components/DocsTable.purs
View file @
d8729444
...
...
@@ -32,7 +32,7 @@ import Gargantext.Components.Category
import Gargantext.Components.Table as T
import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoaderWithCacheAPI, HashedResponse(..))
import Gargantext.Utils
.Seq (sortWith) as Seq
import Gargantext.Utils
(sortWith)
import Gargantext.Utils.Reactix as R2
import Gargantext.Routes as Routes
import Gargantext.Routes (SessionRoute(NodeAPI))
...
...
@@ -377,12 +377,12 @@ pagePaintCpt = R.hooksComponentWithModule thisModule "pagePaintCpt" cpt where
getCategory (localCategories /\ _) {_id, category} = fromMaybe category (localCategories ^. at _id)
orderWith =
case convOrderBy (fst params).orderBy of
Just DateAsc ->
Seq.
sortWith \(DocumentsView { date }) -> date
Just DateDesc ->
Seq.
sortWith \(DocumentsView { date }) -> Down date
Just SourceAsc ->
Seq.
sortWith \(DocumentsView { source }) -> Str.toLower source
Just SourceDesc ->
Seq.
sortWith \(DocumentsView { source }) -> Down $ Str.toLower source
Just TitleAsc ->
Seq.
sortWith \(DocumentsView { title }) -> Str.toLower title
Just TitleDesc ->
Seq.
sortWith \(DocumentsView { title }) -> Down $ Str.toLower title
Just DateAsc -> sortWith \(DocumentsView { date }) -> date
Just DateDesc -> sortWith \(DocumentsView { date }) -> Down date
Just SourceAsc -> sortWith \(DocumentsView { source }) -> Str.toLower source
Just SourceDesc -> sortWith \(DocumentsView { source }) -> Down $ Str.toLower source
Just TitleAsc -> sortWith \(DocumentsView { title }) -> Str.toLower title
Just TitleDesc -> sortWith \(DocumentsView { title }) -> Down $ Str.toLower title
_ -> identity -- the server ordering is enough here
filteredRows = T.filterRows { params: fst params } $ orderWith $ A.toUnfoldable documents
rows localCategories = row <$> filteredRows
...
...
src/Gargantext/Components/NgramsTable.purs
View file @
d8729444
...
...
@@ -42,7 +42,7 @@ import Gargantext.Prelude (class Show, Unit, bind, const, discard, identity, map
import Gargantext.Routes (SessionRoute(..)) as R
import Gargantext.Sessions (Session, get)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
import Gargantext.Utils (queryMatchesLabel, toggleSet)
import Gargantext.Utils (queryMatchesLabel, toggleSet
, sortWith
)
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Seq as Seq
...
...
@@ -423,10 +423,10 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
}
orderWith =
case convOrderBy <$> params.orderBy of
Just ScoreAsc ->
Seq.
sortWith \x -> x ^. _NgramsElement <<< _occurrences
Just ScoreDesc ->
Seq.
sortWith \x -> Down $ x ^. _NgramsElement <<< _occurrences
Just TermAsc ->
Seq.
sortWith \x -> x ^. _NgramsElement <<< _ngrams
Just TermDesc ->
Seq.
sortWith \x -> Down $ x ^. _NgramsElement <<< _ngrams
Just ScoreAsc -> sortWith \x -> x ^. _NgramsElement <<< _occurrences
Just ScoreDesc -> sortWith \x -> Down $ x ^. _NgramsElement <<< _occurrences
Just TermAsc -> sortWith \x -> x ^. _NgramsElement <<< _ngrams
Just TermDesc -> sortWith \x -> Down $ x ^. _NgramsElement <<< _ngrams
_ -> identity -- the server ordering is enough here
colNames = T.ColumnName <$> ["Select", "Map", "Stop", "Terms", "Score"] -- see convOrderBy
...
...
src/Gargantext/Utils.purs
View file @
d8729444
...
...
@@ -2,13 +2,15 @@ module Gargantext.Utils where
import DOM.Simple.Window (window)
import Data.Either (Either(..))
import Data.Foldable (class Foldable, foldr)
import Data.Lens (Lens', lens)
import Data.Newtype (class Newtype, unwrap, wrap)
import Data.Set (Set)
import Data.Set as Set
import Data.Sequence.Ordered as OSeq
import Data.String as S
import Data.Unfoldable (class Unfoldable)
import Effect (Effect)
import Effect.Class (liftEffect)
import FFI.Simple ((..))
import FFI.Simple.Functions (delay)
import Prelude
...
...
@@ -84,5 +86,19 @@ mapLeft _ (Right r) = Right r
location :: Effect String
location = delay unit $ \_ -> pure $ window .. "location"
data On a b = On a b
instance eqOn :: Eq a => Eq (On a b) where
eq (On x _) (On y _) = eq x y
instance ordOn :: Ord a => Ord (On a b) where
compare (On x _) (On y _) = compare x y
-- same as
-- https://github.com/purescript/purescript-arrays/blob/v5.3.1/src/Data/Array.purs#L715-L715
sortWith :: forall a b f. Functor f =>
Foldable f =>
Unfoldable f =>
Ord b =>
(a -> b) -> f a -> f a
sortWith f = map (\(On _ y) -> y) <<< OSeq.toUnfoldable <<< foldr (\x -> OSeq.insert (On (f x) x)) OSeq.empty
\ No newline at end of file
src/Gargantext/Utils/Seq.purs
View file @
d8729444
module Gargantext.Utils.Seq where
module Gargantext.Utils.Seq
(mapMaybe)
where
import Data.Array as Array
import Data.Maybe
import Data.Sequence
import Data.Tuple
import Data.Maybe (Maybe, maybe)
import Data.Sequence (Seq, concatMap, empty, singleton)
import Gargantext.Prelude
import Gargantext.Prelude
((<<<))
mapMaybe :: forall a b. (a -> Maybe b) -> Seq a -> Seq b
mapMaybe f = go empty
where
go acc s =
case uncons s of
Nothing -> 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
mapMaybe f = concatMap (maybe empty singleton <<< f)
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