(fix) debug mode for viewer (#5142)
* Fix the debug usage for the viewer * formatting
This commit is contained in:
@@ -100,11 +100,15 @@ describe('take', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getQueryParameter', () => {
|
||||
describe('getFeatureFlag', () => {
|
||||
describe('in a non-browser environment', () => {
|
||||
it('should return the default value', () => {
|
||||
expect(getFeatureFlag(ObjectLoader2Flags.USE_CACHE)).toBe('true')
|
||||
})
|
||||
|
||||
it('should return undefined when useDefault is false', () => {
|
||||
expect(getFeatureFlag(ObjectLoader2Flags.USE_CACHE, false)).toBe(undefined)
|
||||
})
|
||||
})
|
||||
|
||||
describe('in a browser environment', () => {
|
||||
@@ -137,5 +141,15 @@ describe('getQueryParameter', () => {
|
||||
mockWindow.location.search = ''
|
||||
expect(getFeatureFlag(ObjectLoader2Flags.DEBUG)).toBe('false')
|
||||
})
|
||||
|
||||
it('should return undefined if useDefault is false and parameter is not in URL', () => {
|
||||
mockWindow.location.search = '?otherparam=value'
|
||||
expect(getFeatureFlag(ObjectLoader2Flags.DEBUG, false)).toBe(undefined)
|
||||
})
|
||||
|
||||
it('should still return the parameter value from URL when useDefault is false', () => {
|
||||
mockWindow.location.search = '?debug=custom'
|
||||
expect(getFeatureFlag(ObjectLoader2Flags.DEBUG, false)).toBe('custom')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -60,14 +60,17 @@ const defaultValues: Record<ObjectLoader2Flags, string> = {
|
||||
[ObjectLoader2Flags.USE_CACHE]: 'true'
|
||||
}
|
||||
|
||||
export function getFeatureFlag(paramName: ObjectLoader2Flags): string {
|
||||
export function getFeatureFlag(
|
||||
paramName: ObjectLoader2Flags,
|
||||
useDefault: boolean = true
|
||||
): string | undefined {
|
||||
// Check if the code is running in a browser environment 🌐
|
||||
const isBrowser =
|
||||
typeof window !== 'undefined' && typeof window.document !== 'undefined'
|
||||
|
||||
if (!isBrowser) {
|
||||
// If in Node.js or another server environment, return the default
|
||||
return defaultValues[paramName]
|
||||
return useDefault ? defaultValues[paramName] : undefined
|
||||
}
|
||||
|
||||
// In a browser, parse the query string
|
||||
@@ -76,5 +79,5 @@ export function getFeatureFlag(paramName: ObjectLoader2Flags): string {
|
||||
// .get() returns the value, or null if it's not found.
|
||||
// The nullish coalescing operator (??) provides the default value
|
||||
// if the left-hand side is null or undefined.
|
||||
return params.get(paramName) ?? defaultValues[paramName]
|
||||
return params.get(paramName) ?? (useDefault ? defaultValues[paramName] : undefined)
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ export class SpeckleLoader extends Loader {
|
||||
}
|
||||
|
||||
private progressListen(): void {
|
||||
if (getFeatureFlag(ObjectLoader2Flags.DEBUG) !== 'true') {
|
||||
if (getFeatureFlag(ObjectLoader2Flags.DEBUG, false) !== 'true') {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user