Commit 1a2c37a7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[docs] chart update after docs moved to/from trash

parent 9de858ae
Pipeline #2792 canceled with stage
......@@ -7,7 +7,8 @@ import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Effect.Aff (launchAff)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, categories, clickAgain, star2score, stars)
import Gargantext.Components.DocsTable.Types (DocumentsView(..), LocalCategories, LocalUserScore)
import Gargantext.Config.REST (AffRESTError)
......@@ -15,6 +16,7 @@ import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, put)
import Gargantext.Types (NodeID, NodeType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Simple.JSON as JSON
......@@ -23,19 +25,24 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Category"
type RatingProps =
( score :: Star
( chartReload :: T2.ReloadS
, nodeId :: NodeID
, row :: DocumentsView
, score :: Star
, session :: Session
, setLocalCategories :: R.Setter LocalUserScore
)
rating :: R2.Component RatingProps
rating = R.createElement ratingCpt
ratingCpt :: R.Component RatingProps
ratingCpt = here.component "rating" cpt where
cpt { nodeId, row: DocumentsView r, score, session, setLocalCategories } _ =
cpt { chartReload
, nodeId
, row: DocumentsView r
, score
, session
, setLocalCategories } _ =
pure $ H.div { className:"flex" } divs where
divs = map (\s -> H.div { className : icon' score s
, on: { click: onClick s } } []) stars
......@@ -48,9 +55,9 @@ ratingCpt = here.component "rating" cpt where
else c
setLocalCategories $ Map.insert r._id c'
void $ launchAff
$ putRating session nodeId
$ RatingQuery { nodeIds: [r._id], rating: c' }
launchAff_ $ do
_ <- putRating session nodeId $ RatingQuery { nodeIds: [r._id], rating: c' }
liftEffect $ T2.reload chartReload
newtype RatingQuery =
RatingQuery { nodeIds :: Array Int
......@@ -98,9 +105,8 @@ carousselCpt = here.component "caroussel" cpt
onClick c = \_-> do
setLocalCategories $ Map.insert r._id c
void $ launchAff
$ putCategories session nodeId
$ CategoryQuery {nodeIds: [r._id], category: c}
launchAff_ $ do
putCategories session nodeId $ CategoryQuery {nodeIds: [r._id], category: c}
icon :: Category -> Boolean -> String
icon cat b = btn b $ "fa fa-" <> (color $ size b $ icon' cat b)
......
......@@ -74,6 +74,7 @@ type Path a =
type CommonProps =
( boxes :: Boxes
, cacheState :: T.Box NT.CacheState
, chartReload :: T2.ReloadS
, frontends :: Frontends
, listId :: Int
, mCorpusId :: Maybe Int
......@@ -88,8 +89,8 @@ type CommonProps =
)
type LayoutProps =
( chart :: R.Element
, showSearch :: Boolean
( chart :: R.Element
, showSearch :: Boolean
| CommonProps
-- , path :: Record (Path a)
)
......@@ -126,6 +127,7 @@ docViewCpt = here.component "docView" cpt where
cpt { layout: { boxes
, cacheState
, chart
, chartReload
, frontends
, listId
, mCorpusId
......@@ -204,20 +206,21 @@ docViewCpt = here.component "docView" cpt where
]
, H.div {className: "col-md-12"}
[ pageLayout { boxes
, cacheState
, frontends
, key: "docView-" <> (show cacheState')
, listId
, mCorpusId
, nodeId
, params
, query: query'
, session
, sidePanel
, tabType
, totalRecords
, yearFilter
} []
, cacheState
, chartReload
, frontends
, key: "docView-" <> (show cacheState')
, listId
, mCorpusId
, nodeId
, params
, query: query'
, session
, sidePanel
, tabType
, totalRecords
, yearFilter
} []
]
]
]
......@@ -448,7 +451,7 @@ pageLayoutCpt = here.component "pageLayout" cpt where
pure $ handleResponse <$> eRes
let render (Tuple count documents) = pagePaintRaw { documents
, layout: props' { params = paramsS'
, totalRecords = count }
, totalRecords = count }
, localCategories
, params: paramsS } []
let errorHandler = logRESTError here "[pageLayout]"
......@@ -515,9 +518,10 @@ type PagePaintRawProps =
pagePaintRaw :: R2.Component PagePaintRawProps
pagePaintRaw = R.createElement pagePaintRawCpt
pagePaintRawCpt :: R.Component PagePaintRawProps
pagePaintRawCpt = here.component "pagePaintRawCpt" cpt where
pagePaintRawCpt = here.component "pagePaintRaw" cpt where
cpt { documents
, layout: { boxes
, chartReload
, frontends
, listId
, mCorpusId
......@@ -539,7 +543,7 @@ pagePaintRawCpt = here.component "pagePaintRawCpt" cpt where
{ colNames
, container: TT.defaultContainer
, params
, rows: rows reload localCategories' mCurrentDocId'
, rows: rows reload chartReload localCategories' mCurrentDocId'
, syncResetButton : [ H.div {} [] ]
, totalRecords
, wrapColElts
......@@ -554,9 +558,9 @@ pagePaintRawCpt = here.component "pagePaintRawCpt" cpt where
| otherwise = Routes.Document sid listId
colNames = TT.ColumnName <$> [ "Show", "Tag", "Date", "Title", "Source", "Score" ]
wrapColElts = const identity
rows reload localCategories' mCurrentDocId' = row reload <$> A.toUnfoldable documents
rows reload chartReload localCategories' mCurrentDocId' = row <$> A.toUnfoldable documents
where
row reload dv@(DocumentsView r@{ _id, category }) =
row dv@(DocumentsView r@{ _id, category }) =
{ row:
TT.makeRow [ -- H.div {} [ H.a { className, style, on: {click: click Favorite} } [] ]
H.div { className: "" }
......@@ -568,7 +572,8 @@ pagePaintRawCpt = here.component "pagePaintRawCpt" cpt where
]
--, H.div { className: "column-tag flex" } [ caroussel { category: cat, nodeId, row: dv, session, setLocalCategories } [] ]
, H.div { className: "column-tag flex" }
[ rating { nodeId
[ rating { chartReload
, nodeId
, row: dv
, score: cat
, setLocalCategories: \lc -> T.modify_ lc localCategories
......
......@@ -11,10 +11,8 @@ import Effect.Aff (Aff)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable.Types (Year)
import Gargantext.Components.GraphQL.User (UserInfo)
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.NgramsTable.Core as NTC
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (ContactData)
import Gargantext.Components.Nodes.Lists.Types as LTypes
import Gargantext.Components.Nodes.Texts.Types as TextsT
import Gargantext.Components.Tab as Tab
......@@ -22,6 +20,7 @@ import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType(..), PTabNgramType(..), TabSubType(..), TabType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Record as Record
import Record.Extra as RX
......@@ -67,9 +66,10 @@ tabsCpt = here.component "tabs" cpt where
cpt props _ = do
activeTab <- T.useBox 0
yearFilter <- T.useBox (Nothing :: Maybe Year)
chartReload <- T.useBox T2.newReload
pure $ Tab.tabs { activeTab, tabs: tabs' yearFilter props }
tabs' yearFilter props@{ boxes, defaultListId, sidePanel } =
pure $ Tab.tabs { activeTab, tabs: tabs' yearFilter chartReload props }
tabs' yearFilter chartReload props@{ boxes, defaultListId, sidePanel } =
[ "Documents" /\ docs
, "Patents" /\ ngramsView (viewProps Patents)
, "Books" /\ ngramsView (viewProps Books)
......@@ -78,7 +78,7 @@ tabsCpt = here.component "tabs" cpt where
] where
viewProps mode = Record.merge props { mode }
totalRecords = 4736 -- TODO lol
docs = DT.docViewLayout (Record.merge { boxes, sidePanel } $ Record.merge dtCommon dtExtra)
docs = DT.docViewLayout (Record.merge { boxes, chartReload, sidePanel } $ Record.merge dtCommon dtExtra)
dtCommon = RX.pick props :: Record DTCommon
dtExtra =
{ chart: mempty
......
......@@ -12,7 +12,6 @@ import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable.Types (Year)
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.NgramsTable.Core as NTC
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (ContactData')
import Gargantext.Components.Nodes.Lists.Types as LTypes
import Gargantext.Components.Nodes.Texts.Types as TTypes
import Gargantext.Components.Tab as Tab
......@@ -20,6 +19,7 @@ import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType(..), PTabNgramType(..), TabSubType(..), TabType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Toestand as T
......@@ -72,10 +72,11 @@ tabsCpt = here.component "tabs" cpt
} _ = do
activeTab <- T.useBox 0
yearFilter <- T.useBox (Nothing :: Maybe Year)
chartReload <- T.useBox T2.newReload
pure $ Tab.tabs { activeTab, tabs: tabs' yearFilter }
pure $ Tab.tabs { activeTab, tabs: tabs' yearFilter chartReload }
where
tabs' yearFilter =
tabs' yearFilter chartReload =
[ "Documents" /\ docs
, "Patents" /\ ngramsView patentsView []
, "Books" /\ ngramsView booksView []
......@@ -110,6 +111,7 @@ tabsCpt = here.component "tabs" cpt
{ boxes
, cacheState
, chart
, chartReload
, frontends
, listId: defaultListId
, mCorpusId: Nothing
......
......@@ -6,6 +6,7 @@ import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Data.Show.Generic (genericShow)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (launchAff_)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Charts.Options.ECharts (dispatchAction)
......@@ -16,6 +17,7 @@ import Gargantext.Components.NgramsTable.Loader (clearCache)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild)
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Nodes.Corpus.Chart.Types as CTypes
import Gargantext.Components.Nodes.Corpus.Document as D
import Gargantext.Components.Nodes.Corpus.Types (CorpusData)
import Gargantext.Components.Nodes.Lists.Types as LT
......@@ -203,14 +205,16 @@ tabsCpt = here.component "tabs" cpt
activeTab <- T.useBox 0
chartReload <- T.useBox T2.newReload
pure $ Tab.tabs {
activeTab
, tabs: [
"Documents" /\ R.fragment [
histo { boxes, path, session, onClick, onInit }
, docView' path TabDocs
histoRender { boxes, path, onClick, onInit, reload: chartReload, session } []
, docView' path chartReload TabDocs
]
, "Trash" /\ docView' path TabTrash
, "Trash" /\ docView' path chartReload TabTrash
-- , "More like fav" /\ docView' path TabMoreLikeFav
-- , "More like trash" /\ docView' path TabMoreLikeTrash
]
......@@ -221,31 +225,47 @@ tabsCpt = here.component "tabs" cpt
, listId: corpusData.defaultListId
, limit: Nothing
, tabType: TabCorpus TabDocs }
docView' path tabType = docView { boxes
, cacheState
, corpusData
, corpusId
, frontends
, listId: path.listId
-- , path
, session
, tabType
, sidePanel
, yearFilter
} []
docView' path chartReload tabType = docView { boxes
, cacheState
, chartReload
, corpusData
, corpusId
, frontends
, listId: path.listId
-- , path
, session
, tabType
, sidePanel
, yearFilter
} []
type HistoProps =
( reload :: T2.ReloadS
| CTypes.Props
)
histoRender :: R2.Component HistoProps
histoRender = R.createElement histoRenderCpt
histoRenderCpt :: R.Component HistoProps
histoRenderCpt = here.component "histoRender" cpt where
cpt { boxes, path, onClick, onInit, reload, session } _ = do
reload' <- T.useLive T.unequal reload
pure $ histo { boxes, path, onClick, onInit, session }
type DocViewProps a =
( boxes :: Boxes
, cacheState :: T.Box LT.CacheState
, corpusData :: CorpusData
, corpusId :: NodeID
, frontends :: Frontends
, listId :: ListId
-- , path :: Record DT.Path
, session :: Session
, tabType :: TabSubType a
, sidePanel :: T.Box (Maybe (Record TT.SidePanel))
, yearFilter :: T.Box (Maybe Year)
( boxes :: Boxes
, cacheState :: T.Box LT.CacheState
, chartReload :: T2.ReloadS
, corpusData :: CorpusData
, corpusId :: NodeID
, frontends :: Frontends
, listId :: ListId
-- , path :: Record DT.Path
, session :: Session
, tabType :: TabSubType a
, sidePanel :: T.Box (Maybe (Record TT.SidePanel))
, yearFilter :: T.Box (Maybe Year)
)
docView :: forall a. R2.Component (DocViewProps a)
......@@ -259,6 +279,7 @@ docViewCpt = here.component "docView" cpt
-- docViewLayoutRec :: forall a. DocViewProps a -> Record DT.LayoutProps
docViewLayoutRec { boxes
, cacheState
, chartReload
, corpusId
, frontends
, listId
......@@ -270,6 +291,7 @@ docViewLayoutRec { boxes
{ boxes
, cacheState
, chart : H.div {} []
, chartReload
, frontends
, listId
, mCorpusId: Just corpusId
......@@ -284,6 +306,7 @@ docViewLayoutRec { boxes
}
docViewLayoutRec { boxes
, cacheState
, chartReload
, corpusId
, frontends
, listId
......@@ -295,6 +318,7 @@ docViewLayoutRec { boxes
{ boxes
, cacheState
, chart : H.div {} []
, chartReload
, frontends
, listId
, mCorpusId: Just corpusId
......@@ -309,6 +333,7 @@ docViewLayoutRec { boxes
}
docViewLayoutRec { boxes
, cacheState
, chartReload
, corpusId
, frontends
, listId
......@@ -320,6 +345,7 @@ docViewLayoutRec { boxes
{ boxes
, cacheState
, chart : H.div {} []
, chartReload
, frontends
, listId
, mCorpusId: Just corpusId
......@@ -334,6 +360,7 @@ docViewLayoutRec { boxes
}
docViewLayoutRec { boxes
, cacheState
, chartReload
, corpusId
, frontends
, listId
......@@ -345,6 +372,7 @@ docViewLayoutRec { boxes
{ boxes
, cacheState
, chart : H.div {} []
, chartReload
, frontends
, listId
, mCorpusId: Just corpusId
......@@ -360,6 +388,7 @@ docViewLayoutRec { boxes
-- DUMMY
docViewLayoutRec { boxes
, cacheState
, chartReload
, corpusId
, frontends
, listId
......@@ -371,6 +400,7 @@ docViewLayoutRec { boxes
{ boxes
, cacheState
, chart : H.div {} []
, chartReload
, frontends
, listId
, mCorpusId: Just corpusId
......
......@@ -49,7 +49,6 @@ type TabProps = ( selected :: Int, index :: Int )
tab :: R2.Component TabProps
tab = R.createElement tabCpt
-- | A tab only shows its contents if it is currently selected
tabCpt :: R.Component TabProps
tabCpt = here.component "tab" cpt
......
......@@ -55,3 +55,4 @@ useMemberBox val box = T.useFocused (Set.member val) (toggleSet val) box
toggleSet :: forall s. Ord s => s -> Boolean -> Set s -> Set s
toggleSet val true set = Set.insert val set
toggleSet val false set = Set.delete val set
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