1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-3472 Primitives | Updating the logic for displaying properties for Template objects (#2311)

This commit is contained in:
Konstantin Ivanov 2025-04-14 17:57:05 +02:00 committed by GitHub
parent 0b06e88ae7
commit acefea1db9
Signed by: github
GPG key ID: B5690EEEBB952194
5 changed files with 202 additions and 22 deletions

View file

@ -48,7 +48,7 @@ interface FieldParser {
): Pair<Id?, String?>
suspend fun getObjectParsedProperties(
objectType: ObjectWrapper.Type,
objectType: ObjectWrapper.Type?,
objPropertiesKeys: List<Key>,
storeOfRelations: StoreOfRelations
): ParsedProperties
@ -236,11 +236,24 @@ class FieldParserImpl @Inject constructor(
// Consolidated function to build Parsed Properties.
private suspend fun getParsedProperties(
objType: ObjectWrapper.Type,
objType: ObjectWrapper.Type?,
localPropertiesIds: Collection<Id>,
storeOfRelations: StoreOfRelations
): ParsedProperties {
if (objType == null || !objType.isValid || objType.isDeleted == true) {
val allLocalProperties = storeOfRelations.getValidRelations(
ids = localPropertiesIds.toList()
)
return ParsedProperties(
header = emptyList(),
sidebar = emptyList(),
hidden = emptyList(),
local = allLocalProperties,
file = emptyList()
)
}
// Clean recommended IDs based on priority.
// recommendedFeaturedRelations always remain.
val featuredIds = objType.recommendedFeaturedRelations.distinct()
@ -286,7 +299,7 @@ class FieldParserImpl @Inject constructor(
}
override suspend fun getObjectParsedProperties(
objectType: ObjectWrapper.Type,
objectType: ObjectWrapper.Type?,
objPropertiesKeys: List<Key>,
storeOfRelations: StoreOfRelations
): ParsedProperties {

View file

@ -85,9 +85,7 @@ fun AllContentTab.filtersForSubscribe(
addAll(buildDeletedFilter())
add(buildLayoutFilter(layouts = allContentTabLayouts.getValue(tab)))
add(buildSpaceIdFilter(spaces))
if (tab == AllContentTab.PAGES) {
add(buildTemplateFilter())
}
add(buildTemplateFilter())
if (limitedObjectIds.isNotEmpty()) {
add(buildLimitedObjectIdsFilter(limitedObjectIds = limitedObjectIds))
}
@ -108,9 +106,7 @@ fun AllContentTab.filtersForSearch(
val filters = buildList {
addAll(buildDeletedFilter())
add(buildSpaceIdFilter(spaces))
if (tab == AllContentTab.PAGES) {
add(buildTemplateFilter())
}
add(buildTemplateFilter())
}
return filters
}

View file

@ -2,6 +2,7 @@ package com.anytypeio.anytype.feature_object_type
import android.util.Log
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.RelationFormat
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.StubObjectType
@ -261,4 +262,171 @@ class TestFieldsMappping {
actual = parsedFields.hidden
)
}
@Test
fun `should has only local properties when object type is deleted`() = runTest {
storeOfRelations.apply {
merge(allSpaceRelations)
}
val testObjectType = StubObjectType(
isDeleted = true,
recommendedFeaturedRelations = listOf(field1, field1, field2, field3).map { it.id },
recommendedRelations = listOf(field1, field4, field4).map { it.id },
recommendedFileRelations = listOf(field1, field2, field3, field4, field5, field5).map { it.id },
recommendedHiddenRelations = listOf(field1, field2, field3, field4, field5, fieldCreatedDate, fieldCreatedDate).map { it.id },
space = space
)
storeOfObjectTypes.apply {
merge(listOf(testObjectType, fieldAssigneeObjType2, fieldAssigneeObjType1))
}
val parsedFields = fieldParser.getObjectParsedProperties(
objectType = testObjectType,
storeOfRelations = storeOfRelations,
objPropertiesKeys = listOf(
field1.key,
field2.key,
field3.key,
field4.key,
field5.key
),
)
assertEquals(
expected = listOf(),
actual = parsedFields.header
)
assertEquals(
expected = listOf(),
actual = parsedFields.sidebar
)
assertEquals(
expected = listOf(),
actual = parsedFields.file
)
assertEquals(
expected = listOf(),
actual = parsedFields.hidden
)
assertEquals(
expected = listOf(field1, field2, field3, field4, field5),
actual = parsedFields.local
)
}
@Test
fun `should has only local properties when object type is null`() = runTest {
storeOfRelations.apply {
merge(allSpaceRelations)
}
val testObjectType = null
storeOfObjectTypes.apply {
merge(listOf(fieldAssigneeObjType2, fieldAssigneeObjType1))
}
val parsedFields = fieldParser.getObjectParsedProperties(
objectType = testObjectType,
storeOfRelations = storeOfRelations,
objPropertiesKeys = listOf(
field1.key,
field2.key,
field3.key,
field4.key,
field5.key
),
)
assertEquals(
expected = listOf(),
actual = parsedFields.header
)
assertEquals(
expected = listOf(),
actual = parsedFields.sidebar
)
assertEquals(
expected = listOf(),
actual = parsedFields.file
)
assertEquals(
expected = listOf(),
actual = parsedFields.hidden
)
assertEquals(
expected = listOf(field1, field2, field3, field4, field5),
actual = parsedFields.local
)
}
@Test
fun `should has only local properties when object type is not valid`() = runTest {
storeOfRelations.apply {
merge(allSpaceRelations)
}
val testObjectType = ObjectWrapper.Type(
//without UNIQUE_KEY - not valid
map = mapOf(Relations.ID to "test_object_type_id")
)
storeOfObjectTypes.apply {
merge(listOf(testObjectType, fieldAssigneeObjType2, fieldAssigneeObjType1))
}
storeOfObjectTypes.apply {
merge(listOf(fieldAssigneeObjType2, fieldAssigneeObjType1))
}
val parsedFields = fieldParser.getObjectParsedProperties(
objectType = testObjectType,
storeOfRelations = storeOfRelations,
objPropertiesKeys = listOf(
field1.key,
field2.key,
field3.key,
field4.key,
field5.key
),
)
assertEquals(
expected = listOf(),
actual = parsedFields.header
)
assertEquals(
expected = listOf(),
actual = parsedFields.sidebar
)
assertEquals(
expected = listOf(),
actual = parsedFields.file
)
assertEquals(
expected = listOf(),
actual = parsedFields.hidden
)
assertEquals(
expected = listOf(field1, field2, field3, field4, field5),
actual = parsedFields.local
)
}
}

View file

@ -9,7 +9,6 @@ import com.anytypeio.anytype.analytics.base.EventsDictionary.relationsScreenShow
import com.anytypeio.anytype.analytics.base.sendEvent
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.ObjectViewDetails
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Payload
@ -35,9 +34,10 @@ import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate
import com.anytypeio.anytype.presentation.common.BaseViewModel
import com.anytypeio.anytype.presentation.extension.getObject
import com.anytypeio.anytype.presentation.extension.getStruct
import com.anytypeio.anytype.presentation.extension.getTypeForObject
import com.anytypeio.anytype.presentation.extension.sendAnalyticsRelationEvent
import com.anytypeio.anytype.presentation.objects.LockedStateProvider
import com.anytypeio.anytype.presentation.objects.getTypeForObjectAndTargetTypeForTemplate
import com.anytypeio.anytype.presentation.objects.isTemplateObject
import com.anytypeio.anytype.presentation.relations.model.RelationOperationError
import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationListProvider
import com.anytypeio.anytype.presentation.util.Dispatcher
@ -106,19 +106,21 @@ class RelationListViewModel(
details: ObjectViewDetails
): List<Model> {
val objType = details.getTypeForObject(ctx)
_currentObjectTypeId = objType?.id
if (objType == null) {
Timber.w("Failed to get object type for object: $ctx from types store")
val currentObj = details.getObject(ctx)
if (currentObj == null) {
Timber.e("Object with id $ctx not found.")
return emptyList()
}
val objType = currentObj.getTypeForObjectAndTargetTypeForTemplate(storeOfObjectTypes)
uiSettingsIconState.value = if (objType.uniqueKey == ObjectTypeIds.TEMPLATE) {
UiPropertiesSettingsIconState.Hidden
} else {
UiPropertiesSettingsIconState.Shown
}
_currentObjectTypeId = objType?.id
uiSettingsIconState.value =
if (objType == null || objType.isDeleted == true || currentObj.isTemplateObject(storeOfObjectTypes)) {
UiPropertiesSettingsIconState.Hidden
} else {
UiPropertiesSettingsIconState.Shown
}
val parsedFields = fieldParser.getObjectParsedProperties(
objectType = objType,

View file

@ -1728,7 +1728,8 @@ class ObjectSetViewModel(
val target = obj.id
val space = vmParams.space.id
if (obj.isTemplateObject(storeOfObjectTypes = storeOfObjectTypes)) {
// If the object is a Template (and not a Set or Collection), open it in the Modal Template Screen
if (obj.isTemplateObject(storeOfObjectTypes = storeOfObjectTypes) && !obj.layout.isDataView()) {
obj.getTypeForObjectAndTargetTypeForTemplate(storeOfObjectTypes = storeOfObjectTypes)
?.let { objType ->
val event = AppNavigation.Command.OpenModalTemplateEdit(