Skip to content

Commit 2a23e02

Browse files
committed
Add check result on contribution overview
1 parent a4317b4 commit 2a23e02

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

src/UnisonShare/Check.elm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Url exposing (Url)
1515
type CheckStatus
1616
= NotStarted
1717
| Waiting { startedAt : DateTime }
18-
| TimeOut
18+
| Timeout
1919
{ startedAt : DateTime
2020
, endedAt : DateTime
2121
}
@@ -87,6 +87,7 @@ checkIdFromUrl =
8787
|> Parser.andThen parseMaybe
8888

8989

90+
9091
-- DECODE
9192

9293

@@ -105,8 +106,8 @@ decodeStatus =
105106
Decode.succeed (\s -> Waiting { startedAt = s })
106107
|> required "startedAt" DateTime.decode
107108

108-
decodeTimeOut =
109-
Decode.succeed (\s e -> TimeOut { startedAt = s, endedAt = e })
109+
decodeTimeout =
110+
Decode.succeed (\s e -> Timeout { startedAt = s, endedAt = e })
110111
|> required "startedAt" DateTime.decode
111112
|> required "endedAt" DateTime.decode
112113

@@ -137,7 +138,7 @@ decodeStatus =
137138
Decode.oneOf
138139
[ whenTagIs "NotStarted" (Decode.succeed NotStarted)
139140
, whenTagIs "Waiting" decodeWaiting
140-
, whenTagIs "TimeOut" decodeTimeOut
141+
, whenTagIs "Timeout" decodeTimeout
141142
, whenTagIs "Failure" decodeFailure
142143
, whenTagIs "Success" decodeSuccess
143144
]

src/UnisonShare/Contribution.elm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Json.Decode as Decode
1515
import Json.Decode.Pipeline exposing (optional, required)
1616
import Lib.UserHandle as UserHandle
1717
import UI.DateTime as DateTime exposing (DateTime)
18+
import UnisonShare.Check as Check exposing (Check)
1819
import UnisonShare.Contribution.ContributionRef as ContributionRef exposing (ContributionRef)
1920
import UnisonShare.Contribution.ContributionStatus as ContributionStatus exposing (ContributionStatus)
2021
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
@@ -51,7 +52,10 @@ type alias ContributionSummary =
5152

5253

5354
type alias ContributionDetails =
54-
Contribution { contributionStateToken : ContributionStateToken }
55+
Contribution
56+
{ contributionStateToken : ContributionStateToken
57+
, latestCheckOnSourceBranch : Maybe Check
58+
}
5559

5660

5761

@@ -74,8 +78,8 @@ toSummary contrib =
7478
}
7579

7680

77-
toDetails : ContributionStateToken -> ContributionSummary -> ContributionDetails
78-
toDetails token contrib =
81+
toDetails : ContributionStateToken -> Maybe Check -> ContributionSummary -> ContributionDetails
82+
toDetails token check contrib =
7983
{ ref = contrib.ref
8084
, author = contrib.author
8185
, sourceBranchRef = contrib.sourceBranchRef
@@ -88,6 +92,7 @@ toDetails token contrib =
8892
, title = contrib.title
8993
, description = contrib.description
9094
, contributionStateToken = token
95+
, latestCheckOnSourceBranch = check
9196
}
9297

9398

@@ -116,7 +121,7 @@ decodeDetails =
116121
, User.decodeSummary
117122
]
118123

119-
makeContributionDetails ref author sourceBranchRef targetBranchRef projectRef createdAt updatedAt status numComments title description contributionStateToken =
124+
makeContributionDetails ref author sourceBranchRef targetBranchRef projectRef createdAt updatedAt status numComments title description contributionStateToken check =
120125
{ ref = ref
121126
, author = author
122127
, sourceBranchRef = sourceBranchRef
@@ -129,6 +134,7 @@ decodeDetails =
129134
, title = title
130135
, description = description
131136
, contributionStateToken = contributionStateToken
137+
, latestCheckOnSourceBranch = check
132138
}
133139
in
134140
Decode.succeed makeContributionDetails
@@ -145,6 +151,7 @@ decodeDetails =
145151
|> optional "description" (Decode.map Just Decode.string) Nothing
146152
|> required "contributionStateToken"
147153
(Decode.map ContributionStateToken Decode.string)
154+
|> optional "latestCheckOnSourceBranch" (Decode.map Just Check.decode) Nothing
148155

