|
46 | 46 | :max-nested-depth nil
|
47 | 47 | :display-analytics-hint nil
|
48 | 48 | :analytics-size-cutoff 100000
|
| 49 | + :sort-maps false |
49 | 50 | :pretty-print false})
|
50 | 51 |
|
51 | 52 | (defn- reset-render-state [inspector]
|
|
100 | 101 | (defn- pagination-info
|
101 | 102 | "Calculate if the object should be paginated given the page size. Return a map
|
102 | 103 | with pagination info, or nil if object fits in a single page."
|
103 |
| - [{:keys [page-size current-page view-mode value] :as inspector}] |
| 104 | + [{:keys [page-size current-page view-mode sort-maps value] :as inspector}] |
104 | 105 | (let [page-size (if (= view-mode :hex)
|
105 | 106 | (* page-size 16) ;; In hex view mode, each row is 16 bytes.
|
106 | 107 | page-size)
|
107 | 108 | start-idx (* current-page page-size)
|
| 109 | + ;; Sort maps early to ensure proper paging. |
| 110 | + sort-map? (and (= (object-type value) :map) sort-maps) |
| 111 | + value (if sort-map? |
| 112 | + (try (sort-by key value) |
| 113 | + ;; May throw if keys are not comparable. |
| 114 | + (catch Exception _ value)) |
| 115 | + value) |
108 | 116 | ;; Try grab a chunk that is one element longer than asked in
|
109 | 117 | ;; page-size. This is how we know there are elements beyond the
|
110 | 118 | ;; current page.
|
|
114 | 122 | count+1 (count chunk+1)
|
115 | 123 | paginate? (or (> current-page 0) ;; In non-paginated it's always 0.
|
116 | 124 | (> count+1 page-size))
|
| 125 | + chunk (cond-> chunk+1 |
| 126 | + (> count+1 page-size) pop) |
117 | 127 | clength (or (counted-length inspector value)
|
118 | 128 | (when (<= count+1 page-size)
|
119 | 129 | (+ (* page-size current-page) count+1)))
|
120 | 130 | last-page (if clength
|
121 | 131 | (quot (dec clength) page-size)
|
122 | 132 | ;; Possibly infinite
|
123 | 133 | Integer/MAX_VALUE)]
|
124 |
| - (when paginate? |
125 |
| - {:chunk (cond-> chunk+1 |
126 |
| - (> count+1 page-size) pop) |
127 |
| - :start-idx start-idx |
128 |
| - :last-page last-page}))) |
| 134 | + (cond paginate? {:chunk chunk |
| 135 | + :start-idx start-idx |
| 136 | + :last-page last-page} |
| 137 | + sort-map? {:chunk chunk}))) |
129 | 138 |
|
130 | 139 | (defn- decide-if-paginated
|
131 | 140 | "Make early decision if the inspected object should be paginated. If so,
|
|
0 commit comments