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