Skip to content

Commit 38c03da

Browse files
Scott DoverScott Dover
authored andcommitted
chore: pass sortModel to backend
Signed-off-by: Scott Dover <[email protected]>
1 parent 3e218be commit 38c03da

File tree

8 files changed

+61
-31
lines changed

8 files changed

+61
-31
lines changed

client/src/components/LibraryNavigator/LibraryModel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import { ProgressLocation, l10n, window } from "vscode";
44

5+
import { SortModelItem } from "ag-grid-community";
56
import { Writable } from "stream";
67

78
import PaginatedResultSet from "./PaginatedResultSet";
@@ -27,12 +28,17 @@ class LibraryModel {
2728
item: LibraryItem,
2829
): PaginatedResultSet<{ data: TableData; error?: Error }> {
2930
return new PaginatedResultSet<{ data: TableData; error?: Error }>(
30-
async (start: number, end: number) => {
31+
async (start: number, end: number, sortModel: SortModelItem[]) => {
3132
await this.libraryAdapter.setup();
3233
const limit = end - start + 1;
3334
try {
3435
return {
35-
data: await this.libraryAdapter.getRows(item, start, limit),
36+
data: await this.libraryAdapter.getRows(
37+
item,
38+
start,
39+
limit,
40+
sortModel,
41+
),
3642
};
3743
} catch (e) {
3844
return { error: e, data: { rows: [], count: 0 } };

client/src/components/LibraryNavigator/PaginatedResultSet.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
// Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
import { SortModelItem } from "ag-grid-community";
34

45
class PaginatedResultSet<T> {
5-
private queryForData: (start: number, end: number) => Promise<T>;
6+
constructor(
7+
protected readonly queryForData: PaginatedResultSet<T>["getData"],
8+
) {}
69

7-
constructor(queryForData: (start: number, end: number) => Promise<T>) {
8-
this.queryForData = queryForData;
9-
}
10-
11-
public async getData(start: number, end: number): Promise<T> {
12-
return await this.queryForData(start, end);
10+
public async getData(
11+
start: number,
12+
end: number,
13+
sortModel: SortModelItem[],
14+
): Promise<T> {
15+
return await this.queryForData(start, end, sortModel);
1316
}
1417
}
1518

client/src/components/LibraryNavigator/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
import { SortModelItem } from "ag-grid-community";
4+
35
import { ColumnCollection } from "../../connection/rest/api/compute";
46

57
export const LibraryType = "library";
@@ -39,7 +41,12 @@ export interface LibraryAdapter {
3941
items: LibraryItem[];
4042
count: number;
4143
}>;
42-
getRows(item: LibraryItem, start: number, limit: number): Promise<TableData>;
44+
getRows(
45+
item: LibraryItem,
46+
start: number,
47+
limit: number,
48+
sortModel: SortModelItem[],
49+
): Promise<TableData>;
4350
getRowsAsCSV(
4451
item: LibraryItem,
4552
start: number,

client/src/connection/itc/ItcLibraryAdapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import { l10n } from "vscode";
44

5+
import { SortModelItem } from "ag-grid-community";
56
import { ChildProcessWithoutNullStreams } from "child_process";
67

78
import { onRunError } from "../../commands/run";
@@ -91,6 +92,7 @@ class ItcLibraryAdapter implements LibraryAdapter {
9192
item: LibraryItem,
9293
start: number,
9394
limit: number,
95+
sortModel: SortModelItem[],
9496
): Promise<TableData> {
9597
const { rows: rawRowValues, count } = await this.getDatasetInformation(
9698
item,

client/src/connection/rest/RestLibraryAdapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright © 2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
import { SortModelItem } from "ag-grid-community";
34
import { AxiosResponse } from "axios";
45

56
import { getSession } from "..";
@@ -44,6 +45,7 @@ class RestLibraryAdapter implements LibraryAdapter {
4445
item: LibraryItem,
4546
start: number,
4647
limit: number,
48+
sortModel: SortModelItem[],
4749
): Promise<TableData> {
4850
const { data } = await this.retryOnFail<RowCollection>(
4951
async () =>

client/src/panels/DataViewer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import { Uri, window } from "vscode";
44

5+
import { SortModelItem } from "ag-grid-community";
6+
57
import PaginatedResultSet from "../components/LibraryNavigator/PaginatedResultSet";
68
import { TableData } from "../components/LibraryNavigator/types";
79
import { Column } from "../connection/rest/api/compute";
@@ -66,14 +68,15 @@ class DataViewer extends WebView {
6668
event: Event & {
6769
key: string;
6870
command: string;
69-
data?: { start?: number; end?: number };
71+
data?: { start?: number; end?: number; sortModel?: SortModelItem[] };
7072
},
7173
): Promise<void> {
7274
switch (event.command) {
7375
case "request:loadData": {
7476
const { data, error } = await this._paginator.getData(
7577
event.data!.start!,
7678
event.data!.end!,
79+
event.data!.sortModel!,
7780
);
7881
if (error) {
7982
await window.showErrorMessage(error.message);

client/src/webview/useDataViewer.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
GridReadyEvent,
99
IGetRowsParams,
1010
ModuleRegistry,
11+
SortModelItem,
1112
} from "ag-grid-community";
1213
import { v4 } from "uuid";
1314

@@ -34,12 +35,16 @@ const clearQueryTimeout = (): void => {
3435
clearTimeout(queryTableDataTimeoutId);
3536
queryTableDataTimeoutId = null;
3637
};
37-
const queryTableData = (start: number, end: number): Promise<TableData> => {
38+
const queryTableData = (
39+
start: number,
40+
end: number,
41+
sortModel: SortModelItem[],
42+
): Promise<TableData> => {
3843
const requestKey = v4();
3944
vscode.postMessage({
4045
command: "request:loadData",
4146
key: requestKey,
42-
data: { start, end },
47+
data: { start, end, sortModel },
4348
});
4449

4550
return new Promise((resolve, reject) => {
@@ -103,23 +108,25 @@ const useDataViewer = () => {
103108
const dataSource = {
104109
rowCount: undefined,
105110
getRows: async (params: IGetRowsParams) => {
106-
await queryTableData(params.startRow, params.endRow).then(
107-
({ rows, count }: TableData) => {
108-
const rowData = rows.map(({ cells }) => {
109-
const row = cells.reduce(
110-
(carry, cell, index) => ({
111-
...carry,
112-
[columns[index].field]: cell,
113-
}),
114-
{},
115-
);
116-
117-
return row;
118-
});
119-
120-
params.successCallback(rowData, count);
121-
},
122-
);
111+
await queryTableData(
112+
params.startRow,
113+
params.endRow,
114+
params.sortModel,
115+
).then(({ rows, count }: TableData) => {
116+
const rowData = rows.map(({ cells }) => {
117+
const row = cells.reduce(
118+
(carry, cell, index) => ({
119+
...carry,
120+
[columns[index].field]: cell,
121+
}),
122+
{},
123+
);
124+
125+
return row;
126+
});
127+
128+
params.successCallback(rowData, count);
129+
});
123130
},
124131
};
125132

client/test/components/LibraryNavigator/PaginatedResultSet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("PaginatedResultSet", async function () {
2727
async () => mockAxiosResponse,
2828
);
2929

30-
expect(await paginatedResultSet.getData(0, 100)).to.deep.equal(
30+
expect(await paginatedResultSet.getData(0, 100, [])).to.deep.equal(
3131
mockAxiosResponse,
3232
);
3333
});

0 commit comments

Comments
 (0)