mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[collab/gitlab] fix review diff file update when only selection is changed
#IJPL-164167 Fixed (cherry picked from commit 79634a7d2efe2f45408998990256d4aea10200e0) IJ-CR-149434 GitOrigin-RevId: f60f607d436b47f833c0a81fab2189b9b381f85f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c0b3f1bdab
commit
6e5be878d4
@@ -953,8 +953,6 @@ f:com.intellij.collaboration.api.json.JsonHttpApiHelperKt
|
||||
- com.intellij.collaboration.ui.codereview.diff.model.RefComparisonChangesSorter
|
||||
- sf:INSTANCE:com.intellij.collaboration.ui.codereview.diff.model.RefComparisonChangesSorter$None
|
||||
- sort(java.util.List):java.util.List
|
||||
*f:com.intellij.collaboration.ui.codereview.diff.model.RefComparisonChangesSorterKt
|
||||
- sf:sort(com.intellij.collaboration.ui.codereview.diff.model.RefComparisonChangesSorter,com.intellij.openapi.ListSelection):com.intellij.openapi.ListSelection
|
||||
f:com.intellij.collaboration.ui.codereview.diff.viewer.DiffViewerUtilKt
|
||||
- *sf:controlInlaysIn(com.intellij.diff.tools.util.base.DiffViewerBase,kotlinx.coroutines.CoroutineScope,kotlinx.coroutines.flow.Flow,kotlin.jvm.functions.Function1,kotlin.jvm.functions.Function2):V
|
||||
- *sf:showCodeReview(com.intellij.diff.tools.util.base.DiffViewerBase,kotlin.jvm.functions.Function3,com.intellij.openapi.util.Key,kotlin.jvm.functions.Function2,kotlin.coroutines.Continuation):java.lang.Object
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.intellij.collaboration.ui.codereview.diff.model
|
||||
|
||||
import com.intellij.collaboration.async.MappingScopedItemsContainer
|
||||
import com.intellij.collaboration.async.collectScoped
|
||||
import com.intellij.collaboration.ui.util.selectedItem
|
||||
import com.intellij.collaboration.util.ComputedResult
|
||||
import com.intellij.collaboration.util.onFailure
|
||||
import com.intellij.collaboration.util.onInProgress
|
||||
@@ -49,7 +50,7 @@ interface PreLoadingCodeReviewAsyncDiffViewModelDelegate<C : Any, CVM : AsyncDif
|
||||
companion object {
|
||||
fun <D : Any, C : Any, CVM : AsyncDiffViewModel> create(
|
||||
preloadedDataFlow: Flow<ComputedResult<D>?>,
|
||||
changesPreProcessor: Flow<(ListSelection<C>) -> ListSelection<C>>,
|
||||
changesPreProcessor: Flow<(List<C>) -> List<C>>,
|
||||
createViewModel: CoroutineScope.(D, C) -> CVM,
|
||||
): PreLoadingCodeReviewAsyncDiffViewModelDelegate<C, CVM> =
|
||||
PreLoadingCodeReviewAsyncDiffViewModelDelegateImpl(preloadedDataFlow, changesPreProcessor, createViewModel)
|
||||
@@ -59,7 +60,7 @@ interface PreLoadingCodeReviewAsyncDiffViewModelDelegate<C : Any, CVM : AsyncDif
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private class PreLoadingCodeReviewAsyncDiffViewModelDelegateImpl<D : Any, C : Any, CVM : AsyncDiffViewModel>(
|
||||
preloadedDataFlow: Flow<ComputedResult<D>?>,
|
||||
private val changesPreProcessor: Flow<(ListSelection<C>) -> ListSelection<C>>,
|
||||
private val changesPreProcessor: Flow<(List<C>) -> List<C>>,
|
||||
private val createViewModel: CoroutineScope.(D, C) -> CVM,
|
||||
) : PreLoadingCodeReviewAsyncDiffViewModelDelegate<C, CVM> {
|
||||
private val changesToShow = MutableStateFlow(ChangesState<C>())
|
||||
@@ -81,17 +82,18 @@ private class PreLoadingCodeReviewAsyncDiffViewModelDelegateImpl<D : Any, C : An
|
||||
val vmsContainer = MappingScopedItemsContainer.byEquality<C, CVM>(this) {
|
||||
createViewModel(preloadedData, it)
|
||||
}
|
||||
var lastList: ListSelection<C> = ListSelection.empty()
|
||||
var lastList: List<C> = emptyList()
|
||||
changesPreProcessor.collectLatest { preProcessor ->
|
||||
changesToShow.collectScoped { changesState ->
|
||||
if (changesState.selectedChanges.list != lastList.list) {
|
||||
if (changesState.selectedChanges.list != lastList) {
|
||||
emit(ComputedResult.loading())
|
||||
val processedList = preProcessor(changesState.selectedChanges)
|
||||
vmsContainer.update(processedList.list)
|
||||
lastList = processedList
|
||||
val processedList = preProcessor(changesState.selectedChanges.list)
|
||||
vmsContainer.update(processedList)
|
||||
lastList = changesState.selectedChanges.list
|
||||
}
|
||||
val vms = vmsContainer.mappingState.value.values.toList()
|
||||
val selectedVmIdx = lastList.selectedIndex
|
||||
val mappingState = vmsContainer.mappingState.value
|
||||
val vms = mappingState.values.toList()
|
||||
val selectedVmIdx = mappingState.keys.indexOf(changesState.selectedChanges.selectedItem)
|
||||
val newState = ViewModelsState(ListSelection.createAt(vms, selectedVmIdx), changesState.scrollRequests)
|
||||
emit(ComputedResult.success(newState))
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.collaboration.ui.codereview.diff.model
|
||||
|
||||
import com.intellij.collaboration.ui.util.selectedItem
|
||||
import com.intellij.collaboration.util.RefComparisonChange
|
||||
import com.intellij.collaboration.util.filePath
|
||||
import com.intellij.collaboration.util.fileStatus
|
||||
import com.intellij.openapi.ListSelection
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vcs.FilePath
|
||||
import com.intellij.openapi.vcs.changes.ui.*
|
||||
@@ -40,8 +38,3 @@ fun interface RefComparisonChangesSorter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun RefComparisonChangesSorter.sort(list: ListSelection<RefComparisonChange>): ListSelection<RefComparisonChange> {
|
||||
val newList = sort(list.list)
|
||||
return ListSelection.create(newList, list.selectedItem)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ package org.jetbrains.plugins.gitlab.mergerequest.diff
|
||||
import com.intellij.collaboration.async.computationStateFlow
|
||||
import com.intellij.collaboration.async.mapScoped
|
||||
import com.intellij.collaboration.ui.codereview.diff.DiffLineLocation
|
||||
import com.intellij.collaboration.ui.codereview.diff.model.*
|
||||
import com.intellij.collaboration.ui.codereview.diff.model.CodeReviewDiffProcessorViewModel
|
||||
import com.intellij.collaboration.ui.codereview.diff.model.DiffViewerScrollRequest
|
||||
import com.intellij.collaboration.ui.codereview.diff.model.PreLoadingCodeReviewAsyncDiffViewModelDelegate
|
||||
import com.intellij.collaboration.ui.codereview.diff.model.RefComparisonChangesSorter
|
||||
import com.intellij.collaboration.ui.icon.IconsProvider
|
||||
import com.intellij.collaboration.util.ComputedResult
|
||||
import com.intellij.collaboration.util.RefComparisonChange
|
||||
@@ -54,7 +57,7 @@ internal class GitLabMergeRequestDiffProcessorViewModelImpl(
|
||||
private val changesFetchFlow = computationStateFlow(mergeRequest.changes, GitLabMergeRequestChanges::loadRevisionsAndParseChanges)
|
||||
private val changesSorter = project.service<GitLabMergeRequestsPreferences>().changesGroupingState
|
||||
.map {
|
||||
{ changes: ListSelection<RefComparisonChange> ->
|
||||
{ changes: List<RefComparisonChange> ->
|
||||
RefComparisonChangesSorter.Grouping(project, it).sort(changes)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user