Skip to content

Commit 691677f

Browse files
Scott DoverScott Dover
authored andcommitted
chore: add column pinning
Signed-off-by: Scott Dover <[email protected]>
1 parent 71b1de2 commit 691677f

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

client/src/panels/DataViewer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ class DataViewer extends WebView {
101101
command: "response:loadMessages",
102102
data: {
103103
"Ascending (add to sorting)": l10n.t("Ascending (add to sorting)"),
104-
Ascending: l10n.t("Ascending"),
105104
"Descending (add to sorting)": l10n.t(
106105
"Descending (add to sorting)",
107106
),
108-
Descending: l10n.t("Descending"),
107+
"Not pinned": l10n.t("Not pinned"),
108+
Pin: l10n.t("Pin"),
109+
"Pinned to the left": l10n.t("Pinned to the left"),
110+
"Pinned to the right": l10n.t("Pinned to the right"),
109111
"Remove all sorting": l10n.t("Remove all sorting"),
110112
"Remove sorting": l10n.t("Remove sorting"),
113+
Ascending: l10n.t("Ascending"),
114+
Descending: l10n.t("Descending"),
111115
Sort: l10n.t("Sort"),
112116
},
113117
});

client/src/webview/ColumnHeader.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef } from "react";
22

3-
import { AgColumn, GridApi } from "ag-grid-community";
3+
import { AgColumn, ColDef, GridApi } from "ag-grid-community";
44

55
import { ColumnHeaderProps } from "./ColumnHeaderMenu";
66

@@ -58,6 +58,13 @@ const ColumnHeader = ({
5858
column,
5959
theme,
6060
hasSort: api.getColumnState().some((c) => c.sort),
61+
pinColumn: (pinned: "left" | "right" | null) => {
62+
const columnDefs = api.getColumnDefs().map((colDef: ColDef) => ({
63+
...colDef,
64+
pinned: column.colId === colDef.colId ? pinned : colDef.pinned,
65+
}));
66+
api.updateGridOptions({ columnDefs });
67+
},
6168
sortColumn: (direction: "asc" | "desc" | null) => {
6269
const newColumnState = api.getColumnState().filter((c) => c.sort);
6370
const colIndex = newColumnState.findIndex(

client/src/webview/ColumnHeaderMenu.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface ColumnHeaderProps {
88
hasSort: boolean;
99
left: number;
1010
messages?: Record<string, string>;
11+
pinColumn: (pinned: "left" | "right" | null) => void;
1112
removeAllSorting: () => void;
1213
removeFromSort: () => void;
1314
sortColumn: (direction: "asc" | "desc") => void;
@@ -214,14 +215,45 @@ const ColumnHeaderMenu = ({
214215
dismissMenu,
215216
hasSort,
216217
left,
218+
messages: t,
219+
pinColumn,
217220
removeAllSorting,
218221
removeFromSort,
219222
sortColumn,
220223
theme,
221224
top,
222-
messages: t,
223225
}: ColumnHeaderProps) => {
224226
const menuItems = [
227+
{
228+
name: t["Pin"],
229+
children: [
230+
{
231+
name: t["Not pinned"],
232+
checked: !column?.pinned,
233+
onPress: () => {
234+
pinColumn(null);
235+
dismissMenu();
236+
},
237+
},
238+
{
239+
name: t["Pinned to the left"],
240+
checked: column?.pinned === "left",
241+
onPress: () => {
242+
pinColumn("left");
243+
dismissMenu();
244+
},
245+
},
246+
{
247+
name: t["Pinned to the right"],
248+
checked: column?.pinned === "right",
249+
onPress: () => {
250+
pinColumn("right");
251+
dismissMenu();
252+
},
253+
},
254+
],
255+
},
256+
"separator",
225257
{
226258
name: t["Sort"],
227259
children: [

client/src/webview/useDataViewer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const useDataViewer = (theme: string) => {
179179
field: "#",
180180
suppressMovable: true,
181181
sortable: false,
182+
pinned: "left",
183+
maxWidth: 80,
182184
});
183185

184186
setColumns(columns);

0 commit comments

Comments
 (0)