From 73fdd87dcf851c53f13df6ab5bcfe0b9bac3756f Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 22 Jun 2025 20:42:21 +0800 Subject: [PATCH] enhance(ux): separate delete local graph and remote graph --- src/main/frontend/components/repo.cljs | 136 ++++++++++++------------- src/main/frontend/config.cljs | 4 + 2 files changed, 71 insertions(+), 69 deletions(-) diff --git a/src/main/frontend/components/repo.cljs b/src/main/frontend/components/repo.cljs index 403ce84186..ad9d869887 100644 --- a/src/main/frontend/components/repo.cljs +++ b/src/main/frontend/components/repo.cljs @@ -28,21 +28,22 @@ (rum/defc normalized-graph-label [{:keys [url remote? GraphName GraphUUID] :as graph} on-click] - (when graph - [:span.flex.items-center - (if (or (config/local-file-based-graph? url) - (config/db-based-graph? url)) - (let [local-dir (config/get-local-dir url) - graph-name (text-util/get-graph-name-from-path url)] - [:a.flex.items-center {:title local-dir - :on-click #(on-click graph)} - [:span graph-name (when GraphName [:strong.px-1 "(" GraphName ")"])] - (when remote? [:strong.pr-1.flex.items-center (ui/icon "cloud")])]) + (let [db-based? (config/db-based-graph? url)] + (when graph + [:span.flex.items-center + (if (or (config/local-file-based-graph? url) + db-based?) + (let [local-dir (config/get-local-dir url) + graph-name (text-util/get-graph-name-from-path url)] + [:a.flex.items-center {:title local-dir + :on-click #(on-click graph)} + [:span graph-name (when (and GraphName (not db-based?)) [:strong.pl-1 "(" GraphName ")"])] + (when remote? [:strong.px-1.flex.items-center (ui/icon "cloud")])]) - [:a.flex.items-center {:title GraphUUID - :on-click #(on-click graph)} - (db/get-repo-path (or url GraphName)) - (when remote? [:strong.pl-1.flex.items-center (ui/icon "cloud")])])])) + [:a.flex.items-center {:title GraphUUID + :on-click #(on-click graph)} + (db/get-repo-path (or url GraphName)) + (when remote? [:strong.pl-1.flex.items-center (ui/icon "cloud")])])]))) (defn sort-repos-with-metadata-local [repos] @@ -66,8 +67,8 @@ [repos] (for [{:keys [root url remote? GraphUUID GraphSchemaVersion GraphName created-at last-seen-at] :as repo} (sort-repos-with-metadata-local repos) - :let [only-cloud? (and remote? (nil? root)) - db-based? (config/db-based-graph? url)]] + :let [db-based? (config/db-based-graph? url) + graph-name (if db-based? (config/db-graph-name url) GraphName)]] [:div.flex.justify-between.mb-4.items-center.group {:key (or url GraphUUID) "data-testid" url} [:div @@ -85,7 +86,7 @@ :else (state/pub-event! [:graph/pull-down-remote-graph repo])))))] (when-let [time (some-> (or last-seen-at created-at) (safe-locale-date))] - [:small.text-gray-400.opacity-50 (str "Last opened at: " time)])] + [:small.text-muted-foreground (str "Last opened at: " time)])] [:div.controls [:div.flex.flex-row.items-center @@ -95,57 +96,54 @@ (shui/tabler-icon "folder-pin") [:span.pl-1 root]]) (let [db-graph? (config/db-based-graph? url) - manager? (and db-graph? (user-handler/manager? url)) - title (cond - only-cloud? - "Deletes this remote graph. Note this can't be recovered." - - db-based? - "Unsafe delete this DB-based graph. Note this can't be recovered." - - :else - "Removes Logseq's access to the local file path of your graph. It won't remove your local files.")] - (when-not (and db-graph? only-cloud? (not manager?)) - [:a.text-gray-400.ml-4.font-medium.text-sm.whitespace-nowrap - {:title title + manager? (and db-graph? (user-handler/manager? url))] + (shui/dropdown-menu + (shui/dropdown-menu-trigger + {:asChild true} + (shui/button + {:variant "ghost" + :class "!px-1" + :size :sm} + (ui/icon "dots" {:size 15}))) + (shui/dropdown-menu-content + {:align "end"} + (shui/dropdown-menu-item + {:key "delete-locally" :on-click (fn [] - (let [has-prompt? true - prompt-str (cond only-cloud? - (str "Are you sure to permanently delete the graph \"" GraphName "\" from our server?") - db-based? - (str "Are you sure to permanently delete the graph \"" url "\" from Logseq?") - :else - (str "Are you sure to unlink the graph \"" url "\" from local folder?")) - unlink-or-remote-fn! (fn [] - (repo-handler/remove-repo! repo) - (state/pub-event! [:graph/unlinked repo (state/get-current-repo)])) - action-confirm-fn! (if only-cloud? - (fn [] - (when (or manager? (not db-graph?)) - (let [p (file-sync/ (shui/dialog-confirm! - [:p.font-medium.-my-4 prompt-str - [:span.mt-1.flex.font-normal.opacity-70 - (if (or db-based? only-cloud?) - [:small.text-red-rx-11 "⚠️ Notice that we can't recover this graph after being deleted. Make sure you have backups before deleting it."] - [:small.opacity-70 "⚠️ It won't remove your local files!"])]]) - (p/then #(action-confirm-fn!))))] - - (if has-prompt? - (confirm-fn!) - (unlink-or-remote-fn!))))} - (if only-cloud? "Remove (server)" "Unlink (local)")]))]]])) + (let [prompt-str (if db-based? + (str "Are you sure to permanently delete the graph \"" graph-name "\" from Logseq?") + (str "Are you sure to unlink the graph \"" url "\" from local folder?"))] + (-> (shui/dialog-confirm! + [:p.font-medium.-my-4 prompt-str + [:span.my-2.flex.font-normal.opacity-75 + (if db-based? + [:small "⚠️ Notice that we can't recover this graph after being deleted. Make sure you have backups before deleting it."] + [:small "⚠️ It won't remove your local files!"])]]) + (p/then (fn [] + (repo-handler/remove-repo! repo) + (state/pub-event! [:graph/unlinked repo (state/get-current-repo)]))))))} + "Delete") + (when (and remote? (or (and db-based? manager?) (not db-based?))) + (shui/dropdown-menu-item + {:key "delete-remotelly" + :on-click (fn [] + (let [prompt-str (str "Are you sure to permanently delete the graph \"" graph-name "\" from our server?")] + (-> (shui/dialog-confirm! + [:p.font-medium.-my-4 prompt-str + [:span.my-2.flex.font-normal.opacity-75 + [:small "⚠️ Notice that we can't recover this graph after being deleted. Make sure you have backups before deleting it."]]]) + (p/then + (fn [] + (when (or manager? (not db-graph?)) + (let [p (file-sync/