Skip to content

Commit

Permalink
Preserve query string across action switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Nov 26, 2024
1 parent 8f617e7 commit c61e5f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 11 additions & 1 deletion internal/app/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ func (a *Action) getForm(w http.ResponseWriter, r *http.Request) {
params = append(params, param)
}

linksWithQS := make([]ActionLink, 0, len(a.Links))
for _, link := range a.Links {
if link.Path != a.pagePath { // Don't add self link
if r.URL.RawQuery != "" {
link.Path = link.Path + "?" + r.URL.RawQuery
}
linksWithQS = append(linksWithQS, link)
}
}

input := map[string]any{
"dev": a.isDev,
"name": a.name,
Expand All @@ -623,7 +633,7 @@ func (a *Action) getForm(w http.ResponseWriter, r *http.Request) {
"styleType": string(a.StyleType),
"lightTheme": a.LightTheme,
"darkTheme": a.DarkTheme,
"links": a.Links,
"links": linksWithQS,
}
err := a.actionTemplate.ExecuteTemplate(w, "form.go.html", input)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions internal/app/action/layout.go.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="p-8 grid grid-cols-5">

<div class="col-start-1 col-span-1">
{{ if and (.links) (gt (len .links) 1) }}
{{ if and (.links) (gt (len .links) 0) }}
<div class="dropdown dropdown-bottom" title="Switch between Actions">
<div tabindex="0" role="button" class="btn btn-outline">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
Expand All @@ -39,9 +39,7 @@
</div>
<ul tabindex="0" class="dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow">
{{ range .links }}
{{ if ne .Path $.pagePath }}
<li><a href="{{ .Path }}">{{ .Name }}</a></li>
{{ end }}
{{ end }}
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions internal/app/tests/appaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ app = ace.app("testApp",
}
testutil.AssertStringContains(t, body, `<li><a href="/test/test2">test2Action</a></li>`)

request = httptest.NewRequest("GET", "/test/test2", nil)
request = httptest.NewRequest("GET", "/test/test2?param1=abc", nil)
response = httptest.NewRecorder()
a.ServeHTTP(response, request)

Expand All @@ -851,5 +851,5 @@ app = ace.app("testApp",
if strings.Contains(body, `<li><a href="/test/test2">test2Action</a></li>`) {
t.Errorf("actions switcher should not have current action, got %s", body)
}
testutil.AssertStringContains(t, body, `<li><a href="/test/test1">test1Action</a></li>`)
testutil.AssertStringContains(t, body, `<li><a href="/test/test1?param1=abc">test1Action</a></li>`)
}

0 comments on commit c61e5f2

Please sign in to comment.