Skip to content

Commit

Permalink
ContributionChangesPage: Add ChangeLineId in Route
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Aug 13, 2024
1 parent 103b3ae commit e51ea4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
18 changes: 18 additions & 0 deletions src/UnisonShare/BranchDiff/ChangeLineId.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module UnisonShare.BranchDiff.ChangeLineId exposing (..)

import Code.FullyQualifiedName as FQN exposing (FQN)
import Parser exposing (Parser)
import UnisonShare.BranchDiff.DefinitionType as DefinitionType exposing (DefinitionType)


Expand Down Expand Up @@ -76,6 +77,23 @@ fromString raw =
Nothing


fromUrl : Parser ChangeLineId
fromUrl =
let
parseMaybe clid =
case clid of
Just clid_ ->
Parser.succeed clid_

Nothing ->
Parser.problem "Invalid ChangeLineId"
in
Parser.chompUntilEndOr "/"
|> Parser.getChompedString
|> Parser.map fromString
|> Parser.andThen parseMaybe



-- INTERNAL

Expand Down
4 changes: 2 additions & 2 deletions src/UnisonShare/Page/ProjectContributionChangesPage.elm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import UnisonShare.Api as ShareApi
import UnisonShare.AppContext exposing (AppContext)
import UnisonShare.BranchDiff as BranchDiff exposing (BranchDiff)
import UnisonShare.BranchDiff.ChangeLine as ChangeLine exposing (ChangeLine)
import UnisonShare.BranchDiff.ChangeLineId as ChangeLineId
import UnisonShare.BranchDiff.ChangeLineId as ChangeLineId exposing (ChangeLineId)
import UnisonShare.BranchDiff.ChangedDefinitions as ChangedDefinitions exposing (ChangedDefinitions)
import UnisonShare.BranchDiff.DefinitionType as DefinitionType exposing (DefinitionType)
import UnisonShare.Contribution exposing (Contribution)
Expand All @@ -57,7 +57,7 @@ type alias DiffBranches =
}


init : AppContext -> ProjectRef -> ContributionRef -> Maybe FQN.FQN -> ( Model, Cmd Msg )
init : AppContext -> ProjectRef -> ContributionRef -> Maybe ChangeLineId -> ( Model, Cmd Msg )
init appContext projectRef contribRef _ =
( { branchDiff = Loading
, changedDefinitions = ChangedDefinitions.empty
Expand Down
15 changes: 8 additions & 7 deletions src/UnisonShare/Route.elm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import List.Nonempty as NEL
import Parser exposing ((|.), (|=), Parser, oneOf, succeed, symbol)
import UI.ViewMode as ViewMode exposing (ViewMode)
import UnisonShare.AppError as AppError exposing (AppError)
import UnisonShare.BranchDiff.ChangeLineId as ChangeLineId exposing (ChangeLineId)
import UnisonShare.Contribution.ContributionRef as ContributionRef exposing (ContributionRef)
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
import UnisonShare.Ticket.TicketRef as TicketRef exposing (TicketRef)
Expand All @@ -87,7 +88,7 @@ type UserRoute

type ProjectContributionRoute
= ProjectContributionOverview
| ProjectContributionChanges (Maybe FQN.FQN)
| ProjectContributionChanges (Maybe ChangeLineId)


type ProjectRoute
Expand Down Expand Up @@ -204,9 +205,9 @@ projectContributionChanges projectRef_ contribRef =
Project projectRef_ (ProjectContribution contribRef (ProjectContributionChanges Nothing))


projectContributionChange : ProjectRef -> ContributionRef -> FQN.FQN -> Route
projectContributionChange projectRef_ contribRef fqn =
Project projectRef_ (ProjectContribution contribRef (ProjectContributionChanges (Just fqn)))
projectContributionChange : ProjectRef -> ContributionRef -> ChangeLineId -> Route
projectContributionChange projectRef_ contribRef changeLineId =
Project projectRef_ (ProjectContribution contribRef (ProjectContributionChanges (Just changeLineId)))


projectContributions : ProjectRef -> Route
Expand Down Expand Up @@ -545,7 +546,7 @@ projectParser queryString =
, b (succeed projectBranchRoot_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "code" |. slash |= branchRef |. end)
, b (succeed projectRelease_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "releases" |. slash |= version |. end)
, b (succeed projectReleases_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "releases" |. end)
, b (succeed projectContributionChange_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "contributions" |. slash |= ContributionRef.fromUrl |. slash |. s "changes" |. slash |= fqn |. end)
, b (succeed projectContributionChange_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "contributions" |. slash |= ContributionRef.fromUrl |. slash |. s "changes" |. slash |= ChangeLineId.fromUrl |. end)
, b (succeed projectContributionChanges_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "contributions" |. slash |= ContributionRef.fromUrl |. slash |. s "changes" |. end)
, b (succeed projectContribution_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "contributions" |. slash |= ContributionRef.fromUrl |. end)
, b (succeed projectContributions_ |. slash |= userHandle |. slash |= projectSlug |. slash |. s "contributions" |. end)
Expand Down Expand Up @@ -858,8 +859,8 @@ toUrlString route =
Project projectRef_ (ProjectContribution r (ProjectContributionChanges Nothing)) ->
( ProjectRef.toUrlPath projectRef_ ++ [ "contributions", ContributionRef.toUrlString r, "changes" ], [] )

Project projectRef_ (ProjectContribution r (ProjectContributionChanges (Just fqn))) ->
( ProjectRef.toUrlPath projectRef_ ++ [ "contributions", ContributionRef.toUrlString r, "changes" ] ++ NEL.toList (FQN.toUrlSegments fqn), [] )
Project projectRef_ (ProjectContribution r (ProjectContributionChanges (Just changeLineId))) ->
( ProjectRef.toUrlPath projectRef_ ++ [ "contributions", ContributionRef.toUrlString r, "changes", ChangeLineId.toString changeLineId ], [] )

Project projectRef_ ProjectContributions ->
( ProjectRef.toUrlPath projectRef_ ++ [ "contributions" ], [] )
Expand Down

0 comments on commit e51ea4f

Please sign in to comment.