fix(fe2): various diff mode fixes (#1663)

* fix(fe2): diff not loading if referenced version is an old one

* fix(fe2): diff closing when thread open
This commit is contained in:
Kristaps Fabians Geikins
2023-06-29 16:55:29 +03:00
committed by GitHub
parent e62c0aa38d
commit 40fec1efde
2 changed files with 24 additions and 13 deletions
@@ -264,6 +264,7 @@ export function useApplySerializedState() {
const command = state.ui.diff.command
? deserializeDiffCommand(state.ui.diff.command)
: null
const activeDiffEnabled = !!diff.enabled.value
if (command && command.diffs.length) {
diff.time.value = state.ui.diff.time
diff.mode.value = state.ui.diff.mode
@@ -274,7 +275,7 @@ export function useApplySerializedState() {
instruction.versionA.versionId,
instruction.versionB.versionId
)
} else {
} else if (!activeDiffEnabled) {
await endDiff()
}
@@ -65,7 +65,7 @@ import {
setupUiDiffState
} from '~~/lib/viewer/composables/setup/diff'
import { useDiffUtilities, useFilterUtilities } from '~~/lib/viewer/composables/ui'
import { reduce } from 'lodash-es'
import { flatten, reduce } from 'lodash-es'
import { setupViewerCommentBubbles } from '~~/lib/viewer/composables/setup/comments'
export type LoadedModel = NonNullable<
@@ -273,7 +273,7 @@ type CachedViewerState = Pick<
type InitialSetupState = Pick<
InjectableViewerState,
'projectId' | 'viewer' | 'sessionId'
'projectId' | 'viewer' | 'sessionId' | 'urlHashState'
>
type InitialStateWithRequest = InitialSetupState & {
@@ -283,8 +283,7 @@ type InitialStateWithRequest = InitialSetupState & {
export type InitialStateWithRequestAndResponse = InitialSetupState &
Pick<InjectableViewerState, 'resources'>
export type InitialStateWithUrlHashState = InitialStateWithRequestAndResponse &
Pick<InjectableViewerState, 'urlHashState'>
export type InitialStateWithUrlHashState = InitialStateWithRequestAndResponse
export type InitialStateWithInterface = InitialStateWithUrlHashState &
Pick<InjectableViewerState, 'ui'>
@@ -388,7 +387,8 @@ function setupInitialState(params: UseSetupViewerParams): InitialSetupState {
ref: computed(() => isInitialized.value)
},
metadata: setupViewerMetadata({ viewer: instance })
}
},
urlHashState: setupUrlHashState()
}
}
@@ -587,7 +587,8 @@ function setupResponseResourceData(
projectId,
resources: {
request: { resourceIdString, threadFilters }
}
},
urlHashState: { diff }
} = state
const { resourceItems } = resourceItemsData
@@ -601,8 +602,21 @@ function setupResponseResourceData(
!!r.modelId
)
)
const diffVersionIds = computed(() =>
flatten(
(diff.value?.diffs || []).map((d) => [d.versionA.versionId, d.versionB.versionId])
)
)
// model.loadedVersion will be the actually currently loaded version +
// any diff versions, if they're requested. the naming is confusing, but
// model.loadedVersion = all currently loaded versions of that model, altho there's usually only 1
const versionIds = computed(() =>
nonObjectResourceItems.value.map((r) => r.versionId).sort()
[
...nonObjectResourceItems.value.map((r) => r.versionId),
...diffVersionIds.value
].sort()
)
const versionCursors = ref({} as Record<string, Nullable<string>>)
@@ -865,11 +879,7 @@ export function useSetupViewer(params: UseSetupViewerParams): InjectableViewerSt
const initState = setupInitialState(params)
const initialStateWithRequest = setupResourceRequest(initState)
const stateWithResources = setupResourceResponse(initialStateWithRequest)
const stateWithUrlHashState: InitialStateWithUrlHashState = {
...stateWithResources,
urlHashState: setupUrlHashState()
}
const state: InjectableViewerState = setupInterfaceState(stateWithUrlHashState)
const state: InjectableViewerState = setupInterfaceState(stateWithResources)
// Inject it into descendant components
provide(InjectableViewerStateKey, state)