Browse Source

fix: disallow remove pages from #Page view

Tienson Qin 5 months ago
parent
commit
791f073a7f

+ 9 - 8
src/main/frontend/components/selection.cljs

@@ -10,7 +10,7 @@
             [rum.core :as rum]))
             [rum.core :as rum]))
 
 
 (rum/defc action-bar < rum/reactive
 (rum/defc action-bar < rum/reactive
-  [& {:keys [on-cut on-copy selected-blocks hide-dots? button-border?]
+  [& {:keys [on-cut on-copy selected-blocks hide-dots? button-border? view-parent]
       :or {on-cut #(editor-handler/cut-selection-blocks true)}}]
       :or {on-cut #(editor-handler/cut-selection-blocks true)}}]
   (when-not (or (state/sub :search/mode)
   (when-not (or (state/sub :search/mode)
                 (state/sub :ui/show-property-dialog?))
                 (state/sub :ui/show-property-dialog?))
@@ -66,13 +66,14 @@
                                                                               :select-opts {:show-new-when-not-exact-match? false}
                                                                               :select-opts {:show-new-when-not-exact-match? false}
                                                                               :on-dialog-close #(state/pub-event! [:editor/hide-action-bar])}])))
                                                                               :on-dialog-close #(state/pub-event! [:editor/hide-action-bar])}])))
            "Unset property"))
            "Unset property"))
-        (shui/button
-         (assoc button-opts
-                :on-pointer-down (fn [e]
-                                   (util/stop e)
-                                   (on-cut)
-                                   (state/pub-event! [:editor/hide-action-bar])))
-         (ui/icon "trash" {:size 13}))
+        (when-not (contains? #{:logseq.class/Page} (:db/ident view-parent))
+          (shui/button
+           (assoc button-opts
+                  :on-pointer-down (fn [e]
+                                     (util/stop e)
+                                     (on-cut)
+                                     (state/pub-event! [:editor/hide-action-bar])))
+           (ui/icon "trash" {:size 13})))
         (when-not hide-dots?
         (when-not hide-dots?
           (shui/button
           (shui/button
            (assoc button-opts
            (assoc button-opts

+ 6 - 4
src/main/frontend/components/views.cljs

@@ -584,7 +584,8 @@
     {:on-cut #(on-delete-rows table selected-rows)
     {:on-cut #(on-delete-rows table selected-rows)
      :selected-blocks selected-rows
      :selected-blocks selected-rows
      :hide-dots? true
      :hide-dots? true
-     :button-border? true})))
+     :button-border? true
+     :view-parent (:logseq.property/view-for (:view-entity table))})))
 
 
 (rum/defc column-resizer
 (rum/defc column-resizer
   [_column on-sized!]
   [_column on-sized!]
@@ -714,9 +715,10 @@
       (case view-feature-type
       (case view-feature-type
         :class-objects
         :class-objects
         (when (seq page-ids)
         (when (seq page-ids)
-          (let [tx-data (map (fn [pid] [:db/retract pid :block/tags (:db/id view-parent)]) page-ids)]
-            (when (seq tx-data)
-              (outliner-op/transact! tx-data {:outliner-op :save-block}))))
+          (when-not (= :logseq.class/Page (:db/ident view-parent))
+            (let [tx-data (map (fn [pid] [:db/retract pid :block/tags (:db/id view-parent)]) page-ids)]
+              (when (seq tx-data)
+                (outliner-op/transact! tx-data {:outliner-op :save-block})))))
 
 
         :property-objects
         :property-objects
         ;; Relationships with built-in properties must not be deleted e.g. built-in? or parent
         ;; Relationships with built-in properties must not be deleted e.g. built-in? or parent