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

appview: state: populate new pull form from query params

Changed files
+73 -7
appview
pages
state
+6
appview/pages/pages.go
···
LoggedInUser *oauth.User
RepoInfo repoinfo.RepoInfo
Branches []types.Branch
Active string
}
···
type PullCompareForkParams struct {
RepoInfo repoinfo.RepoInfo
Forks []db.Repo
}
func (p *Pages) PullCompareForkFragment(w io.Writer, params PullCompareForkParams) error {
···
LoggedInUser *oauth.User
RepoInfo repoinfo.RepoInfo
Branches []types.Branch
+
Strategy string
+
SourceBranch string
+
TargetBranch string
+
Title string
+
Body string
Active string
}
···
type PullCompareForkParams struct {
RepoInfo repoinfo.RepoInfo
Forks []db.Repo
+
Selected string
}
func (p *Pages) PullCompareForkFragment(w io.Writer, params PullCompareForkParams) error {
+9 -2
appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html
···
{{ define "repo/pulls/fragments/pullCompareBranches" }}
<div id="patch-upload">
-
<label for="targetBranch" class="dark:text-white">select a branch</label>
<div class="flex flex-wrap gap-2 items-center">
<select
name="sourceBranch"
···
{{ $recent := index .Branches 0 }}
{{ range .Branches }}
{{ $isRecent := eq .Reference.Name $recent.Reference.Name }}
<option
value="{{ .Reference.Name }}"
-
{{ if $isRecent }}
selected
{{ end }}
class="py-1"
···
{{ define "repo/pulls/fragments/pullCompareBranches" }}
<div id="patch-upload">
+
<label for="targetBranch" class="dark:text-white">select a source branch</label>
<div class="flex flex-wrap gap-2 items-center">
<select
name="sourceBranch"
···
{{ $recent := index .Branches 0 }}
{{ range .Branches }}
{{ $isRecent := eq .Reference.Name $recent.Reference.Name }}
+
{{ $preset := false }}
+
{{ if $.SourceBranch }}
+
{{ $preset = eq .Reference.Name $.SourceBranch }}
+
{{ else }}
+
{{ $preset = $isRecent }}
+
{{ end }}
+
<option
value="{{ .Reference.Name }}"
+
{{ if $preset }}
selected
{{ end }}
class="py-1"
+2 -1
appview/pages/templates/repo/pulls/fragments/pullCompareForks.html
···
<label for="forkSelect" class="dark:text-white"
>select a fork to compare</label
>
<div class="flex flex-wrap gap-4 items-center">
<div class="flex flex-wrap gap-2 items-center">
<select
···
>
<option disabled selected>select a fork</option>
{{ range .Forks }}
-
<option value="{{ .Name }}" class="py-1">
{{ .Name }}
</option>
{{ end }}
···
<label for="forkSelect" class="dark:text-white"
>select a fork to compare</label
>
+
selected: {{ .Selected }}
<div class="flex flex-wrap gap-4 items-center">
<div class="flex flex-wrap gap-2 items-center">
<select
···
>
<option disabled selected>select a fork</option>
{{ range .Forks }}
+
<option value="{{ .Name }}" {{ if eq .Name $.Selected }}selected{{ end }} class="py-1">
{{ .Name }}
</option>
{{ end }}
+44 -4
appview/pages/templates/repo/pulls/new.html
···
{{ define "title" }}new pull &middot; {{ .RepoInfo.FullName }}{{ end }}
{{ define "repoContent" }}
<form
hx-post="/{{ .RepoInfo.FullName }}/pulls/new"
hx-indicator="#create-pull-spinner"
···
class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600"
>
<option disabled selected>target branch</option>
{{ range .Branches }}
-
<option value="{{ .Reference.Name }}" class="py-1" {{if .IsDefault}}selected{{end}}>
{{ .Reference.Name }}
</option>
{{ end }}
···
</div>
<div class="flex flex-col gap-2">
-
<p>Next, choose a pull strategy.</p>
<nav class="flex space-x-4 items-center">
<button
type="button"
···
<span class="text-sm text-gray-500 dark:text-gray-400">
or
</span>
<button
type="button"
class="btn"
hx-get="/{{ .RepoInfo.FullName }}/pulls/new/compare-forks"
hx-target="#patch-strategy"
hx-swap="innerHTML"
>
compare forks
</button>
</nav>
<section id="patch-strategy" class="flex flex-col gap-2">
-
{{ template "repo/pulls/fragments/pullPatchUpload" . }}
</section>
<div id="patch-error" class="error dark:text-red-300"></div>
···
type="text"
name="title"
id="title"
class="w-full dark:bg-gray-700 dark:text-white dark:border-gray-600"
placeholder="One-line summary of your change."
/>
···
rows="6"
class="w-full resize-y dark:bg-gray-700 dark:text-white dark:border-gray-600"
placeholder="Describe your change. Markdown is supported."
-
></textarea>
</div>
<div class="flex justify-start items-center gap-2 mt-4">
···
{{ define "title" }}new pull &middot; {{ .RepoInfo.FullName }}{{ end }}
{{ define "repoContent" }}
+
<h2 class="font-bold text-sm mb-4 uppercase dark:text-white">
+
Create new pull request
+
</h2>
+
<form
hx-post="/{{ .RepoInfo.FullName }}/pulls/new"
hx-indicator="#create-pull-spinner"
···
class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600"
>
<option disabled selected>target branch</option>
+
+
{{ range .Branches }}
+
+
{{ $preset := false }}
+
{{ if $.TargetBranch }}
+
{{ $preset = eq .Reference.Name $.TargetBranch }}
+
{{ else }}
+
{{ $preset = .IsDefault }}
+
{{ end }}
+
+
<option value="{{ .Reference.Name }}" class="py-1" {{if $preset}}selected{{end}}>
{{ .Reference.Name }}
</option>
{{ end }}
···
</div>
<div class="flex flex-col gap-2">
+
<h2 class="font-bold text-sm mb-4 uppercase dark:text-white">
+
Choose pull strategy
+
</h2>
<nav class="flex space-x-4 items-center">
<button
type="button"
···
<span class="text-sm text-gray-500 dark:text-gray-400">
or
</span>
+
<script>
+
function getQueryParams() {
+
return Object.fromEntries(new URLSearchParams(window.location.search));
+
}
+
</script>
+
<!--
+
since compare-forks need the server to load forks, we
+
hx-get this button; unlike simply loading the pullCompareForks template
+
as we do for the rest of the gang below. the hx-vals thing just populates
+
the query params so the forks page gets it.
+
-->
<button
type="button"
class="btn"
hx-get="/{{ .RepoInfo.FullName }}/pulls/new/compare-forks"
hx-target="#patch-strategy"
hx-swap="innerHTML"
+
{{ if eq .Strategy "fork" }}
+
hx-trigger="click, load"
+
hx-vals='js:{...getQueryParams()}'
+
{{ end }}
>
compare forks
</button>
+
+
</nav>
<section id="patch-strategy" class="flex flex-col gap-2">
+
{{ if eq .Strategy "patch" }}
+
{{ template "repo/pulls/fragments/pullPatchUpload" . }}
+
{{ else if eq .Strategy "branch" }}
+
{{ template "repo/pulls/fragments/pullCompareBranches" . }}
+
{{ else }}
+
{{ template "repo/pulls/fragments/pullPatchUpload" . }}
+
{{ end }}
</section>
<div id="patch-error" class="error dark:text-red-300"></div>
···
type="text"
name="title"
id="title"
+
value="{{ .Title }}"
class="w-full dark:bg-gray-700 dark:text-white dark:border-gray-600"
placeholder="One-line summary of your change."
/>
···
rows="6"
class="w-full resize-y dark:bg-gray-700 dark:text-white dark:border-gray-600"
placeholder="Describe your change. Markdown is supported."
+
>{{ .Body }}</textarea>
</div>
<div class="flex justify-start items-center gap-2 mt-4">
+12
appview/state/pull.go
···
return
}
s.pages.RepoNewPull(w, pages.RepoNewPullParams{
LoggedInUser: user,
RepoInfo: f.RepoInfo(s, user),
Branches: result.Branches,
})
case http.MethodPost:
···
s.pages.PullCompareForkFragment(w, pages.PullCompareForkParams{
RepoInfo: f.RepoInfo(s, user),
Forks: forks,
})
}
···
return
}
+
// can be one of "patch", "branch" or "fork"
+
strategy := r.URL.Query().Get("strategy")
+
// ignored if strategy is "patch"
+
sourceBranch := r.URL.Query().Get("sourceBranch")
+
targetBranch := r.URL.Query().Get("targetBranch")
+
s.pages.RepoNewPull(w, pages.RepoNewPullParams{
LoggedInUser: user,
RepoInfo: f.RepoInfo(s, user),
Branches: result.Branches,
+
Strategy: strategy,
+
SourceBranch: sourceBranch,
+
TargetBranch: targetBranch,
+
Title: r.URL.Query().Get("title"),
+
Body: r.URL.Query().Get("body"),
})
case http.MethodPost:
···
s.pages.PullCompareForkFragment(w, pages.PullCompareForkParams{
RepoInfo: f.RepoInfo(s, user),
Forks: forks,
+
Selected: r.URL.Query().Get("fork"),
})
}