|
1 | 1 | import { ContentPage } from "~/layouts"; |
2 | | -import { PageHeader, Link, AssistantLinks, DevLinkButton } from "~/components"; |
3 | | -import { Divider, AnchorButton, Card, Icon } from "@blueprintjs/core"; |
| 2 | +import { |
| 3 | + AssistantLinks, |
| 4 | + DevLinkButton, |
| 5 | + PageBreadcrumbs, |
| 6 | + StickyHeader, |
| 7 | +} from "~/components"; |
| 8 | +import { AnchorButton, ButtonGroup, InputGroup } from "@blueprintjs/core"; |
| 9 | +import { Tag } from "@macrostrat/data-components"; |
4 | 10 | import { useState } from "react"; |
5 | | -import h from "./main.module.scss"; |
| 11 | +import h from "./main.module.sass"; |
6 | 12 | import { useData } from "vike-react/useData"; |
7 | 13 | import { ClientOnly } from "vike-react/ClientOnly"; |
| 14 | +import { navigate } from "vike/client/router"; |
8 | 15 |
|
9 | 16 | export function Page(props) { |
10 | 17 | return h(ColumnListPage, props); |
@@ -55,40 +62,59 @@ function ColumnListPage({ title = "Columns", linkPrefix = "/" }) { |
55 | 62 | .map((col) => col.col_id) |
56 | 63 | ); |
57 | 64 |
|
58 | | - const handleInputChange = (event) => { |
59 | | - setColumnInput(event.target.value.toLowerCase()); |
| 65 | + const handleInputChange = (value, target) => { |
| 66 | + setColumnInput(value.toLowerCase()); |
60 | 67 | }; |
61 | 68 |
|
62 | 69 | const allGroups = filteredGroups ?? columnGroups ?? []; |
63 | 70 |
|
64 | 71 | return h("div.column-list-page", [ |
65 | | - h(AssistantLinks, [ |
66 | | - h(AnchorButton, { href: "/projects", minimal: true }, "Projects"), |
67 | | - h(DevLinkButton, { href: "/columns/correlation" }, "Correlation chart"), |
68 | | - h(ColumnMapContainer, { columnIDs, projectID: project?.project_id }), |
69 | | - ]), |
70 | 72 | h(ContentPage, [ |
71 | | - h(PageHeader, { title }), |
72 | | - h(Card, { className: "search-bar" }, [ |
73 | | - h(Icon, { icon: "search" }), |
74 | | - h("input", { |
75 | | - type: "text", |
76 | | - placeholder: "Search columns...", |
77 | | - onChange: handleInputChange, |
78 | | - }), |
| 73 | + h("div.flex-row", [ |
| 74 | + h("div.main", [ |
| 75 | + h(StickyHeader, [ |
| 76 | + h(PageBreadcrumbs, { showLogo: true }), |
| 77 | + h("div.search-bar", [ |
| 78 | + h(InputGroup, { |
| 79 | + placeholder: "Search columns...", |
| 80 | + onValueChange: handleInputChange, |
| 81 | + leftIcon: "search", |
| 82 | + large: true, |
| 83 | + fill: true, |
| 84 | + }), |
| 85 | + ]), |
| 86 | + ]), |
| 87 | + h( |
| 88 | + "div.column-groups", |
| 89 | + allGroups.map((d) => |
| 90 | + h(ColumnGroup, { |
| 91 | + data: d, |
| 92 | + key: d.id, |
| 93 | + linkPrefix, |
| 94 | + columnInput, |
| 95 | + shouldFilter, |
| 96 | + }) |
| 97 | + ) |
| 98 | + ), |
| 99 | + ]), |
| 100 | + h("div.sidebar", [ |
| 101 | + h("div.sidebar-content", [ |
| 102 | + h(ButtonGroup, { vertical: true, large: true }, [ |
| 103 | + h(AnchorButton, { href: "/projects", minimal: true }, "Projects"), |
| 104 | + h( |
| 105 | + DevLinkButton, |
| 106 | + { href: "/columns/correlation" }, |
| 107 | + "Correlation chart" |
| 108 | + ), |
| 109 | + ]), |
| 110 | + h(ColumnMapContainer, { |
| 111 | + columnIDs, |
| 112 | + projectID: project?.project_id, |
| 113 | + className: "column-map-container", |
| 114 | + }), |
| 115 | + ]), |
| 116 | + ]), |
79 | 117 | ]), |
80 | | - h( |
81 | | - "div.column-groups", |
82 | | - allGroups.map((d) => |
83 | | - h(ColumnGroup, { |
84 | | - data: d, |
85 | | - key: d.id, |
86 | | - linkPrefix, |
87 | | - columnInput, |
88 | | - shouldFilter, |
89 | | - }) |
90 | | - ) |
91 | | - ), |
92 | 118 | ]), |
93 | 119 | ]); |
94 | 120 | } |
@@ -117,29 +143,66 @@ function ColumnGroup({ data, linkPrefix, columnInput, shouldFilter }) { |
117 | 143 | ), |
118 | 144 | ]), |
119 | 145 | h("div.column-list", [ |
120 | | - h(Divider), |
121 | | - h("div.column-table", [ |
122 | | - h("div.column-row.column-header", [ |
123 | | - h("span.col-id", "Id"), |
124 | | - h("span.col-name", "Name"), |
| 146 | + h("table.column-table", [ |
| 147 | + h("thead.column-row.column-header", [ |
| 148 | + h("tr", [ |
| 149 | + h("th.col-id", "ID"), |
| 150 | + h("th.col-name", "Name"), |
| 151 | + h("th.col-status", "Status"), |
| 152 | + ]), |
| 153 | + ]), |
| 154 | + h("tbody", [ |
| 155 | + filteredColumns.map((data) => h(ColumnItem, { data, linkPrefix })), |
125 | 156 | ]), |
126 | | - h(Divider), |
127 | | - filteredColumns.map((data) => h(ColumnItem, { data, linkPrefix })), |
128 | 157 | ]), |
129 | 158 | ]), |
130 | 159 | ] |
131 | 160 | ); |
132 | 161 | } |
133 | 162 |
|
134 | 163 | function ColumnItem({ data, linkPrefix = "/" }) { |
135 | | - const { col_id, col_name, status } = data; |
136 | | - const href = linkPrefix + `columns/${col_id}`; |
137 | | - return h("div.column-row", [ |
138 | | - h("span.col-id", "#" + col_id), |
139 | | - h(Link, { className: "col-link", href }, [col_name]), |
140 | | - ]); |
141 | | -} |
| 164 | + const { col_id, col_name } = data; |
| 165 | + |
| 166 | + let nUnits = 0; |
| 167 | + try { |
| 168 | + nUnits = parseInt(data.t_units); |
| 169 | + } catch (e) { |
| 170 | + console.warn("Invalid number of units for column", col_id, data.t_units); |
| 171 | + } |
| 172 | + |
| 173 | + const unitsText = nUnits > 0 ? `${nUnits} units` : "empty"; |
142 | 174 |
|
143 | | -function UpperCase(str) { |
144 | | - return str.charAt(0).toUpperCase() + str.slice(1); |
| 175 | + const href = linkPrefix + `columns/${col_id}`; |
| 176 | + return h( |
| 177 | + "tr.column-row", |
| 178 | + { |
| 179 | + onClick() { |
| 180 | + navigate(href); |
| 181 | + }, |
| 182 | + }, |
| 183 | + [ |
| 184 | + h("td.col-id", h("code.bp5-code", col_id)), |
| 185 | + // Keep the semantic HTML structure for accessibility |
| 186 | + h("td.col-name", h("a", { href }, col_name)), |
| 187 | + h("td.col-status", [ |
| 188 | + h.if(data.status == "in process")([ |
| 189 | + h( |
| 190 | + Tag, |
| 191 | + { minimal: true, color: "lightgreen", size: "small" }, |
| 192 | + "in process" |
| 193 | + ), |
| 194 | + ]), |
| 195 | + " ", |
| 196 | + h( |
| 197 | + Tag, |
| 198 | + { |
| 199 | + minimal: true, |
| 200 | + size: "small", |
| 201 | + color: nUnits == 0 ? "orange" : "dodgerblue", |
| 202 | + }, |
| 203 | + unitsText |
| 204 | + ), |
| 205 | + ]), |
| 206 | + ] |
| 207 | + ); |
145 | 208 | } |
0 commit comments