forked from tangled.org/core
this repo has no description

appview: state: populate new pull form from query params

anirudh.fi 52bf64f9 c200b4ec

verified
Changed files
+73 -7
appview
pages
state
+6
appview/pages/pages.go
··· 698 698 LoggedInUser *oauth.User 699 699 RepoInfo repoinfo.RepoInfo 700 700 Branches []types.Branch 701 + Strategy string 702 + SourceBranch string 703 + TargetBranch string 704 + Title string 705 + Body string 701 706 Active string 702 707 } 703 708 ··· 805 810 type PullCompareForkParams struct { 806 811 RepoInfo repoinfo.RepoInfo 807 812 Forks []db.Repo 813 + Selected string 808 814 } 809 815 810 816 func (p *Pages) PullCompareForkFragment(w io.Writer, params PullCompareForkParams) error {
+9 -2
appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html
··· 1 1 {{ define "repo/pulls/fragments/pullCompareBranches" }} 2 2 <div id="patch-upload"> 3 - <label for="targetBranch" class="dark:text-white">select a branch</label> 3 + <label for="targetBranch" class="dark:text-white">select a source branch</label> 4 4 <div class="flex flex-wrap gap-2 items-center"> 5 5 <select 6 6 name="sourceBranch" ··· 11 11 {{ $recent := index .Branches 0 }} 12 12 {{ range .Branches }} 13 13 {{ $isRecent := eq .Reference.Name $recent.Reference.Name }} 14 + {{ $preset := false }} 15 + {{ if $.SourceBranch }} 16 + {{ $preset = eq .Reference.Name $.SourceBranch }} 17 + {{ else }} 18 + {{ $preset = $isRecent }} 19 + {{ end }} 20 + 14 21 <option 15 22 value="{{ .Reference.Name }}" 16 - {{ if $isRecent }} 23 + {{ if $preset }} 17 24 selected 18 25 {{ end }} 19 26 class="py-1"
+2 -1
appview/pages/templates/repo/pulls/fragments/pullCompareForks.html
··· 3 3 <label for="forkSelect" class="dark:text-white" 4 4 >select a fork to compare</label 5 5 > 6 + selected: {{ .Selected }} 6 7 <div class="flex flex-wrap gap-4 items-center"> 7 8 <div class="flex flex-wrap gap-2 items-center"> 8 9 <select ··· 18 19 > 19 20 <option disabled selected>select a fork</option> 20 21 {{ range .Forks }} 21 - <option value="{{ .Name }}" class="py-1"> 22 + <option value="{{ .Name }}" {{ if eq .Name $.Selected }}selected{{ end }} class="py-1"> 22 23 {{ .Name }} 23 24 </option> 24 25 {{ end }}
+44 -4
appview/pages/templates/repo/pulls/new.html
··· 1 1 {{ define "title" }}new pull &middot; {{ .RepoInfo.FullName }}{{ end }} 2 2 3 3 {{ define "repoContent" }} 4 + <h2 class="font-bold text-sm mb-4 uppercase dark:text-white"> 5 + Create new pull request 6 + </h2> 7 + 4 8 <form 5 9 hx-post="/{{ .RepoInfo.FullName }}/pulls/new" 6 10 hx-indicator="#create-pull-spinner" ··· 16 20 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 17 21 > 18 22 <option disabled selected>target branch</option> 23 + 24 + 19 25 {{ range .Branches }} 20 - <option value="{{ .Reference.Name }}" class="py-1" {{if .IsDefault}}selected{{end}}> 26 + 27 + {{ $preset := false }} 28 + {{ if $.TargetBranch }} 29 + {{ $preset = eq .Reference.Name $.TargetBranch }} 30 + {{ else }} 31 + {{ $preset = .IsDefault }} 32 + {{ end }} 33 + 34 + <option value="{{ .Reference.Name }}" class="py-1" {{if $preset}}selected{{end}}> 21 35 {{ .Reference.Name }} 22 36 </option> 23 37 {{ end }} ··· 26 40 </div> 27 41 28 42 <div class="flex flex-col gap-2"> 29 - <p>Next, choose a pull strategy.</p> 43 + <h2 class="font-bold text-sm mb-4 uppercase dark:text-white"> 44 + Choose pull strategy 45 + </h2> 30 46 <nav class="flex space-x-4 items-center"> 31 47 <button 32 48 type="button" ··· 57 73 <span class="text-sm text-gray-500 dark:text-gray-400"> 58 74 or 59 75 </span> 76 + <script> 77 + function getQueryParams() { 78 + return Object.fromEntries(new URLSearchParams(window.location.search)); 79 + } 80 + </script> 81 + <!-- 82 + since compare-forks need the server to load forks, we 83 + hx-get this button; unlike simply loading the pullCompareForks template 84 + as we do for the rest of the gang below. the hx-vals thing just populates 85 + the query params so the forks page gets it. 86 + --> 60 87 <button 61 88 type="button" 62 89 class="btn" 63 90 hx-get="/{{ .RepoInfo.FullName }}/pulls/new/compare-forks" 64 91 hx-target="#patch-strategy" 65 92 hx-swap="innerHTML" 93 + {{ if eq .Strategy "fork" }} 94 + hx-trigger="click, load" 95 + hx-vals='js:{...getQueryParams()}' 96 + {{ end }} 66 97 > 67 98 compare forks 68 99 </button> 100 + 101 + 69 102 </nav> 70 103 <section id="patch-strategy" class="flex flex-col gap-2"> 71 - {{ template "repo/pulls/fragments/pullPatchUpload" . }} 104 + {{ if eq .Strategy "patch" }} 105 + {{ template "repo/pulls/fragments/pullPatchUpload" . }} 106 + {{ else if eq .Strategy "branch" }} 107 + {{ template "repo/pulls/fragments/pullCompareBranches" . }} 108 + {{ else }} 109 + {{ template "repo/pulls/fragments/pullPatchUpload" . }} 110 + {{ end }} 72 111 </section> 73 112 74 113 <div id="patch-error" class="error dark:text-red-300"></div> ··· 81 120 type="text" 82 121 name="title" 83 122 id="title" 123 + value="{{ .Title }}" 84 124 class="w-full dark:bg-gray-700 dark:text-white dark:border-gray-600" 85 125 placeholder="One-line summary of your change." 86 126 /> ··· 97 137 rows="6" 98 138 class="w-full resize-y dark:bg-gray-700 dark:text-white dark:border-gray-600" 99 139 placeholder="Describe your change. Markdown is supported." 100 - ></textarea> 140 + >{{ .Body }}</textarea> 101 141 </div> 102 142 103 143 <div class="flex justify-start items-center gap-2 mt-4">
+12
appview/state/pull.go
··· 634 634 return 635 635 } 636 636 637 + // can be one of "patch", "branch" or "fork" 638 + strategy := r.URL.Query().Get("strategy") 639 + // ignored if strategy is "patch" 640 + sourceBranch := r.URL.Query().Get("sourceBranch") 641 + targetBranch := r.URL.Query().Get("targetBranch") 642 + 637 643 s.pages.RepoNewPull(w, pages.RepoNewPullParams{ 638 644 LoggedInUser: user, 639 645 RepoInfo: f.RepoInfo(s, user), 640 646 Branches: result.Branches, 647 + Strategy: strategy, 648 + SourceBranch: sourceBranch, 649 + TargetBranch: targetBranch, 650 + Title: r.URL.Query().Get("title"), 651 + Body: r.URL.Query().Get("body"), 641 652 }) 642 653 643 654 case http.MethodPost: ··· 1180 1191 s.pages.PullCompareForkFragment(w, pages.PullCompareForkParams{ 1181 1192 RepoInfo: f.RepoInfo(s, user), 1182 1193 Forks: forks, 1194 + Selected: r.URL.Query().Get("fork"), 1183 1195 }) 1184 1196 } 1185 1197