Added :block/instance to db schema

This commit is contained in:
Tienson Qin
2023-07-10 16:44:51 +08:00
parent 30c7605d7e
commit 23d3091fce
8 changed files with 53 additions and 16 deletions

View File

@@ -2060,10 +2060,8 @@
nil)))
(rum/defc db-properties-cp
[config block properties properties-text-values edit-input-id opts]
[config block edit-input-id opts]
(property-component/properties-area block
properties
properties-text-values
edit-input-id
(merge
{:inline-text inline-text
@@ -2848,8 +2846,6 @@
(when (config/db-based-graph? repo)
(db-properties-cp config
block
(:block/properties block)
(:block/properties-text-values block)
edit-input-id
{:selected? selected?}))])

View File

@@ -461,8 +461,6 @@
(component-block/db-properties-cp
{:editor-box editor/box}
page
(:block/properties page)
(:block/properties-text-values page)
edit-input-id
{:selected? false})))
@@ -1153,8 +1151,7 @@
type (:block/type page)
class? (= "class" type)
property? (= "property" type)
journal? (:block/journal? page)
{:keys [properties] :as _schema} (:block/schema page)]
journal? (:block/journal? page)]
(when page
[:div.page-configure
[:h1.title "Configure page"]
@@ -1180,8 +1177,6 @@
(component-block/db-properties-cp
{:editor-box editor/box}
page
(map (fn [k] [k nil]) properties)
{}
edit-input-id
{:selected? false
:page-configure? true
@@ -1194,8 +1189,6 @@
(component-block/db-properties-cp
{:editor-box editor/box}
page
(:block/properties page)
(:block/properties-text-values page)
edit-input-id
{:selected? false
:page-configure? true})])])]

View File

@@ -518,9 +518,30 @@
:editor-id editor-id
:dom-id dom-id}))])))
(defn- resolve-instance-page-if-exists
"Properties will be updated for the instance page instead of the refed block.
For example, the block below has a reference to the page \"How to solve it\",
we'd like the properties of the class \"book\" (e.g. Authors, Published year)
to be assigned for the page `How to solve it` instead of the referenced block.
Block:
- [[How to solve it]] #book
"
[block]
(if-let [instance (:block/instance block)]
(db/sub-block (:db/id instance))
(db/sub-block (:db/id block))))
(rum/defcs properties-area < rum/reactive
[state block properties properties-text-values edit-input-id opts]
[state target-block edit-input-id opts]
(let [repo (state/get-current-repo)
block (resolve-instance-page-if-exists target-block)
properties (if (and (:class-schema? opts) (:block/schema block))
(let [properties (:properties (:block/schema block))]
(map (fn [k] [k nil]) properties))
(:block/properties block))
properties-text-values (if (:class-schema? opts) {}
(:block/properties-text-values block))
new-property? (= edit-input-id (state/sub :ui/new-property-input-id))
class-properties (->> (:block/tags block)
(mapcat (fn [tag]

View File

@@ -40,6 +40,7 @@
:block/_refs
:block/path-refs
:block/tags
:block/instance
:block/content
:block/marker
:block/priority

View File

@@ -635,6 +635,7 @@
:push false
:path-params {:name to-page-name}})))
;; FIXME:
(defn db-based-rename!
([old-name new-name]
(db-based-rename! old-name new-name true))
@@ -695,7 +696,6 @@
(defn rename!
([old-name new-name] (rename! old-name new-name true))
([old-name new-name redirect?]
(prn "db based? " (config/db-based-graph? (state/get-current-repo)))
(let [f (if (config/db-based-graph? (state/get-current-repo))
db-based-rename!
file-based-rename!)]

View File

@@ -125,6 +125,22 @@
new-refs (remove-self-page (:block/refs m))]
(remove-orphaned-page-refs! (:db/id block-entity) txs-state old-refs new-refs))))
(defn- assoc-instance-when-save
[txs-state block-entity m]
(let [tags (seq (:block/tags m))]
(when (and (config/db-based-graph? (state/get-current-repo))
(:block/page block-entity)
tags)
(when-let [instance-id (first (remove (set (map :block/uuid tags))
(map :block/uuid (:block/refs m))))]
(swap! txs-state (fn [txs]
(concat txs
[{:block/uuid instance-id
:block/tags (:block/tags m)}
{:db/id (:db/id block-entity)
:block/instance [:block/uuid instance-id]}])))))))
;; -get-id, -get-parent-id, -get-left-id return block-id
;; the :block/parent, :block/left should be datascript lookup ref
@@ -208,6 +224,8 @@
(vec (concat txs other-tx)))))
(swap! txs-state conj (dissoc m :db/other-tx)))
(assoc-instance-when-save txs-state block-entity m)
this))
(-del [this txs-state children?]