Browse Source

fix: add back disallowing adding hidden built-in properties

Without this adding a built in prop and value leads to it disappearing
with no explanation. Also cleaned up gp-property into sections mostly
to differentiate between file and db graph properties
Gabriel Horner 2 years ago
parent
commit
47cea36e7d

+ 49 - 38
deps/graph-parser/src/logseq/graph_parser/property.cljs

@@ -6,6 +6,8 @@
             [goog.string :as gstring]
             [goog.string.format]))
 
+;; Graph agnostic fns
+;; ==================
 (def colons "Property delimiter for markdown mode" "::")
 (defn colons-org
   "Property delimiter for org mode"
@@ -34,6 +36,9 @@
    (contains? #{"Property_Drawer" "Properties"}
               (first block))))
 
+;; Configuration and fns for older, file graph properties
+;; =============
+
 ;; Built-in properties are properties that logseq uses for its features. Most of
 ;; these properties are hidden from the user but a few like the editable ones
 ;; are visible for the user to edit.
@@ -80,44 +85,6 @@
      :todo :doing :now :later :done}
    @built-in-extended-properties))
 
-;; FIXME: no support for built-in-extended-properties
-(def db-built-in-properties
-  {:alias {:schema {:type :page
-                    :cardinality :many}}
-   :tags {:schema {:type :page
-                   :cardinality :many}}
-   :background-color {:schema {:type :default}}
-   :heading {:schema {:type :any}}      ; number (1-6) or boolean for auto heading
-   :query-table {:schema {:type :checkbox}}
-   :query-properties {:schema {:type :coll}}
-   :query-sort-by {:schema {:type :checkbox}}
-   :query-sort-desc {:schema {:type :checkbox}}
-   :logseq.query/nlp-date {:schema {:type :checkbox}}
-   :ls-type {:schema {:type :keyword}}
-   :hl-type {:schema {:type :keyword}}
-   :hl-page {:schema {:type :number}}
-   :hl-stamp {:schema {:type :number}}
-   :hl-color {:schema {:type :default}}
-   :logseq.macro-name {:schema {:type :default}}
-   :logseq.macro-arguments {:schema {:type :default}}
-   :logseq.order-list-type {:schema {:type :checkbox}}
-   :logseq.tldraw.page {:schema {:type :map}}
-   :logseq.tldraw.shape {:schema {:type :map}}
-   :icon {:schema {:type :default}}
-   :public {:schema {:type :checkbox}}
-   :filters {:schema {:type :map}}
-   :exclude-from-graph-view {:schema {:type :checkbox}}})
-
-(def db-user-facing-built-in-properties
-  "These are built-in properties that users can see and use"
-  #{:alias :tags})
-
-(defonce db-built-in-properties-keys
-  (set (keys db-built-in-properties)))
-
-(defonce db-built-in-properties-keys-str
-  (set (map name (keys db-built-in-properties))))
-
 (def built-in-property-types
   "Types for built-in properties. Built-in properties whose values are to be
   parsed by gp-text/parse-non-string-property-value should be added here"
@@ -196,3 +163,47 @@
           (string/join "\n" lines))
         content))
     content))
+
+;; Configuration for db graph properties
+;; =============
+
+;; FIXME: no support for built-in-extended-properties
+(def db-built-in-properties
+  {:alias {:schema {:type :page
+                    :cardinality :many}}
+   :tags {:schema {:type :page
+                   :cardinality :many}}
+   :background-color {:schema {:type :default}}
+   :heading {:schema {:type :any}}      ; number (1-6) or boolean for auto heading
+   :query-table {:schema {:type :checkbox}}
+   :query-properties {:schema {:type :coll}}
+   :query-sort-by {:schema {:type :checkbox}}
+   :query-sort-desc {:schema {:type :checkbox}}
+   :logseq.query/nlp-date {:schema {:type :checkbox}}
+   :ls-type {:schema {:type :keyword}}
+   :hl-type {:schema {:type :keyword}}
+   :hl-page {:schema {:type :number}}
+   :hl-stamp {:schema {:type :number}}
+   :hl-color {:schema {:type :default}}
+   :logseq.macro-name {:schema {:type :default}}
+   :logseq.macro-arguments {:schema {:type :default}}
+   :logseq.order-list-type {:schema {:type :checkbox}}
+   :logseq.tldraw.page {:schema {:type :map}}
+   :logseq.tldraw.shape {:schema {:type :map}}
+   :icon {:schema {:type :default}}
+   :public {:schema {:type :checkbox}}
+   :filters {:schema {:type :map}}
+   :exclude-from-graph-view {:schema {:type :checkbox}}})
+
+(def db-user-facing-built-in-properties
+  "These are built-in properties that users can see and use"
+  #{:alias :tags})
+
+(defonce db-built-in-properties-keys
+  (set (keys db-built-in-properties)))
+
+(def db-hidden-built-in-properties
+  (set/difference db-built-in-properties-keys db-user-facing-built-in-properties))
+
+(defonce db-built-in-properties-keys-str
+  (set (map name (keys db-built-in-properties))))

+ 8 - 6
src/main/frontend/components/property.cljs

@@ -16,7 +16,6 @@
             [clojure.string :as string]
             [goog.dom :as gdom]
             [frontend.search :as search]
-            [frontend.components.search.highlight :as highlight]
             [frontend.components.svg :as svg]
             [frontend.modules.shortcut.core :as shortcut]
             [frontend.components.select :as select]
@@ -330,8 +329,7 @@
                                (set))
         properties (->> (search/get-all-properties)
                         (remove entity-properties)
-                        (remove (->> (set/difference gp-property/db-built-in-properties-keys
-                                                     gp-property/db-user-facing-built-in-properties)
+                        (remove (->> gp-property/db-hidden-built-in-properties
                                      (map name)
                                      set)))
         get-property-f (fn [name]
@@ -353,11 +351,15 @@
                        :dropdown? true
                        :show-new-when-not-exact-match? true
                        :input-default-placeholder "Add a property"
-                       :on-chosen (fn [{:keys [value] :as opts}]
+                       :on-chosen (fn [{:keys [value]}]
                                     (reset! *property-key value)
                                     (if-let [property (get-property-f value)]
-                                      (let [editor-id (str "ls-property-" blocks-container-id (:db/id entity) "-" (:db/id property))]
-                                        (set-editing! property editor-id "" ""))
+                                      (if (contains? gp-property/db-hidden-built-in-properties (keyword value))
+                                        (do (notification/show! "This is a built-in property that can't be used." :error)
+                                            (reset! *property-key nil)
+                                            (exit-edit-property))
+                                        (let [editor-id (str "ls-property-" blocks-container-id (:db/id entity) "-" (:db/id property))]
+                                          (set-editing! property editor-id "" "")))
                                       (do
                                         (db-property/upsert-property! repo value {:type :default} {})
                                         ;; configure new property