mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
ux enhancements
This commit is contained in:
79
deps/db/src/logseq/db.cljs
vendored
79
deps/db/src/logseq/db.cljs
vendored
@@ -705,48 +705,49 @@
|
|||||||
(and (or (db-property/user-property-namespace? attr-ns)
|
(and (or (db-property/user-property-namespace? attr-ns)
|
||||||
(db-property/plugin-property? attr))
|
(db-property/plugin-property? attr))
|
||||||
(when-let [property (d/entity db attr)]
|
(when-let [property (d/entity db attr)]
|
||||||
(and
|
(= :db.type/ref (:db/valueType property)))))))
|
||||||
(seq (:logseq.property/classes property))
|
|
||||||
(= :db.type/ref (:db/valueType property))))))))
|
|
||||||
|
|
||||||
(defn get-bidirectional-properties
|
(defn get-bidirectional-properties
|
||||||
"Given a target entity id, returns a seq of maps with:
|
"Given a target entity id, returns a seq of maps with:
|
||||||
* :title - pluralized class title
|
* :title - pluralized class title
|
||||||
* :entities - page entities that reference the target via ref properties"
|
* :entities - page entities that reference the target via ref properties"
|
||||||
[db target-id]
|
[db target-id]
|
||||||
(when (and db target-id)
|
(when (and db target-id (d/entity db target-id))
|
||||||
(let [target (d/entity db target-id)]
|
(let [add-entity
|
||||||
(when target
|
(fn [acc class-id entity]
|
||||||
(let [add-entity
|
(if class-id
|
||||||
(fn [acc class-ent entity]
|
(update acc class-id (fnil conj #{}) entity)
|
||||||
(if-let [title (pluralize-class-title (:block/title class-ent))]
|
acc))]
|
||||||
(update acc title (fnil conj #{}) entity)
|
(->> (d/q '[:find ?e ?a
|
||||||
acc))]
|
:in $ ?v
|
||||||
(->> (d/q '[:find ?e ?a
|
:where
|
||||||
:in $ ?v
|
[?e ?a ?v]
|
||||||
:where [?e ?a ?v]]
|
[?ea :db/ident ?a]
|
||||||
db
|
[?ea :logseq.property/classes]]
|
||||||
target-id)
|
db
|
||||||
(keep (fn [[e a]]
|
target-id)
|
||||||
(when (bidirectional-property-attr? db a)
|
(keep (fn [[e a]]
|
||||||
(when-let [entity (d/entity db e)]
|
(when (bidirectional-property-attr? db a)
|
||||||
(when (and (not= (:db/id entity) target-id)
|
(when-let [entity (d/entity db e)]
|
||||||
(not (entity-util/class? entity))
|
(when (and (not= (:db/id entity) target-id)
|
||||||
(not (entity-util/property? entity)))
|
(not (entity-util/class? entity))
|
||||||
(let [classes (->> (:block/tags entity)
|
(not (entity-util/property? entity)))
|
||||||
(filter entity-util/class?))]
|
(let [classes (filter entity-util/class? (:block/tags entity))]
|
||||||
(when (seq classes)
|
(when (seq classes)
|
||||||
(map (fn [class-ent]
|
(map (fn [class-ent]
|
||||||
[class-ent entity])
|
[(:db/id class-ent) entity])
|
||||||
classes))))))))
|
classes))))))))
|
||||||
(mapcat identity)
|
(mapcat identity)
|
||||||
(reduce (fn [acc [class-ent entity]]
|
(reduce (fn [acc [class-ent entity]]
|
||||||
(add-entity acc class-ent entity))
|
(add-entity acc class-ent entity))
|
||||||
{})
|
{})
|
||||||
(map (fn [[title entities]]
|
(map (fn [[class-id entities]]
|
||||||
{:title title
|
(let [class (d/entity db class-id)
|
||||||
:entities (->> entities
|
title (pluralize-class-title (:block/title class))]
|
||||||
(sort-by (comp string/lower-case :block/title))
|
{:title title
|
||||||
vec)}))
|
:class class
|
||||||
(sort-by (comp string/lower-case :title))
|
:entities (->> entities
|
||||||
vec))))))
|
(sort-by :block/created-at)
|
||||||
|
vec)})))
|
||||||
|
(sort-by (comp :block/created-at :class))
|
||||||
|
vec))))
|
||||||
|
|||||||
@@ -1131,6 +1131,10 @@ html.is-mac {
|
|||||||
.block-tags {
|
.block-tags {
|
||||||
margin-top: 17px;
|
margin-top: 17px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ls-properties-area .block-tags {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ls-page-title .ls-properties-area {
|
.ls-page-title .ls-properties-area {
|
||||||
|
|||||||
@@ -341,36 +341,46 @@
|
|||||||
(:block/title property)]
|
(:block/title property)]
|
||||||
(property-key-title block property class-schema?))]))
|
(property-key-title block property class-schema?))]))
|
||||||
|
|
||||||
(rum/defc bidirectional-page-link
|
(defn- bidirectional-property-icon-cp
|
||||||
[page]
|
[property]
|
||||||
(let [title (ldb/get-title-with-parents page)]
|
(if-let [icon (:logseq.property/icon property)]
|
||||||
[:a.page-ref
|
(icon-component/icon icon {:size 15 :color? true})
|
||||||
{:on-click (fn [e]
|
(ui/icon "letter-b" {:class "opacity-50" :size 15})))
|
||||||
(util/stop e)
|
|
||||||
(route-handler/redirect-to-page! (:block/uuid page)))}
|
(rum/defcs bidirectional-values-cp < rum/static
|
||||||
title]))
|
{:init (fn [state]
|
||||||
|
(assoc state ::container-id (state/get-next-container-id)))}
|
||||||
|
[state entities]
|
||||||
|
(let [blocks-container (state/get-component :block/blocks-container)
|
||||||
|
container-id (::container-id state)
|
||||||
|
config {:id (str "bidirectional-" container-id)
|
||||||
|
:container-id container-id
|
||||||
|
:editor-box (state/get-component :editor/box)
|
||||||
|
:view? true}]
|
||||||
|
(if (and blocks-container (seq entities))
|
||||||
|
[:div.property-block-container.content.w-full
|
||||||
|
(blocks-container config entities)]
|
||||||
|
[:span.opacity-60 "Empty"])))
|
||||||
|
|
||||||
(rum/defc bidirectional-properties-section < rum/static
|
(rum/defc bidirectional-properties-section < rum/static
|
||||||
[bidirectional-properties]
|
[bidirectional-properties]
|
||||||
(when (seq bidirectional-properties)
|
(when (seq bidirectional-properties)
|
||||||
(for [{:keys [title entities]} bidirectional-properties]
|
(for [{:keys [class title entities]} bidirectional-properties]
|
||||||
[:div.property-pair.items-start {:key (str "bidirectional-" title)}
|
[:div.property-pair.items-start {:key (str "bidirectional-" title)}
|
||||||
[:div.property-key
|
[:div.property-key
|
||||||
[:div.property-key-inner
|
[:div.property-key-inner
|
||||||
[:div.property-k.flex.select-none.w-full title]]]
|
[:div.property-icon
|
||||||
|
(bidirectional-property-icon-cp class)]
|
||||||
|
(if class
|
||||||
|
[:a.property-k.flex.select-none.w-full.jtrigger
|
||||||
|
{:on-click (fn [e]
|
||||||
|
(util/stop e)
|
||||||
|
(route-handler/redirect-to-page! (:block/uuid class)))}
|
||||||
|
title]
|
||||||
|
[:div.property-k.flex.select-none.w-full title])]]
|
||||||
[:div.ls-block.property-value-container.flex.flex-row.gap-1.items-start
|
[:div.ls-block.property-value-container.flex.flex-row.gap-1.items-start
|
||||||
[:div.property-value.flex.flex-1
|
[:div.property-value.flex.flex-1
|
||||||
[:div.multi-values.flex.flex-1.flex-row.items-center.flex-wrap.gap-1
|
(bidirectional-values-cp entities)]]])))
|
||||||
(let [items (map (fn [entity]
|
|
||||||
(rum/with-key
|
|
||||||
(bidirectional-page-link entity)
|
|
||||||
(str "bi-property-" title "-" (:db/id entity))))
|
|
||||||
entities)]
|
|
||||||
(if (seq items)
|
|
||||||
[:div.flex.flex-col
|
|
||||||
(for [item items]
|
|
||||||
item)]
|
|
||||||
[:span.opacity-60 "Empty"]))]]]])))
|
|
||||||
|
|
||||||
(rum/defcs ^:large-vars/cleanup-todo property-input < rum/reactive
|
(rum/defcs ^:large-vars/cleanup-todo property-input < rum/reactive
|
||||||
(rum/local false ::show-new-property-config?)
|
(rum/local false ::show-new-property-config?)
|
||||||
|
|||||||
Reference in New Issue
Block a user