浏览代码

fix: don't create bi-directional alias

related to LOG-3124
Tienson Qin 1 年之前
父节点
当前提交
1858180476

+ 3 - 3
deps/db/src/logseq/db/frontend/property/util.cljs

@@ -30,9 +30,9 @@
 (defn get-block-property-value
   "Get the value of built-in block's property by its db-ident"
   [repo db block db-ident]
-  (assert db "DB required")
-  (let [block (or (d/entity db (:db/id block)) block)]
-    (lookup repo (:block/properties block) db-ident)))
+  (when db
+    (let [block (or (d/entity db (:db/id block)) block)]
+     (lookup repo (:block/properties block) db-ident))))
 
 (defn shape-block?
   [repo db block]

+ 8 - 21
deps/graph-parser/src/logseq/graph_parser/extract.cljc

@@ -124,7 +124,7 @@
             first-block-name)))))
 
 (defn- extract-page-alias-and-tags
-  [page-m page page-name properties]
+  [page-m page-name properties]
   (let [alias (:alias properties)
         alias' (if (coll? alias) alias [(str alias)])
         aliases (and alias'
@@ -132,24 +132,11 @@
                                        (string/blank? %)) ;; disable blank alias
                                   alias')))
         aliases' (keep
-                   (fn [alias]
-                     (let [page-name (common-util/page-name-sanity-lc alias)
-                           aliases (distinct
-                                    (conj
-                                     (remove #{alias} aliases)
-                                     page))
-                           aliases (when (seq aliases)
-                                     (map
-                                       (fn [alias]
-                                         {:block/name (common-util/page-name-sanity-lc alias)})
-                                       aliases))]
-                       (if (seq aliases)
-                         {:block/name page-name
-                          :block/original-name alias
-                          :block/alias aliases}
-                         {:block/name page-name
-                          :block/original-name alias})))
-                   aliases)
+                  (fn [alias]
+                    (let [page-name (common-util/page-name-sanity-lc alias)]
+                      {:block/name page-name
+                       :block/original-name alias}))
+                  aliases)
         result (cond-> page-m
                  (seq aliases')
                  (assoc :block/alias aliases')
@@ -160,7 +147,7 @@
                                           tags (remove string/blank? tags)]
                                       (map (fn [tag] {:block/name (common-util/page-name-sanity-lc tag)
                                                       :block/original-name tag})
-                                        tags))))]
+                                           tags))))]
     (update result :block/properties #(apply dissoc % gp-property/editable-linkable-built-in-properties))))
 
 (defn- build-page-map
@@ -177,7 +164,7 @@
                   (gp-block/page-name->map page false db true date-formatter
                                            :from-page from-page)
                   :block/file {:file/path (common-util/path-normalize file)}))
