From 9af119ab29d5f15b50635e038c402abc12b83003 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 May 2025 18:04:28 +0800 Subject: [PATCH 1/7] enhance: between support any :datetime property Not just :block/created-at and :block/updated-at --- .../frontend/components/query/builder.cljs | 10 +++-- src/main/frontend/db/query_dsl.cljs | 38 +++++++++++-------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/main/frontend/components/query/builder.cljs b/src/main/frontend/components/query/builder.cljs index 820ea05649..9ed1d4bc8a 100644 --- a/src/main/frontend/components/query/builder.cljs +++ b/src/main/frontend/components/query/builder.cljs @@ -13,10 +13,10 @@ [frontend.handler.editor :as editor-handler] [frontend.handler.query.builder :as query-builder] [frontend.mixins :as mixins] - [frontend.util.ref :as ref] [frontend.state :as state] [frontend.ui :as ui] [frontend.util :as util] + [frontend.util.ref :as ref] [logseq.common.util :as common-util] [logseq.common.util.page-ref :as page-ref] [logseq.db :as ldb] @@ -506,9 +506,13 @@ (symbol? end)) (name end) (second end))] - (str (if (= k :block/created-at) + (str (cond + (= k :block/created-at) "Created" - "Updated") + (= k :block/updated-at) + "Updated" + :else + (or (:block/title (db/entity k)) (name k))) " " start (when end (str " ~ " end)))) diff --git a/src/main/frontend/db/query_dsl.cljs b/src/main/frontend/db/query_dsl.cljs index b1fc176164..5625613177 100644 --- a/src/main/frontend/db/query_dsl.cljs +++ b/src/main/frontend/db/query_dsl.cljs @@ -19,6 +19,7 @@ [logseq.common.util.date-time :as date-time-util] [logseq.common.util.page-ref :as page-ref] [logseq.db.file-based.rules :as file-rules] + [logseq.db.frontend.property :as db-property] [logseq.db.frontend.rules :as rules] [logseq.graph-parser.text :as text])) @@ -208,25 +209,30 @@ ;; =============== (defn- resolve-timestamp-property [e] - (let [k' (second e)] - (when (or (keyword? k') (symbol? k') (string? k')) - (let [k (-> k' - (name) - (string/lower-case) - (string/replace "_" "-") - keyword)] - (case k - :created-at - :block/created-at - :updated-at - :block/updated-at - k))))) + (let [k (second e)] + (when (or (keyword? k) (symbol? k) (string? k)) + (let [k' (-> k + (name) + (string/lower-case) + (string/replace "_" "-") + keyword)] + (if (and (config/db-based-graph?) (db-property/property? k')) + k' + (case k' + :created-at + :block/created-at + :updated-at + :block/updated-at + nil)))))) (defn get-timestamp-property [e] - (let [k (resolve-timestamp-property e)] - (when (contains? #{:block/created-at :block/updated-at} k) - k))) + (when-let [k (resolve-timestamp-property e)] + (if (config/db-based-graph?) + (when (keyword? k) + k) + (when (contains? #{:block/created-at :block/updated-at} k) + k)))) (defn- build-journal-between-two-arg [e] From 9404e5b5bff71a8648021c6617d7da1f1ce56c14 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 May 2025 18:51:01 +0800 Subject: [PATCH 2/7] fix: buggy between ui --- .../frontend/components/query/builder.cljs | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/main/frontend/components/query/builder.cljs b/src/main/frontend/components/query/builder.cljs index 9ed1d4bc8a..a3b5767617 100644 --- a/src/main/frontend/components/query/builder.cljs +++ b/src/main/frontend/components/query/builder.cljs @@ -91,43 +91,38 @@ {:will-unmount (fn [state] (swap! *between-dates dissoc (first (:rum/args state))) state)} - [state id placeholder {:keys [auto-focus on-select]}] + [state id placeholder {:keys [on-select]}] (let [*input-value (::input-value state)] - [:div.ml-4 - [:input.query-builder-datepicker.form-input.block.sm:text-sm.sm:leading-5 - {:auto-focus (or auto-focus false) - :data-key (name id) - :placeholder placeholder - :aria-label placeholder - :value (some-> @*input-value (first)) - :on-focus (fn [^js e] - (js/setTimeout - #(shui/popup-show! (.-target e) - (let [select-handle! (fn [^js d] - (let [gd (date/js-date->goog-date d) - journal-date (date/js-date->journal-title gd)] - (reset! *input-value [journal-date d]) - (swap! *between-dates assoc id journal-date)) - (some-> on-select (apply [])) - (shui/popup-hide!))] - (ui/single-calendar - {:initial-focus true - :selected (some-> @*input-value (second)) - :on-select select-handle!})) - {:id :query-datepicker - :content-props {:class "p-0"} - :align :start}) 16))}]])) + (shui/button + {:variant :secondary + :size :sm + :on-click (fn [^js e] + (shui/popup-show! (.-target e) + (let [select-handle! (fn [^js d] + (let [gd (date/js-date->goog-date d) + journal-date (date/js-date->journal-title gd)] + (reset! *input-value [journal-date d]) + (swap! *between-dates assoc id journal-date)) + (some-> on-select (apply [])) + (shui/popup-hide!))] + (ui/single-calendar + {:initial-focus false + :selected (some-> @*input-value (second)) + :on-select select-handle!})) + {:id :query-datepicker + :content-props {:class "p-0"} + :align :start}))} + (or (first @*input-value) placeholder)))) (rum/defcs between < (rum/local nil ::start) (rum/local nil ::end) [state {:keys [tree loc] :as opts}] [:div.between-date.p-4 {:on-pointer-down (fn [e] (util/stop-propagation e))} - [:div.flex.flex-row - [:div.font-medium.mt-2 "Between: "] + [:div.flex.flex-row.items-center.gap-2 + [:div.font-medium "Between: "] (datepicker :start "Start date" - (merge opts {:auto-focus true - :on-select (fn [] + (merge opts {:on-select (fn [] (when-let [^js end-input (js/document.querySelector ".query-builder-datepicker[data-key=end]")] (when (string/blank? (.-value end-input)) (.focus end-input))))})) @@ -138,6 +133,7 @@ (let [{:keys [start end]} @*between-dates] (when (and start end) (let [clause [:between [:page-ref start] [:page-ref end]]] + (prn :debug :tree tree) (append-tree! tree opts loc clause) (reset! *between-dates {}))))))]]) From b88375ba4b6dad47ee5b7f0902172d4285f9ed1b Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 May 2025 18:54:49 +0800 Subject: [PATCH 3/7] chore: remove debug --- src/main/frontend/components/query/builder.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/frontend/components/query/builder.cljs b/src/main/frontend/components/query/builder.cljs index a3b5767617..8888669fe3 100644 --- a/src/main/frontend/components/query/builder.cljs +++ b/src/main/frontend/components/query/builder.cljs @@ -133,7 +133,6 @@ (let [{:keys [start end]} @*between-dates] (when (and start end) (let [clause [:between [:page-ref start] [:page-ref end]]] - (prn :debug :tree tree) (append-tree! tree opts loc clause) (reset! *between-dates {}))))))]]) From 65f5b9cd64839e1245ebc48b9e099df0a2c96e94 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 May 2025 00:11:51 +0800 Subject: [PATCH 4/7] enhance(ux): tag properties using select --- deps/db/src/logseq/db/frontend/db.cljs | 3 +- src/main/frontend/components/objects.cljs | 5 +- src/main/frontend/components/property.cljs | 84 +++++-------------- .../frontend/components/property/value.cljs | 57 +++++++------ src/main/frontend/components/views.cljs | 2 +- src/main/frontend/db/async.cljs | 28 +------ src/main/frontend/db/model.cljs | 47 +++++++++++ src/main/frontend/handler/property.cljs | 18 ++++ 8 files changed, 126 insertions(+), 118 deletions(-) diff --git a/deps/db/src/logseq/db/frontend/db.cljs b/deps/db/src/logseq/db/frontend/db.cljs index 031d062ab0..63244ae402 100644 --- a/deps/db/src/logseq/db/frontend/db.cljs +++ b/deps/db/src/logseq/db/frontend/db.cljs @@ -40,8 +40,7 @@ (defn get-all-properties [db] (->> (d/datoms db :avet :block/tags :logseq.class/Property) - (map (fn [d] - (d/entity db (:e d)))))) + (map (fn [d] (d/entity db (:e d)))))) (defn get-page-parents [node & {:keys [node-class?]}] diff --git a/src/main/frontend/components/objects.cljs b/src/main/frontend/components/objects.cljs index e0e78fe921..aeb9e46186 100644 --- a/src/main/frontend/components/objects.cljs +++ b/src/main/frontend/components/objects.cljs @@ -94,9 +94,10 @@ :add-new-object! add-new-object! :show-add-property? true :show-items-count? true - :add-property! (fn [] + :add-property! (fn [e] (state/pub-event! [:editor/new-property {:block class - :class-schema? true}]))})])) + :class-schema? true + :target (.-target e)}]))})])) (rum/defcs class-objects < rum/reactive db-mixins/query mixins/container-id [state class {:keys [current-page? sidebar?]}] diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 731766a724..a2dd3c3e21 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -148,22 +148,19 @@ [:span "Changing the property type clears some property configurations."]))])) (rum/defc property-select - [exclude-properties select-opts] + [select-opts] (let [[properties set-properties!] (rum/use-state nil) - [classes set-classes!] (rum/use-state nil) - [excluded-properties set-excluded-properties!] (rum/use-state nil)] + [classes set-classes!] (rum/use-state nil)] (hooks/use-effect! (fn [] (p/let [repo (state/get-current-repo) - properties (db-async/db-based-get-all-properties repo) + properties (if (:class-schema? select-opts) + (property-handler/get-class-property-choices) + (db-model/get-all-properties repo {:remove-ui-non-suitable-properties? true})) classes (->> (db-model/get-all-classes repo) (remove ldb/built-in?))] (set-classes! classes) - (set-properties! (remove exclude-properties properties)) - (set-excluded-properties! (->> properties - (filter exclude-properties) - (map :block/title) - set)))) + (set-properties! properties))) []) (let [items (->> (concat @@ -186,7 +183,7 @@ :close-modal? false :new-case-sensitive? true :show-new-when-not-exact-match? true - :exact-match-exclude-items (fn [s] (contains? excluded-properties s)) + ;; :exact-match-exclude-items (fn [s] (contains? excluded-properties s)) :input-default-placeholder "Add or change property"} select-opts))]]))) @@ -270,7 +267,8 @@ (shui/trigger-as :a {:tabIndex 0 - :title (:block/title property) + :title (or (:block/title (:logseq.property/description property)) + (:block/title property)) :class "property-k flex select-none jtrigger w-full" :on-pointer-down (fn [^js e] (when (util/meta-key? e) @@ -363,26 +361,11 @@ state)} [state block *property-key {:keys [class-schema?] :as opts}] + (prn :debug :key *property-key) (let [*property (::property state) *show-new-property-config? (::show-new-property-config? state) *show-class-select? (::show-class-select? state) *property-schema (::property-schema state) - page? (entity-util/page? block) - block-types (let [types (ldb/get-entity-types block)] - (cond-> types - (and page? (not (contains? types :page))) - (conj :page) - (empty? types) - (conj :block))) - exclude-properties (fn [m] - (let [view-context (get m :logseq.property/view-context :all)] - (or (contains? #{:logseq.property/query} (:db/ident m)) - (and (not page?) (contains? #{:block/alias} (:db/ident m))) - ;; Filters out properties from being in wrong :view-context and :never view-contexts - (and (not= view-context :all) (not (contains? block-types view-context))) - (and (ldb/built-in? block) (contains? #{:logseq.property/parent} (:db/ident m))) - ;; Filters out adding buggy class properties e.g. Alias and Parent - (and class-schema? (ldb/public-built-in-property? m) (:logseq.property/view-context m))))) property (rum/react *property) property-key (rum/react *property-key) batch? (pv/batch-operation?) @@ -434,9 +417,9 @@ (= "" (.-value (.-target e)))) (util/stop e) (shui/popup-hide!)))}] - (property-select exclude-properties - (merge (:select-opts opts) {:on-chosen on-chosen - :input-opts input-opts}))))])) + (property-select (merge (:select-opts opts) {:on-chosen on-chosen + :input-opts input-opts + :class-schema? class-schema?}))))])) (rum/defcs new-property < rum/reactive [state block opts] @@ -491,8 +474,6 @@ :page-cp page-cp))] [:div {:key (str "property-pair-" (:db/id block) "-" (:db/id property)) :class (cond - (= (:db/ident property) :logseq.property.class/properties) - "property-pair !flex !flex-col" (or date? datetime? checkbox?) "property-pair items-center" :else @@ -501,21 +482,14 @@ (dnd/sortable-item (assoc sortable-opts :class "property-key") property-key-cp') [:div.property-key property-key-cp']) - (let [class-properties? (= (:db/ident property) :logseq.property.class/properties) - property-desc (when-not (= (:db/ident property) :logseq.property/description) + (let [property-desc (when-not (= (:db/ident property) :logseq.property/description) (:logseq.property/description property))] [:div.ls-block.property-value-container.flex.flex-row.gap-1.items-center - (cond-> {} - class-properties? (assoc :class (if (:logseq.property.class/properties block) - "ml-2 -mt-1" - "-ml-1"))) - (when-not (or block? class-properties? (and property-desc (:class-schema? opts))) + (when-not (or block? (and property-desc (:class-schema? opts))) [:div {:class "pl-1.5 -mr-[3px] opacity-60"} [:span.bullet-container [:span.bullet]]]) [:div.flex.flex-1 [:div.property-value.flex.flex-1 - (cond-> {} - class-properties? (assoc :class :opacity-90)) (if (:class-schema? opts) (pv/property-value property (db/entity :logseq.property/description) opts) (pv/property-value block property opts))]]])])))) @@ -592,7 +566,6 @@ (and show? (or (= mode :global) (and (set? ids) (contains? ids (:block/uuid block)))))) - class? (ldb/class? block) properties (:block/properties block) remove-built-in-or-other-position-properties (fn [properties] @@ -667,9 +640,7 @@ result))) result)) full-properties (->> (concat block-own-properties' - (map (fn [p] [p (get block p)]) class-properties) - (when (and class? (nil? (:logseq.property.class/properties block))) - [[:logseq.property.class/properties nil]])) + (map (fn [p] [p (get block p)]) class-properties)) remove-built-in-or-other-position-properties)] (cond (empty? full-properties) @@ -678,28 +649,15 @@ :else (let [remove-properties #{:logseq.property/icon :logseq.property/query} - properties' (remove (fn [[k _v]] (contains? remove-properties k)) full-properties) - properties'' (->> properties' - (remove (fn [[k _v]] (= k :logseq.property.class/properties)))) + properties' (remove (fn [[k _v]] (contains? remove-properties k)) + full-properties) page? (entity-util/page? block)] [:div.ls-properties-area {:id id :class (util/classnames [{:ls-page-properties page?}]) :tab-index 0} [:<> - (properties-section block properties'' opts) + (properties-section block properties' opts) - (when (and page? (not class?)) - (rum/with-key (new-property block opts) (str id "-add-property")))] - - (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}} - "Tag Properties:"] - [:div - (properties-section block properties opts') - (rum/with-key (new-property block opts') (str id "-class-add-property"))]]]))])))) + (when page? + (rum/with-key (new-property block opts) (str id "-add-property")))]])))) diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index 0cb2fabf7a..7ca9b555f8 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -679,7 +679,7 @@ (rum/defc ^:large-vars/cleanup-todo select-node < rum/static [property - {:keys [block multiple-choices? dropdown? input-opts on-input add-new-choice!] :as opts} + {:keys [block multiple-choices? dropdown? input-opts on-input add-new-choice! target] :as opts} result] (let [repo (state/get-current-repo) classes (:logseq.property/classes property) @@ -695,9 +695,6 @@ parent-property? (= (:db/ident property) :logseq.property/parent) children-pages (when parent-property? (model/get-structured-children repo (:db/id block))) property-type (:logseq.property/type property) - get-all-classes-f (fn [] - (model/get-all-classes repo {:except-root-class? true - :except-private-tags? (not (contains? #{:logseq.property/template-applied-to} (:db/ident property)))})) nodes (cond parent-property? (let [;; Disallows cyclic hierarchies @@ -709,8 +706,14 @@ excluded-options (remove (fn [e] (contains? exclude-ids (:block/uuid e))) options)] excluded-options) - (= property-type :class) - (get-all-classes-f) + (contains? #{:class :property} property-type) + (let [classes (model/get-all-classes + repo + {:except-root-class? true + :except-private-tags? (not (contains? #{:logseq.property/template-applied-to} (:db/ident property)))})] + (if (= property-type :class) + classes + (property-handler/get-class-property-choices))) (seq classes) (->> @@ -766,7 +769,7 @@ (breadcrumb {:search? true} (state/get-current-repo) (:block/uuid node) {})])) label [:div.flex.flex-row.items-center.gap-1 (when-not (or (:logseq.property/classes property) - (= (:db/ident property) :block/tags)) + (contains? #{:class :property} (:logseq.property/type property))) (ui/icon icon {:size 14})) [:div title]]] [header label]) @@ -806,10 +809,18 @@ :input-opts input-opts :on-input (debounce on-input 50) :on-chosen (fn [chosen selected?] - (p/let [id (if (integer? chosen) + (p/let [add-tag-property? (and (= (:db/ident property) :logseq.property.class/properties) (not (integer? chosen))) + id (if (integer? chosen) chosen (when-not (string/blank? (string/trim chosen)) - (> (if (entity-map? v) #{v} v) (= (:db/ident property) :block/tags) (remove (fn [v] (contains? ldb/hidden-tags (:db/ident v))))) - select-cp (fn [select-opts] + select-cp (fn [select-opts target] (let [select-opts (merge {:multiple-choices? true :on-chosen (fn [] (when on-chosen (on-chosen)))} @@ -1378,18 +1390,20 @@ [:div.property-select (if (contains? #{:node :page :class :property} type) (property-value-select-node block property - select-opts + (assoc select-opts :target target) opts) (select block property select-opts opts))]))] (if editing? - (select-cp {}) + (select-cp {} nil) (let [toggle-fn shui/popup-hide! - content-fn (fn [{:keys [_id content-props]}] - (select-cp {:content-props content-props})) + content-fn (fn [{:keys [_id content-props]} target] + (select-cp {:content-props content-props} target)) show-popup! (fn [^js e] (let [target (.-target e)] (when-not (or (util/link? target) (.closest target "a") config/publishing?) - (shui/popup-show! (rum/deref *el) content-fn + (shui/popup-show! (rum/deref *el) + (fn [opts] + (content-fn opts target)) {:as-dropdown? true :as-content? false :align "start" :auto-focus? true}))))] [:div.multi-values.jtrigger @@ -1432,7 +1446,6 @@ (ui/catch-error (ui/block-error "Something wrong" {}) (let [block-cp (state/get-component :block/blocks-container) - properties-cp (state/get-component :block/properties-cp) opts (merge opts {:page-cp (state/get-component :block/page-cp) :inline-text (state/get-component :block/inline-text) @@ -1486,10 +1499,6 @@ :class (str (when empty-value? "empty-value") (when-not (:other-position? opts) " w-full"))} (cond - (= property-ident :logseq.property.class/properties) - (properties-cp {} block {:selected? false - :class-schema? true}) - (and multiple-values? (contains? #{:default :url} type) (not closed-values?) (not editing?)) (property-normal-block-value block property v opts) diff --git a/src/main/frontend/components/views.cljs b/src/main/frontend/components/views.cljs index c81dedb75b..6ffe2dfb46 100644 --- a/src/main/frontend/components/views.cljs +++ b/src/main/frontend/components/views.cljs @@ -695,7 +695,7 @@ {:id "add property" :prop {:style {:width "-webkit-fill-available" :min-width 160} - :on-click (fn [] (when (fn? add-property!) (add-property!)))} + :on-click (fn [e] (when (fn? add-property!) (add-property! e)))} :value :add-new-property :content (add-property-button) :disabled? true}) diff --git a/src/main/frontend/db/async.cljs b/src/main/frontend/db/async.cljs index 1122e4a75f..624789acdc 100644 --- a/src/main/frontend/db/async.cljs +++ b/src/main/frontend/db/async.cljs @@ -9,16 +9,14 @@ [frontend.db :as db] [frontend.db.async.util :as db-async-util] [frontend.db.file-based.async :as file-async] - [frontend.db.model :as db-model] [frontend.db.file-based.model :as file-model] + [frontend.db.model :as db-model] [frontend.db.react :as react] [frontend.db.utils :as db-utils] [frontend.handler.file-based.property.util :as property-util] [frontend.state :as state] [frontend.util :as util] [logseq.common.util :as common-util] - [logseq.db :as ldb] - [logseq.db.frontend.property :as db-property] [promesa.core :as p])) (def > (d/datoms (db/get-db graph) :avet :block/tags :logseq.class/Property) - (map (fn [datom] (db/entity (:e datom)))) - (sort-by (juxt ldb/built-in? :block/title)))] - (cond->> result - remove-built-in-property? - ;; remove private built-in properties - (remove (fn [p] - (let [ident (:db/ident p)] - (and (ldb/built-in? p) - (not (ldb/public-built-in-property? p)) - (not= ident :logseq.property/icon))))) - remove-non-queryable-built-in-property? - (remove (fn [p] - (let [ident (:db/ident p)] - (and (ldb/built-in? p) - (not (:queryable? (db-property/built-in-properties ident)))))))))) - (defn types + (and block-page? (not (contains? types :page))) + (conj :page) + (empty? types) + (conj :block))) + view-context (get m :logseq.property/view-context :all)] + (or (contains? #{:logseq.property/query} (:db/ident m)) + (and (not block-page?) (contains? #{:block/alias} (:db/ident m))) + ;; Filters out properties from being in wrong :view-context and :never view-contexts + (and (not= view-context :all) (not (contains? block-types view-context))) + (and (ldb/built-in? block) (contains? #{:logseq.property/parent} (:db/ident m))) + ;; Filters out adding buggy class properties e.g. Alias and Parent + (and class-schema? (ldb/public-built-in-property? m) (:logseq.property/view-context m)))))) + +(defn get-all-properties + "Return seq of all property names except for private built-in properties." + [graph & {:keys [remove-built-in-property? remove-non-queryable-built-in-property? remove-ui-non-suitable-properties? + class-schema? block] + :or {remove-built-in-property? true + remove-non-queryable-built-in-property? false + remove-ui-non-suitable-properties? false}}] + (let [db (conn/get-db graph) + result (sort-by (juxt ldb/built-in? :block/title) + (ldb/get-all-properties db))] + (cond->> result + remove-built-in-property? + ;; remove private built-in properties + (remove (fn [p] + (let [ident (:db/ident p)] + (and (ldb/built-in? p) + (not (ldb/public-built-in-property? p)) + (not= ident :logseq.property/icon))))) + remove-non-queryable-built-in-property? + (remove (fn [p] + (let [ident (:db/ident p)] + (and (ldb/built-in? p) + (not (:queryable? (db-property/built-in-properties ident))))))) + remove-ui-non-suitable-properties? + (remove (fn [p] + (ui-non-suitable-property? block p {:class-schema? class-schema?})))))) + (defn get-all-readable-classes "Gets all classes that are used in a read only context e.g. querying or used for property value selection. This should _not_ be used in a write context e.g. diff --git a/src/main/frontend/handler/property.cljs b/src/main/frontend/handler/property.cljs index 75ed7fbe98..4d5e6391cd 100644 --- a/src/main/frontend/handler/property.cljs +++ b/src/main/frontend/handler/property.cljs @@ -1,6 +1,7 @@ (ns frontend.handler.property "Property fns for both file and DB graphs" (:require [frontend.config :as config] + [frontend.db.model :as db-model] [frontend.handler.db-based.property :as db-property-handler] [frontend.handler.file-based.page-property :as file-page-property] [frontend.handler.file-based.property :as file-property-handler] @@ -66,3 +67,20 @@ (assert (uuid? block-id)) (when (config/db-based-graph? repo) (db-property-handler/set-block-properties! block-id properties))) + +(defonce class-property-excludes + #{:logseq.property.class/properties :block/tags + :logseq.property/icon :block/alias :logseq.property/enable-history? + :logseq.property/exclude-from-graph-view :logseq.property/template-applied-to + :logseq.property/hide-empty-value :logseq.property.class/hide-from-node + :logseq.property/page-tags :logseq.property/parent + :logseq.property/publishing-public? :logseq.property.user/avatar + :logseq.property.user/email :logseq.property.user/name}) + +(defn get-class-property-choices + [] + (->> + (db-model/get-all-properties (state/get-current-repo) + {:remove-ui-non-suitable-properties? true}) + (remove (fn [p] + (contains? class-property-excludes (:db/ident p)))))) From 0787d7ae366545feda56da05b37e185046b5f150 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 May 2025 01:33:23 +0800 Subject: [PATCH 5/7] fix: create new property in tag properties --- src/main/frontend/components/property.cljs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index a2dd3c3e21..8ee2903e03 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -361,7 +361,6 @@ state)} [state block *property-key {:keys [class-schema?] :as opts}] - (prn :debug :key *property-key) (let [*property (::property state) *show-new-property-config? (::show-new-property-config? state) *show-class-select? (::show-class-select? state) @@ -388,7 +387,7 @@ [:div.flex.flex-row {:on-pointer-down (fn [e] (util/stop-propagation e))} (when (not= @*show-new-property-config? :adding-property) (cond - @*show-new-property-config? + (or (nil? property) @*show-new-property-config?) (property-type-select property (merge opts {:*property *property :*property-name *property-key From ed0860fcc32cf3c92dcbb5e15a6261d8ba886e07 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 May 2025 02:08:04 +0800 Subject: [PATCH 6/7] enhance(ux): set different hovering actions for tag, property and page --- src/main/frontend/components/page.cljs | 24 ++++++++++++++++++---- src/main/frontend/components/property.cljs | 9 +++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index bd6dfba145..ac39ce849f 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -10,6 +10,7 @@ [frontend.components.file-based.hierarchy :as hierarchy] [frontend.components.objects :as objects] [frontend.components.plugins :as plugins] + [frontend.components.property.config :as property-config] [frontend.components.query :as query] [frontend.components.reference :as reference] [frontend.components.scheduled-deadlines :as scheduled] @@ -438,9 +439,24 @@ :size :sm :class "px-2 py-0 h-6 text-xs text-muted-foreground" :on-click (fn [e] - (state/pub-event! [:editor/new-property {:block page - :target (.-target e)}]))} - "Set property")]]) + (if (ldb/property? page) + (shui/popup-show! + (.-target e) + (fn [] + [:div.ls-property-dropdown + (property-config/property-dropdown page nil {})]) + {:align :center}) + (let [opts (cond-> {:block page :target (.-target e)} + (ldb/class? page) + (assoc :class-schema? true))] + (state/pub-event! [:editor/new-property opts]))))} + (cond + (ldb/class? page) + "Add tag property" + (ldb/property? page) + "Configure" + :else + "Set property"))]]) (rum/defc db-page-title [page whiteboard-page? sidebar? container-id] @@ -558,7 +574,7 @@ (shui/tabs {:defaultValue default-tab :class "w-full"} - (when (or both? property?) + (when both? [:div.flex.flex-row.gap-1.items-center (shui/tabs-list {:class "h-8"} diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 8ee2903e03..67d62e6d4f 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -638,9 +638,12 @@ (into result cur-properties) result))) result)) - full-properties (->> (concat block-own-properties' - (map (fn [p] [p (get block p)]) class-properties)) - remove-built-in-or-other-position-properties)] + full-properties (cond-> + (->> (concat block-own-properties' + (map (fn [p] [p (get block p)]) class-properties)) + remove-built-in-or-other-position-properties) + (and (ldb/class? block) (empty? (:logseq.property.class/properties block))) + (concat [[:logseq.property.class/properties nil]]))] (cond (empty? full-properties) (when sidebar-properties? From 3ba5028aa9171c7dc26d4c93130bedc3b9a0a571 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 May 2025 02:42:18 +0800 Subject: [PATCH 7/7] enhance(ux): show collapsed triangle for page title --- src/main/frontend/components/block.cljs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 9051f93f75..300bea2b82 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -2131,8 +2131,9 @@ own-number-list? (:own-order-number-list? config) order-list? (boolean own-number-list?) order-list-idx (:own-order-list-index config) + page-title? (:page-title? config) collapsable? (editor-handler/collapsable? uuid {:semantic? true - :ignore-children? (:page-title? config)}) + :ignore-children? page-title?}) link? (boolean (:original-block config)) icon-size (if collapsed? 12 14) icon (icon-component/get-node-icon-cp block {:size icon-size :color? true}) @@ -2147,7 +2148,8 @@ :is-with-icon with-icon? :bullet-closed collapsed? :bullet-hidden (:hide-bullet? config)}])} - (when (and (or (not fold-button-right?) collapsable?) (not (:table? config))) + (when (and (or (not fold-button-right?) collapsable?) + (not (:table? config))) [:a.block-control {:id (str "control-" uuid) :on-click (fn [event] @@ -2162,7 +2164,7 @@ (when (and (state/developer-mode?) (.-metaKey event)) (js/console.debug "[block config]==" config)))} [:span {:class (if (or (and control-show? (or collapsed? collapsable?)) - (and collapsed? (or order-list? config/publishing?))) + (and collapsed? (or page-title? order-list? config/publishing?))) "control-show cursor-pointer" "control-hide")} (ui/rotating-arrow collapsed?)]])