Skip to content

Commit 3554bce

Browse files
committed
Split compare view messages
This splits the compare view messages into two different messages. One contains the metadata that doesn't change when the user selects a different result set, and the other contains the actual results.
1 parent 151c031 commit 3554bce

File tree

5 files changed

+68
-38
lines changed

5 files changed

+68
-38
lines changed

extensions/ql-vscode/src/common/interface-types.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,15 @@ interface ChangeCompareMessage {
334334
newResultSetName: string;
335335
}
336336

337-
export type ToCompareViewMessage = SetComparisonsMessage;
337+
export type ToCompareViewMessage =
338+
| SetComparisonQueryInfoMessage
339+
| SetComparisonsMessage;
338340

339341
/**
340-
* Message to the compare view that specifies the query results to compare.
342+
* Message to the compare view that sets the metadata of the compared queries.
341343
*/
342-
export interface SetComparisonsMessage {
343-
readonly t: "setComparisons";
344+
export interface SetComparisonQueryInfoMessage {
345+
readonly t: "setComparisonQueryInfo";
344346
readonly stats: {
345347
fromQuery?: {
346348
name: string;
@@ -353,11 +355,18 @@ export interface SetComparisonsMessage {
353355
time: string;
354356
};
355357
};
358+
readonly databaseUri: string;
359+
}
360+
361+
/**
362+
* Message to the compare view that specifies the query results to compare.
363+
*/
364+
export interface SetComparisonsMessage {
365+
readonly t: "setComparisons";
356366
readonly commonResultSetNames: string[];
357367
readonly currentResultSetName: string;
358368
readonly result: RawQueryCompareResult | undefined;
359369
readonly message: string | undefined;
360-
readonly databaseUri: string;
361370
}
362371

363372
/**

extensions/ql-vscode/src/compare/compare-view.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,26 @@ export class CompareView extends AbstractWebview<
6969
toSchemas,
7070
};
7171

72+
await this.postMessage({
73+
t: "setComparisonQueryInfo",
74+
stats: {
75+
fromQuery: {
76+
// since we split the description into several rows
77+
// only run interpolation if the label is user-defined
78+
// otherwise we will wind up with duplicated rows
79+
name: this.labelProvider.getShortLabel(from),
80+
status: from.completedQuery.statusString,
81+
time: from.startTime,
82+
},
83+
toQuery: {
84+
name: this.labelProvider.getShortLabel(to),
85+
status: to.completedQuery.statusString,
86+
time: to.startTime,
87+
},
88+
},
89+
databaseUri: to.initialInfo.databaseInfo.databaseUri,
90+
});
91+
7292
await this.showResultsInternal(selectedResultSetName);
7393
}
7494

@@ -77,8 +97,6 @@ export class CompareView extends AbstractWebview<
7797
return;
7898
}
7999

80-
const { from, to } = this.comparePair;
81-
82100
const panel = await this.getPanel();
83101
panel.reveal(undefined, true);
84102

@@ -103,26 +121,10 @@ export class CompareView extends AbstractWebview<
103121

104122
await this.postMessage({
105123
t: "setComparisons",
106-
stats: {
107-
fromQuery: {
108-
// since we split the description into several rows
109-
// only run interpolation if the label is user-defined
110-
// otherwise we will wind up with duplicated rows
111-
name: this.labelProvider.getShortLabel(from),
112-
status: from.completedQuery.statusString,
113-
time: from.startTime,
114-
},
115-
toQuery: {
116-
name: this.labelProvider.getShortLabel(to),
117-
status: to.completedQuery.statusString,
118-
time: to.startTime,
119-
},
120-
},
121124
result,
122125
commonResultSetNames,
123126
currentResultSetName: currentResultSetDisplayName,
124127
message,
125-
databaseUri: to.initialInfo.databaseInfo.databaseUri,
126128
});
127129
}
128130
}

extensions/ql-vscode/src/stories/compare/CompareTable.stories.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const Template: StoryFn<typeof CompareTableComponent> = (args) => (
1717

1818
export const CompareTable = Template.bind({});
1919
CompareTable.args = {
20-
comparison: {
21-
t: "setComparisons",
20+
queryInfo: {
21+
t: "setComparisonQueryInfo",
2222
stats: {
2323
fromQuery: {
2424
name: "Query built from user-controlled sources",
@@ -31,6 +31,10 @@ CompareTable.args = {
3131
time: "8/16/2023, 3:07:21 PM",
3232
},
3333
},
34+
databaseUri: "file:///java",
35+
},
36+
comparison: {
37+
t: "setComparisons",
3438
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
3539
currentResultSetName: "edges",
3640
result: {
@@ -65,6 +69,5 @@ CompareTable.args = {
6569
],
6670
},
6771
message: undefined,
68-
databaseUri: "file:///java",
6972
},
7073
};

extensions/ql-vscode/src/view/compare/Compare.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import { styled } from "styled-components";
55
import {
66
ToCompareViewMessage,
77
SetComparisonsMessage,
8+
SetComparisonQueryInfoMessage,
89
} from "../../common/interface-types";
910
import CompareSelector from "./CompareSelector";
1011
import { vscode } from "../vscode-api";
1112
import CompareTable from "./CompareTable";
1213

1314
import "../results/resultsView.css";
15+
import { assertNever } from "../../common/helpers-pure";
1416

1517
const Header = styled.div`
1618
display: flex;
@@ -25,6 +27,8 @@ const Message = styled.div`
2527
`;
2628

2729
export function Compare(_: Record<string, never>): JSX.Element {
30+
const [queryInfo, setQueryInfo] =
31+
useState<SetComparisonQueryInfoMessage | null>(null);
2832
const [comparison, setComparison] = useState<SetComparisonsMessage | null>(
2933
null,
3034
);
@@ -39,8 +43,14 @@ export function Compare(_: Record<string, never>): JSX.Element {
3943
if (evt.origin === window.origin) {
4044
const msg: ToCompareViewMessage = evt.data;
4145
switch (msg.t) {
46+
case "setComparisonQueryInfo":
47+
setQueryInfo(msg);
48+
break;
4249
case "setComparisons":
4350
setComparison(msg);
51+
break;
52+
default:
53+
assertNever(msg);
4454
}
4555
} else {
4656
// sanitize origin
@@ -55,7 +65,7 @@ export function Compare(_: Record<string, never>): JSX.Element {
5565
};
5666
}, []);
5767

58-
if (!comparison) {
68+
if (!queryInfo || !comparison) {
5969
return <div>Waiting for results to load.</div>;
6070
}
6171

@@ -73,7 +83,10 @@ export function Compare(_: Record<string, never>): JSX.Element {
7383
/>
7484
</Header>
7585
{hasRows ? (
76-
<CompareTable comparison={comparison}></CompareTable>
86+
<CompareTable
87+
queryInfo={queryInfo}
88+
comparison={comparison}
89+
></CompareTable>
7790
) : (
7891
<Message>{message}</Message>
7992
)}

extensions/ql-vscode/src/view/compare/CompareTable.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as React from "react";
22

3-
import { SetComparisonsMessage } from "../../common/interface-types";
3+
import {
4+
SetComparisonQueryInfoMessage,
5+
SetComparisonsMessage,
6+
} from "../../common/interface-types";
47
import { className } from "../results/result-table-utils";
58
import { vscode } from "../vscode-api";
69
import TextButton from "../common/TextButton";
710
import { styled } from "styled-components";
811
import { RawCompareResultTable } from "./RawCompareResultTable";
912

1013
interface Props {
14+
queryInfo: SetComparisonQueryInfoMessage;
1115
comparison: SetComparisonsMessage;
1216
}
1317

@@ -26,9 +30,8 @@ const Table = styled.table`
2630
}
2731
`;
2832

29-
export default function CompareTable(props: Props) {
30-
const comparison = props.comparison;
31-
const result = props.comparison.result!;
33+
export default function CompareTable({ queryInfo, comparison }: Props) {
34+
const result = comparison.result!;
3235

3336
async function openQuery(kind: "from" | "to") {
3437
vscode.postMessage({
@@ -43,18 +46,18 @@ export default function CompareTable(props: Props) {
4346
<tr>
4447
<td>
4548
<OpenButton onClick={() => openQuery("from")}>
46-
{comparison.stats.fromQuery?.name}
49+
{queryInfo.stats.fromQuery?.name}
4750
</OpenButton>
4851
</td>
4952
<td>
5053
<OpenButton onClick={() => openQuery("to")}>
51-
{comparison.stats.toQuery?.name}
54+
{queryInfo.stats.toQuery?.name}
5255
</OpenButton>
5356
</td>
5457
</tr>
5558
<tr>
56-
<td>{comparison.stats.fromQuery?.time}</td>
57-
<td>{comparison.stats.toQuery?.time}</td>
59+
<td>{queryInfo.stats.fromQuery?.time}</td>
60+
<td>{queryInfo.stats.toQuery?.time}</td>
5861
</tr>
5962
<tr>
6063
<th>{result.from.length} rows removed</th>
@@ -68,7 +71,7 @@ export default function CompareTable(props: Props) {
6871
columns={result.columns}
6972
schemaName={comparison.currentResultSetName}
7073
rows={result.from}
71-
databaseUri={comparison.databaseUri}
74+
databaseUri={queryInfo.databaseUri}
7275
className={className}
7376
/>
7477
</td>
@@ -77,7 +80,7 @@ export default function CompareTable(props: Props) {
7780
columns={result.columns}
7881
schemaName={comparison.currentResultSetName}
7982
rows={result.to}
80-
databaseUri={comparison.databaseUri}
83+
databaseUri={queryInfo.databaseUri}
8184
className={className}
8285
/>
8386
</td>

0 commit comments

Comments
 (0)