@@ -4,6 +4,7 @@ import {graphql, navigate, useStaticQuery} from 'gatsby';
4
4
import { parse } from 'query-string' ;
5
5
6
6
import { PageContext } from 'sentry-docs/components/pageContext' ;
7
+ import { Platform , PlatformGuide } from 'sentry-docs/types' ;
7
8
8
9
import { useLocalStorage } from './useLocalStorage' ;
9
10
@@ -34,62 +35,6 @@ const query = graphql`
34
35
}
35
36
` ;
36
37
37
- export const formatCaseStyle = ( style : string , value : string ) : string => {
38
- switch ( style ) {
39
- case 'snake_case' :
40
- return value . replace ( / - / g, '_' ) ;
41
- case 'camelCase' :
42
- return value
43
- . split ( / - / g)
44
- . map ( ( val , idx ) =>
45
- idx === 0 ? val : val . charAt ( 0 ) . toUpperCase ( ) + val . substring ( 1 )
46
- )
47
- . join ( '' ) ;
48
- case 'PascalCase' :
49
- return value
50
- . split ( / - / g)
51
- . map ( val => val . charAt ( 0 ) . toUpperCase ( ) + val . substring ( 1 ) )
52
- . join ( '' ) ;
53
- default :
54
- return value ;
55
- }
56
- } ;
57
-
58
- // export enum CaseStyle {
59
- // canonical,
60
- // camelCase,
61
- // PascalCase,
62
- // snake_case,
63
- // }
64
-
65
- // export enum SupportLevel {
66
- // production,
67
- // community,
68
- // }
69
-
70
- export type Guide = {
71
- caseStyle : string ;
72
- fallbackPlatform : string ;
73
- key : string ;
74
- name : string ;
75
- sdk : string ;
76
- supportLevel : string ;
77
- title : string ;
78
- url : string ;
79
- } ;
80
-
81
- export type Platform = {
82
- caseStyle : string ;
83
- key : string ;
84
- name : string ;
85
- sdk : string ;
86
- supportLevel : string ;
87
- title : string ;
88
- url : string ;
89
- fallbackPlatform ?: string ;
90
- guides ?: Guide [ ] ;
91
- } ;
92
-
93
38
export const DEFAULT_PLATFORM = 'javascript' ;
94
39
95
40
const normalizeSlug = ( name : string ) : string => {
@@ -161,8 +106,9 @@ const rebuildPathForPlatform = (key: string, currentPath?: string): string => {
161
106
export const usePlatformList = ( ) : Platform [ ] => {
162
107
const {
163
108
allPlatform : { nodes : platformList } ,
164
- } = useStaticQuery ( query ) ;
165
- return platformList . sort ( ( a : Platform , b : Platform ) => {
109
+ } = useStaticQuery < { allPlatform : { nodes : Platform [ ] } } > ( query ) ;
110
+
111
+ return platformList . sort ( ( a , b ) => {
166
112
// Exclude leading non-alphanumeric characters to order .NET between Native and NodeJS instead of the beginning.
167
113
const skippedPrefix = / ^ [ ^ a - z A - Z ] + / ;
168
114
return a . title
@@ -176,7 +122,7 @@ export const usePlatformList = (): Platform[] => {
176
122
177
123
* @param value platform key in format of `platformName[.guideName]`
178
124
*/
179
- export const getPlatform = ( key : string ) : Platform | Guide | null => {
125
+ export const getPlatform = ( key : string ) : Platform | PlatformGuide | null => {
180
126
// XXX(epurkhiser): This is almost certinally a mistake, we should figure out
181
127
// if `getPlatforms` should actually be something more like `useGetPlatforms`
182
128
// or something
@@ -191,14 +137,13 @@ export const getPlatform = (key: string): Platform | Guide | null => {
191
137
const [ platformName , guideName ] = key . split ( '.' , 2 ) ;
192
138
const activePlatform = platformList . find ( ( p : Platform ) => p . key === platformName ) ;
193
139
const activeGuide =
194
- activePlatform &&
195
- ( activePlatform as Platform ) . guides . find ( ( g : Guide ) => g . name === guideName ) ;
140
+ activePlatform && activePlatform . guides . find ( g => g . name === guideName ) ;
196
141
197
142
return activeGuide ?? activePlatform ?? null ;
198
143
} ;
199
144
200
145
type UsePlatform = [
201
- Platform | Guide | null ,
146
+ Platform | PlatformGuide | null ,
202
147
( value : string , options ?: SetPlatformOptions ) => void ,
203
148
boolean
204
149
] ;
@@ -207,7 +152,9 @@ type SetPlatformOptions = {
207
152
noQueryString ?: boolean ;
208
153
} ;
209
154
210
- export const getPlatformsWithFallback = ( platform : Platform | Guide ) : string [ ] => {
155
+ export const getPlatformsWithFallback = (
156
+ platform : Platform | PlatformGuide
157
+ ) : string [ ] => {
211
158
const result = [ platform . key ] ;
212
159
let curPlatform = platform ;
213
160
while ( curPlatform . fallbackPlatform ) {
@@ -258,7 +205,7 @@ export function usePlatform(
258
205
259
206
const [ stateValue , setStateValue ] = useState ( currentValue ) ;
260
207
261
- const setValue = ( newValue : string , options : SetPlatformOptions = { } ) => {
208
+ const setPlatform = ( newValue : string , options : SetPlatformOptions = { } ) => {
262
209
if ( newValue === currentValue ) {
263
210
return ;
264
211
}
@@ -276,8 +223,8 @@ export function usePlatform(
276
223
setStateValue ( newValue ) ;
277
224
} ;
278
225
279
- const activeValue : Platform | Guide | null =
226
+ const activePlatform : Platform | PlatformGuide | null =
280
227
getPlatform ( stateValue ) ?? ( useDefault ? getPlatform ( defaultValue ) : null ) ;
281
228
282
- return [ activeValue , setValue , isFixed ] ;
229
+ return [ activePlatform , setPlatform , isFixed ] ;
283
230
}
0 commit comments