fix(admin): pre-compute pagination in Java, remove arithmetic from Qute template
Deploy to Production / deploy (push) Successful in 3m12s
Deploy to Production / deploy (push) Successful in 3m12s
Qute cannot evaluate + and * as arithmetic operators at runtime even with requireTypeSafeExpressions=false — it tries to look them up as map keys. Pre-compute hasPrev/hasNext/displayPage/prevPage/nextPage in the resource. Co-Authored-By: Mira Rehfeld <noreply@anthropic.com>
This commit is contained in:
+7
-3
@@ -26,9 +26,10 @@ public class SandboxListResource {
|
|||||||
@ConfigProperty(name = "apix.admin.key")
|
@ConfigProperty(name = "apix.admin.key")
|
||||||
String adminKey;
|
String adminKey;
|
||||||
|
|
||||||
@CheckedTemplate(requireTypeSafeExpressions = false)
|
@CheckedTemplate
|
||||||
static class Templates {
|
static class Templates {
|
||||||
static native TemplateInstance list(AdminSandboxListResponse result, int page, int size, String tier);
|
static native TemplateInstance list(AdminSandboxListResponse result, int page, int size, String tier,
|
||||||
|
boolean hasPrev, boolean hasNext, int displayPage, int prevPage, int nextPage);
|
||||||
static native TemplateInstance error(String message);
|
static native TemplateInstance error(String message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +41,10 @@ public class SandboxListResource {
|
|||||||
try {
|
try {
|
||||||
String tierParam = tier.isBlank() ? null : tier;
|
String tierParam = tier.isBlank() ? null : tier;
|
||||||
AdminSandboxListResponse result = registry.listSandboxes(adminKey, page, size, tierParam);
|
AdminSandboxListResponse result = registry.listSandboxes(adminKey, page, size, tierParam);
|
||||||
return Templates.list(result, page, size, tier);
|
boolean hasPrev = page > 0;
|
||||||
|
boolean hasNext = (long)(page + 1) * size < result.total();
|
||||||
|
return Templates.list(result, page, size, tier,
|
||||||
|
hasPrev, hasNext, page + 1, page - 1, page + 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.errorf(e, "Failed to load sandbox list");
|
LOG.errorf(e, "Failed to load sandbox list");
|
||||||
return Templates.error("Could not load sandbox list");
|
return Templates.error("Could not load sandbox list");
|
||||||
|
|||||||
@@ -103,12 +103,12 @@ tr:hover td { background: #161b22; }
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{#if page > 0}
|
{#if hasPrev}
|
||||||
<a class="page-link" href="/sandboxes?page={page - 1}&size={size}&tier={tier}">← Previous</a>
|
<a class="page-link" href="/sandboxes?page={prevPage}&size={size}&tier={tier}">← Previous</a>
|
||||||
{/if}
|
{/if}
|
||||||
<span class="page-info">Page {page + 1} · {result.sandboxes.size} of {result.total}</span>
|
<span class="page-info">Page {displayPage} · {result.sandboxes.size} of {result.total}</span>
|
||||||
{#if (page + 1) * size < result.total}
|
{#if hasNext}
|
||||||
<a class="page-link" href="/sandboxes?page={page + 1}&size={size}&tier={tier}">Next →</a>
|
<a class="page-link" href="/sandboxes?page={nextPage}&size={size}&tier={tier}">Next →</a>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user