mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-11 10:18:05 +09:00
Relations | Apply target object types for relations when searching for an object for relation value (#2040)
This commit is contained in:
parent
bbd56b0846
commit
75be1a13a9
14 changed files with 106 additions and 44 deletions
|
@ -2,13 +2,17 @@
|
|||
|
||||
## Version 0.5.1 (WIP)
|
||||
|
||||
### New features & enhancements 🚀
|
||||
|
||||
* Relations | Apply target object types in filtering when searching for an object for a relation's value (#2040)
|
||||
* Objects and sets | Close objects and sets after moving to bin (#2038)
|
||||
|
||||
### Design & UX 🔳
|
||||
|
||||
* Sets | Fix tag and status colors for night mode for lists (#2030)
|
||||
|
||||
### Fixes & tech 🚒
|
||||
|
||||
* Objects and sets | Close objects and sets after moving to bin (#2038)
|
||||
* Editor | Failing to render objects containing at least one file block with embedded pdf (#2037)
|
||||
* Editor | When trying to set a link to an object or to a web page for a text selection, the dedicated screen should not block the editor when the bottom sheet is hidden by swiping down (#2036)
|
||||
|
||||
|
|
|
@ -953,7 +953,7 @@ open class EditorFragment : NavigationFragment(R.layout.fragment_editor),
|
|||
SelectProgrammingLanguageFragment.new(command.target)
|
||||
.show(childFragmentManager, null)
|
||||
}
|
||||
is Command.OpenObjectRelationScreen.Add -> {
|
||||
is Command.OpenObjectRelationScreen.RelationAdd -> {
|
||||
hideKeyboard()
|
||||
RelationListFragment
|
||||
.new(
|
||||
|
@ -963,7 +963,7 @@ open class EditorFragment : NavigationFragment(R.layout.fragment_editor),
|
|||
)
|
||||
.show(childFragmentManager, null)
|
||||
}
|
||||
is Command.OpenObjectRelationScreen.List -> {
|
||||
is Command.OpenObjectRelationScreen.RelationList -> {
|
||||
hideKeyboard()
|
||||
findNavController().navigate(
|
||||
R.id.objectRelationListScreen,
|
||||
|
@ -979,7 +979,8 @@ open class EditorFragment : NavigationFragment(R.layout.fragment_editor),
|
|||
val fr = RelationValueFragment.new(
|
||||
ctx = command.ctx,
|
||||
target = command.target,
|
||||
relation = command.relation
|
||||
relation = command.relation,
|
||||
targetObjectTypes = command.targetObjectTypes
|
||||
)
|
||||
fr.show(childFragmentManager, null)
|
||||
}
|
||||
|
|
|
@ -168,7 +168,8 @@ open class RelationListFragment : BaseBottomSheetFragment(),
|
|||
bundleOf(
|
||||
RelationValueBaseFragment.CTX_KEY to command.ctx,
|
||||
RelationValueBaseFragment.TARGET_KEY to command.target,
|
||||
RelationValueBaseFragment.RELATION_KEY to command.relation
|
||||
RelationValueBaseFragment.RELATION_KEY to command.relation,
|
||||
RelationValueBaseFragment.TARGET_TYPES_KEY to command.targetObjectTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ class RelationObjectValueAddFragment : BaseDialogFragment() {
|
|||
private val ctx get() = argString(CONTEXT_ID)
|
||||
private val objectId get() = argString(OBJECT_ID)
|
||||
private val relationId get() = argString(RELATION_ID)
|
||||
private val types get() = arg<List<String>>(TARGET_TYPES)
|
||||
private val flow get() = arg<Int>(FLOW_KEY)
|
||||
|
||||
private lateinit var searchRelationInput: EditText
|
||||
|
@ -103,7 +104,7 @@ class RelationObjectValueAddFragment : BaseDialogFragment() {
|
|||
}
|
||||
super.onStart()
|
||||
setupAppearance()
|
||||
vm.onStart(objectId = objectId, relationId = relationId)
|
||||
vm.onStart(objectId = objectId, relationId = relationId, targetTypes = types)
|
||||
}
|
||||
|
||||
private fun observeState(state: ObjectValueAddView) {
|
||||
|
@ -162,12 +163,14 @@ class RelationObjectValueAddFragment : BaseDialogFragment() {
|
|||
ctx: Id,
|
||||
objectId: Id,
|
||||
relationId: Id,
|
||||
types: List<Id>,
|
||||
flow: Int = FLOW_DEFAULT
|
||||
) = RelationObjectValueAddFragment().apply {
|
||||
arguments = bundleOf(
|
||||
CONTEXT_ID to ctx,
|
||||
OBJECT_ID to objectId,
|
||||
RELATION_ID to relationId,
|
||||
TARGET_TYPES to types,
|
||||
FLOW_KEY to flow
|
||||
)
|
||||
}
|
||||
|
@ -175,6 +178,7 @@ class RelationObjectValueAddFragment : BaseDialogFragment() {
|
|||
const val CONTEXT_ID = "arg.relation.add.object.context"
|
||||
const val RELATION_ID = "arg.relation.add.object.relation.id"
|
||||
const val OBJECT_ID = "arg.relation.add.object.object.id"
|
||||
const val TARGET_TYPES = "arg.relation.add.object.target_types"
|
||||
const val FLOW_KEY = "arg.relation.add.object.flow"
|
||||
const val FLOW_DEFAULT = 0
|
||||
const val FLOW_DATAVIEW = 1
|
||||
|
|
|
@ -59,6 +59,7 @@ abstract class RelationValueBaseFragment : BaseBottomSheetFragment(),
|
|||
protected val target get() = argString(TARGET_KEY)
|
||||
protected val dataview get() = argString(DATAVIEW_KEY)
|
||||
protected val viewer get() = argString(VIEWER_KEY)
|
||||
protected val types get() = arg<List<String>>(TARGET_TYPES_KEY)
|
||||
|
||||
abstract val vm: RelationValueBaseViewModel
|
||||
|
||||
|
@ -364,6 +365,7 @@ abstract class RelationValueBaseFragment : BaseBottomSheetFragment(),
|
|||
const val TARGET_KEY = "arg.edit-cell-tag.target"
|
||||
const val DATAVIEW_KEY = "arg.edit-cell-tag.dataview"
|
||||
const val VIEWER_KEY = "arg.edit-cell-tag.viewer"
|
||||
const val TARGET_TYPES_KEY = "arg.relation-value.target-types"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,6 +460,7 @@ open class RelationValueDVFragment : RelationValueBaseFragment() {
|
|||
ctx = ctx,
|
||||
relationId = relation,
|
||||
objectId = target,
|
||||
types = types,
|
||||
flow = fragmentFlow
|
||||
)
|
||||
fr.show(childFragmentManager, null)
|
||||
|
@ -623,7 +626,8 @@ class RelationValueFragment : RelationValueBaseFragment() {
|
|||
val fr = RelationObjectValueAddFragment.new(
|
||||
ctx = ctx,
|
||||
relationId = relation,
|
||||
objectId = target
|
||||
objectId = target,
|
||||
types = types
|
||||
)
|
||||
fr.show(childFragmentManager, null)
|
||||
}
|
||||
|
@ -691,12 +695,14 @@ class RelationValueFragment : RelationValueBaseFragment() {
|
|||
fun new(
|
||||
ctx: Id,
|
||||
target: Id,
|
||||
relation: Id
|
||||
relation: Id,
|
||||
targetObjectTypes: List<Id>
|
||||
) = RelationValueFragment().apply {
|
||||
arguments = bundleOf(
|
||||
CTX_KEY to ctx,
|
||||
TARGET_KEY to target,
|
||||
RELATION_KEY to relation
|
||||
RELATION_KEY to relation,
|
||||
TARGET_TYPES_KEY to targetObjectTypes
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -500,7 +500,8 @@ open class ObjectSetFragment :
|
|||
RelationValueBaseFragment.TARGET_KEY to command.target,
|
||||
RelationValueBaseFragment.DATAVIEW_KEY to command.dataview,
|
||||
RelationValueBaseFragment.RELATION_KEY to command.relation,
|
||||
RelationValueBaseFragment.VIEWER_KEY to command.viewer
|
||||
RelationValueBaseFragment.VIEWER_KEY to command.viewer,
|
||||
RelationValueBaseFragment.TARGET_TYPES_KEY to command.targetObjectTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1820,7 +1820,7 @@ class EditorViewModel(
|
|||
|
||||
fun onDocRelationsClicked() {
|
||||
Timber.d("onDocRelationsClicked, ")
|
||||
dispatch(Command.OpenObjectRelationScreen.List(ctx = context, target = null))
|
||||
dispatch(Command.OpenObjectRelationScreen.RelationList(ctx = context, target = null))
|
||||
}
|
||||
|
||||
fun onSearchToolbarEvent(event: SearchInDocEvent) {
|
||||
|
@ -3338,7 +3338,7 @@ class EditorViewModel(
|
|||
is ListenerType.Relation.Placeholder -> {
|
||||
when (mode) {
|
||||
EditorMode.Edit -> dispatch(
|
||||
Command.OpenObjectRelationScreen.Add(
|
||||
Command.OpenObjectRelationScreen.RelationAdd(
|
||||
ctx = context,
|
||||
target = clicked.target
|
||||
)
|
||||
|
@ -3394,7 +3394,8 @@ class EditorViewModel(
|
|||
Command.OpenObjectRelationScreen.Value.Default(
|
||||
ctx = context,
|
||||
target = context,
|
||||
relation = relationId
|
||||
relation = relationId,
|
||||
targetObjectTypes = relation.objectTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -3463,7 +3464,8 @@ class EditorViewModel(
|
|||
Command.OpenObjectRelationScreen.Value.Default(
|
||||
ctx = context,
|
||||
target = context,
|
||||
relation = relationId
|
||||
relation = relationId,
|
||||
targetObjectTypes = relation.objectTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.anytypeio.anytype.presentation.editor.editor
|
|||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.SmartBlockType
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
|
||||
|
||||
sealed class Command {
|
||||
|
||||
|
@ -87,17 +86,27 @@ sealed class Command {
|
|||
}
|
||||
|
||||
sealed class OpenObjectRelationScreen : Command() {
|
||||
data class List(val ctx: String, val target: String?) : OpenObjectRelationScreen()
|
||||
data class Add(val ctx: String, val target: String) : OpenObjectRelationScreen()
|
||||
data class RelationList(val ctx: String, val target: String?) : OpenObjectRelationScreen()
|
||||
data class RelationAdd(val ctx: String, val target: String) : OpenObjectRelationScreen()
|
||||
sealed class Value : OpenObjectRelationScreen() {
|
||||
data class Default(val ctx: Id, val target: Id, val relation: Id) :
|
||||
OpenObjectRelationScreen.Value()
|
||||
data class Default(
|
||||
val ctx: Id,
|
||||
val target: Id,
|
||||
val relation: Id,
|
||||
val targetObjectTypes: List<Id>
|
||||
) : OpenObjectRelationScreen.Value()
|
||||
|
||||
data class Text(val ctx: Id, val target: Id, val relation: Id) :
|
||||
OpenObjectRelationScreen.Value()
|
||||
data class Text(
|
||||
val ctx: Id,
|
||||
val target: Id,
|
||||
val relation: Id
|
||||
) : OpenObjectRelationScreen.Value()
|
||||
|
||||
data class Date(val ctx: Id, val target: Id, val relation: Id) :
|
||||
OpenObjectRelationScreen.Value()
|
||||
data class Date(
|
||||
val ctx: Id,
|
||||
val target: Id,
|
||||
val relation: Id
|
||||
) : OpenObjectRelationScreen.Value()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +132,7 @@ sealed class Command {
|
|||
val target: Id
|
||||
) : Command()
|
||||
|
||||
object ShowTextLinkMenu: Command()
|
||||
object ShowTextLinkMenu : Command()
|
||||
|
||||
data class SaveTextToSystemClipboard(val text: String) : Command()
|
||||
}
|
|
@ -206,7 +206,8 @@ class RelationListViewModel(
|
|||
Command.EditRelationValue(
|
||||
ctx = ctx,
|
||||
relation = view.relationId,
|
||||
target = ctx
|
||||
target = ctx,
|
||||
targetObjectTypes = relation.objectTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -304,7 +305,8 @@ class RelationListViewModel(
|
|||
data class EditRelationValue(
|
||||
val ctx: Id,
|
||||
val relation: Id,
|
||||
val target: Id
|
||||
val target: Id,
|
||||
val targetObjectTypes: List<Id>
|
||||
) : Command()
|
||||
|
||||
data class SetRelationKey(
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.anytypeio.anytype.presentation.relations
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.*
|
||||
import com.anytypeio.anytype.core_utils.ext.typeOf
|
||||
import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider
|
||||
import com.anytypeio.anytype.domain.dataview.interactor.SearchObjects
|
||||
|
@ -33,24 +33,27 @@ class RelationObjectValueAddViewModel(
|
|||
val commands = MutableSharedFlow<ObjectValueAddCommand>(0)
|
||||
val viewsFiltered: StateFlow<ObjectValueAddView> = _viewsFiltered
|
||||
|
||||
fun onStart(relationId: Id, objectId: String) {
|
||||
fun onStart(relationId: Id, objectId: String, targetTypes: List<Id>) {
|
||||
processingViewsSelectionsAndFilter()
|
||||
val relation = relations.get(relationId)
|
||||
val values = values.get(objectId)
|
||||
when (val ids = values[relation.key]) {
|
||||
is List<*> -> {
|
||||
proceedWithSearchObjects(
|
||||
ids = ids.typeOf()
|
||||
ids = ids.typeOf(),
|
||||
targetTypes = targetTypes
|
||||
)
|
||||
}
|
||||
is Id -> {
|
||||
proceedWithSearchObjects(
|
||||
ids = listOf(ids)
|
||||
ids = listOf(ids),
|
||||
targetTypes = targetTypes
|
||||
)
|
||||
}
|
||||
null -> {
|
||||
proceedWithSearchObjects(
|
||||
ids = emptyList()
|
||||
ids = emptyList(),
|
||||
targetTypes = targetTypes
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -121,12 +124,38 @@ class RelationObjectValueAddViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun proceedWithSearchObjects(ids: List<String>) {
|
||||
private fun proceedWithSearchObjects(
|
||||
ids: List<String>,
|
||||
targetTypes: List<Id>
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val filters = mutableListOf<DVFilter>()
|
||||
filters.addAll(ObjectSearchConstants.filterAddObjectToRelation)
|
||||
if (targetTypes.isEmpty()) {
|
||||
filters.add(
|
||||
DVFilter(
|
||||
relationKey = Relations.TYPE,
|
||||
condition = DVFilterCondition.NOT_IN,
|
||||
value = listOf(
|
||||
ObjectType.OBJECT_TYPE_URL,
|
||||
ObjectType.RELATION_URL,
|
||||
ObjectType.TEMPLATE_URL
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
filters.add(
|
||||
DVFilter(
|
||||
relationKey = Relations.TYPE,
|
||||
condition = DVFilterCondition.IN,
|
||||
value = targetTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
searchObjects(
|
||||
SearchObjects.Params(
|
||||
sorts = ObjectSearchConstants.sortAddObjectToRelation,
|
||||
filters = ObjectSearchConstants.filterAddObjectToRelation,
|
||||
filters = filters,
|
||||
fulltext = SearchObjects.EMPTY_TEXT,
|
||||
offset = SearchObjects.INIT_OFFSET,
|
||||
limit = SearchObjects.LIMIT
|
||||
|
|
|
@ -129,15 +129,6 @@ object ObjectSearchConstants {
|
|||
relationKey = Relations.IS_HIDDEN,
|
||||
condition = DVFilterCondition.NOT_EQUAL,
|
||||
value = true
|
||||
),
|
||||
DVFilter(
|
||||
relationKey = Relations.TYPE,
|
||||
condition = DVFilterCondition.NOT_IN,
|
||||
value = listOf(
|
||||
OBJECT_TYPE_URL,
|
||||
RELATION_URL,
|
||||
TEMPLATE_URL
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ sealed class ObjectSetCommand {
|
|||
val dataview: Id,
|
||||
val target: Id,
|
||||
val relation: Id,
|
||||
val targetObjectTypes: List<Id>,
|
||||
val viewer: Id
|
||||
) : Modal()
|
||||
|
||||
|
|
|
@ -436,13 +436,23 @@ class ObjectSetViewModel(
|
|||
)
|
||||
}
|
||||
is CellView.Tag, is CellView.Status, is CellView.Object, is CellView.File -> {
|
||||
val targetObjectTypes = mutableListOf<String>()
|
||||
if (cell is CellView.Object) {
|
||||
val relation = reducer.state.value.dataview.content<DV>().relations.find { relation ->
|
||||
relation.key == cell.key
|
||||
}
|
||||
if (relation != null) {
|
||||
targetObjectTypes.addAll(relation.objectTypes)
|
||||
}
|
||||
}
|
||||
dispatch(
|
||||
ObjectSetCommand.Modal.EditRelationCell(
|
||||
ctx = context,
|
||||
target = cell.id,
|
||||
dataview = block.id,
|
||||
relation = cell.key,
|
||||
viewer = viewer
|
||||
viewer = viewer,
|
||||
targetObjectTypes = targetObjectTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -166,7 +166,8 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
|
|||
dataview = dv.id,
|
||||
target = firstRecordId,
|
||||
viewer = viewer.id,
|
||||
relation = linkedProjectRelation.key
|
||||
relation = linkedProjectRelation.key,
|
||||
targetObjectTypes = emptyList()
|
||||
)
|
||||
)
|
||||
cancelAndConsumeRemainingEvents()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue