Skip to content

Commit 3386907

Browse files
committed
Improve DataExplorer UX
Update UI screenshot
1 parent 2b509d1 commit 3386907

File tree

3 files changed

+85
-41
lines changed

3 files changed

+85
-41
lines changed

docs/static/windiff_screenshot.png

8.65 KB
Loading

windiff_frontend/src/app/data_explorer.tsx

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import pako from "pako";
77

88
import DarkTabs from "./tabs";
99
import DarkCombobox from "./combobox";
10-
import { WinDiffFileData, WinDiffIndexData } from "./windiff_types";
10+
import {
11+
WinDiffFileData,
12+
WinDiffIndexData,
13+
WinDiffIndexOS,
14+
} from "./windiff_types";
1115

1216
const compressedJsonFetcher = async (url: string) => {
1317
const response = await fetch(url);
@@ -41,10 +45,10 @@ const tabNames = [
4145

4246
export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
4347
const [currentTabId, setCurrentTabId] = useState(Tab.Exports);
44-
const [selectedType, setSelectedType] = useState("");
4548
let [leftOSVersion, setLeftOSVersion] = useState("");
4649
let [rightOSVersion, setRightOSVersion] = useState("");
4750
let [binary, setBinary] = useState("");
51+
let [selectedType, setSelectedType] = useState("");
4852

4953
// Fetch index content
5054
const { data: indexData, error: indexError } = useSWR<WinDiffIndexData>(
@@ -56,18 +60,20 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
5660
let rightFileName: string = "";
5761
if (indexData) {
5862
if (leftOSVersion.length == 0) {
59-
leftOSVersion = osVersionToPathSuffix(indexData.oses[0]);
63+
leftOSVersion = osVersionToHumanString(indexData.oses[0]);
6064
}
6165
if (rightOSVersion.length == 0) {
62-
rightOSVersion = osVersionToPathSuffix(indexData.oses[0]);
66+
rightOSVersion = osVersionToHumanString(indexData.oses[0]);
6367
}
6468
if (binary.length == 0) {
6569
binary = indexData.binaries[0];
6670
}
6771

68-
leftFileName = `${binary}_${leftOSVersion}.json.gz`;
72+
const binaryVersion = humanOsVersionToPathSuffix(leftOSVersion);
73+
leftFileName = `${binary}_${binaryVersion}.json.gz`;
6974
if (mode == ExplorerMode.Diff) {
70-
rightFileName = `${binary}_${rightOSVersion}.json.gz`;
75+
const binaryVersion = humanOsVersionToPathSuffix(rightOSVersion);
76+
rightFileName = `${binary}_${binaryVersion}.json.gz`;
7177
}
7278
}
7379

@@ -88,12 +94,43 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
8894
return <div>Loading...</div>;
8995
}
9096

97+
// Setup the combobox used to select types if needed
98+
const typesCombobox: JSX.Element = (() => {
99+
if (leftFileData) {
100+
let typeList: Set<string> | string[];
101+
if (rightFileData) {
102+
typeList = new Set(
103+
Object.keys(leftFileData.types).concat(
104+
Object.keys(rightFileData.types)
105+
)
106+
);
107+
} else {
108+
typeList = Object.keys(leftFileData.types);
109+
}
110+
if (selectedType.length == 0) {
111+
// Select the first element of the list by default
112+
selectedType = typeList.values().next().value;
113+
}
114+
if (currentTabId == Tab.Types) {
115+
return (
116+
<DarkCombobox
117+
selectedOption={selectedType}
118+
options={[...typeList]}
119+
onChange={(value) => setSelectedType(value)}
120+
/>
121+
);
122+
}
123+
}
124+
return <></>;
125+
})();
126+
91127
// Prepare the appropriate data
92128
const compareStrings = (a: string, b: string) => (a > b ? 1 : b > a ? -1 : 0);
93129
const sortedOSes: string[] = indexData.oses
94-
.map((osVersion: any) => osVersionToPathSuffix(osVersion))
130+
.map((osVersion: any) => osVersionToHumanString(osVersion))
95131
.sort(compareStrings);
96132
const sortedBinaries: string[] = indexData.binaries.sort(compareStrings);
133+
97134
// Data displayed on the left (in diff mode) or in the center (in browse mode)
98135
const leftData: string = (() => {
99136
if (!leftFileData) {
@@ -134,32 +171,12 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
134171
return <></>;
135172
})();
136173

137-
// Setup the combobox used to select types if needed
138-
const typesCombobox: JSX.Element = (() => {
139-
if (leftFileData) {
140-
let typeList: Set<string> | string[];
141-
if (rightFileData) {
142-
typeList = new Set(
143-
Object.keys(leftFileData.types).concat(
144-
Object.keys(rightFileData.types)
145-
)
146-
);
147-
} else {
148-
typeList = Object.keys(leftFileData.types);
149-
}
150-
if (currentTabId == Tab.Types) {
151-
return (
152-
<DarkCombobox
153-
selectedOption={selectedType}
154-
options={[...typeList]}
155-
onChange={(value) => setSelectedType(value)}
156-
/>
157-
);
158-
}
159-
}
160-
return <></>;
161-
})();
162-
174+
// Setup the combobox grid with 3 columns in browsing mode and 2 columns in
175+
// diffing mode
176+
const comboboxGridClass =
177+
mode == ExplorerMode.Browse
178+
? "grid grid-cols-3 gap-2"
179+
: "grid grid-cols-2 gap-2";
163180
const editorLanguage = currentTabId == Tab.Types ? "cpp" : "plaintext";
164181
return (
165182
<div className="flex flex-row justify-center items-center">
@@ -170,7 +187,7 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
170187
onChange={(value) => setCurrentTabId(value)}
171188
/>
172189
{/* Comboboxes used to select the binary versions */}
173-
<div className="grid grid-cols-4 gap-2">
190+
<div className={comboboxGridClass}>
174191
<DarkCombobox
175192
selectedOption={leftOSVersion}
176193
options={sortedOSes}
@@ -200,16 +217,39 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
200217
);
201218
}
202219

203-
function osVersionToHumanString(osVersion: any): string {
204-
return `${osVersion.version} ${osVersion.architecture} (${osVersion.update})`;
220+
function osVersionToHumanString(osVersion: WinDiffIndexOS): string {
221+
// Normalize version names between Windows 10 and 11
222+
let versionPrefix = "";
223+
if (!osVersion.version.startsWith("11")) {
224+
// Windows 10
225+
versionPrefix = "10-";
226+
}
227+
228+
return `Windows ${versionPrefix}${osVersion.version} ${osVersion.architecture} (${osVersion.update})`;
205229
}
206230

207-
function osVersionToPathSuffix(osVersion: any): string {
208-
return `${osVersion.version}_${osVersion.update}_${osVersion.architecture}`;
231+
// Convert "human" versions of version strings to the corresponding file path suffixes
232+
function humanOsVersionToPathSuffix(osVersionName: string): string {
233+
const versionParts = osVersionName.split(" ");
234+
let osVersion = versionParts[1];
235+
if (osVersion.startsWith("10-")) {
236+
// Remove added prefix
237+
osVersion = osVersion.substring(3);
238+
}
239+
240+
const osArchitecture = versionParts[2];
241+
const osUpdateWithParentheses = versionParts[3];
242+
// Remove parentheses
243+
const osUpdate = osUpdateWithParentheses.substring(
244+
1,
245+
osUpdateWithParentheses.length - 1
246+
);
247+
248+
return `${osVersion}_${osUpdate}_${osArchitecture}`;
209249
}
210250

211251
function getEditorDataFromFileData(
212-
fileData: any,
252+
fileData: WinDiffFileData,
213253
tab: Tab,
214254
selectedType: string | undefined
215255
): string {

windiff_frontend/src/app/windiff_types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ export type WinDiffIndexData = {
33
oses: WinDiffIndexOS[];
44
binaries: WinDiffIndexBinary[];
55
};
6-
type WinDiffIndexOS = { version: string; update: string; architecture: string };
7-
type WinDiffIndexBinary = string;
6+
export type WinDiffIndexOS = {
7+
version: string;
8+
update: string;
9+
architecture: string;
10+
};
11+
export type WinDiffIndexBinary = string;
812

913
// File data
1014
export type WinDiffFileData = {

0 commit comments

Comments
 (0)