Преглед изворни кода

enhance: delete property ux

Tienson Qin пре 2 година
родитељ
комит
86bc8ec9d6

+ 0 - 31
src/main/frontend/components/content.cljs

@@ -5,7 +5,6 @@
             [frontend.components.editor :as editor]
             [frontend.components.page-menu :as page-menu]
             [frontend.components.export :as export]
-            [frontend.components.property :as property]
             [frontend.context.i18n :refer [t]]
             [frontend.db :as db]
             [frontend.extensions.srs :as srs]
@@ -28,7 +27,6 @@
             [goog.dom :as gdom]
             [goog.object :as gobj]
             [rum.core :as rum]
-            [logseq.db.property :as db-property]
             [frontend.config :as config]))
 
 ;; TODO i18n support
@@ -346,22 +344,6 @@
            (ui/menu-link options title)
            title))])))
 
-(rum/defc property-custom-context-menu-content
-  [block property {:keys [class-schema?]}]
-  (let [repo (state/get-current-repo)
-        built-in-property? (contains? db-property/built-in-properties-keys-str (:block/name property))]
-    [:.menu-links-wrapper
-     (ui/menu-link
-      {:key "Delete this property"
-       :on-click (fn []
-                   (let [class? (contains? (:block/type block) "class")
-                         f (if (and class? class-schema?)
-                             property-handler/class-remove-property!
-                             property-handler/remove-block-property!)]
-                     (f repo (:block/uuid block) (:block/uuid property))))}
-      (t :context-menu/delete-property)
-      nil)]))
-
 ;; TODO: content could be changed
 ;; Also, keyboard bindings should only be activated after
 ;; blocks were already selected.
@@ -375,22 +357,9 @@
                       (let [target (gobj/get e "target")
                             block-el (.closest target ".bullet-container[blockid]")
                             block-id (some-> block-el (.getAttribute "blockid"))
-                            property-el (.closest target ".property-k")
-                            property-id (some-> property-el (.getAttribute "data-propertyid"))
-                            property-block-id (some-> property-el (.getAttribute "data-blockid"))
                             {:keys [block block-ref]} (state/sub :block-ref/context)
                             {:keys [page]} (state/sub :page-title/context)]
                         (cond
-                          (and property-id property-block-id)
-                          (let [block (db/entity [:block/uuid (uuid property-block-id)])
-                                property (db/entity [:block/uuid (uuid property-id)])]
-                            (when (and block property (not config/publishing?))
-                              (common-handler/show-custom-context-menu!
-                               e
-                               (property-custom-context-menu-content block
-                                                                     property
-                                                                     {:class-schema? (some-> property-el (.getAttribute "data-class-schema") (= "true"))}))))
-
                           page
                           (do
                             (common-handler/show-custom-context-menu!

+ 1 - 1
src/main/frontend/components/icon.cljs

@@ -35,7 +35,7 @@
                       (map (fn [k]
                              (-> (string/replace (csk/->Camel_Snake_Case (name k)) "_" " ")
                                  (string/replace-first "Icon " ""))))
-       ;; FIXME: somehow those icons don't work
+                      ;; FIXME: somehow those icons don't work
                       (remove #{"Ab" "Ab 2" "Ab Off"}))]
       (reset! *tabler-icons result)
       result)))

+ 2 - 1
src/main/frontend/components/page.cljs

@@ -377,7 +377,8 @@
         (when class?
           (page-properties page true))
         (when property?
-          (property/property-config page (assoc opts :inline-text component-block/inline-text)))])]))
+          (property/property-config page page (assoc opts
+                                                     :inline-text component-block/inline-text)))])]))
 
 (rum/defc page-configure
   [page *hover? *configuring?]

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

@@ -284,12 +284,15 @@
                    (reset! (::property-name state) (:block/original-name property))
                    (reset! (::property-schema state) (:block/schema property))
                    state))}
-  [state property {:keys [toggle-fn inline-text] :as opts}]
+  [state block property {:keys [toggle-fn inline-text class-schema? add-new-property?] :as opts}]
   (let [*property-name (::property-name state)
         *property-schema (::property-schema state)
         built-in-property? (contains? db-property/built-in-properties-keys-str (:block/original-name property))
         property (db/sub-block (:db/id property))
-        disabled? (or built-in-property? config/publishing?)]
+        disabled? (or built-in-property? config/publishing?)
+        hide-delete? (or (= (:db/id block) (:db/id property)) ; property page
+                         add-new-property?)
+        class? (contains? (:block/type block) "class")]
     [:div.property-configure.flex.flex-1.flex-col
      [:div.grid.gap-2.p-1
       [:div.grid.grid-cols-4.gap-1.items-center.leading-8
@@ -405,7 +408,22 @@
           :on-click (fn [e]
                       (util/stop e)
                       (update-property! property @*property-name @*property-schema)
-                      (when toggle-fn (toggle-fn)))))]]]))
+                      (when toggle-fn (toggle-fn)))))]
+
+      (when-not hide-delete?
+        [:hr])
+
+      (when-not hide-delete?
+        [:a.fade-link {:on-click (fn [e]
+                                   (util/stop e)
+                                   (when (js/confirm "Are you sure to delete this property?")
+                                     (let [repo (state/get-current-repo)
+                                           f (if (and class? class-schema?)
+                                               property-handler/class-remove-property!
+                                               property-handler/remove-block-property!)]
+                                       (f repo (:block/uuid block) (:block/uuid property))
+                                       (when toggle-fn (toggle-fn)))))}
+         "Delete property from this block"])]]))
 
 (defn- get-property-from-db [name]
   (when-not (string/blank? name)
@@ -476,8 +494,9 @@
                   (pv/property-value entity property @*property-value (assoc opts :editing? true)))
                 (fn [{:keys [toggle-fn]}]
                   [:div.p-6
-                   (property-config property (merge opts {:toggle-fn toggle-fn
-                                                          :block entity}))])
+                   (property-config entity property (merge opts {:toggle-fn toggle-fn
+                                                                 :block entity
+                                                                 :add-new-property? true}))])
                 {:initial-open? true
                  :modal-class (util/hiccup->class
                                "origin-top-right.absolute.left-0.rounded-md.shadow-lg.mt-2")})
@@ -603,7 +622,10 @@
            [:div {:style {:padding-left 6}} (:block/original-name property)]]))
       (fn [{:keys [toggle-fn]}]
         [:div.p-8
-         (property-config property {:toggle-fn toggle-fn :inline-text inline-text})])
+         (property-config block property
+                          {:toggle-fn toggle-fn
+                           :inline-text inline-text
+                           :class-schema? class-schema?})])
       {:modal-class (util/hiccup->class
                      "origin-top-right.absolute.left-0.rounded-md.shadow-lg")})]))
 

+ 0 - 2
src/resources/dicts/en.edn

@@ -267,8 +267,6 @@
  :context-menu/input-template-name "What's the template's name?"
  :context-menu/template-include-parent-block "Including the parent block in the template?"
  :context-menu/template-exists-warning "Template already exists!"
- :context-menu/delete-property "Delete property"
- :context-menu/configure-property "Configure property"
  :settings-page/git-tip "If you have Logseq Sync enabled, you can view a page's edit history directly. This section is for tech-savvy only."
  :settings-page/git-desc-1 "To view page's edit history, click the three horizontal dots in the top-right corner and select \"View page history\"."
  :settings-page/git-desc-2 "For professional users, Logseq also supports using "