|
49 | 49 |
|
50 | 50 | (def ^:private yyyy-MM-dd-formatter (tf/formatter "yyyy-MM-dd")) |
51 | 51 |
|
| 52 | +(defn- virtualized-list |
| 53 | + [{:keys [total-count item-content compute-item-key] :as option} |
| 54 | + disable-virtualized?] |
| 55 | + (if disable-virtualized? |
| 56 | + [:div.content |
| 57 | + (for [i (range 0 total-count)] |
| 58 | + (rum/with-key (item-content i) |
| 59 | + (compute-item-key i)))] |
| 60 | + (ui/virtualized-list option))) |
| 61 | + |
52 | 62 | (defn- get-scroll-parent |
53 | 63 | [config] |
54 | 64 | (if (:sidebar? config) |
|
1598 | 1608 |
|
1599 | 1609 | (rum/defc table-body < rum/static |
1600 | 1610 | [table option rows *scroller-ref set-items-rendered!] |
1601 | | - (let [[scrolling? set-scrolling!] (hooks/use-state false) |
1602 | | - [ready? set-ready!] (hooks/use-state false)] |
1603 | | - |
1604 | | - (hooks/use-effect! |
1605 | | - (fn [] (util/schedule #(set-ready! true))) |
1606 | | - []) |
1607 | | - |
1608 | | - (when (and ready? (seq rows)) |
1609 | | - (ui/virtualized-list |
| 1611 | + (let [[scrolling? set-scrolling!] (hooks/use-state false)] |
| 1612 | + (when (seq rows) |
| 1613 | + (virtualized-list |
1610 | 1614 | {:ref #(reset! *scroller-ref %) |
1611 | 1615 | :increase-viewport-by {:top 300 :bottom 300} |
1612 | 1616 | :custom-scroll-parent (get-scroll-parent |
|
1621 | 1625 | :is-scrolling set-scrolling! |
1622 | 1626 | :item-content (fn [idx _user ^js context] |
1623 | 1627 | (let [option (assoc option |
1624 | | - :scrolling? (.-scrolling context) |
| 1628 | + :scrolling? (when context (.-scrolling context)) |
1625 | 1629 | :table-view? true)] |
1626 | 1630 | (lazy-item (:data table) idx option |
1627 | 1631 | (fn [row] |
1628 | 1632 | (table-row table row {} option))))) |
1629 | 1633 | :items-rendered (fn [props] |
1630 | 1634 | (when (seq props) |
1631 | | - (set-items-rendered! true)))})))) |
| 1635 | + (set-items-rendered! true)))} |
| 1636 | + (:disable-virtualized? option))))) |
1632 | 1637 |
|
1633 | 1638 | (rum/defc table-view < rum/static |
1634 | 1639 | [table option row-selection *scroller-ref] |
|
1646 | 1651 | (shui/table-footer (add-new-row (:view-entity option) table)))]])))) |
1647 | 1652 |
|
1648 | 1653 | (rum/defc list-view < rum/static |
1649 | | - [{:keys [config ref-matched-children-ids groups?] :as option} view-entity {:keys [rows]} *scroller-ref] |
| 1654 | + [{:keys [config ref-matched-children-ids disable-virtualized?] :as option} view-entity {:keys [rows]} *scroller-ref] |
1650 | 1655 | (let [lazy-item-render (fn [rows idx] |
1651 | 1656 | (lazy-item rows idx (assoc option :list-view? true) |
1652 | 1657 | (fn [block] |
|
1657 | 1662 | (= :linked-references (:logseq.property.view/feature-type view-entity)) |
1658 | 1663 | (assoc :ref-matched-children-ids ref-matched-children-ids))] |
1659 | 1664 | (block-container config' block))))) |
1660 | | - list-cp (fn [rows groups?] |
| 1665 | + list-cp (fn [rows] |
1661 | 1666 | (when (seq rows) |
1662 | | - (if groups? |
1663 | | - [:div.content |
1664 | | - (for [[idx _row] (medley/indexed rows)] |
1665 | | - (lazy-item-render rows idx))] |
1666 | | - (ui/virtualized-list |
1667 | | - {:ref #(reset! *scroller-ref %) |
1668 | | - :class "content" |
1669 | | - :custom-scroll-parent (get-scroll-parent config) |
1670 | | - :increase-viewport-by {:top 64 :bottom 64} |
1671 | | - :compute-item-key (fn [idx] |
1672 | | - (let [block-id (util/nth-safe rows idx)] |
1673 | | - (str "list-row-" block-id))) |
1674 | | - :total-count (count rows) |
1675 | | - :skipAnimationFrameInResizeObserver true |
1676 | | - :item-content (fn [idx] (lazy-item-render rows idx))})))) |
| 1667 | + (virtualized-list |
| 1668 | + {:ref #(reset! *scroller-ref %) |
| 1669 | + :class "content" |
| 1670 | + :custom-scroll-parent (get-scroll-parent config) |
| 1671 | + :increase-viewport-by {:top 64 :bottom 64} |
| 1672 | + :compute-item-key (fn [idx] |
| 1673 | + (let [block-id (util/nth-safe rows idx)] |
| 1674 | + (str "list-row-" block-id))) |
| 1675 | + :total-count (count rows) |
| 1676 | + :skipAnimationFrameInResizeObserver true |
| 1677 | + :item-content (fn [idx] (lazy-item-render rows idx))} |
| 1678 | + disable-virtualized?))) |
1677 | 1679 | breadcrumb (state/get-component :block/breadcrumb) |
1678 | 1680 | all-numbers? (every? number? rows)] |
1679 | 1681 | (if all-numbers? |
1680 | | - (list-cp rows groups?) |
| 1682 | + (list-cp rows) |
1681 | 1683 | (for [[idx row] (medley/indexed rows)] |
1682 | 1684 | (if (and (vector? row) (uuid? (first row))) |
1683 | 1685 | (let [[first-block-id blocks] row] |
|
1687 | 1689 | (breadcrumb (assoc config :list-view? true) |
1688 | 1690 | (state/get-current-repo) first-block-id |
1689 | 1691 | {:show-page? false})] |
1690 | | - (list-cp blocks groups?)]) |
| 1692 | + (list-cp blocks)]) |
1691 | 1693 | (rum/with-key |
1692 | 1694 | (lazy-item-render rows idx) |
1693 | 1695 | (str "partition-" idx))))))) |
|
1812 | 1814 | (ui/icon "arrows-up-down"))) |
1813 | 1815 |
|
1814 | 1816 | (rum/defc view-cp |
1815 | | - [view-entity table option* {:keys [*scroller-ref display-type row-selection groups?]}] |
| 1817 | + [view-entity table option* {:keys [*scroller-ref display-type row-selection]}] |
1816 | 1818 | (let [[viewid] (hooks/use-state #(random-uuid)) |
1817 | 1819 | option (assoc option* |
1818 | 1820 | :view-entity view-entity |
1819 | | - :viewid viewid |
1820 | | - :groups? groups?)] |
| 1821 | + :viewid viewid)] |
1821 | 1822 | [:div {:id viewid} |
1822 | 1823 | (case display-type |
1823 | 1824 | :logseq.property.view/type.list |
|
2000 | 2001 | (when (and db-based? add-new-object!) (new-record-button table view-entity))]])) |
2001 | 2002 |
|
2002 | 2003 | (rum/defc ^:large-vars/cleanup-todo view-inner < rum/static |
2003 | | - [view-entity {:keys [view-parent data full-data set-data! columns add-new-object! foldable-options input set-input! sorting set-sorting! filters set-filters! display-type group-by-property-ident] :as option*} |
| 2004 | + [view-entity {:keys [view-parent data full-data set-data! columns add-new-object! foldable-options input set-input! sorting set-sorting! filters set-filters! display-type group-by-property-ident config] :as option*} |
2004 | 2005 | *scroller-ref] |
2005 | 2006 | (let [db-based? (config/db-based-graph?) |
| 2007 | + journals? (:journals? config) |
2006 | 2008 | option (assoc option* :properties |
2007 | 2009 | (-> (remove #{:id :select} (map :id columns)) |
2008 | 2010 | (conj :block/uuid :block/name) |
|
2072 | 2074 | *view-ref (rum/use-ref nil) |
2073 | 2075 | gallery? (= display-type :logseq.property.view/type.gallery) |
2074 | 2076 | list-view? (= display-type :logseq.property.view/type.list) |
| 2077 | + disable-virtualized? journals? |
2075 | 2078 | [ready? set-ready?] (hooks/use-state false)] |
2076 | 2079 |
|
2077 | 2080 | (run-effects! option table-map *scroller-ref gallery? set-ready?) |
|
2091 | 2094 | (if (and group-by-property-ident (not (number? (first (:rows table))))) |
2092 | 2095 | (when (and ready? (seq (:rows table))) |
2093 | 2096 | [:div.flex.flex-col.border-t.pt-2.gap-2 |
2094 | | - (ui/virtualized-list |
| 2097 | + (virtualized-list |
2095 | 2098 | {:class (when list-view? "group-list-view") |
2096 | 2099 | :custom-scroll-parent (util/app-scroll-container-node (rum/deref *view-ref)) |
2097 | 2100 | :increase-viewport-by {:top 300 :bottom 300} |
|
2139 | 2142 | (fn [] |
2140 | 2143 | (let [render (view-cp view-entity |
2141 | 2144 | (assoc table' :rows group) |
2142 | | - option |
2143 | | - (assoc view-opts :groups? (or group-by-page? |
2144 | | - group-by-property-ident)))] |
| 2145 | + (assoc option |
| 2146 | + ;; disabled virtualization for nested view |
| 2147 | + :disable-virtualized? true) |
| 2148 | + view-opts)] |
2145 | 2149 | (if list-view? [:div.-ml-2 render] render))) |
2146 | 2150 | {:title-trigger? false}) |
2147 | | - (str (:db/id view-entity) "-group-idx-" idx))))})]) |
| 2151 | + (str (:db/id view-entity) "-group-idx-" idx))))} |
| 2152 | + disable-virtualized?)]) |
2148 | 2153 | (view-cp view-entity table |
2149 | | - (assoc option :group-by-property-ident group-by-property-ident) |
| 2154 | + (assoc option |
| 2155 | + :group-by-property-ident group-by-property-ident |
| 2156 | + :disable-virtualized? disable-virtualized?) |
2150 | 2157 | view-opts)))]) |
2151 | 2158 | (merge {:title-trigger? false} foldable-options))])) |
2152 | 2159 |
|
|
2188 | 2195 | :advanced-query? advanced-query?})))))) |
2189 | 2196 |
|
2190 | 2197 | (defn- load-view-data-aux |
2191 | | - [config view-entity view-parent {:keys [query? query query-entity-ids sorting filters input |
2192 | | - view-feature-type group-by-property-ident |
2193 | | - set-data! set-ref-pages-count! set-ref-matched-children-ids! set-properties! set-loading!]}] |
| 2198 | + [view-entity view-parent {:keys [query? query query-entity-ids sorting filters input |
| 2199 | + view-feature-type group-by-property-ident |
| 2200 | + set-data! set-ref-pages-count! set-ref-matched-children-ids! set-properties! set-loading!]}] |
2194 | 2201 | (c.m/run-task* |
2195 | 2202 | (m/sp |
2196 | 2203 | (let [need-query? (and query? (seq query-entity-ids) (or sorting filters (not (string/blank? input))))] |
|
2221 | 2228 | (set-ref-matched-children-ids! ref-matched-children-ids)) |
2222 | 2229 | (set-properties! properties)) |
2223 | 2230 | (finally |
2224 | | - (set-loading! false) |
2225 | | - (when (contains? #{:class-objects :property-objects} view-feature-type) |
2226 | | - (when-let [*objects-ready? (:*objects-ready? config)] |
2227 | | - (reset! *objects-ready? true))))))))))) |
| 2231 | + (set-loading! false))))))))) |
2228 | 2232 |
|
2229 | 2233 | (rum/defc view-aux |
2230 | 2234 | [view-entity {:keys [config view-parent view-feature-type data query-entity-ids query set-view-entity!] :as option}] |
|
2260 | 2264 | [ref-pages-count set-ref-pages-count!] (hooks/use-state nil) |
2261 | 2265 | [ref-matched-children-ids set-ref-matched-children-ids!] (hooks/use-state nil) |
2262 | 2266 | load-view-data (fn load-view-data [] |
2263 | | - (load-view-data-aux config view-entity view-parent |
| 2267 | + (load-view-data-aux view-entity view-parent |
2264 | 2268 | {:query? query? |
2265 | 2269 | :query query |
2266 | 2270 | :query-entity-ids query-entity-ids |
|
2307 | 2311 | (+ total 1) |
2308 | 2312 | (let [[_k col] item] |
2309 | 2313 | (if (and (vector? (first col)) |
2310 | | - (and (not (map? col)) |
2311 | | - (uuid? (ffirst col)))) |
| 2314 | + (not (map? col)) |
| 2315 | + (uuid? (ffirst col))) |
2312 | 2316 | (+ total (count-col col)) |
2313 | 2317 | (+ total (count col)))))) 0 data))] |
2314 | 2318 | (f data))) |
|
0 commit comments