Skip to content

Commit

Permalink
DROID-2764 Editor | Fix | User should be able to move or add an objec…
Browse files Browse the repository at this point in the history
…t inside another object by drag-and-drop (#1928)
  • Loading branch information
uburoiubu authored Dec 16, 2024
1 parent 45ee14a commit 5354a5c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.anytypeio.anytype.domain.block.interactor.ClearBlockStyle
import com.anytypeio.anytype.domain.block.interactor.CreateBlock
import com.anytypeio.anytype.domain.block.interactor.DuplicateBlock
import com.anytypeio.anytype.domain.block.interactor.MergeBlocks
import com.anytypeio.anytype.domain.block.interactor.Move
import com.anytypeio.anytype.domain.block.interactor.MoveOld
import com.anytypeio.anytype.domain.block.interactor.RemoveLinkMark
import com.anytypeio.anytype.domain.block.interactor.ReplaceBlock
Expand Down Expand Up @@ -141,7 +142,7 @@ open class EditorTestSetup {
lateinit var uploadBlock: UploadBlock
lateinit var splitBlock: SplitBlock
lateinit var updateBackgroundColor: UpdateBackgroundColor
lateinit var move: MoveOld
lateinit var move: Move
lateinit var setRelationKey: SetRelationKey
lateinit var updateDetail: UpdateDetail

Expand Down Expand Up @@ -371,7 +372,9 @@ open class EditorTestSetup {
clipboard = clipboard,
matcher = uriMatcher
)
move = MoveOld(repo)
move = Move(
repo, dispatchers
)
getObjectTypes = GetObjectTypes(repo, dispatchers)

updateBackgroundColor = UpdateBackgroundColor(repo)
Expand Down
13 changes: 2 additions & 11 deletions app/src/main/java/com/anytypeio/anytype/di/feature/EditorDI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.anytypeio.anytype.domain.block.interactor.ClearBlockStyle
import com.anytypeio.anytype.domain.block.interactor.CreateBlock
import com.anytypeio.anytype.domain.block.interactor.DuplicateBlock
import com.anytypeio.anytype.domain.block.interactor.MergeBlocks
import com.anytypeio.anytype.domain.block.interactor.MoveOld
import com.anytypeio.anytype.domain.block.interactor.Move
import com.anytypeio.anytype.domain.block.interactor.RemoveLinkMark
import com.anytypeio.anytype.domain.block.interactor.ReplaceBlock
import com.anytypeio.anytype.domain.block.interactor.SetLinkAppearance
Expand Down Expand Up @@ -447,7 +447,7 @@ object EditorSessionModule {
createTable: CreateTable,
fillTableRow: FillTableRow,
matcher: DefaultPatternMatcher,
move: MoveOld,
move: Move,
copy: Copy,
paste: Paste,
undo: Undo,
Expand Down Expand Up @@ -819,15 +819,6 @@ object EditorUseCaseModule {
clipboard = clipboard
)

@JvmStatic
@Provides
@PerScreen
fun provideMoveUseCase(
repo: BlockRepository
): MoveOld = MoveOld(
repo = repo
)

@JvmStatic
@Provides
@PerScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.ResultInteractor
import com.anytypeio.anytype.domain.block.interactor.Move.Params
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import javax.inject.Inject

/**
* Use-case for moving a group of blocks (cross-document, inside one document, one block after another, etc).
* @see Params for details.
*/
class Move(
class Move @Inject constructor(
private val repo: BlockRepository,
appCoroutineDispatchers: AppCoroutineDispatchers
) : ResultInteractor<Params, Payload>(appCoroutineDispatchers.io) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6360,7 +6360,7 @@ class EditorViewModel(
orchestrator.proxies.intents.send(
Intent.Document.Move(
context = context,
target = target,
target = if (targetContext != context) "" else target,
targetContext = targetContext,
blocks = listOf(dragged),
position = position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.anytypeio.anytype.analytics.base.Analytics
import com.anytypeio.anytype.analytics.event.EventAnalytics
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.domain.base.fold
import com.anytypeio.anytype.domain.base.suspendFold
import com.anytypeio.anytype.domain.block.UpdateDivider
import com.anytypeio.anytype.domain.block.interactor.ClearBlockContent
import com.anytypeio.anytype.domain.block.interactor.ClearBlockStyle
import com.anytypeio.anytype.domain.block.interactor.CreateBlock
import com.anytypeio.anytype.domain.block.interactor.DuplicateBlock
import com.anytypeio.anytype.domain.block.interactor.MergeBlocks
import com.anytypeio.anytype.domain.block.interactor.Move
import com.anytypeio.anytype.domain.block.interactor.MoveOld
import com.anytypeio.anytype.domain.block.interactor.ReplaceBlock
import com.anytypeio.anytype.domain.block.interactor.SplitBlock
Expand Down Expand Up @@ -81,7 +83,7 @@ class Orchestrator(
private val updateFields: UpdateFields,
private val createTable: CreateTable,
private val fillTableRow: FillTableRow,
private val move: MoveOld,
private val move: Move,
private val copy: Copy,
private val paste: Paste,
private val undo: Undo,
Expand Down Expand Up @@ -417,20 +419,22 @@ class Orchestrator(
)
}
is Intent.Document.Move -> {
move(
params = MoveOld.Params(
move.async(
params = Move.Params(
context = intent.context,
targetContext = intent.targetContext,
targetId = intent.target,
blockIds = intent.blocks,
position = intent.position
)
).proceed(
failure = defaultOnError,
success = {
).fold(
onSuccess = {
intent.onSuccess?.invoke()
proxies.payloads.send(it)
analytics.sendAnalyticsReorderBlockEvent(intent.blocks.size)
},
onFailure = {
Timber.e(it, "Error while moving blocks")
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.anytypeio.anytype.domain.block.interactor.ClearBlockStyle
import com.anytypeio.anytype.domain.block.interactor.CreateBlock
import com.anytypeio.anytype.domain.block.interactor.DuplicateBlock
import com.anytypeio.anytype.domain.block.interactor.MergeBlocks
import com.anytypeio.anytype.domain.block.interactor.Move
import com.anytypeio.anytype.domain.block.interactor.MoveOld
import com.anytypeio.anytype.domain.block.interactor.RemoveLinkMark
import com.anytypeio.anytype.domain.block.interactor.ReplaceBlock
Expand Down Expand Up @@ -277,7 +278,7 @@ open class EditorViewModelTest {
lateinit var updateTitle: UpdateTitle

@Mock
lateinit var move: MoveOld
lateinit var move: Move

@Mock
lateinit var turnIntoDocument: TurnIntoDocument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.anytypeio.anytype.domain.block.interactor.ClearBlockStyle
import com.anytypeio.anytype.domain.block.interactor.CreateBlock
import com.anytypeio.anytype.domain.block.interactor.DuplicateBlock
import com.anytypeio.anytype.domain.block.interactor.MergeBlocks
import com.anytypeio.anytype.domain.block.interactor.Move
import com.anytypeio.anytype.domain.block.interactor.MoveOld
import com.anytypeio.anytype.domain.block.interactor.RemoveLinkMark
import com.anytypeio.anytype.domain.block.interactor.ReplaceBlock
Expand Down Expand Up @@ -249,7 +250,7 @@ open class EditorPresentationTestSetup {
lateinit var replaceBlock: ReplaceBlock

@Mock
lateinit var move: MoveOld
lateinit var move: Move

lateinit var fieldParser: FieldParser

Expand Down Expand Up @@ -574,7 +575,7 @@ open class EditorPresentationTestSetup {

fun stubMove() {
move.stub {
onBlocking { invoke(any()) } doReturn Either.Right(
onBlocking { async(any()) } doReturn Resultat.Success(
Payload(
context = root,
events = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.Position
import com.anytypeio.anytype.core_models.ext.content
import com.anytypeio.anytype.domain.block.interactor.Move
import com.anytypeio.anytype.domain.block.interactor.MoveOld
import com.anytypeio.anytype.presentation.MockBlockFactory.link
import com.anytypeio.anytype.presentation.editor.EditorViewModel
Expand Down Expand Up @@ -440,8 +441,8 @@ class EditorScrollAndMoveTest : EditorPresentationTestSetup() {
}

verifyBlocking(move, times(1)) {
invoke(
params = MoveOld.Params(
async(
params = Move.Params(
context = root,
targetContext = root,
targetId = b.id,
Expand Down Expand Up @@ -511,8 +512,8 @@ class EditorScrollAndMoveTest : EditorPresentationTestSetup() {
}

verifyBlocking(move, times(1)) {
invoke(
params = MoveOld.Params(
async(
params = Move.Params(
context = root,
targetContext = root,
targetId = b.id,
Expand Down Expand Up @@ -573,8 +574,8 @@ class EditorScrollAndMoveTest : EditorPresentationTestSetup() {
}

verifyBlocking(move, times(1)) {
invoke(
params = MoveOld.Params(
async(
params = Move.Params(
context = root,
targetContext = b.content<Block.Content.Link>().target,
targetId = b.id,
Expand Down Expand Up @@ -882,8 +883,8 @@ class EditorScrollAndMoveTest : EditorPresentationTestSetup() {
// Verifying order of selected blocks used in request

verifyBlocking(move, times(1)) {
invoke(
params = MoveOld.Params(
async(
params = Move.Params(
context = root,
targetContext = root,
targetId = a.id,
Expand Down

0 comments on commit 5354a5c

Please sign in to comment.