Skip to content

Commit df3a66e

Browse files
committed
PB-2064: fix map ready state parsed legacy state
1 parent 40fc0b7 commit df3a66e

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

packages/viewer/src/router/legacyPermalink.routerPlugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
isLegacyParams,
3131
} from '@/utils/legacyLayerParamUtils'
3232

33+
const dispatcher = { name: 'legacyPermalinkRouterPlugin' }
34+
3335
function toNumber(input: string | number): number {
3436
return typeof input === 'number' ? input : parseFloat(input)
3537
}
@@ -180,7 +182,7 @@ export function handleLegacyParam(
180182
newValue = legacyParamValue
181183
break
182184
}
183-
185+
console.log('handleLegacyParam', legacyParamName, legacyParamValue, key, newValue)
184186
if (newValue !== undefined) {
185187
// When receiving a query, the application will encode the URI components
186188
// We decode those so that the new query won't encode encoded character
@@ -449,7 +451,9 @@ export const legacyPermalinkManagementRouterPlugin: RouterPlugin = (router): voi
449451
titleColor: LogPreDefinedColor.Amber,
450452
messages: [`redirect to the converted params`, newRoute],
451453
})
452-
router.replace(newRoute).catch((error) => {
454+
router.replace(newRoute).then(() => {
455+
useAppStore().setLegacyUrlParamsParsedHasHappened(dispatcher)
456+
}).catch((error) => {
453457
log.error({
454458
title: 'Legacy URL',
455459
titleColor: LogPreDefinedColor.Amber,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { AppStore } from '@/store/modules/app/types/app'
2+
import type { ActionDispatcher } from '@/store/types'
3+
4+
export default function setLegacyUrlParamsParsedHasHappened(
5+
this: AppStore,
6+
dispatcher: ActionDispatcher
7+
) {
8+
this.legacParamsParsingHasHappened = true
9+
}

packages/viewer/src/store/modules/app/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { AppStoreGetters, AppStoreState } from '@/store/modules/app/types/a
55
import nextState from '@/store/modules/app/actions/nextState'
66
import setHasPendingUrlParsing from '@/store/modules/app/actions/setHasPendingUrlParsing'
77
import setInitialUrlParsingHasHappened from '@/store/modules/app/actions/setInitialUrlParsingHasHappened'
8+
import setLegacyUrlParamsParsedHasHappened from '@/store/modules/app/actions/setLegacyUrlParamsParsingHasHappened'
89
import isConfigLoaded from '@/store/modules/app/getters/isConfigLoaded'
910
import isCurrentStateFulfilled from '@/store/modules/app/getters/isCurrentStateFulfilled'
1011
import isLoadingConfig from '@/store/modules/app/getters/isLoadingConfig'
@@ -51,7 +52,10 @@ const initiateUrlParsing: AppState = {
5152

5253
const parseLegacyUrlParams: AppState = {
5354
name: AppStateNames.LegacyParsing,
54-
isFulfilled: () => !isLegacyParams(window?.location?.search),
55+
// legacParamsParsingHasHappened is necessary to reevaluate after the legacy parsing has happened, without it,
56+
// isFulfilled would always return false/true after the first time
57+
// it also has to be the first condition because the && operator is short-circuiting
58+
isFulfilled: () => useAppStore().legacParamsParsingHasHappened && !isLegacyParams(window?.location?.search),
5559
next: () => {
5660
return initiateUrlParsing
5761
},
@@ -89,6 +93,7 @@ const state = (): AppStoreState => ({
8993
appState: initializing,
9094
initialUrlParsingHasHappened: false,
9195
hasPendingUrlParsing: false,
96+
legacParamsParsingHasHappened: false,
9297
})
9398

9499
const getters: AppStoreGetters = {
@@ -105,6 +110,7 @@ const actions = {
105110
nextState,
106111
setHasPendingUrlParsing,
107112
setInitialUrlParsingHasHappened,
113+
setLegacyUrlParamsParsedHasHappened,
108114
}
109115

110116
const useAppStore = defineStore('app', {

packages/viewer/src/store/modules/app/types/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { AppState } from '@/store/modules/app/types/appState'
44
export interface AppStoreState {
55
appState: AppState
66
initialUrlParsingHasHappened: boolean
7+
legacParamsParsingHasHappened: boolean
78
hasPendingUrlParsing: boolean
89
}
910
export type AppStoreGetters = {

0 commit comments

Comments
 (0)