-                (extract-page-alias-and-tags page page-name properties))]
+                (extract-page-alias-and-tags page-name properties))]
     (cond->
       page-m
 

+ 54 - 53
src/main/frontend/components/repo.cljs

@@ -275,8 +275,9 @@
             rtc-graphs (state/sub :rtc/graphs)
             downloading-graph-id (state/sub :rtc/downloading-graph-uuid)
             repos (sort-repos-with-metadata-local repos)
-            repos (if (and (or (seq remotes) (seq rtc-graphs)) login?)
-                    (repo-handler/combine-local-&-remote-graphs repos (concat remotes rtc-graphs)) repos)
+            repos (distinct
+                   (if (and (or (seq remotes) (seq rtc-graphs)) login?)
+                     (repo-handler/combine-local-&-remote-graphs repos (concat remotes rtc-graphs)) repos))
             items-fn #(repos-dropdown-links repos current-repo downloading-graph-id multiple-windows? opts)
             header-fn #(when (> (count repos) 1)            ; show switch to if there are multiple repos
                          [:div.font-medium.text-sm.opacity-50.px-1.py-1.flex.flex-row.justify-between.items-center
@@ -286,14 +287,14 @@
                             (if remotes-loading?
                               (ui/loading "")
                               (shui/button
-                                {:variant :ghost
-                                 :size :sm
-                                 :title "Refresh remote graphs"
-                                 :class "!h-6 !px-1 relative right-[-4px]"
-                                 :on-click (fn []
-                                             (file-sync/load-session-graphs)
-                                             (rtc-handler/<get-remote-graphs))}
-                                (ui/icon "refresh" {:size 15}))))])]
+                               {:variant :ghost
+                                :size :sm
+                                :title "Refresh remote graphs"
+                                :class "!h-6 !px-1 relative right-[-4px]"
+                                :on-click (fn []
+                                            (file-sync/load-session-graphs)
+                                            (rtc-handler/<get-remote-graphs))}
+                               (ui/icon "refresh" {:size 15}))))])]
         (when (seq repos)
           (let [remote? (and current-repo (:remote? (first (filter #(= current-repo (:url %)) repos))))
                 repo-name (when current-repo (db/get-repo-name current-repo))
@@ -301,50 +302,50 @@
                                   (db/get-short-repo-name repo-name)
                                   "Select a Graph")]
             (shui/trigger-as :a
-              {:tab-index 0
-               :class "item cp__repos-select-trigger"
-               :on-pointer-down
-               (fn [^js e]
-                 (check-multiple-windows? state)
-                 (some-> (.-target e)
-                   (.closest "a.item")
-                   (shui/popup-show!
-                     (fn [{:keys [id]}]
-                       [:<>
-                        (header-fn)
-                        (for [{:keys [hr item hover-detail title options icon]} (items-fn)]
-                          (let [on-click' (:on-click options)
-                                href' (:href options)]
-                            (if hr
-                              (shui/dropdown-menu-separator)
-                              (shui/dropdown-menu-item
-                                (assoc options
-                                       :title hover-detail
-                                       :on-click (fn [^js e]
-                                                   (when on-click'
-                                                     (when-not (false? (on-click' e))
-                                                       (shui/popup-hide! id)))))
-                                (or item
-                                  (if href'
-                                    [:a.flex.items-center.w-full
-                                     {:href href' :on-click #(shui/popup-hide! id)
-                                      :style {:color "inherit"}} title]
-                                    [:span.flex.items-center.gap-1.w-full
-                                     icon [:div title]]))))))])
-                     {:as-dropdown? true
-                      :auto-focus? false
-                      :align "start"
-                      :content-props {:class "repos-list"}})))
-               :title repo-name}                            ;; show full path on hover
-              [:div.flex.relative.graph-icon.rounded
-               (shui/tabler-icon "database" {:size 15})]
+                             {:tab-index 0
+                              :class "item cp__repos-select-trigger"
+                              :on-pointer-down
+                              (fn [^js e]
+                                (check-multiple-windows? state)
+                                (some-> (.-target e)
+                                        (.closest "a.item")
+                                        (shui/popup-show!
+                                         (fn [{:keys [id]}]
+                                           [:<>
+                                            (header-fn)
+                                            (for [{:keys [hr item hover-detail title options icon]} (items-fn)]
+                                              (let [on-click' (:on-click options)
+                                                    href' (:href options)]
+                                                (if hr
+                                                  (shui/dropdown-menu-separator)
+                                                  (shui/dropdown-menu-item
+                                                   (assoc options
+                                                          :title hover-detail
+                                                          :on-click (fn [^js e]
+                                                                      (when on-click'
+                                                                        (when-not (false? (on-click' e))
+                                                                          (shui/popup-hide! id)))))
+                                                   (or item
+                                                       (if href'
+                                                         [:a.flex.items-center.w-full
+                                                          {:href href' :on-click #(shui/popup-hide! id)
+                                                           :style {:color "inherit"}} title]
+                                                         [:span.flex.items-center.gap-1.w-full
+                                                          icon [:div title]]))))))])
+                                         {:as-dropdown? true
+                                          :auto-focus? false
+                                          :align "start"
+                                          :content-props {:class "repos-list"}})))
+                              :title repo-name}                            ;; show full path on hover
+                             [:div.flex.relative.graph-icon.rounded
+                              (shui/tabler-icon "database" {:size 15})]
 
-              [:div.repo-switch.pr-2.whitespace-nowrap
-               [:span.repo-name.font-medium
-                [:span.repo-text.overflow-hidden.text-ellipsis
-                 (if (= config/demo-repo short-repo-name) "Demo" short-repo-name)]
-                (when remote? [:span.pl-1 (ui/icon "cloud")])]
-               [:span.dropdown-caret]])))))))
+                             [:div.repo-switch.pr-2.whitespace-nowrap
+                              [:span.repo-name.font-medium
+                               [:span.repo-text.overflow-hidden.text-ellipsis
+                                (if (= config/demo-repo short-repo-name) "Demo" short-repo-name)]
+                               (when remote? [:span.pl-1 (ui/icon "cloud")])]
+                              [:span.dropdown-caret]])))))))
 
 (defn invalid-graph-name-warning
   []

+ 1 - 1
src/main/frontend/state.cljs

@@ -955,7 +955,7 @@ Similar to re-frame subscriptions"
 
 (defn set-repos!
   [repos]
-  (set-state! [:me :repos] repos))
+  (set-state! [:me :repos] (distinct repos)))
 
 (defn add-repo!
   [repo]