Skip to content

Commit c062ccf

Browse files
fstachurarjarry
authored andcommitted
web: fill patch filter form with current query
Currently, Patchwork does not fully remember filters. For example, if you first filter patches by State, and then attempt to filter the results by Archived, the results will only be filtered by Archived. That is because the filter form is not filled with query values. After submitting the form, it is basically cleared. Fill filters form with query values to allow modifying the query. Signed-off-by: Franciszek Stachura <fbstachura@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
1 parent 0625f64 commit c062ccf

1 file changed

Lines changed: 52 additions & 7 deletions

File tree

‎pkg/web/patches.templ‎

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ type appliedFilter struct {
3636
RemoveURL string
3737
}
3838

39+
func getFilterValue(filters []appliedFilter, label string) string {
40+
for _, filter := range filters {
41+
if filter.Label == label {
42+
return strings.TrimSpace(filter.Value)
43+
}
44+
}
45+
return ""
46+
}
47+
3948
templ patchListPage(d patchListData) {
4049
@layout(d.Project.Name, []breadcrumb{
4150
{Label: d.Project.Name, URL: "/project/" + d.Project.Linkname},
@@ -64,24 +73,60 @@ templ patchListPage(d patchListData) {
6473
<select name="state" title="State">
6574
<option value="*">Action required</option>
6675
<option value="all">All states</option>
76+
{{ currentState := getFilterValue(d.Filters, "State") }}
6777
for _, s := range d.States {
68-
<option value={ intStr(int(s.ID)) }>{ s.Name }</option>
78+
if currentState == s.Name {
79+
<option value={ intStr(int(s.ID)) } selected>{ s.Name }</option>
80+
} else {
81+
<option value={ intStr(int(s.ID)) }>{ s.Name }</option>
82+
}
6983
}
7084
</select>
85+
{{ currentArchived := getFilterValue(d.Filters, "Archive") }}
7186
<fieldset title="Archived">
7287
<legend>Archived</legend>
73-
<label><input type="radio" name="archive" value="" checked/> No</label>
74-
<label><input type="radio" name="archive" value="true"/> Yes</label>
75-
<label><input type="radio" name="archive" value="both"/> Both</label>
88+
if currentArchived == "" || currentArchived == "No" {
89+
<label><input type="radio" name="archive" value="" checked/> No</label>
90+
} else {
91+
<label><input type="radio" name="archive" value=""/> No</label>
92+
}
93+
if currentArchived == "Archived" {
94+
<label><input type="radio" name="archive" value="true" checked/> Yes</label>
95+
} else {
96+
<label><input type="radio" name="archive" value="true"/> Yes</label>
97+
}
98+
if currentArchived == "Both" {
99+
<label><input type="radio" name="archive" value="both" checked/> Both</label>
100+
} else {
101+
<label><input type="radio" name="archive" value="both"/> Both</label>
102+
}
76103
</fieldset>
77104
<select name="delegate" title="Delegate">
78105
<option value="">Delegate...</option>
106+
{{ currentDelegate := getFilterValue(d.Filters, "Delegate") }}
79107
for _, u := range d.Delegates {
80-
<option value={ fmt.Sprintf("%d", u.ID) }>{ u.Username }</option>
108+
{{ idString := fmt.Sprintf("%d", u.ID) }}
109+
if idString == currentDelegate {
110+
<option value={ idString } selected>{ u.Username }</option>
111+
} else {
112+
<option value={ idString }>{ u.Username }</option>
113+
}
81114
}
82115
</select>
83-
<input type="text" name="submitter" placeholder="Submitter" title="Submitter"/>
84-
<input type="text" name="q" placeholder="Search" title="Search"/>
116+
<input
117+
type="text"
118+
name="submitter"
119+
placeholder="Submitter"
120+
title="Submitter"
121+
value={ getFilterValue(d.Filters, "Submitter") }
122+
/>
123+
<input
124+
type="text"
125+
name="q"
126+
placeholder="Search"
127+
title="Search"
128+
value={ getFilterValue(d.Filters, "Search") }
129+
/>
85130
<button type="submit">Filter</button>
86131
</form>
87132
</patch-filters>

0 commit comments

Comments
 (0)