@@ -9,6 +9,11 @@ const Context = createContext();
99
1010export const DEFAULT_VERSION = "latest" ;
1111export const DEFAULT_PLATFORM = "oss" ;
12+ const VERSIONS_LIST = publicRuntimeConfig . VERSIONS_LIST ;
13+ const LATEST_OSS_VERSION = publicRuntimeConfig . LATEST_OSS_VERSION ;
14+ const PLATFORM_VERSIONS = publicRuntimeConfig . PLATFORM_VERSIONS ;
15+ const PLATFORM_LATEST_VERSIONS = publicRuntimeConfig . PLATFORM_LATEST_VERSIONS ;
16+ const PLATFORMS = publicRuntimeConfig . PLATFORMS ;
1217
1318export function VersionContextProvider ( { children } ) {
1419 const [ initialized , setInitialized ] = useState ( false ) ;
@@ -19,21 +24,12 @@ export function VersionContextProvider({ children }) {
1924 const router = useRouter ( ) ;
2025
2126 const initialize = useCallback (
22- ( {
23- newVersion,
24- newPlatform,
25- versionList,
26- snowflakeVersions,
27- functionName = null ,
28- currMenuItem = null ,
29- } ) => {
27+ ( { newVersion, newPlatform, functionName = null , currMenuItem = null } ) => {
3028 if ( initialized ) return [ version , platform ] ;
3129
3230 setVersionAndPlatform ( {
3331 newVersion,
3432 newPlatform,
35- versionList,
36- snowflakeVersions,
3733 functionName,
3834 currMenuItem,
3935 updateURL : true ,
@@ -50,20 +46,11 @@ export function VersionContextProvider({ children }) {
5046 ( {
5147 newVersion,
5248 newPlatform,
53- versionList,
54- snowflakeVersions,
5549 functionName = null ,
5650 currMenuItem = null ,
5751 updateURL = true ,
5852 } ) => {
59- if (
60- ! versionAndPlatformAreCompatible (
61- newVersion ,
62- newPlatform ,
63- versionList ,
64- snowflakeVersions ,
65- )
66- ) {
53+ if ( ! versionAndPlatformAreCompatible ( newVersion , newPlatform ) ) {
6754 console . error (
6855 "Incompatible version and platform:" ,
6956 newVersion ,
@@ -76,12 +63,7 @@ export function VersionContextProvider({ children }) {
7663 return ;
7764 }
7865
79- const cleanedVersion = isLatestVersion (
80- newVersion ,
81- newPlatform ,
82- versionList ,
83- snowflakeVersions ,
84- )
66+ const cleanedVersion = isLatestVersion ( newVersion , newPlatform )
8567 ? DEFAULT_VERSION
8668 : newVersion ;
8769 setVersionState ( cleanedVersion ) ;
@@ -131,16 +113,11 @@ export function useVersion() {
131113 return useContext ( Context ) ;
132114}
133115
134- export function isLatestVersion (
135- version ,
136- platform ,
137- versionList ,
138- snowflakeVersions ,
139- ) {
116+ export function isLatestVersion ( version , platform ) {
140117 const maxVersion =
141118 platform == DEFAULT_PLATFORM
142- ? getLatest ( versionList )
143- : getLatest ( snowflakeVersions [ platform ] ) ;
119+ ? LATEST_OSS_VERSION
120+ : PLATFORM_LATEST_VERSIONS [ platform ] ;
144121
145122 return version == DEFAULT_VERSION || version == maxVersion ;
146123}
@@ -239,55 +216,38 @@ export function getVersionAndPlatformFromPathPart(pathPart) {
239216 return [ version , cleanedPlatform ] ;
240217}
241218
242- export function versionAndPlatformAreCompatible (
243- version ,
244- platform ,
245- versionList ,
246- snowflakeVersions ,
247- ) {
219+ export function versionAndPlatformAreCompatible ( version , platform ) {
248220 if ( version == DEFAULT_VERSION ) return true ;
249221
250- if ( platform == DEFAULT_PLATFORM && versionList . indexOf ( version ) >= 0 ) {
222+ if ( platform == DEFAULT_PLATFORM && VERSIONS_LIST . indexOf ( version ) >= 0 ) {
251223 return true ;
252224 }
253225
254- return snowflakeVersions [ platform ] . indexOf ( version ) >= 0 ;
226+ return PLATFORM_VERSIONS [ platform ] . indexOf ( version ) >= 0 ;
255227}
256228
257- export function getBestNumericVersion (
258- version ,
259- platform ,
260- versionList ,
261- snowflakeVersions ,
262- ) {
229+ export function getBestNumericVersion ( version , platform ) {
263230 if ( version == DEFAULT_VERSION ) {
264- if ( snowflakeVersions [ platform ] ) {
231+ if ( PLATFORM_VERSIONS [ platform ] ) {
265232 // This is a valid platform so return the latest version in the platform.
266- return [ getLatest ( snowflakeVersions [ platform ] ) , platform ] ;
233+ return [ PLATFORM_LATEST_VERSIONS [ platform ] , platform ] ;
267234 } else {
268235 // This is an invalid platform so we return the latest version for OSS.
269- return [ getLatest ( versionList ) , DEFAULT_PLATFORM ] ;
236+ return [ LATEST_OSS_VERSION , DEFAULT_PLATFORM ] ;
270237 }
271238 } else {
272- if (
273- versionAndPlatformAreCompatible (
274- version ,
275- platform ,
276- versionList ,
277- snowflakeVersions ,
278- )
279- ) {
239+ if ( versionAndPlatformAreCompatible ( version , platform ) ) {
280240 // This is a numeric version that is compatible with the platform. Return it all back.
281241 return [ version , platform ] ;
282242 } else {
283- if ( snowflakeVersions [ platform ] ) {
243+ if ( PLATFORM_VERSIONS [ platform ] ) {
284244 // Version and platform are incompatible, but platform exists. So return the latest
285245 // for the platform.
286- return [ getLatest ( snowflakeVersions [ platform ] ) , platform ] ;
246+ return [ PLATFORM_LATEST_VERSIONS [ platform ] , platform ] ;
287247 } else {
288248 // Version and platform are incompatible, and platform does not exist. So return the
289249 // latest for OSS.
290- return [ getLatest ( versionList ) , DEFAULT_PLATFORM ] ;
250+ return [ LATEST_OSS_VERSION , DEFAULT_PLATFORM ] ;
291251 }
292252 }
293253 }
0 commit comments