Kaynağa Gözat

Remove fromDetachedToUI

jherve 1 yıl önce
ebeveyn
işleme
e0ef65a824

+ 2 - 2
src/LinkedIn/Output.purs

@@ -16,7 +16,7 @@ import LinkedIn.Page.Skills (SkillsPage)
 import LinkedIn.Page.WorkExperiences (WorkExperiencesPage)
 import LinkedIn.PageUrl (PageUrl(..))
 import LinkedIn.QueryRunner (QueryError)
-import LinkedIn.UI.Elements.Parser (fromDetachedToUI)
+import LinkedIn.UI.Elements.Parser (toUIElement)
 import Type.Proxy (Proxy(..))
 import Web.DOM (Document)
 
@@ -28,7 +28,7 @@ run :: forall t.
   -> ExceptT String Effect Output
 run prox dom = do
   detached <- withExceptT (\_ -> "Error on detach") $ runToDetached prox dom
-  asUI <- except $ fromDetachedToUI detached
+  asUI <- withExceptT (\_ -> "error on conversion to UI element") $ except $ traverse toUIElement detached
   except $ LE.extract asUI
 
 runToDetached :: forall t.

+ 0 - 6
src/LinkedIn/UI/Elements/Parser.purs

@@ -6,17 +6,11 @@ import Control.Alt ((<|>))
 import Data.Either (Either(..))
 import Data.List as L
 import Data.Maybe (Maybe(..))
-import Data.Traversable (class Traversable, traverse)
 import LinkedIn.DetachedNode (DetachedNode(..))
 import LinkedIn.UI.Strings.Parser (uiStringP)
 import LinkedIn.UI.Elements.Types (UIElement(..))
 import Parsing (ParseError(..), initialPos, runParser)
 
-fromDetachedToUI ∷ ∀ t. Traversable t ⇒ t DetachedNode → Either String (t UIElement)
-fromDetachedToUI el = case traverse toUIElement el of
-  Left _ -> Left "error on conversion to UI element"
-  Right ui -> Right ui
-
 -- TODO : should certainly use another type than ParseError here
 toUIElement ∷ DetachedNode → Either ParseError UIElement
 toUIElement (DetachedElement {content}) = wrapInUiElement content

+ 1 - 2
test/ArtDecoCard.purs

@@ -20,11 +20,10 @@ import LinkedIn.QueryRunner (runQuery)
 import LinkedIn.UI.Basic.Types (Duration(..), TimeSpan(..))
 import LinkedIn.UI.Components.ArtDeco (ArtDecoCenter(..), ArtDecoCenterContent(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..), ArtDecoPvsEntitySubComponent(..))
 import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement(..))
-import LinkedIn.UI.Elements.Parser (fromDetachedToUI)
 import Node.JsDom (jsDomFromFile)
 import Partial.Unsafe (unsafePartial)
 import Test.Assert (assert, assertEqual)
-import Test.Utils (toMonthYear')
+import Test.Utils (toMonthYear', fromDetachedToUI)
 
 testArtDecoCards :: Effect Unit
 testArtDecoCards = do

+ 1 - 1
test/JobsUnifiedTopCard.purs

@@ -17,10 +17,10 @@ import LinkedIn.Page.JobOffer (JobOfferPage(..))
 import LinkedIn.QueryRunner (runQuery)
 import LinkedIn.UI.Basic.Types (JobFlexibility(..))
 import LinkedIn.UI.Components.JobsUnifiedTopCard (JobsUnifiedTopCardElement(..), TopCardAction(..), TopCardInsight(..), TopCardInsightContent(..), TopCardPrimaryDescription(..), TopCardSecondaryInsight(..))
-import LinkedIn.UI.Elements.Parser (fromDetachedToUI)
 import Node.JsDom (jsDomFromFile)
 import Partial.Unsafe (unsafePartial)
 import Test.Assert (assert, assertEqual)
+import Test.Utils (fromDetachedToUI)
 
 main :: Effect Unit
 main = do

+ 10 - 0
test/Utils.purs

@@ -3,12 +3,22 @@ module Test.Utils where
 import Prelude
 
 import Data.Date (Month)
+import Data.Either (Either(..))
 import Data.Int (toNumber)
 import Data.Maybe (fromJust)
+import Data.Traversable (class Traversable, traverse)
+import LinkedIn.DetachedNode (DetachedNode)
 import LinkedIn.UI.Basic.Parser (toYear)
 import LinkedIn.UI.Basic.Types (MonthYear(..))
+import LinkedIn.UI.Elements.Parser (toUIElement)
+import LinkedIn.UI.Elements.Types (UIElement)
 import Partial.Unsafe (unsafePartial)
 
 toMonthYear' :: Month -> Int -> MonthYear
 toMonthYear' m y = MonthYear m y' where
   y' = unsafePartial $ fromJust $ toYear $ toNumber y
+
+fromDetachedToUI ∷ ∀ t. Traversable t ⇒ t DetachedNode → Either String (t UIElement)
+fromDetachedToUI el = case traverse toUIElement el of
+  Left _ -> Left "error on conversion to UI element"
+  Right ui -> Right ui