149156

150157
decodeSummary : Decode.Decoder ContributionSummary

src/UnisonShare/Page/ProjectContributionChecksPage.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ viewTitle appContext folds check =
218218
, foldToggle = FoldToggle.view FoldToggle.disabled
219219
}
220220

221-
Check.TimeOut { startedAt, endedAt } ->
221+
Check.Timeout { startedAt, endedAt } ->
222222
{ result = StatusIndicator.view StatusIndicator.bad
223223
, date = DateTime.view (DateTime.DistanceFrom appContext.now) appContext.timeZone check.createdAt
224224
, timing = viewTiming startedAt endedAt

src/UnisonShare/Page/ProjectContributionOverviewPage.elm

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import UI
1010
import UI.Button as Button
1111
import UI.ByAt as ByAt
1212
import UI.Card as Card
13+
import UI.Click as Click
1314
import UI.DateTime as DateTime
1415
import UI.Icon as Icon
1516
import UI.PageContent as PageContent exposing (PageContent)
@@ -19,6 +20,7 @@ import UI.Tooltip as Tooltip
1920
import UnisonShare.Account as Account
2021
import UnisonShare.Api as ShareApi
2122
import UnisonShare.AppContext exposing (AppContext)
23+
import UnisonShare.Check as Check
2224
import UnisonShare.Contribution as Contribution exposing (ContributionDetails, ContributionStateToken)
2325
import UnisonShare.Contribution.ContributionEvent as ContributionEvent
2426
import UnisonShare.Contribution.ContributionMergeability as ContributionMergeability exposing (ContributionMergeability)
@@ -333,10 +335,42 @@ viewContribution session project updateStatus contribution mergeStatus =
333335
else
334336
UI.nothing
335337

338+
leftAction =
339+
let
340+
checkLink c html =
341+
Link.view_ html
342+
(Link.projectContributionCheck
343+
c.projectRef
344+
contribution.ref
345+
c.id
346+
)
347+
in
348+
-- TODO: verify causal hash somehow
349+
case contribution.latestCheckOnSourceBranch of
350+
Just c ->
351+
case c.status of
352+
Check.NotStarted ->
353+
UI.nothing
354+
355+
Check.Waiting _ ->
356+
checkLink c (StatusBanner.working "Check in progress..")
357+
358+
Check.Timeout _ ->
359+
checkLink c (StatusBanner.bad "Check failed with timeout")
360+
361+
Check.Failure _ ->
362+
checkLink c (StatusBanner.bad "Check failed")
363+
364+
Check.Success _ ->
365+
checkLink c (StatusBanner.good "Check succeeded")
366+
367+
Nothing ->
368+
UI.nothing
369+
336370
actions =
337371
case contribution.status of
338372
ContributionStatus.Draft ->
339-
[ div [ class "left-actions" ] []
373+
[ div [ class "left-actions" ] [ leftAction ]
340374
, div [ class "right-actions" ]
341375
[ Button.iconThenLabel (UpdateStatus ContributionStatus.InReview) Icon.conversation "Submit for review"
342376
|> Button.emphasized
@@ -345,7 +379,7 @@ viewContribution session project updateStatus contribution mergeStatus =
345379
]
346380

347381
ContributionStatus.InReview ->
348-
[ div [ class "left-actions" ] []
382+
[ div [ class "left-actions" ] [ leftAction ]
349383
, div [ class "right-actions" ] [ archiveButton, mergeButton ]
350384
]
351385

src/UnisonShare/Page/ProjectContributionPage.elm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,14 @@ update appContext projectRef contribRef _ project msg model =
179179

180180
ProjectContributionFormModal.Saved newContrib ->
181181
-- TODO: also add a ContributionEvent
182-
( NoModal, Success (Contribution.toDetails contrib.contributionStateToken newContrib) )
182+
( NoModal
183+
, Success
184+
(Contribution.toDetails
185+
contrib.contributionStateToken
186+
Nothing
187+
newContrib
188+
)
189+
)
183190
in
184191
( { model | modal = modal, contribution = contribution }
185192
, Cmd.map ProjectContributionFormModalMsg cmd

0 commit comments

Comments
 (0)