mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-2252 Relations | Fix | Relations search and relation blocks visibility (#968)
This commit is contained in:
parent
45ad524fc2
commit
2c9f86eefb
3 changed files with 39 additions and 24 deletions
|
@ -3,6 +3,7 @@ package com.anytypeio.anytype.domain.search
|
|||
import com.anytypeio.anytype.core_models.DVFilter
|
||||
import com.anytypeio.anytype.core_models.DVFilterCondition
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Marketplace
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.domain.workspace.SpaceManager
|
||||
|
@ -21,7 +22,7 @@ class RelationsSubscriptionManager @Inject constructor(
|
|||
private val spaceManager: SpaceManager
|
||||
) {
|
||||
private val pipeline = spaceManager.observe().flatMapLatest { config ->
|
||||
val params = buildParams(config.space)
|
||||
val params = buildParams(listOf(config.space, config.techSpace, Marketplace.MARKETPLACE_SPACE_ID))
|
||||
container.observe(params)
|
||||
}
|
||||
|
||||
|
@ -32,7 +33,7 @@ class RelationsSubscriptionManager @Inject constructor(
|
|||
job = scope.launch { pipeline.collect() }
|
||||
}
|
||||
|
||||
private fun buildParams(space: Id) = RelationsSubscriptionContainer.Params(
|
||||
private fun buildParams(spaces: List<Id>) = RelationsSubscriptionContainer.Params(
|
||||
subscription = RelationsSubscriptionContainer.SUBSCRIPTION_ID,
|
||||
filters = listOf(
|
||||
DVFilter(
|
||||
|
@ -42,13 +43,18 @@ class RelationsSubscriptionManager @Inject constructor(
|
|||
),
|
||||
DVFilter(
|
||||
relation = Relations.IS_DELETED,
|
||||
condition = DVFilterCondition.EQUAL,
|
||||
value = false
|
||||
condition = DVFilterCondition.NOT_EQUAL,
|
||||
value = true
|
||||
),
|
||||
DVFilter(
|
||||
relation = Relations.IS_ARCHIVED,
|
||||
condition = DVFilterCondition.NOT_EQUAL,
|
||||
value = true
|
||||
),
|
||||
DVFilter(
|
||||
relation = Relations.SPACE_ID,
|
||||
condition = DVFilterCondition.EQUAL,
|
||||
value = space
|
||||
condition = DVFilterCondition.IN,
|
||||
value = spaces
|
||||
)
|
||||
),
|
||||
limit = 0,
|
||||
|
|
|
@ -37,11 +37,10 @@ fun ObjectWrapper.Relation.view(
|
|||
values: Map<String, Any?>,
|
||||
urlBuilder: UrlBuilder,
|
||||
isFeatured: Boolean = false
|
||||
): ObjectRelationView? {
|
||||
): ObjectRelationView {
|
||||
val relation = this
|
||||
return when {
|
||||
relation.isHidden == true -> null
|
||||
relation.format == RelationFormat.OBJECT -> {
|
||||
return when (relation.format) {
|
||||
RelationFormat.OBJECT -> {
|
||||
val objects = values.buildRelationValueObjectViews(
|
||||
relationKey = relation.key,
|
||||
details = details.details,
|
||||
|
@ -57,7 +56,7 @@ fun ObjectWrapper.Relation.view(
|
|||
system = relation.key.isSystemKey()
|
||||
)
|
||||
}
|
||||
relation.format == RelationFormat.FILE -> {
|
||||
RelationFormat.FILE -> {
|
||||
val files = values.buildFileViews(
|
||||
relationKey = relation.key,
|
||||
details = details.details
|
||||
|
@ -72,7 +71,7 @@ fun ObjectWrapper.Relation.view(
|
|||
system = relation.key.isSystemKey()
|
||||
)
|
||||
}
|
||||
relation.format == RelationFormat.DATE -> {
|
||||
RelationFormat.DATE -> {
|
||||
//TODO In DataView Relation Date uses DateFormat and TimeFormat
|
||||
// so SimpleDateFormat can be different from what we have here
|
||||
// see {SetsExtension:buildGridRow()}
|
||||
|
@ -96,7 +95,7 @@ fun ObjectWrapper.Relation.view(
|
|||
system = relation.key.isSystemKey()
|
||||
)
|
||||
}
|
||||
relation.format == RelationFormat.STATUS -> {
|
||||
RelationFormat.STATUS -> {
|
||||
val options = buildList {
|
||||
when(val value = values[relation.key]) {
|
||||
is Id -> {
|
||||
|
@ -133,7 +132,7 @@ fun ObjectWrapper.Relation.view(
|
|||
system = relation.key.isSystemKey()
|
||||
)
|
||||
}
|
||||
relation.format == RelationFormat.TAG -> {
|
||||
RelationFormat.TAG -> {
|
||||
val options = buildList {
|
||||
when(val value = values[relation.key]) {
|
||||
is Id -> {
|
||||
|
@ -170,7 +169,7 @@ fun ObjectWrapper.Relation.view(
|
|||
system = relation.key.isSystemKey()
|
||||
)
|
||||
}
|
||||
relation.format == RelationFormat.CHECKBOX -> {
|
||||
RelationFormat.CHECKBOX -> {
|
||||
ObjectRelationView.Checkbox(
|
||||
id = relation.id,
|
||||
key = relation.key,
|
||||
|
@ -181,7 +180,7 @@ fun ObjectWrapper.Relation.view(
|
|||
system = relation.key.isSystemKey()
|
||||
)
|
||||
}
|
||||
relation.format == RelationFormat.NUMBER -> {
|
||||
RelationFormat.NUMBER -> {
|
||||
val value = values[relation.key]
|
||||
ObjectRelationView.Default(
|
||||
id = relation.id,
|
||||
|
|
|
@ -46,6 +46,8 @@ class RelationTextValueViewModel(
|
|||
val title = MutableStateFlow("")
|
||||
val isDismissed = MutableStateFlow<Boolean>(false)
|
||||
|
||||
private var isEditableRelation = false
|
||||
|
||||
private val jobs = mutableListOf<Job>()
|
||||
|
||||
fun onDateStart(
|
||||
|
@ -74,17 +76,16 @@ class RelationTextValueViewModel(
|
|||
values.subscribe(ctx = ctx, target = objectId)
|
||||
) { relation, values ->
|
||||
Timber.d("combine, relation:[$relation], values:[$values]")
|
||||
setupIsRelationNotEditable(relation, isLocked)
|
||||
val obj = ObjectWrapper.Basic(values)
|
||||
val value = values[relationKey]?.toString()
|
||||
val isValueReadOnly = values[Relations.IS_READ_ONLY] as? Boolean ?: false
|
||||
val isValueEditable = !(isValueReadOnly || isLocked)
|
||||
title.value = relation.name.orEmpty()
|
||||
when (relation.format) {
|
||||
RelationFormat.SHORT_TEXT -> {
|
||||
views.value = listOf(
|
||||
RelationTextValueView.TextShort(
|
||||
value = value,
|
||||
isEditable = isValueEditable
|
||||
isEditable = isEditableRelation
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -92,7 +93,7 @@ class RelationTextValueViewModel(
|
|||
views.value = listOf(
|
||||
RelationTextValueView.Text(
|
||||
value = value,
|
||||
isEditable = isValueEditable
|
||||
isEditable = isEditableRelation
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ class RelationTextValueViewModel(
|
|||
views.value = listOf(
|
||||
RelationTextValueView.Number(
|
||||
value = NumberParser.parse(value),
|
||||
isEditable = isValueEditable
|
||||
isEditable = isEditableRelation
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ class RelationTextValueViewModel(
|
|||
views.value = listOf(
|
||||
RelationTextValueView.Url(
|
||||
value = value,
|
||||
isEditable = isValueEditable
|
||||
isEditable = isEditableRelation
|
||||
)
|
||||
)
|
||||
actions.value = buildList {
|
||||
|
@ -131,7 +132,7 @@ class RelationTextValueViewModel(
|
|||
views.value = listOf(
|
||||
RelationTextValueView.Email(
|
||||
value = value,
|
||||
isEditable = isValueEditable
|
||||
isEditable = isEditableRelation
|
||||
)
|
||||
)
|
||||
if (value != null) {
|
||||
|
@ -145,7 +146,7 @@ class RelationTextValueViewModel(
|
|||
views.value = listOf(
|
||||
RelationTextValueView.Phone(
|
||||
value = value,
|
||||
isEditable = isValueEditable
|
||||
isEditable = isEditableRelation
|
||||
)
|
||||
)
|
||||
if (value != null) {
|
||||
|
@ -266,6 +267,15 @@ class RelationTextValueViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupIsRelationNotEditable(relation: ObjectWrapper.Relation, isLocked: Boolean) {
|
||||
isEditableRelation = !(isLocked
|
||||
|| relation.isReadonlyValue
|
||||
|| relation.isHidden == true
|
||||
|| relation.isDeleted == true
|
||||
|| relation.isArchived == true
|
||||
|| !relation.isValid)
|
||||
}
|
||||
|
||||
class Factory(
|
||||
private val relations: ObjectRelationProvider,
|
||||
private val values: ObjectValueProvider,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue