mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
enhance: graph list displays current graph
like git and npm. Also remove confusing GRAPH header and make validate consistent like other read graph commands
This commit is contained in:
@@ -174,7 +174,8 @@
|
||||
(:help opts)
|
||||
(command-core/help-result cmd-summary)
|
||||
|
||||
(and (#{:graph-create :graph-switch :graph-remove :graph-validate} command)
|
||||
;; Require graphs when writing to graph
|
||||
(and (#{:graph-create :graph-switch :graph-remove :graph-import} command)
|
||||
(not (seq graph)))
|
||||
(missing-graph-result summary)
|
||||
|
||||
@@ -257,9 +258,6 @@
|
||||
(and (= command :graph-import) (not (seq (:input opts))))
|
||||
(missing-input-result summary)
|
||||
|
||||
(and (= command :graph-import) (not (seq (:graph opts))))
|
||||
(missing-graph-result summary)
|
||||
|
||||
(and (= command :graph-import)
|
||||
(not (contains? (graph-command/import-export-types)
|
||||
(graph-command/normalize-import-export-type (:type opts)))))
|
||||
|
||||
@@ -79,8 +79,9 @@
|
||||
|
||||
(defn- format-counted-table
|
||||
[headers rows]
|
||||
(str (render-table headers rows)
|
||||
"\n"
|
||||
(str (if headers
|
||||
(str (render-table headers rows) "\n")
|
||||
(str (string/join "\n" (map (comp string/trimr first) rows)) "\n"))
|
||||
"Count: "
|
||||
(count rows)))
|
||||
|
||||
@@ -215,10 +216,19 @@
|
||||
(mapv #(format-list-property-row % include-ident? now-ms) items))))
|
||||
|
||||
(defn- format-graph-list
|
||||
[graphs]
|
||||
(format-counted-table
|
||||
["GRAPH"]
|
||||
(mapv (fn [graph] [graph]) (or graphs []))))
|
||||
[graphs current-graph]
|
||||
(let [graphs (or graphs [])
|
||||
has-current? (and (seq current-graph)
|
||||
(some #(= % current-graph) graphs))]
|
||||
(format-counted-table
|
||||
nil
|
||||
(mapv (fn [graph]
|
||||
[(if has-current?
|
||||
(if (= graph current-graph)
|
||||
(str "* " graph)
|
||||
(str " " graph))
|
||||
graph)])
|
||||
graphs))))
|
||||
|
||||
(defn- format-server-list
|
||||
[servers]
|
||||
@@ -478,12 +488,12 @@
|
||||
(string/join "\n" (into [header] check-lines))))
|
||||
|
||||
(defn- ->human
|
||||
[{:keys [status data error command context]} {:keys [now-ms]}]
|
||||
[{:keys [status data error command context]} {:keys [now-ms graph]}]
|
||||
(let [now-ms (or now-ms (js/Date.now))]
|
||||
(case status
|
||||
:ok
|
||||
(case command
|
||||
:graph-list (format-graph-list (:graphs data))
|
||||
:graph-list (format-graph-list (:graphs data) graph)
|
||||
:graph-info (format-graph-info data now-ms)
|
||||
(:graph-create :graph-switch :graph-remove :graph-validate)
|
||||
(format-graph-action command context)
|
||||
|
||||
@@ -61,6 +61,29 @@
|
||||
{:output-format nil})]
|
||||
(is (= "Found 1 entity with errors:\n({:entity {:db/id 1}})\n" result)))))
|
||||
|
||||
(deftest test-human-output-graph-list
|
||||
(testing "graph list without current graph shows plain list"
|
||||
(let [result (format/format-result {:status :ok
|
||||
:command :graph-list
|
||||
:data {:graphs ["alpha" "beta"]}}
|
||||
{:output-format nil})]
|
||||
(is (= (str "alpha\n"
|
||||
"beta\n"
|
||||
"Count: 2")
|
||||
result))))
|
||||
|
||||
(testing "graph list with current graph marks it with * and indents others"
|
||||
(let [result (format/format-result {:status :ok
|
||||
:command :graph-list
|
||||
:data {:graphs ["alpha" "beta" "gamma"]}}
|
||||
{:output-format nil
|
||||
:graph "beta"})]
|
||||
(is (= (str " alpha\n"
|
||||
"* beta\n"
|
||||
" gamma\n"
|
||||
"Count: 3")
|
||||
result)))))
|
||||
|
||||
(deftest test-human-output-list-page
|
||||
(testing "list page renders a table with count"
|
||||
(let [result (format/format-result {:status :ok
|
||||
|
||||
Reference in New Issue
Block a user