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

DROID-642 Editor | Suggest marketplace relations for user (#2764)

* DROID-642 legacy relationList useCase

* DROID-642 legacy useCases

* DROID-642 legacy object relations store

* DROID-642 di

* DROID-642 search relations by workspace id

* DROID-642 if else fix

* DROID-642 fix, invoking the wrong method leeded to the loop

* DROID-642 fix relation blocks binding

* DROID-642 navigation fixed

* DROID-642 fix tests
This commit is contained in:
Konstantin Ivanov 2022-12-16 08:48:01 +01:00 committed by GitHub
parent 1eb7ae4c7f
commit 4ac2255dd4
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 357 additions and 433 deletions

View file

@ -26,7 +26,6 @@ import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.objects.StoreOfRelations
import com.anytypeio.anytype.domain.relations.AddToFeaturedRelations
import com.anytypeio.anytype.domain.relations.DeleteRelationFromObject
import com.anytypeio.anytype.domain.relations.ObjectRelationList
import com.anytypeio.anytype.domain.relations.RemoveFromFeaturedRelations
import com.anytypeio.anytype.presentation.editor.Editor
import com.anytypeio.anytype.presentation.editor.editor.DetailModificationManager
@ -80,7 +79,6 @@ class ObjectRelationListTest {
@Mock
lateinit var storeOfRelations: StoreOfRelations
private lateinit var objectRelationList: ObjectRelationList
private lateinit var updateDetail: UpdateDetail
private lateinit var addToFeaturedRelations: AddToFeaturedRelations
private lateinit var removeFromFeaturedRelations: RemoveFromFeaturedRelations
@ -95,7 +93,6 @@ class ObjectRelationListTest {
fun setup() {
MockitoAnnotations.openMocks(this)
urlBuilder = UrlBuilder(gateway)
objectRelationList = ObjectRelationList(repo)
updateDetail = UpdateDetail(repo)
addToFeaturedRelations = AddToFeaturedRelations(repo)
removeFromFeaturedRelations = RemoveFromFeaturedRelations(repo)
@ -103,7 +100,6 @@ class ObjectRelationListTest {
TestRelationListFragment.testVmFactory = ObjectRelationListViewModelFactory(
stores = storage,
urlBuilder = urlBuilder,
objectRelationList = objectRelationList,
dispatcher = dispatcher,
detailModificationManager = detailModificationManager,
updateDetail = updateDetail,

View file

@ -9,7 +9,6 @@ import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.objects.StoreOfRelations
import com.anytypeio.anytype.domain.relations.AddToFeaturedRelations
import com.anytypeio.anytype.domain.relations.DeleteRelationFromObject
import com.anytypeio.anytype.domain.relations.ObjectRelationList
import com.anytypeio.anytype.domain.relations.RemoveFromFeaturedRelations
import com.anytypeio.anytype.presentation.editor.Editor
import com.anytypeio.anytype.presentation.editor.editor.DetailModificationManager
@ -41,7 +40,6 @@ object DocumentRelationModule {
fun provideObjectRelationViewModelFactory(
stores: Editor.Storage,
urlBuilder: UrlBuilder,
objectRelationList: ObjectRelationList,
dispatcher: Dispatcher<Payload>,
updateDetail: UpdateDetail,
detailModificationManager: DetailModificationManager,
@ -54,7 +52,6 @@ object DocumentRelationModule {
return ObjectRelationListViewModelFactory(
stores = stores,
urlBuilder = urlBuilder,
objectRelationList = objectRelationList,
dispatcher = dispatcher,
updateDetail = updateDetail,
detailModificationManager = detailModificationManager,
@ -69,22 +66,18 @@ object DocumentRelationModule {
@JvmStatic
@Provides
@PerModal
fun provideObjectRelationListUseCase(
repository: BlockRepository
) : ObjectRelationList = ObjectRelationList(repository)
fun addToFeaturedRelations(repo: BlockRepository): AddToFeaturedRelations =
AddToFeaturedRelations(repo)
@JvmStatic
@Provides
@PerModal
fun addToFeaturedRelations(repo: BlockRepository) : AddToFeaturedRelations = AddToFeaturedRelations(repo)
fun removeFromFeaturedRelations(repo: BlockRepository): RemoveFromFeaturedRelations =
RemoveFromFeaturedRelations(repo)
@JvmStatic
@Provides
@PerModal
fun removeFromFeaturedRelations(repo: BlockRepository) : RemoveFromFeaturedRelations = RemoveFromFeaturedRelations(repo)
@JvmStatic
@Provides
@PerModal
fun deleteRelationFromObject(repo: BlockRepository) : DeleteRelationFromObject = DeleteRelationFromObject(repo)
fun deleteRelationFromObject(repo: BlockRepository): DeleteRelationFromObject =
DeleteRelationFromObject(repo)
}

View file

@ -10,8 +10,8 @@ import com.anytypeio.anytype.domain.dataview.interactor.UpdateDataViewViewer
import com.anytypeio.anytype.domain.objects.StoreOfRelations
import com.anytypeio.anytype.domain.relations.AddRelationToObject
import com.anytypeio.anytype.domain.relations.GetRelations
import com.anytypeio.anytype.domain.relations.ObjectRelationList
import com.anytypeio.anytype.domain.workspace.AddObjectToWorkspace
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
import com.anytypeio.anytype.presentation.relations.RelationAddToDataViewViewModel
import com.anytypeio.anytype.presentation.relations.RelationAddToObjectViewModel
import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider
@ -54,7 +54,8 @@ object RelationAddToObjectModule {
relationsProvider: ObjectRelationProvider,
getRelations: GetRelations,
appCoroutineDispatchers: AppCoroutineDispatchers,
addObjectToWorkspace: AddObjectToWorkspace
addObjectToWorkspace: AddObjectToWorkspace,
workspaceManager: WorkspaceManager
): RelationAddToObjectViewModel.Factory = RelationAddToObjectViewModel.Factory(
storeOfRelations = storeOfRelations,
addRelationToObject = addRelationToObject,
@ -63,16 +64,10 @@ object RelationAddToObjectModule {
relationsProvider = relationsProvider,
getRelations = getRelations,
appCoroutineDispatchers = appCoroutineDispatchers,
addObjectToWorkspace = addObjectToWorkspace
addObjectToWorkspace = addObjectToWorkspace,
workspaceManager = workspaceManager
)
@JvmStatic
@Provides
@PerDialog
fun provideObjectRelationListUseCase(
repo: BlockRepository
): ObjectRelationList = ObjectRelationList(repo)
@JvmStatic
@Provides
@PerDialog
@ -128,7 +123,8 @@ object RelationAddToDataViewModule {
relationsProvider: ObjectRelationProvider,
appCoroutineDispatchers: AppCoroutineDispatchers,
getRelations: GetRelations,
addObjectToWorkspace: AddObjectToWorkspace
addObjectToWorkspace: AddObjectToWorkspace,
workspaceManager: WorkspaceManager
): RelationAddToDataViewViewModel.Factory = RelationAddToDataViewViewModel.Factory(
addRelationToDataView = addRelationToDataView,
dispatcher = dispatcher,
@ -139,16 +135,10 @@ object RelationAddToDataViewModule {
relationsProvider = relationsProvider,
appCoroutineDispatchers = appCoroutineDispatchers,
getRelations = getRelations,
addObjectToWorkspace = addObjectToWorkspace
addObjectToWorkspace = addObjectToWorkspace,
workspaceManager = workspaceManager
)
@JvmStatic
@Provides
@PerDialog
fun provideObjectRelationListUseCase(
repo: BlockRepository
): ObjectRelationList = ObjectRelationList(repo)
@JvmStatic
@Provides
@PerDialog

View file

@ -136,10 +136,7 @@ import com.anytypeio.anytype.ui.objects.appearance.ObjectAppearanceSettingFragme
import com.anytypeio.anytype.ui.objects.types.pickers.DraftObjectSelectTypeFragment
import com.anytypeio.anytype.ui.objects.types.pickers.ObjectSelectTypeFragment
import com.anytypeio.anytype.ui.objects.types.pickers.OnObjectSelectTypeAction
import com.anytypeio.anytype.ui.relations.RelationAddBaseFragment.Companion.CTX_KEY
import com.anytypeio.anytype.ui.relations.RelationAddResult
import com.anytypeio.anytype.ui.relations.RelationAddToObjectBlockFragment
import com.anytypeio.anytype.ui.relations.RelationAddToObjectBlockFragment.Companion.RELATION_ADD_RESULT_KEY
import com.anytypeio.anytype.ui.relations.RelationCreateFromScratchForObjectBlockFragment.Companion.RELATION_NEW_RESULT_KEY
import com.anytypeio.anytype.ui.relations.RelationDateValueFragment
import com.anytypeio.anytype.ui.relations.RelationListFragment
@ -1107,14 +1104,11 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
}
is Command.OpenAddRelationScreen -> {
hideSoftInput()
findNavController().safeNavigate(
R.id.pageScreen,
R.id.action_pageScreen_to_relationAddToObjectBlockFragment,
bundleOf(
CTX_KEY to command.ctx,
RelationAddToObjectBlockFragment.TARGET_KEY to command.target
)
val fr = RelationAddToObjectBlockFragment.newInstance(
ctx = command.ctx,
target = command.target
)
fr.showChildFragment()
}
is Command.OpenLinkToObjectOrWebScreen -> {
hideSoftInput()
@ -2116,17 +2110,14 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
}
}
override fun onAddRelationToTarget(target: Id, relationKey: Key) {
vm.proceedWithAddingRelationToTarget(
target = target,
relationKey = relationKey
)
}
private fun proceedWithResult(savedStateHandle: SavedStateHandle) {
if (savedStateHandle.contains(RELATION_ADD_RESULT_KEY)) {
val resultRelationAdd = savedStateHandle.get<RelationAddResult>(RELATION_ADD_RESULT_KEY)
savedStateHandle.remove<RelationAddResult>(RELATION_ADD_RESULT_KEY)
if (resultRelationAdd != null) {
vm.proceedWithAddingRelationToTarget(
target = resultRelationAdd.target,
relationKey = resultRelationAdd.relation
)
}
}
if (savedStateHandle.contains(RELATION_NEW_RESULT_KEY)) {
val resultRelationNew = savedStateHandle.get<RelationNewResult>(RELATION_NEW_RESULT_KEY)
savedStateHandle.remove<RelationNewResult>(RELATION_NEW_RESULT_KEY)
@ -2199,4 +2190,5 @@ interface OnFragmentInteractionListener {
fun onSetTextBlockValue()
fun onMentionClicked(target: Id)
fun onCopyLink(link: String)
fun onAddRelationToTarget(target: Id, relationKey: Key)
}

View file

@ -10,7 +10,6 @@ import android.widget.FrameLayout
import androidx.core.os.bundleOf
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
@ -30,6 +29,7 @@ import com.anytypeio.anytype.core_utils.ext.statusBarHeight
import com.anytypeio.anytype.core_utils.ext.subscribe
import com.anytypeio.anytype.core_utils.ext.toast
import com.anytypeio.anytype.core_utils.ext.visible
import com.anytypeio.anytype.core_utils.ext.withParent
import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetTextInputFragment
import com.anytypeio.anytype.databinding.FragmentRelationAddBinding
import com.anytypeio.anytype.di.common.componentManager
@ -37,12 +37,13 @@ import com.anytypeio.anytype.presentation.relations.RelationAddToDataViewViewMod
import com.anytypeio.anytype.presentation.relations.RelationAddToObjectViewModel
import com.anytypeio.anytype.presentation.relations.RelationAddViewModelBase
import com.anytypeio.anytype.presentation.relations.RelationAddViewModelBase.Command
import com.anytypeio.anytype.ui.editor.OnFragmentInteractionListener
import com.google.android.material.bottomsheet.BottomSheetBehavior
import java.io.Serializable
import javax.inject.Inject
abstract class RelationAddBaseFragment : BaseBottomSheetTextInputFragment<FragmentRelationAddBinding>() {
abstract class RelationAddBaseFragment :
BaseBottomSheetTextInputFragment<FragmentRelationAddBinding>() {
abstract val vm: RelationAddViewModelBase
@ -100,7 +101,7 @@ abstract class RelationAddBaseFragment : BaseBottomSheetTextInputFragment<Fragme
if (it.isEmpty()) clearSearchText.invisible() else clearSearchText.visible()
}
subscribe(vm.command) { command ->
when(command) {
when (command) {
is Command.DispatchSelectedRelation -> {
onRelationSelected(
ctx = command.ctx,
@ -157,12 +158,11 @@ class RelationAddToObjectFragment : RelationAddBaseFragment() {
}
override fun onCreateFromScratchClicked() {
RelationCreateFromScratchForObjectFragment
.new(
ctx = ctx,
query = createFromScratchAdapter.query
)
.showChildFragment()
val fr = RelationCreateFromScratchForObjectFragment.new(
ctx = ctx,
query = createFromScratchAdapter.query
)
fr.showChildFragment()
}
override fun injectDependencies() {
@ -200,13 +200,12 @@ class RelationAddToDataViewFragment : RelationAddBaseFragment() {
}
override fun onCreateFromScratchClicked() {
RelationCreateFromScratchForDataViewFragment
.new(
ctx = ctx,
dv = dv,
query = createFromScratchAdapter.query
)
.showChildFragment()
val fr = RelationCreateFromScratchForDataViewFragment.new(
ctx = ctx,
dv = dv,
query = createFromScratchAdapter.query
)
fr.showChildFragment()
}
override fun injectDependencies() {
@ -232,7 +231,8 @@ class RelationAddToDataViewFragment : RelationAddBaseFragment() {
}
}
class RelationAddToObjectBlockFragment : RelationAddBaseFragment() {
class RelationAddToObjectBlockFragment : RelationAddBaseFragment(),
OnCreateFromScratchRelationListener {
override val ctx get() = arg<Id>(CTX_KEY)
private val target get() = arg<Id>(TARGET_KEY)
@ -260,24 +260,34 @@ class RelationAddToObjectBlockFragment : RelationAddBaseFragment() {
private fun execute(command: RelationAddToObjectViewModel.Command) {
when (command) {
is RelationAddToObjectViewModel.Command.OnRelationAdd -> {
findNavController().run {
val result = RelationAddResult(target = target, relation = command.relation)
previousBackStackEntry?.savedStateHandle?.set(RELATION_ADD_RESULT_KEY, result)
popBackStack()
withParent<OnFragmentInteractionListener> {
onAddRelationToTarget(
target = target,
relationKey = command.relation
)
}
dismiss()
}
}
}
override fun onCreateFromScratchClicked() {
findNavController().navigate(
R.id.action_relationAddToObjectBlockFragment_to_relationCreateFromScratchForObjectBlockFragment,
bundleOf(
RelationCreateFromScratchBaseFragment.CTX_KEY to ctx,
RelationCreateFromScratchBaseFragment.QUERY_KEY to createFromScratchAdapter.query,
RelationCreateFromScratchForObjectBlockFragment.TARGET_KEY to target
)
val fr = RelationCreateFromScratchForObjectBlockFragment.newInstance(
ctx = ctx,
target = target,
query = createFromScratchAdapter.query
)
fr.showChildFragment()
}
override fun onCreateRelation(target: Id, relation: Key) {
withParent<OnFragmentInteractionListener> {
onAddRelationToTarget(
target = target,
relationKey = relation
)
}
dismiss()
}
override fun injectDependencies() {
@ -290,8 +300,12 @@ class RelationAddToObjectBlockFragment : RelationAddBaseFragment() {
companion object {
const val TARGET_KEY = "arg.relation-add-to-object-block.target"
const val RELATION_ADD_RESULT_KEY = "arg.relation-add-to-object-block.result"
}
}
data class RelationAddResult(val target: String, val relation: String) : Serializable
fun newInstance(
ctx: Id,
target: Id
): RelationAddToObjectBlockFragment = RelationAddToObjectBlockFragment().apply {
arguments = bundleOf(CTX_KEY to ctx, TARGET_KEY to target)
}
}
}

View file

@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.anytypeio.anytype.R
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_ui.features.relations.LimitObjectTypeAdapter
import com.anytypeio.anytype.core_ui.features.relations.RelationConnectWithAdapter
import com.anytypeio.anytype.core_ui.features.relations.RelationFormatAdapter
@ -22,6 +23,7 @@ import com.anytypeio.anytype.core_utils.ext.arg
import com.anytypeio.anytype.core_utils.ext.drawable
import com.anytypeio.anytype.core_utils.ext.subscribe
import com.anytypeio.anytype.core_utils.ext.toast
import com.anytypeio.anytype.core_utils.ext.withParent
import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetFragment
import com.anytypeio.anytype.databinding.FragmentRelationCreateFromScratchBinding
import com.anytypeio.anytype.di.common.componentManager
@ -255,13 +257,12 @@ class RelationCreateFromScratchForObjectBlockFragment : RelationCreateFromScratc
private fun observeCommands(command: RelationCreateFromScratchForObjectBlockViewModel.Command) {
when (command) {
is RelationCreateFromScratchForObjectBlockViewModel.Command.OnSuccess -> {
val result = RelationNewResult(
target = target,
relation = command.relation
)
val editorScreenEntry = findNavController().getBackStackEntry(R.id.pageScreen)
editorScreenEntry.savedStateHandle.set(RELATION_NEW_RESULT_KEY, result)
findNavController().popBackStack(R.id.pageScreen, false)
withParent<OnCreateFromScratchRelationListener> {
onCreateRelation(
target = target,
relation = command.relation
)
}
}
}
}
@ -301,7 +302,24 @@ class RelationCreateFromScratchForObjectBlockFragment : RelationCreateFromScratc
companion object {
const val TARGET_KEY = "arg.rel-create-object-block.target"
const val RELATION_NEW_RESULT_KEY = "arg.rel-create-object-block.result"
fun newInstance(
ctx: Id,
target: Id,
query: String
) = RelationCreateFromScratchForObjectBlockFragment().apply {
arguments = bundleOf(
CTX_KEY to ctx,
QUERY_KEY to query,
TARGET_KEY to target
)
}
}
}
interface OnCreateFromScratchRelationListener {
fun onCreateRelation(target: Id, relation: Key)
}
data class RelationNewResult(val target: String, val relation: String) : Serializable

View file

@ -27,13 +27,6 @@
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/action_pageScreen_to_relationAddToObjectBlockFragment"
app:destination="@id/relationAddToObjectBlockFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<dialog
android:id="@+id/objectRelationListScreen"

View file

@ -14,7 +14,6 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_ui.BuildConfig
import com.anytypeio.anytype.core_ui.R
import com.anytypeio.anytype.core_ui.databinding.ItemBlockBookmarkBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockBookmarkErrorBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockBookmarkUploadingBinding
@ -1180,7 +1179,7 @@ class BlockAdapter(
is RelationBlockViewHolder -> {
when (holder) {
is RelationBlockViewHolder.Placeholder -> {
bindViewHolder(holder, position)
onBindViewHolder(holder, position)
}
else -> {
holder.processChangePayload(
@ -1482,50 +1481,32 @@ class BlockAdapter(
is RelationBlockViewHolder.Default -> {
val item = (blocks[position] as BlockView.Relation.Related)
holder.bind(item = item.view)
holder.indentize(item = item)
holder.applyBackground(item)
val container = holder.itemView.findViewById<ViewGroup>(R.id.content)
container.isSelected = item.isSelected
holder.bindHolder(item)
}
is RelationBlockViewHolder.Status -> {
val item = (blocks[position] as BlockView.Relation.Related)
holder.bind(item = item.view)
holder.indentize(item = item)
holder.applyBackground(item)
val container = holder.itemView.findViewById<ViewGroup>(R.id.content)
container.isSelected = item.isSelected
holder.bindHolder(item)
}
is RelationBlockViewHolder.Tags -> {
val item = (blocks[position] as BlockView.Relation.Related)
holder.bind(item = item.view)
holder.indentize(item = item)
holder.applyBackground(item)
val container = holder.itemView.findViewById<ViewGroup>(R.id.content)
container.isSelected = item.isSelected
holder.bindHolder(item)
}
is RelationBlockViewHolder.Object -> {
val item = (blocks[position] as BlockView.Relation.Related)
holder.bind(item = item.view)
holder.indentize(item = item)
holder.applyBackground(item)
val container = holder.itemView.findViewById<ViewGroup>(R.id.content)
container.isSelected = item.isSelected
holder.bindHolder(item)
}
is RelationBlockViewHolder.File -> {
val item = (blocks[position] as BlockView.Relation.Related)
holder.bind(item = item.view)
holder.indentize(item = item)
holder.applyBackground(item)
val container = holder.itemView.findViewById<ViewGroup>(R.id.content)
container.isSelected = item.isSelected
holder.bindHolder(item)
}
is RelationBlockViewHolder.Checkbox -> {
val item = (blocks[position] as BlockView.Relation.Related)
holder.bind(item = item.view)
holder.indentize(item = item)
holder.applyBackground(item)
val container = holder.itemView.findViewById<ViewGroup>(R.id.content)
container.isSelected = item.isSelected
holder.bindHolder(item)
}
is FeaturedRelationListViewHolder -> {
holder.bind(

View file

@ -45,6 +45,12 @@ sealed class RelationBlockViewHolder(
abstract val content: ViewGroup
abstract val relationName: TextView
fun bindHolder(item: BlockView.Relation.Related) {
indentize(item = item)
applyBackground(item)
applySelection(item)
}
fun indent(item: BlockView.Indentable, view: View) {
if (!BuildConfig.NESTED_DECORATION_ENABLED) {
val indent = dimen(R.dimen.indent) * item.indent

View file

@ -421,8 +421,6 @@ class BlockDataRepository(
subscriptions: List<Id>
) = remote.cancelObjectSearchSubscription(subscriptions)
override suspend fun relationListAvailable(ctx: Id) = remote.relationListAvailable(ctx)
override suspend fun addRelationToObject(
ctx: Id, relation: Id
): Payload = remote.addRelationToObject(ctx, relation)

View file

@ -153,7 +153,6 @@ interface BlockDataStore {
suspend fun cancelObjectSearchSubscription(subscriptions: List<Id>)
suspend fun relationListAvailable(ctx: Id): List<Relation>
suspend fun addRelationToObject(ctx: Id, relation: Key) : Payload
suspend fun deleteRelationFromObject(ctx: Id, relation: Key): Payload

View file

@ -164,7 +164,6 @@ interface BlockRemote {
suspend fun cancelObjectSearchSubscription(subscriptions: List<Id>)
suspend fun relationListAvailable(ctx: Id): List<Relation>
suspend fun addRelationToObject(ctx: Id, relation: Key): Payload
suspend fun deleteRelationFromObject(ctx: Id, relation: Key): Payload

View file

@ -344,9 +344,6 @@ class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore {
subscriptions: List<Id>
) = remote.cancelObjectSearchSubscription(subscriptions)
override suspend fun relationListAvailable(ctx: Id): List<Relation> =
remote.relationListAvailable(ctx)
override suspend fun addRelationToObject(
ctx: Id,
relation: Key

View file

@ -1,29 +0,0 @@
package com.anytypeio.anytype.domain.block.interactor
import com.anytypeio.anytype.core_models.Command
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.domain.base.BaseUseCase
import com.anytypeio.anytype.domain.block.repo.BlockRepository
class AddRelationToBlock(
private val repo: BlockRepository
) : BaseUseCase<Payload, AddRelationToBlock.Params>() {
override suspend fun run(params: AddRelationToBlock.Params) = safe {
repo.addRelationToBlock(
command = Command.AddRelationToBlock(
contextId = params.context,
blockId = params.target,
relation = params.relation
)
)
}
data class Params(
val context: Id,
val target: Id,
val relation: Relation
)
}

View file

@ -1,4 +0,0 @@
package com.anytypeio.anytype.domain.block.interactor.sets
class AddObjectType {
}

View file

@ -1,18 +0,0 @@
package com.anytypeio.anytype.domain.block.interactor.sets
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.domain.base.BaseUseCase
import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.core_models.Url
class AddObjectTypeRelation : BaseUseCase<List<Relation>, AddObjectTypeRelation.Params>() {
override suspend fun run(params: Params): Either<Throwable, List<Relation>> {
TODO("Not yet implemented")
}
data class Params(
val objectType: Url,
val relations: List<Relation>
)
}

View file

@ -1,2 +0,0 @@
package com.anytypeio.anytype.domain.block.interactor.sets

View file

@ -1,18 +0,0 @@
package com.anytypeio.anytype.domain.block.interactor.sets
import com.anytypeio.anytype.domain.base.BaseUseCase
import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_models.Url
class RemoveObjectTypeRelation : BaseUseCase<List<Relation>, RemoveObjectTypeRelation.Params>() {
override suspend fun run(params: Params): Either<Throwable, List<Relation>> {
TODO("Not yet implemented")
}
data class Params(
val objectType: Url,
val relationKey: String
)
}

View file

@ -1,21 +0,0 @@
package com.anytypeio.anytype.domain.block.interactor.sets
import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider
import com.anytypeio.anytype.domain.base.BaseUseCase
import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.domain.block.repo.BlockRepository
/**
* Use case for storing in memory cache all object types(archived or not) of account
*/
@Deprecated("To be deleted")
class StoreObjectTypes(
private val repo: BlockRepository,
private val objectTypesProvider: ObjectTypesProvider
) : BaseUseCase<Unit, Unit>() {
override suspend fun run(params: Unit): Either<Throwable, Unit> = safe {
// val objectTypes = repo.getObjectTypes()
// objectTypesProvider.set(objectTypes)
}
}

View file

@ -210,8 +210,6 @@ interface BlockRepository {
suspend fun cancelObjectSearchSubscription(subscriptions: List<Id>)
suspend fun relationListAvailable(ctx: Id): List<Relation>
suspend fun addRelationToObject(ctx: Id, relation: Key): Payload
suspend fun deleteRelationFromObject(ctx: Id, relation: Key): Payload

View file

@ -1,32 +0,0 @@
package com.anytypeio.anytype.domain.relations
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.BaseUseCase
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import kotlinx.coroutines.Dispatchers
class ObjectRelationList(
private val repo: BlockRepository,
dispatchers: AppCoroutineDispatchers = AppCoroutineDispatchers(
io = Dispatchers.IO,
computation = Dispatchers.Default,
main = Dispatchers.Main
)
) : BaseUseCase<List<Relation>, ObjectRelationList.Params>(context = dispatchers.io) {
override suspend fun run(params: Params) = safe {
val relations = repo.relationListAvailable(ctx = params.ctx)
if (params.sorted) {
relations.sortedBy { it.name }
} else {
relations
}
}
class Params(
val ctx: Id,
val sorted: Boolean = true
)
}

View file

@ -371,10 +371,6 @@ class BlockMiddleware(
subscriptions: List<Id>
) = middleware.objectSearchUnsubscribe(subscriptions = subscriptions)
override suspend fun relationListAvailable(
ctx: Id
): List<Relation> = middleware.objectRelationListAvailable(ctx).map { it.toCoreModels() }
override suspend fun addRelationToObject(
ctx: Id, relation: Key
): Payload = middleware.objectRelationAdd(ctx, relation)

View file

@ -1097,17 +1097,6 @@ class Middleware(
return response.event.toPayload()
}
@Throws(Exception::class)
fun objectRelationListAvailable(ctx: Id): List<MRelation> {
val request = Rpc.ObjectRelation.ListAvailable.Request(
contextId = ctx
)
if (BuildConfig.DEBUG) logRequest(request)
val response = service.objectRelationListAvailable(request)
if (BuildConfig.DEBUG) logResponse(response)
return response.relations
}
@Throws(Exception::class)
fun objectRelationRemoveFeatured(
ctx: Id,

View file

@ -520,7 +520,6 @@ class EditorViewModel(
when (event) {
is Event.Command.ShowObject -> {
orchestrator.stores.details.update(event.details)
orchestrator.stores.relations.update(event.relations)
orchestrator.stores.objectTypes.update(event.objectTypes)
orchestrator.stores.relationLinks.update(event.relationLinks)
orchestrator.stores.objectRestrictions.update(event.objectRestrictions)

View file

@ -9,7 +9,6 @@ import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.objects.StoreOfRelations
import com.anytypeio.anytype.domain.relations.AddToFeaturedRelations
import com.anytypeio.anytype.domain.relations.DeleteRelationFromObject
import com.anytypeio.anytype.domain.relations.ObjectRelationList
import com.anytypeio.anytype.domain.relations.RemoveFromFeaturedRelations
import com.anytypeio.anytype.presentation.editor.Editor
import com.anytypeio.anytype.presentation.editor.editor.DetailModificationManager
@ -18,7 +17,6 @@ import com.anytypeio.anytype.presentation.util.Dispatcher
class ObjectRelationListViewModelFactory(
private val stores: Editor.Storage,
private val urlBuilder: UrlBuilder,
private val objectRelationList: ObjectRelationList,
private val dispatcher: Dispatcher<Payload>,
private val updateDetail: UpdateDetail,
private val detailModificationManager: DetailModificationManager,
@ -34,7 +32,6 @@ class ObjectRelationListViewModelFactory(
return RelationListViewModel(
stores = stores,
urlBuilder = urlBuilder,
objectRelationList = objectRelationList,
dispatcher = dispatcher,
updateDetail = updateDetail,
detailModificationManager = detailModificationManager,

View file

@ -15,6 +15,7 @@ import com.anytypeio.anytype.domain.dataview.interactor.AddRelationToDataView
import com.anytypeio.anytype.domain.dataview.interactor.UpdateDataViewViewer
import com.anytypeio.anytype.domain.relations.GetRelations
import com.anytypeio.anytype.domain.workspace.AddObjectToWorkspace
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
import com.anytypeio.anytype.presentation.extension.getPropName
import com.anytypeio.anytype.presentation.extension.sendAnalyticsAddRelationEvent
import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider
@ -35,12 +36,14 @@ class RelationAddToDataViewViewModel(
private val dispatcher: Dispatcher<Payload>,
private val analytics: Analytics,
private val addObjectToWorkspace: AddObjectToWorkspace,
appCoroutineDispatchers: AppCoroutineDispatchers
private val appCoroutineDispatchers: AppCoroutineDispatchers,
private val workspaceManager: WorkspaceManager
) : RelationAddViewModelBase(
relationsProvider = relationsProvider,
appCoroutineDispatchers = appCoroutineDispatchers,
getRelations = getRelations,
addObjectToWorkspace = addObjectToWorkspace
addObjectToWorkspace = addObjectToWorkspace,
workspaceManager = workspaceManager
) {
fun onRelationSelected(
@ -116,7 +119,8 @@ class RelationAddToDataViewViewModel(
private val relationsProvider: ObjectRelationProvider,
private val appCoroutineDispatchers: AppCoroutineDispatchers,
private val getRelations: GetRelations,
private val addObjectToWorkspace: AddObjectToWorkspace
private val addObjectToWorkspace: AddObjectToWorkspace,
private val workspaceManager: WorkspaceManager
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@ -130,7 +134,8 @@ class RelationAddToDataViewViewModel(
relationsProvider = relationsProvider,
appCoroutineDispatchers = appCoroutineDispatchers,
getRelations = getRelations,
addObjectToWorkspace = addObjectToWorkspace
addObjectToWorkspace = addObjectToWorkspace,
workspaceManager = workspaceManager
) as T
}
}

View file

@ -14,6 +14,7 @@ import com.anytypeio.anytype.domain.objects.StoreOfRelations
import com.anytypeio.anytype.domain.relations.AddRelationToObject
import com.anytypeio.anytype.domain.relations.GetRelations
import com.anytypeio.anytype.domain.workspace.AddObjectToWorkspace
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
import com.anytypeio.anytype.presentation.extension.getPropName
import com.anytypeio.anytype.presentation.extension.sendAnalyticsAddRelationEvent
import com.anytypeio.anytype.presentation.extension.sendAnalyticsSearchQueryEvent
@ -31,12 +32,14 @@ class RelationAddToObjectViewModel(
val storeOfRelations: StoreOfRelations,
appCoroutineDispatchers: AppCoroutineDispatchers,
getRelations: GetRelations,
addObjectToWorkspace: AddObjectToWorkspace
addObjectToWorkspace: AddObjectToWorkspace,
workspaceManager: WorkspaceManager
) : RelationAddViewModelBase(
relationsProvider = relationsProvider,
appCoroutineDispatchers = appCoroutineDispatchers,
getRelations = getRelations,
addObjectToWorkspace = addObjectToWorkspace
addObjectToWorkspace = addObjectToWorkspace,
workspaceManager = workspaceManager
) {
val commands = MutableSharedFlow<Command>(replay = 0)
@ -89,7 +92,8 @@ class RelationAddToObjectViewModel(
private val relationsProvider: ObjectRelationProvider,
private val appCoroutineDispatchers: AppCoroutineDispatchers,
private val getRelations: GetRelations,
private val addObjectToWorkspace: AddObjectToWorkspace
private val addObjectToWorkspace: AddObjectToWorkspace,
private val workspaceManager: WorkspaceManager
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@ -101,7 +105,8 @@ class RelationAddToObjectViewModel(
analytics = analytics,
appCoroutineDispatchers = appCoroutineDispatchers,
getRelations = getRelations,
addObjectToWorkspace = addObjectToWorkspace
addObjectToWorkspace = addObjectToWorkspace,
workspaceManager = workspaceManager
) as T
}
}

View file

@ -6,12 +6,14 @@ import com.anytypeio.anytype.core_models.DVFilterCondition
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.Marketplace
import com.anytypeio.anytype.core_models.Marketplace.MARKETPLACE_ID
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.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.relations.GetRelations
import com.anytypeio.anytype.domain.workspace.AddObjectToWorkspace
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
import com.anytypeio.anytype.presentation.common.BaseViewModel
import com.anytypeio.anytype.presentation.relations.model.RelationItemView
import com.anytypeio.anytype.presentation.relations.model.RelationView
@ -39,10 +41,11 @@ import timber.log.Timber
* Base view model for adding a relation either to an object or to a set.
*/
abstract class RelationAddViewModelBase(
private val relationsProvider: ObjectRelationProvider,
relationsProvider: ObjectRelationProvider,
private val getRelations: GetRelations,
private val appCoroutineDispatchers: AppCoroutineDispatchers,
private val addObjectToWorkspace: AddObjectToWorkspace
private val addObjectToWorkspace: AddObjectToWorkspace,
private val workspaceManager: WorkspaceManager
) : BaseViewModel() {
private val userInput = MutableStateFlow(DEFAULT_INPUT)
@ -65,10 +68,13 @@ abstract class RelationAddViewModelBase(
searchQuery,
objectRelationKeys
) { query, keys ->
val myRelations = proceedWithGettingMyRelations(query = query)
val myRelations = proceedWithGettingMyRelations(
query = query
)
val excludedRelations = myRelations.mapNotNull { it.sourceObject }
val marketplaceRelations = proceedWithGettingMarketplaceRelations(
query = query,
excluded = myRelations.mapNotNull { it.sourceObject }
excluded = excludedRelations
)
buildViews(
myRelations = myRelations,
@ -76,7 +82,7 @@ abstract class RelationAddViewModelBase(
objectRelationKeys = keys
)
}.flowOn(appCoroutineDispatchers.io).catch {
sendToast("An error occured. Please try again later.")
sendToast("An error occurred. Please try again later.")
}.collect { views ->
results.value = views
}
@ -123,8 +129,8 @@ abstract class RelationAddViewModelBase(
private suspend fun proceedWithGettingMarketplaceRelations(
excluded: List<Id>,
query: String
) = getRelations.execute(
GetRelations.Params(
): List<ObjectWrapper.Relation> {
val params = GetRelations.Params(
sorts = defaultObjectSearchSorts(),
filters = buildList {
addAll(filterMarketplaceRelations())
@ -144,13 +150,26 @@ abstract class RelationAddViewModelBase(
value = false
)
)
add(
DVFilter(
relationKey = Relations.WORKSPACE_ID,
condition = DVFilterCondition.EQUAL,
value = MARKETPLACE_ID
)
)
},
query = query
)
)
val result = getRelations.execute(
params = params
)
return result
}
private suspend fun proceedWithGettingMyRelations(query: String) = getRelations.execute(
GetRelations.Params(
private suspend fun proceedWithGettingMyRelations(
query: String
): List<ObjectWrapper.Relation> {
val params = GetRelations.Params(
sorts = defaultObjectSearchSorts(),
filters = buildList {
addAll(filterMyRelations())
@ -161,10 +180,21 @@ abstract class RelationAddViewModelBase(
value = false
)
)
add(
DVFilter(
relationKey = Relations.WORKSPACE_ID,
condition = DVFilterCondition.EQUAL,
value = workspaceManager.getCurrentWorkspace()
)
)
},
query = query
)
)
val result = getRelations.execute(
params = params
)
return result
}
abstract fun sendAnalyticsEvent(length: Int)
@ -178,7 +208,7 @@ abstract class RelationAddViewModelBase(
relation: RelationView.Existing
) {
viewModelScope.launch {
if (relation.workspace == Marketplace.MARKETPLACE_ID) {
if (relation.workspace == MARKETPLACE_ID) {
addObjectToWorkspace(
AddObjectToWorkspace.Params(
objects = listOf(relation.id)
@ -196,11 +226,12 @@ abstract class RelationAddViewModelBase(
sendToast("Something went wrong. Please, try again later.")
}
)
} else {
proceedWithDispatchingSelectedRelation(
ctx = ctx,
relation = relation
)
}
proceedWithDispatchingSelectedRelation(
ctx = ctx,
relation = relation
)
}
}
@ -222,7 +253,7 @@ abstract class RelationAddViewModelBase(
val ctx: Id,
val relation: Key,
val format: RelationFormat
): Command()
) : Command()
}
companion object {

View file

@ -17,7 +17,6 @@ import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.objects.StoreOfRelations
import com.anytypeio.anytype.domain.relations.AddToFeaturedRelations
import com.anytypeio.anytype.domain.relations.DeleteRelationFromObject
import com.anytypeio.anytype.domain.relations.ObjectRelationList
import com.anytypeio.anytype.domain.relations.RemoveFromFeaturedRelations
import com.anytypeio.anytype.presentation.BuildConfig
import com.anytypeio.anytype.presentation.common.BaseViewModel
@ -38,7 +37,6 @@ import timber.log.Timber
class RelationListViewModel(
private val stores: Editor.Storage,
private val urlBuilder: UrlBuilder,
private val objectRelationList: ObjectRelationList,
private val dispatcher: Dispatcher<Payload>,
private val updateDetail: UpdateDetail,
private val detailModificationManager: DetailModificationManager,

View file

@ -3,18 +3,21 @@ package com.anytypeio.anytype.presentation.relations
import app.cash.turbine.test
import com.anytypeio.anytype.core_models.DVFilter
import com.anytypeio.anytype.core_models.DVFilterCondition
import com.anytypeio.anytype.core_models.Marketplace.MARKETPLACE_ID
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.StubRelationObject
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import com.anytypeio.anytype.domain.relations.GetRelations
import com.anytypeio.anytype.domain.workspace.AddObjectToWorkspace
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
import com.anytypeio.anytype.presentation.relations.model.RelationView
import com.anytypeio.anytype.presentation.relations.model.Section
import com.anytypeio.anytype.presentation.relations.providers.FakeObjectRelationProvider
import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
@ -41,8 +44,13 @@ class RelationAddViewModelBaseTest {
@Mock
lateinit var repo: BlockRepository
@Mock
lateinit var workspaceManager: WorkspaceManager
private val relationsProvider = FakeObjectRelationProvider()
private val workspaceId = MockDataFactory.randomString()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
@ -53,7 +61,15 @@ class RelationAddViewModelBaseTest {
// SETUP
val relation = StubRelationObject()
val relation = StubRelationObject(
workspaceId = workspaceId
)
workspaceManager.stub {
onBlocking {
getCurrentWorkspace()
} doReturn workspaceId
}
repo.stub {
onBlocking {
@ -68,6 +84,13 @@ class RelationAddViewModelBaseTest {
value = false
)
)
add(
DVFilter(
relationKey = Relations.WORKSPACE_ID,
condition = DVFilterCondition.EQUAL,
value = workspaceId
)
)
},
limit = 0,
offset = 0,
@ -96,6 +119,13 @@ class RelationAddViewModelBaseTest {
value = false
)
)
add(
DVFilter(
relationKey = Relations.WORKSPACE_ID,
condition = DVFilterCondition.EQUAL,
value = MARKETPLACE_ID
)
)
},
limit = 0,
offset = 0,
@ -120,7 +150,7 @@ class RelationAddViewModelBaseTest {
id = relation.id,
name = relation.name.orEmpty(),
format = relation.format,
workspace = null
workspace = workspaceId
)
)
)
@ -129,137 +159,158 @@ class RelationAddViewModelBaseTest {
@Test
fun `added relations equal to available - results are empty`() = runTest {
// SETUP
val vm = givenViewModel(relationsProvider)
// TESTING
vm.results.test {
assertEquals(
actual = awaitItem(),
expected = emptyList()
)
}
}
@Test
fun `should query relations from library and marketplace filtering out already addded relations`() = runTest {
// SETUP
val marketplace = listOf(
StubRelationObject(),
StubRelationObject(),
StubRelationObject()
)
val library = listOf(
StubRelationObject(sourceObject = marketplace[0].id),
StubRelationObject(),
StubRelationObject()
)
repo.stub {
onBlocking {
searchObjects(
sorts = ObjectSearchConstants.defaultObjectSearchSorts(),
filters = buildList {
addAll(ObjectSearchConstants.filterMyRelations())
add(
DVFilter(
relationKey = Relations.IS_HIDDEN,
condition = DVFilterCondition.EQUAL,
value = false
)
)
},
limit = 0,
offset = 0,
fulltext = ""
)
} doReturn library.map { it.map }
}
repo.stub {
onBlocking {
searchObjects(
sorts = ObjectSearchConstants.defaultObjectSearchSorts(),
filters = buildList {
addAll(ObjectSearchConstants.filterMarketplaceRelations())
add(
DVFilter(
relationKey = Relations.ID,
condition = DVFilterCondition.NOT_IN,
value = library.mapNotNull { it.sourceObject }
)
)
add(
DVFilter(
relationKey = Relations.IS_HIDDEN,
condition = DVFilterCondition.EQUAL,
value = false
)
)
},
limit = 0,
offset = 0,
fulltext = ""
)
} doReturn marketplace.takeLast(2).map { it.map }
}
val vm = givenViewModel(relationsProvider = relationsProvider)
val vm = givenViewModel(relationsProvider)
// TESTING
coroutineTestRule.testDispatcher.scheduler.runCurrent()
vm.results.test {
assertEquals(
actual = awaitItem(),
expected = listOf(
Section.Library,
RelationView.Existing(
key = library[0].key,
id = library[0].id,
name = library[0].name.orEmpty(),
format = library[0].format,
workspace = null
),
RelationView.Existing(
key = library[1].key,
id = library[1].id,
name = library[1].name.orEmpty(),
format = library[1].format,
workspace = null
),
RelationView.Existing(
key = library[2].key,
id = library[2].id,
name = library[2].name.orEmpty(),
format = library[2].format,
workspace = null
),
Section.Marketplace,
RelationView.Existing(
key = marketplace[1].key,
id = marketplace[1].id,
name = marketplace[1].name.orEmpty(),
format = marketplace[1].format,
workspace = null
),
RelationView.Existing(
key = marketplace[2].key,
id = marketplace[2].id,
name = marketplace[2].name.orEmpty(),
format = marketplace[2].format,
workspace = null
),
)
expected = emptyList()
)
}
}
@Test
fun `should query relations from library and marketplace filtering out already addded relations`() =
runTest {
// SETUP
val marketplace = listOf(
StubRelationObject(workspaceId = MARKETPLACE_ID),
StubRelationObject(workspaceId = MARKETPLACE_ID),
StubRelationObject(workspaceId = MARKETPLACE_ID)
)
val library = listOf(
StubRelationObject(sourceObject = marketplace[0].id, workspaceId = workspaceId),
StubRelationObject(workspaceId = workspaceId),
StubRelationObject(workspaceId = workspaceId)
)
workspaceManager.stub {
onBlocking {
getCurrentWorkspace()
} doReturn workspaceId
}
repo.stub {
onBlocking {
searchObjects(
sorts = ObjectSearchConstants.defaultObjectSearchSorts(),
filters = buildList {
addAll(ObjectSearchConstants.filterMyRelations())
add(
DVFilter(
relationKey = Relations.IS_HIDDEN,
condition = DVFilterCondition.EQUAL,
value = false
)
)
add(
DVFilter(
relationKey = Relations.WORKSPACE_ID,
condition = DVFilterCondition.EQUAL,
value = workspaceId
)
)
},
limit = 0,
offset = 0,
fulltext = ""
)
} doReturn library.map { it.map }
}
repo.stub {
onBlocking {
searchObjects(
sorts = ObjectSearchConstants.defaultObjectSearchSorts(),
filters = buildList {
addAll(ObjectSearchConstants.filterMarketplaceRelations())
add(
DVFilter(
relationKey = Relations.ID,
condition = DVFilterCondition.NOT_IN,
value = library.mapNotNull { it.sourceObject }
)
)
add(
DVFilter(
relationKey = Relations.IS_HIDDEN,
condition = DVFilterCondition.EQUAL,
value = false
)
)
add(
DVFilter(
relationKey = Relations.WORKSPACE_ID,
condition = DVFilterCondition.EQUAL,
value = MARKETPLACE_ID
)
)
},
limit = 0,
offset = 0,
fulltext = ""
)
} doReturn marketplace.takeLast(2).map { it.map }
}
val vm = givenViewModel(relationsProvider = relationsProvider)
// TESTING
coroutineTestRule.testDispatcher.scheduler.runCurrent()
vm.results.test {
assertEquals(
actual = awaitItem(),
expected = listOf(
Section.Library,
RelationView.Existing(
key = library[0].key,
id = library[0].id,
name = library[0].name.orEmpty(),
format = library[0].format,
workspace = workspaceId
),
RelationView.Existing(
key = library[1].key,
id = library[1].id,
name = library[1].name.orEmpty(),
format = library[1].format,
workspace = workspaceId
),
RelationView.Existing(
key = library[2].key,
id = library[2].id,
name = library[2].name.orEmpty(),
format = library[2].format,
workspace = workspaceId
),
Section.Marketplace,
RelationView.Existing(
key = marketplace[1].key,
id = marketplace[1].id,
name = marketplace[1].name.orEmpty(),
format = marketplace[1].format,
workspace = MARKETPLACE_ID
),
RelationView.Existing(
key = marketplace[2].key,
id = marketplace[2].id,
name = marketplace[2].name.orEmpty(),
format = marketplace[2].format,
workspace = MARKETPLACE_ID
),
)
)
}
}
private fun givenViewModel(
relationsProvider: ObjectRelationProvider
) = object : RelationAddViewModelBase(
@ -269,7 +320,8 @@ class RelationAddViewModelBaseTest {
addObjectToWorkspace = AddObjectToWorkspace(
repo = repo,
dispatchers = appCoroutineDispatchers
)
),
workspaceManager = workspaceManager
) {
override fun sendAnalyticsEvent(length: Int) {}
}

View file

@ -11,7 +11,8 @@ fun StubRelationObject(
isReadOnly: Boolean = false,
objectTypes: List<Id> = emptyList(),
relationOptionsDict: List<Id> = emptyList(),
sourceObject: Id = MockDataFactory.randomUuid()
sourceObject: Id = MockDataFactory.randomUuid(),
workspaceId: Id = MockDataFactory.randomString()
): ObjectWrapper.Relation = ObjectWrapper.Relation(
map = mapOf(
Relations.ID to id,
@ -22,7 +23,8 @@ fun StubRelationObject(
Relations.RELATION_FORMAT_OBJECT_TYPES to objectTypes,
Relations.RELATION_FORMAT to format.code.toDouble(),
Relations.RELATION_OPTION_DICT to relationOptionsDict,
Relations.SOURCE_OBJECT to sourceObject
Relations.SOURCE_OBJECT to sourceObject,
Relations.WORKSPACE_ID to workspaceId
)
)