1module SideBar.Pipeline exposing (pipeline)
2
3import Assets
4import Concourse
5import HoverState
6import Message.Message exposing (DomID(..), Message(..), PipelinesSection(..))
7import Routes
8import Set exposing (Set)
9import SideBar.Styles as Styles
10import SideBar.Views as Views
11
12
13type alias PipelineScoped a =
14    { a
15        | teamName : String
16        , pipelineName : String
17    }
18
19
20pipeline :
21    { a
22        | hovered : HoverState.HoverState
23        , currentPipeline : Maybe (PipelineScoped b)
24        , favoritedPipelines : Set Int
25        , isFavoritesSection : Bool
26    }
27    -> Concourse.Pipeline
28    -> Views.Pipeline
29pipeline params p =
30    let
31        isCurrent =
32            case params.currentPipeline of
33                Just cp ->
34                    cp.pipelineName == p.name && cp.teamName == p.teamName
35
36                Nothing ->
37                    False
38
39        pipelineId =
40            { pipelineName = p.name, teamName = p.teamName }
41
42        domID =
43            SideBarPipeline
44                (if params.isFavoritesSection then
45                    FavoritesSection
46
47                 else
48                    AllPipelinesSection
49                )
50                pipelineId
51
52        isHovered =
53            HoverState.isHovered domID params.hovered
54
55        isFavorited =
56            Set.member p.id params.favoritedPipelines
57    in
58    { icon =
59        { asset =
60            if p.archived then
61                Assets.ArchivedPipelineIcon
62
63            else
64                Assets.BreadcrumbIcon Assets.PipelineComponent
65        , opacity =
66            if isCurrent || isHovered then
67                Styles.Bright
68
69            else
70                Styles.Dim
71        }
72    , name =
73        { opacity =
74            if isCurrent || isHovered then
75                Styles.Bright
76
77            else
78                Styles.Dim
79        , text = p.name
80        , weight =
81            if isCurrent then
82                Styles.Bold
83
84            else
85                Styles.Default
86        }
87    , background =
88        if isCurrent then
89            Styles.Dark
90
91        else if isHovered then
92            Styles.Light
93
94        else
95            Styles.Invisible
96    , href =
97        Routes.toString <|
98            Routes.Pipeline { id = pipelineId, groups = [] }
99    , domID = domID
100    , starIcon =
101        { opacity =
102            if isFavorited then
103                Styles.Bright
104
105            else
106                Styles.Dim
107        , filled = isFavorited
108        }
109    , id = p.id
110    }
111