Merge branch 'feat/db' into feat/repeated-tasks

This commit is contained in:
Tienson Qin
2024-12-26 05:44:00 +08:00
11 changed files with 102 additions and 78 deletions

View File

@@ -54,7 +54,8 @@
[data set-data!] (rum/use-state nil)
[loading? set-loading!] (rum/use-state true)
columns' (views/build-columns {} (columns)
{:with-object-name? false})
{:with-object-name? false
:with-id? false})
view-entity (first (ldb/get-all-pages-views db))]
(rum/use-effect!
(fn []

View File

@@ -182,6 +182,9 @@
(let [pages (filter ldb/page? selected-rows)
blocks (remove ldb/page? selected-rows)]
(p/do!
(set-data! (get-class-objects class))
(when-let [f (get-in table [:data-fns :set-row-selection!])]
(f {}))
(ui-outliner-tx/transact!
{:outliner-op :delete-blocks}
(when (seq blocks)
@@ -189,10 +192,7 @@
(let [page-ids (map :db/id pages)
tx-data (map (fn [pid] [:db/retract pid :block/tags (:db/id class)]) page-ids)]
(when (seq tx-data)
(outliner-op/transact! tx-data {:outliner-op :save-block}))))
(set-data! (get-class-objects class))
(when-let [f (get-in table [:data-fns :set-row-selection!])]
(f {})))))}))))
(outliner-op/transact! tx-data {:outliner-op :save-block})))))))}))))
(rum/defcs class-objects < rum/reactive db-mixins/query mixins/container-id
[state class {:keys [current-page? sidebar?]}]
@@ -258,6 +258,9 @@
(let [pages (filter ldb/page? selected-rows)
blocks (remove ldb/page? selected-rows)]
(p/do!
(set-data! (get-property-related-objects (state/get-current-repo) property))
(when-let [f (get-in table [:data-fns :set-row-selection!])]
(f {}))
(ui-outliner-tx/transact!
{:outliner-op :delete-blocks}
(when (seq blocks)
@@ -265,10 +268,7 @@
(let [page-ids (map :db/id pages)
tx-data (map (fn [pid] [:db/retract pid (:db/ident property)]) page-ids)]
(when (seq tx-data)
(outliner-op/transact! tx-data {:outliner-op :save-block}))))
(set-data! (get-property-related-objects (state/get-current-repo) property))
(when-let [f (get-in table [:data-fns :set-row-selection!])]
(f {}))))))}))))
(outliner-op/transact! tx-data {:outliner-op :save-block}))))))))}))))
;; Show all nodes containing the given property
(rum/defcs property-related-objects < rum/reactive db-mixins/query mixins/container-id

View File

@@ -446,7 +446,7 @@
:on-click (fn [e]
(state/pub-event! [:editor/new-property {:block page
:target (.-target e)}]))}
"Set node property")]])
"Set page property")]])
(rum/defc db-page-title
[page whiteboard-page? sidebar? container-id]

View File

@@ -437,9 +437,7 @@
[:div.flex.flex-row.items-center.shrink-0
(ui/icon "plus" {:size 16})
[:div.ml-1
(if (:class-schema? opts)
"Add tag property"
"Add property")]]]]))
"Add property"]]]]))
(defn- resolve-linked-block-if-exists
"Properties will be updated for the linked page instead of the refed block.
@@ -588,7 +586,7 @@
:will-remount (fn [state]
(let [block (db/entity (:db/id (::block state)))]
(assoc state ::classes (async-load-classes! block))))}
[state _target-block {:keys [class-schema? sidebar-properties?] :as opts}]
[state _target-block {:keys [sidebar-properties?] :as opts}]
(let [id (::id state)
db-id (:db/id (::block state))
block (db/sub-block db-id)
@@ -600,15 +598,7 @@
(db/sub-block (:db/id class)))
class? (ldb/class? block)
block-properties (:block/properties block)
properties (cond
class-schema?
(->> (db-property/get-class-ordered-properties block)
(map :db/ident)
distinct
(map #(vector % %)))
:else
block-properties)
properties block-properties
remove-built-in-or-other-position-properties
(fn [properties]
(remove (fn [property]
@@ -687,37 +677,34 @@
[[:logseq.property.class/properties nil]]))
remove-built-in-or-other-position-properties)]
(cond
(and (empty? full-properties) (not (:class-schema? opts)))
(empty? full-properties)
(when sidebar-properties?
(rum/with-key (new-property block opts) (str id "-add-property")))
:else
(let [remove-properties #{:logseq.property/icon :logseq.property/query}
properties' (remove (fn [[k _v]] (contains? remove-properties k)) full-properties)
properties'' (cond->> properties'
(not class-schema?)
(remove (fn [[k _v]] (= k :logseq.property.class/properties))))
properties'' (->> properties'
(remove (fn [[k _v]] (= k :logseq.property.class/properties))))
page? (ldb/page? block)]
[:div.ls-properties-area
{:id id
:class (util/classnames [{:class-properties class-schema?
:ls-page-properties (and page? (not class-schema?))}])
:tab-index 0
:on-key-up #(when-let [block (and (= "Escape" (.-key %))
(.closest (.-target %) "[blockid]"))]
(let [target (.-target %)]
(when-not (d/has-class? target "ls-popup-closed")
(state/set-selection-blocks! [block])
(some-> js/document.activeElement (.blur)))
(d/remove-class! target "ls-popup-closed")))}
(properties-section block (if class-schema? properties properties'') opts)
:class (util/classnames [{:ls-page-properties page?}])
:tab-index 0}
[:<>
(properties-section block properties'' opts)
(when page?
(rum/with-key (new-property block opts) (str id "-add-property")))
(when (and page? (not class?))
(rum/with-key (new-property block opts) (str id "-add-property")))]
(when page?
(let [properties'' (filter (fn [[k _v]] (= k :logseq.property.class/properties)) properties')]
(when (seq properties'')
[:<>
(when-not class-schema? [:hr.my-4])
(properties-section block (if class-schema? properties properties'') opts)])))]))))
(when class?
(let [properties (->> (:logseq.property.class/properties block)
(map (fn [e] [(:db/ident e)])))
opts' (assoc opts :class-schema? true)]
[:<>
[:div.mt-2
[:div.text-sm.text-muted-foreground.mb-2 {:style {:margin-left 10}}
"Tagged node properties:"]
[:div
(properties-section block properties opts')
(rum/with-key (new-property block opts') (str id "-class-add-property"))]]]))]))))

View File

@@ -4,7 +4,11 @@
[frontend.db :as db]
[logseq.db :as ldb]
[rum.core :as rum]
[frontend.mixins :as mixins]))
[frontend.mixins :as mixins]
[promesa.core :as p]
[frontend.modules.outliner.ui :as ui-outliner-tx]
[frontend.modules.outliner.op :as outliner-op]
[frontend.state]))
(defn- columns
[config result]
@@ -41,11 +45,25 @@
[state config view-entity result]
(let [*result (::result state)
result' (or @*result (init-result result view-entity))
columns' (columns (assoc config :container-id (::container-id state)) result')]
columns' (columns (assoc config :container-id (::container-id state)) result')
set-data! (fn [data] (reset! *result data))]
[:div.query-result.w-full
(views/view view-entity
{:title-key :views.table/live-query-title
:data result'
:set-data! (fn [data]
(when (seq data) (reset! *result data)))
:columns columns'})]))
:set-data! set-data!
:columns columns'
:on-delete-rows (fn [table selected-rows]
(let [pages (filter ldb/page? selected-rows)
blocks (remove ldb/page? selected-rows)
selected (set (map :id selected-rows))
data' (remove (fn [row] (contains? selected (:id row))) (:data table))]
(p/do!
(set-data! data')
(ui-outliner-tx/transact!
{:outliner-op :delete-blocks}
(when (seq blocks)
(outliner-op/delete-blocks! blocks nil))
(doseq [page pages]
(when-let [id (:block/uuid page)]
(outliner-op/delete-page! id)))))))})]))

View File

@@ -53,6 +53,12 @@
:class (str "flex transition-opacity "
(if (or show? selected-all? selected-some?) "opacity-100" "opacity-0"))})]))
(rum/defc header-index < rum/static
[]
[:label.h-8.w-6.flex.items-center.justify-center
{:html-for "header-index"}
"ID"])
(rum/defc row-checkbox < rum/static
[{:keys [row-selected? row-toggle-selected!]} row _column]
(let [id (str (:id row) "-" "checkbox")
@@ -138,8 +144,9 @@
(container config row')])))
(defn build-columns
[config properties & {:keys [with-object-name? add-tags-column?]
[config properties & {:keys [with-object-name? with-id? add-tags-column?]
:or {with-object-name? true
with-id? true
add-tags-column? true}}]
(let [;; FIXME: Shouldn't file graphs have :block/tags?
add-tags-column?' (and (config/db-based-graph? (state/get-current-repo)) add-tags-column?)
@@ -156,6 +163,14 @@
(row-checkbox table row column))
:column-list? false
:resizable? false}
(when with-id?
{:id :id
:name "ID"
:header (fn [_table _column] (header-index))
:cell (fn [table row _column]
(let [rows (map :id (:rows table))]
(inc (.indexOf rows (:id row)))))
:resizable? false})
(when with-object-name?
{:id :block/title
:name "Name"
@@ -270,6 +285,9 @@
(let [id (:id column)
size (get sized-columns id)]
(cond
(= id :id)
48
(number? size)
size
@@ -1259,18 +1277,17 @@
(more-actions columns table)
(when add-new-object! (new-record-button table view-entity))]]
(fn []
[:div.ls-view-body.flex.flex-col.gap-2.grid
(filters-row table)
[:div.ls-view-body.flex.flex-col.gap-2.grid
(filters-row table)
(case display-type
:logseq.property.view/type.list
(list-view (:config option) view-entity (:rows table))
(case display-type
:logseq.property.view/type.list
(list-view (:config option) view-entity (:rows table))
:logseq.property.view/type.gallery
(gallery-view (:config option) table view-entity (:rows table) *scroller-ref)
:logseq.property.view/type.gallery
(gallery-view (:config option) table view-entity (:rows table) *scroller-ref)
(table-view table option row-selection add-new-object! *scroller-ref))])
(table-view table option row-selection add-new-object! *scroller-ref))]
{:title-trigger? false})]))
(rum/defcs view