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

DROID-3424 Primitives | Updating the logic of adding a new Property to a Type (#2154)

This commit is contained in:
Konstantin Ivanov 2025-03-13 10:10:47 +01:00 committed by GitHub
parent 3512703594
commit 3d929005b1
Signed by: github
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 43 deletions

View file

@ -199,6 +199,9 @@ sealed class ObjectWrapper {
else -> emptyList()
}
val allRecommendedRelations: List<Id>
get() = recommendedRelations + recommendedFeaturedRelations + recommendedHiddenRelations + recommendedFileRelations
}
data class Relation(override val map: Struct) : ObjectWrapper() {

View file

@ -54,6 +54,32 @@ fun HorizontalButtons(
shape = RoundedCornerShape(size = 8.dp)
)
if (uiFieldsButtonState is UiFieldsButtonState.Visible) {
Row(
modifier = modifierButton.noRippleThrottledClickable {
onTypeEvent(TypeEvent.OnFieldsButtonClick)
},
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier
.wrapContentSize()
.padding(start = 12.dp),
text = stringResource(R.string.button_fields),
style = PreviewTitle2Medium,
color = colorResource(R.color.text_primary)
)
Text(
modifier = Modifier
.wrapContentSize()
.padding(start = 6.dp, end = 12.dp),
text = uiFieldsButtonState.count.toString(),
style = PreviewTitle2Medium,
color = colorResource(R.color.glyph_active)
)
}
}
if (uiLayoutButtonState is UiLayoutButtonState.Visible) {
Row(
modifier = modifierButton.noRippleThrottledClickable {
@ -81,31 +107,6 @@ fun HorizontalButtons(
)
}
}
if (uiFieldsButtonState is UiFieldsButtonState.Visible) {
Row(
modifier = modifierButton.noRippleThrottledClickable {
onTypeEvent(TypeEvent.OnFieldsButtonClick)
},
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier
.wrapContentSize()
.padding(start = 12.dp),
text = stringResource(R.string.button_fields),
style = PreviewTitle2Medium,
color = colorResource(R.color.text_primary)
)
Text(
modifier = Modifier
.wrapContentSize()
.padding(start = 6.dp, end = 12.dp),
text = uiFieldsButtonState.count.toString(),
style = PreviewTitle2Medium,
color = colorResource(R.color.glyph_active)
)
}
}
if (uiTemplatesButtonState is UiTemplatesButtonState.Visible) {
Row(

View file

@ -3,7 +3,6 @@ package com.anytypeio.anytype.feature_properties
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_ui.extensions.simpleIcon
@ -89,13 +88,12 @@ class EditTypePropertiesViewModel(
) { _, _, queryText ->
val objType = storeOfObjectTypes.get(id = vmParams.objectTypeId)
if (objType != null) {
val typeKeys =
objType.recommendedRelations + objType.recommendedFeaturedRelations + objType.recommendedFileRelations + objType.recommendedHiddenRelations
queryText to filterProperties(
allProperties = storeOfRelations.getAll(),
typeKeys = typeKeys,
val filteredAllSpaceProperties = filterSpacePropertiesByTypeIds(
allSpaceProperties = storeOfRelations.getAll(),
objTypeIds = objType.allRecommendedRelations,
queryText = queryText
)
queryText to filteredAllSpaceProperties
} else {
Timber.w("Object type:[${vmParams.objectTypeId}] not found in the store")
queryText to emptyList()
@ -106,10 +104,10 @@ class EditTypePropertiesViewModel(
UiEditTypePropertiesErrorState.Reason.Other("Error while filtering properties")
)
}
.collect { (queryText, filteredProperties) ->
.collect { (queryText, filteredAllSpaceProperties) ->
val sortedExistingItems = filteredProperties.mapNotNull { field ->
field.mapToStateItem(
val sortedExistingItems = filteredAllSpaceProperties.mapNotNull { property ->
property.mapToStateItem(
stringResourceProvider = stringResourceProvider
)
}.sortedBy { it.title }
@ -174,14 +172,14 @@ class EditTypePropertiesViewModel(
}
}
private fun filterProperties(
allProperties: List<ObjectWrapper.Relation>,
typeKeys: List<Key>,
private fun filterSpacePropertiesByTypeIds(
allSpaceProperties: List<ObjectWrapper.Relation>,
objTypeIds: List<Id>,
queryText: String
): List<ObjectWrapper.Relation> = allProperties.filter { field ->
field.key !in typeKeys &&
field.isValidToUse &&
(queryText.isBlank() || field.name?.contains(queryText, ignoreCase = true) == true)
): List<ObjectWrapper.Relation> = allSpaceProperties.filter { property ->
property.id !in objTypeIds &&
property.isValidToUse &&
(queryText.isBlank() || property.name?.contains(queryText, ignoreCase = true) == true)
}
fun hideError() {

View file

@ -788,7 +788,7 @@
<string name="set">Set</string>
<string name="collection">Collection</string>
<string name="layout">Layout</string>
<string name="button_fields">Fields</string>
<string name="button_fields">Properties</string>
<string name="button_layout">Layout</string>
<string name="button_templates">Templates</string>
<string name="restore_from_archive">Restore from archive</string>
@ -1876,7 +1876,7 @@ Please provide specific details of your needs here.</string>
<string name="object_type_fields_new_field">New field</string>
<string name="object_type_fields_preview_field">Preview field</string>
<string name="object_type_fields_btn_save">Save</string>
<string name="object_type_fields_menu_delete">Delete</string>
<string name="object_type_fields_menu_delete">Unlink from type</string>
<string name="object_type_fields_menu_add_to_type">Add to the current type</string>
<string name="object_type_fields_menu_remove">Remove</string>
<string name="object_type_fields_local_info_title">Local fields</string>