mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-2640 Data View | Fix | Fix view's relations logic (#1384)
This commit is contained in:
parent
0d899ada9d
commit
068abfe1cd
2 changed files with 44 additions and 14 deletions
|
@ -3,6 +3,7 @@ package com.anytypeio.anytype.presentation.mapper
|
|||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.DVFilterCondition
|
||||
import com.anytypeio.anytype.core_models.DVFilterOperator
|
||||
import com.anytypeio.anytype.core_models.DVViewerRelation
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
|
@ -621,6 +622,22 @@ fun List<Block.Content.DataView.Viewer.ViewerRelation>.toViewerColumns(
|
|||
return columns
|
||||
}
|
||||
|
||||
fun List<ObjectWrapper.Relation>.mapToSimpleRelationView(
|
||||
viewerRelations: List<DVViewerRelation>
|
||||
): List<SimpleRelationView> = this.map { dataViewRelation ->
|
||||
val isVisible =
|
||||
viewerRelations.firstOrNull { it.key == dataViewRelation.key }?.isVisible ?: false
|
||||
SimpleRelationView(
|
||||
key = dataViewRelation.key,
|
||||
title = dataViewRelation.name.orEmpty(),
|
||||
format = dataViewRelation.format.toView(),
|
||||
isVisible = isVisible,
|
||||
isHidden = dataViewRelation.isHidden ?: false,
|
||||
isReadonly = dataViewRelation.isReadonlyValue,
|
||||
isDefault = Relations.systemRelationKeys.contains(dataViewRelation.key)
|
||||
)
|
||||
}
|
||||
|
||||
fun List<Block.Content.DataView.Viewer.ViewerRelation>.toSimpleRelationView(
|
||||
relations: List<ObjectWrapper.Relation>
|
||||
): ArrayList<SimpleRelationView> {
|
||||
|
|
|
@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.DVViewerRelation
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.domain.base.fold
|
||||
|
@ -12,7 +13,7 @@ import com.anytypeio.anytype.domain.objects.StoreOfRelations
|
|||
import com.anytypeio.anytype.domain.relations.DeleteRelationFromDataView
|
||||
import com.anytypeio.anytype.presentation.common.BaseListViewModel
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsRelationDeleteEvent
|
||||
import com.anytypeio.anytype.presentation.mapper.toSimpleRelationView
|
||||
import com.anytypeio.anytype.presentation.mapper.mapToSimpleRelationView
|
||||
import com.anytypeio.anytype.presentation.sets.dataViewState
|
||||
import com.anytypeio.anytype.presentation.sets.filterHiddenRelations
|
||||
import com.anytypeio.anytype.presentation.sets.model.SimpleRelationView
|
||||
|
@ -52,8 +53,9 @@ class ObjectSetSettingsViewModel(
|
|||
|
||||
Timber.d("Found in store: ${inStore.size}, available in index: ${state.dataViewContent.relationLinks.size}")
|
||||
|
||||
val relations = viewer.viewerRelations.toSimpleRelationView(inStore)
|
||||
.filterHiddenRelations()
|
||||
val relations = inStore.mapToSimpleRelationView(
|
||||
viewer.viewerRelations
|
||||
).filterHiddenRelations()
|
||||
.map { view -> ViewerRelationListView.Relation(view) }
|
||||
|
||||
result.addAll(relations)
|
||||
|
@ -177,17 +179,28 @@ class ObjectSetSettingsViewModel(
|
|||
private fun proceedWithVisibilityUpdate(ctx: Id, viewerId: Id, item: SimpleRelationView) {
|
||||
val state = objectState.value.dataViewState() ?: return
|
||||
val viewer = state.viewerById(viewerId) ?: return
|
||||
val viewerRelation = viewer.viewerRelations
|
||||
.find { it.key == item.key }
|
||||
?.copy(isVisible = item.isVisible)
|
||||
?: return
|
||||
val params = UpdateDataViewViewer.Params.ViewerRelation.Replace(
|
||||
ctx = ctx,
|
||||
dv = state.dataViewBlock.id,
|
||||
view = viewer.id,
|
||||
key = item.key,
|
||||
relation = viewerRelation
|
||||
)
|
||||
|
||||
val viewerRelation = viewer.viewerRelations.find { it.key == item.key }
|
||||
val params = if (viewerRelation == null) {
|
||||
UpdateDataViewViewer.Params.ViewerRelation.Add(
|
||||
ctx = ctx,
|
||||
dv = state.dataViewBlock.id,
|
||||
view = viewer.id,
|
||||
relation = DVViewerRelation(
|
||||
key = item.key,
|
||||
isVisible = true
|
||||
)
|
||||
)
|
||||
} else {
|
||||
UpdateDataViewViewer.Params.ViewerRelation.Replace(
|
||||
ctx = ctx,
|
||||
dv = state.dataViewBlock.id,
|
||||
view = viewer.id,
|
||||
key = item.key,
|
||||
relation = viewerRelation.copy(isVisible = item.isVisible)
|
||||
)
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
updateDataViewViewer.async(params).fold(
|
||||
onSuccess = { dispatcher.send(it) },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue