@@ -7,7 +7,11 @@ import pako from "pako";
7
7
8
8
import DarkTabs from "./tabs" ;
9
9
import DarkCombobox from "./combobox" ;
10
- import { WinDiffFileData , WinDiffIndexData } from "./windiff_types" ;
10
+ import {
11
+ WinDiffFileData ,
12
+ WinDiffIndexData ,
13
+ WinDiffIndexOS ,
14
+ } from "./windiff_types" ;
11
15
12
16
const compressedJsonFetcher = async ( url : string ) => {
13
17
const response = await fetch ( url ) ;
@@ -41,10 +45,10 @@ const tabNames = [
41
45
42
46
export default function DataExplorer ( { mode } : { mode : ExplorerMode } ) {
43
47
const [ currentTabId , setCurrentTabId ] = useState ( Tab . Exports ) ;
44
- const [ selectedType , setSelectedType ] = useState ( "" ) ;
45
48
let [ leftOSVersion , setLeftOSVersion ] = useState ( "" ) ;
46
49
let [ rightOSVersion , setRightOSVersion ] = useState ( "" ) ;
47
50
let [ binary , setBinary ] = useState ( "" ) ;
51
+ let [ selectedType , setSelectedType ] = useState ( "" ) ;
48
52
49
53
// Fetch index content
50
54
const { data : indexData , error : indexError } = useSWR < WinDiffIndexData > (
@@ -56,18 +60,20 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
56
60
let rightFileName : string = "" ;
57
61
if ( indexData ) {
58
62
if ( leftOSVersion . length == 0 ) {
59
- leftOSVersion = osVersionToPathSuffix ( indexData . oses [ 0 ] ) ;
63
+ leftOSVersion = osVersionToHumanString ( indexData . oses [ 0 ] ) ;
60
64
}
61
65
if ( rightOSVersion . length == 0 ) {
62
- rightOSVersion = osVersionToPathSuffix ( indexData . oses [ 0 ] ) ;
66
+ rightOSVersion = osVersionToHumanString ( indexData . oses [ 0 ] ) ;
63
67
}
64
68
if ( binary . length == 0 ) {
65
69
binary = indexData . binaries [ 0 ] ;
66
70
}
67
71
68
- leftFileName = `${ binary } _${ leftOSVersion } .json.gz` ;
72
+ const binaryVersion = humanOsVersionToPathSuffix ( leftOSVersion ) ;
73
+ leftFileName = `${ binary } _${ binaryVersion } .json.gz` ;
69
74
if ( mode == ExplorerMode . Diff ) {
70
- rightFileName = `${ binary } _${ rightOSVersion } .json.gz` ;
75
+ const binaryVersion = humanOsVersionToPathSuffix ( rightOSVersion ) ;
76
+ rightFileName = `${ binary } _${ binaryVersion } .json.gz` ;
71
77
}
72
78
}
73
79
@@ -88,12 +94,43 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
88
94
return < div > Loading...</ div > ;
89
95
}
90
96
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
+
91
127
// Prepare the appropriate data
92
128
const compareStrings = ( a : string , b : string ) => ( a > b ? 1 : b > a ? - 1 : 0 ) ;
93
129
const sortedOSes : string [ ] = indexData . oses
94
- . map ( ( osVersion : any ) => osVersionToPathSuffix ( osVersion ) )
130
+ . map ( ( osVersion : any ) => osVersionToHumanString ( osVersion ) )
95
131
. sort ( compareStrings ) ;
96
132
const sortedBinaries : string [ ] = indexData . binaries . sort ( compareStrings ) ;
133
+
97
134
// Data displayed on the left (in diff mode) or in the center (in browse mode)
98
135
const leftData : string = ( ( ) => {
99
136
if ( ! leftFileData ) {
@@ -134,32 +171,12 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
134
171
return < > </ > ;
135
172
} ) ( ) ;
136
173
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" ;
163
180
const editorLanguage = currentTabId == Tab . Types ? "cpp" : "plaintext" ;
164
181
return (
165
182
< div className = "flex flex-row justify-center items-center" >
@@ -170,7 +187,7 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
170
187
onChange = { ( value ) => setCurrentTabId ( value ) }
171
188
/>
172
189
{ /* Comboboxes used to select the binary versions */ }
173
- < div className = "grid grid-cols-4 gap-2" >
190
+ < div className = { comboboxGridClass } >
174
191
< DarkCombobox
175
192
selectedOption = { leftOSVersion }
176
193
options = { sortedOSes }
@@ -200,16 +217,39 @@ export default function DataExplorer({ mode }: { mode: ExplorerMode }) {
200
217
) ;
201
218
}
202
219
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 } )` ;
205
229
}
206
230
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 } ` ;
209
249
}
210
250
211
251
function getEditorDataFromFileData (
212
- fileData : any ,
252
+ fileData : WinDiffFileData ,
213
253
tab : Tab ,
214
254
selectedType : string | undefined
215
255
) : string {
0 commit comments