From cdb6d5d7aec157ca49049c0081460a8c86dc48ea Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 3 Aug 2023 16:01:35 +0800 Subject: [PATCH] fix: hide page configure for built-in property pages Also, disabled page delete and rename for built-in property pages --- src/main/frontend/components/content.cljs | 18 ++++++++++-------- src/main/frontend/components/page.cljs | 9 +++++++-- src/main/frontend/components/page_menu.cljs | 14 ++++++++++---- src/main/frontend/components/property.cljs | 17 ++++++++++------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/main/frontend/components/content.cljs b/src/main/frontend/components/content.cljs index 2dac235b07..d98288c5f4 100644 --- a/src/main/frontend/components/content.cljs +++ b/src/main/frontend/components/content.cljs @@ -28,7 +28,7 @@ [goog.dom :as gdom] [goog.object :as gobj] [rum.core :as rum] - )) + [logseq.graph-parser.property :as gp-property])) ;; TODO i18n support @@ -365,14 +365,16 @@ (rum/defc property-custom-context-menu-content [block property {:keys [class-schema?]}] - (let [repo (state/get-current-repo)] + (let [repo (state/get-current-repo) + built-in-property? (contains? gp-property/db-built-in-properties-keys-str (:block/name property))] [:.menu-links-wrapper - (ui/menu-link - {:key "Configure this property" - :on-click (fn [] - (state/set-modal! #(property/property-config repo property)))} - (t :context-menu/configure-property) - nil) + (when-not built-in-property? + (ui/menu-link + {:key "Configure this property" + :on-click (fn [] + (state/set-modal! #(property/property-config repo property)))} + (t :context-menu/configure-property) + nil)) (ui/menu-link {:key "Delete this property" :on-click (fn [] diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index 366ea72ff0..ce584e994f 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -40,7 +40,8 @@ [rum.core :as rum] [logseq.graph-parser.util.page-ref :as page-ref] [logseq.graph-parser.mldoc :as gp-mldoc] - [frontend.handler.property.util :as pu])) + [frontend.handler.property.util :as pu] + [logseq.graph-parser.property :as gp-property])) (defn- get-page-name [state] @@ -318,7 +319,11 @@ repo (:db/id page) :page)) - (when (and (not hls-page?) (not fmt-journal?) (not config/publishing?)) + (when (and (not hls-page?) + (not fmt-journal?) + (not config/publishing?) + (not (and (= "property" (:block/type page)) + (contains? gp-property/db-built-in-properties-keys-str page-name)))) (reset! *input-value (if untitled? "" old-name)) (reset! *edit? true)))))} (when (not= icon "") [:span.page-icon icon]) diff --git a/src/main/frontend/components/page_menu.cljs b/src/main/frontend/components/page_menu.cljs index 7115e8b8cf..4db22a12cd 100644 --- a/src/main/frontend/components/page_menu.cljs +++ b/src/main/frontend/components/page_menu.cljs @@ -18,7 +18,8 @@ [frontend.handler.user :as user-handler] [frontend.handler.file-sync :as file-sync-handler] [logseq.common.path :as path] - [frontend.handler.property.util :as pu])) + [frontend.handler.property.util :as pu] + [logseq.graph-parser.property :as gp-property])) (defn- delete-page! [page-name] @@ -78,11 +79,14 @@ _ (state/sub :auth/id-token) file-sync-graph-uuid (and (user-handler/logged-in?) (file-sync-handler/enable-sync?) - (file-sync-handler/get-current-graph-uuid))] + (file-sync-handler/get-current-graph-uuid)) + built-in-property? (and (= "property" (:block/type page)) + (contains? gp-property/db-built-in-properties-keys-str page-name))] (when (and page (not block?)) (->> [(when (and (not config/publishing?) - (config/db-based-graph? repo)) + (config/db-based-graph? repo) + (not built-in-property?)) {:title (t :page/configure) :options {:on-click (fn [] @@ -118,7 +122,9 @@ :options {:on-click #(page-handler/copy-page-url page-original-name)}}) (when-not (or contents? - config/publishing?) + config/publishing? + (and (config/db-based-graph? repo) + built-in-property?)) {:title (t :page/delete) :options {:on-click #(state/set-modal! (delete-page-dialog page-name))}}) diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index d275e39acd..e2fb9a0e3e 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -36,16 +36,19 @@ [state repo property ] (let [*property-name (::property-name state) *property-schema (::property-schema state) - disabled? (contains? gp-property/db-built-in-properties-keys-str (:block/original-name property))] + built-in-property? (contains? gp-property/db-built-in-properties-keys-str (:block/original-name property))] [:div.property-configure - [:h1.title "Configure property"] + [:h1.title + (if built-in-property? + "Built-in property" + "Configure property")] [:div.grid.gap-2.p-1 [:div.grid.grid-cols-4.gap-1.items-center.leading-8 [:label "Name:"] [:input.form-input {:on-change #(reset! *property-name (util/evalue %)) - :disabled disabled? + :disabled built-in-property? :value @*property-name}]] [:div.grid.grid-cols-4.gap-1.leading-8 @@ -55,7 +58,7 @@ (map (comp string/capitalize name)) (map (fn [type] {:label type - :disabled disabled? + :disabled built-in-property? :value type :selected (= (keyword (string/lower-case type)) (:type @*property-schema))})))] @@ -69,7 +72,7 @@ [:label "Multiple values:"] (let [many? (boolean (= :many (:cardinality @*property-schema)))] (ui/checkbox {:checked many? - :disabled disabled? + :disabled built-in-property? :on-change (fn [] (swap! *property-schema assoc :cardinality (if many? :one :many)))}))]) @@ -79,11 +82,11 @@ (ui/ls-textarea {:on-change (fn [e] (swap! *property-schema assoc :description (util/evalue e))) - :disabled disabled? + :disabled built-in-property? :value (:description @*property-schema)})]] [:div - (when-not disabled? + (when-not built-in-property? (ui/button "Save" :on-click (fn []