Replace Python sx_call loops with data-driven SX defcomps using map
Move rendering logic from Python for-loops building sx_call strings into SX defcomp components that use map/lambda over data dicts. Python now serializes display data into plain dicts and passes them via a single sx_call; the SX layer handles iteration and conditional rendering. Covers orders (rows, items, calendar, tickets), federation (timeline, search, actors, profile activities), and blog (cards, pages, filters, snippets, menu items, tag groups, page search, nav OOB). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,57 @@
|
||||
(<> auth (~header-child-sx :id "auth-header-child" :inner
|
||||
(<> orders (~header-child-sx :id "orders-header-child" :inner order))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Data-driven order rows (replaces Python loop)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defcomp ~order-rows-from-data (&key orders page total-pages next-url)
|
||||
(<>
|
||||
(map (lambda (o)
|
||||
(<>
|
||||
(~order-row-desktop :oid (get o "oid") :created (get o "created")
|
||||
:desc (get o "desc") :total (get o "total")
|
||||
:pill (get o "pill_desktop") :status (get o "status") :url (get o "url"))
|
||||
(~order-row-mobile :oid (get o "oid") :created (get o "created")
|
||||
:total (get o "total") :pill (get o "pill_mobile")
|
||||
:status (get o "status") :url (get o "url"))))
|
||||
(or orders (list)))
|
||||
(if next-url
|
||||
(~infinite-scroll :url next-url :page page :total-pages total-pages
|
||||
:id-prefix "orders" :colspan 5)
|
||||
(~order-end-row))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Data-driven order items (replaces Python loop)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defcomp ~order-items-from-data (&key items)
|
||||
(~order-items-panel
|
||||
:items (<> (map (lambda (item)
|
||||
(let* ((img (if (get item "product_image")
|
||||
(~order-item-image :src (get item "product_image") :alt (or (get item "product_title") "Product image"))
|
||||
(~order-item-no-image))))
|
||||
(~order-item-row
|
||||
:href (get item "href") :img img
|
||||
:title (or (get item "product_title") "Unknown product")
|
||||
:pid (str "Product ID: " (get item "product_id"))
|
||||
:qty (str "Qty: " (get item "quantity"))
|
||||
:price (get item "price"))))
|
||||
(or items (list))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Data-driven calendar entries (replaces Python loop)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defcomp ~order-calendar-from-data (&key entries)
|
||||
(~order-calendar-section
|
||||
:items (<> (map (lambda (e)
|
||||
(~order-calendar-entry
|
||||
:name (get e "name") :pill (get e "pill")
|
||||
:status (get e "status") :date-str (get e "date_str")
|
||||
:cost (get e "cost")))
|
||||
(or entries (list))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Checkout error screens
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user