Skip to content

Commit

Permalink
enhance: display row id for table view
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 25, 2024
1 parent 0253ae6 commit b30bc6d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
7 changes: 3 additions & 4 deletions deps/shui/src/logseq/shui/table/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

(defn column-visible?
[column visible-columns]
(not (false? (get visible-columns (column-id column)))))
(let [value (get visible-columns (column-id column))]
(not (false? value))))

(defn visible-columns
[columns visible-columns']
(if (seq visible-columns')
(filter #(column-visible? % visible-columns') columns)
columns))
(filter #(column-visible? % visible-columns') columns))

(defn sort-rows
"Support multiple sorts"
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/components/all_pages.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
[data set-data!] (rum/use-state nil)
[loading? set-loading!] (rum/use-state true)
columns' (views/build-columns {} (columns)
{:with-object-name? false})
{:with-object-name? false
:with-id? false})
view-entity (first (ldb/get-all-pages-views db))]
(rum/use-effect!
(fn []
Expand Down
20 changes: 19 additions & 1 deletion src/main/frontend/components/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
:class (str "flex transition-opacity "
(if (or show? selected-all? selected-some?) "opacity-100" "opacity-0"))})]))

(rum/defc header-index < rum/static
[]
[:label.h-8.w-6.flex.items-center.justify-center
{:html-for "header-index"}
"ID"])

(rum/defc row-checkbox < rum/static
[{:keys [row-selected? row-toggle-selected!]} row _column]
(let [id (str (:id row) "-" "checkbox")
Expand Down Expand Up @@ -138,8 +144,9 @@
(container config row')])))

(defn build-columns
[config properties & {:keys [with-object-name? add-tags-column?]
[config properties & {:keys [with-object-name? with-id? add-tags-column?]
:or {with-object-name? true
with-id? true
add-tags-column? true}}]
(let [;; FIXME: Shouldn't file graphs have :block/tags?
add-tags-column?' (and (config/db-based-graph? (state/get-current-repo)) add-tags-column?)
Expand All @@ -156,6 +163,14 @@
(row-checkbox table row column))
:column-list? false
:resizable? false}
(when with-id?
{:id :id
:name "ID"
:header (fn [_table _column] (header-index))
:cell (fn [table row _column]
(let [rows (map :id (:rows table))]
(inc (.indexOf rows (:id row)))))
:resizable? false})
(when with-object-name?
{:id :block/title
:name "Name"
Expand Down Expand Up @@ -270,6 +285,9 @@
(let [id (:id column)
size (get sized-columns id)]
(cond
(= id :id)
48

(number? size)
size

Expand Down

0 comments on commit b30bc6d

Please sign in to comment.