Skip to content

Commit ac86748

Browse files
Scott DoverScott Dover
authored andcommitted
chore: finish sorting for rest
Signed-off-by: Scott Dover <[email protected]>
1 parent a9d2b14 commit ac86748

File tree

6 files changed

+260
-202
lines changed

6 files changed

+260
-202
lines changed

client/src/panels/DataViewer.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { Uri, window } from "vscode";
3+
import { Uri, l10n, window } from "vscode";
44

55
import { SortModelItem } from "ag-grid-community";
66

@@ -95,6 +95,23 @@ class DataViewer extends WebView {
9595
data: await this._fetchColumns(),
9696
});
9797
break;
98+
case "request:loadMessages":
99+
this.panel.webview.postMessage({
100+
key: event.key,
101+
command: "response:loadMessages",
102+
data: {
103+
"Ascending (add to sorting)": l10n.t("Ascending (add to sorting)"),
104+
Ascending: l10n.t("Ascending"),
105+
"Descending (add to sorting)": l10n.t(
106+
"Descending (add to sorting)",
107+
),
108+
Descending: l10n.t("Descending"),
109+
"Remove all sorting": l10n.t("Remove all sorting"),
110+
"Remove sorting": l10n.t("Remove sorting"),
111+
Sort: l10n.t("Sort"),
112+
},
113+
});
114+
break;
98115
default:
99116
break;
100117
}

client/src/webview/ColumnHeader.tsx

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,60 @@ const ColumnHeader = ({
4141
}) => {
4242
const ref = useRef<HTMLButtonElement>(undefined!);
4343
const currentColumn = getCurrentColumn();
44+
const currentSortedColumns = api.getColumnState().filter((c) => c.sort);
45+
const columnNumber = column.sort
46+
? currentSortedColumns.length > 1
47+
? currentSortedColumns.findIndex((c) => c.colId === column.colId) + 1
48+
: ""
49+
: "";
50+
51+
const displayColumnMenu = () => {
52+
if (currentColumn) {
53+
return setColumnMenu(undefined);
54+
}
55+
const { height, top, left } = ref.current.getBoundingClientRect();
56+
setColumnMenu({
57+
left,
58+
top: top + height,
59+
column,
60+
theme,
61+
hasSort: api.getColumnState().some((c) => c.sort),
62+
sortColumn: (direction: "asc" | "desc" | null) => {
63+
const newColumnState = api.getColumnState().filter((c) => c.sort);
64+
const colIndex = newColumnState.findIndex(
65+
(c) => c.colId === column.colId,
66+
);
67+
if (colIndex === -1) {
68+
newColumnState.push({
69+
colId: column.colId,
70+
sort: direction,
71+
});
72+
} else {
73+
newColumnState[colIndex].sort = direction;
74+
}
75+
api.applyColumnState({
76+
state: newColumnState,
77+
defaultState: { sort: null },
78+
});
79+
},
80+
removeAllSorting: () =>
81+
api.applyColumnState({
82+
state: api
83+
.getColumnState()
84+
.filter((c) => c.sort)
85+
.map((c) => ({ colId: c.colId, sort: null })),
86+
defaultState: { sort: null },
87+
}),
88+
removeFromSort: () =>
89+
api.applyColumnState({
90+
state: api
91+
.getColumnState()
92+
.filter((c) => c.sort && c.colId !== column.colId),
93+
defaultState: { sort: null },
94+
}),
95+
dismissMenu: () => setColumnMenu(undefined),
96+
});
97+
};
4498

4599
return (
46100
<div className={`ag-cell-label-container ${theme}`} role="presentation">
@@ -53,41 +107,28 @@ const ColumnHeader = ({
53107
className={`header-icon ${getIconForColumnType(columnType)}`}
54108
></span>
55109
<span className="ag-header-cell-text">{column.colId}</span>
56-
{column.sort === "asc" && (
57-
<span className="sort-icon-wrapper">
58-
<span className="sort-icon ascending"></span>
59-
</span>
60-
)}
61-
{column.sort === "desc" && (
62-
<span className="sort-icon-wrapper">
63-
<span className="sort-icon descending"></span>
64-
</span>
65-
)}
66-
<div className="dropdown">
67-
<button
68-
ref={ref}
69-
type="button"
70-
className={currentColumn?.colId === column.colId ? "active" : ""}
71-
onClick={() => {
72-
if (currentColumn) {
73-
return setColumnMenu(undefined);
74-
}
75-
const { height, top, left } = ref.current.getBoundingClientRect();
76-
setColumnMenu({
77-
left,
78-
top: top + height,
79-
column,
80-
theme,
81-
sortColumn: (direction: "asc" | "desc" | null) => {
82-
api.applyColumnState({
83-
state: [{ colId: column.colId, sort: direction }],
84-
defaultState: { sort: null },
85-
});
86-
},
87-
dismissMenu: () => setColumnMenu(undefined),
88-
});
89-
}}
90-
>
110+
111+
<span className="sort-icon-wrapper">
112+
{!!column.sort && (
113+
<>
114+
<span
115+
className={`sort-icon ${column.sort === "asc" ? "ascending" : "descending"}`}
116+
></span>
117+
{!!columnNumber && (
118+
<span className="sort-number">{columnNumber}</span>
119+
)}
120+
</>
121+
)}
122+
</span>
123+
124+
<div
125+
className={
126+
currentColumn?.colId === column.colId
127+
? "active dropdown"
128+
: "dropdown"
129+
}
130+
>
131+
<button ref={ref} type="button" onClick={displayColumnMenu}>
91132
<span></span>
92133
</button>
93134
</div>

0 commit comments

Comments
 (0)