Skip to content

chore: replace repository dependencies with use cases in Files view models - WPB-26913#4986

Open
jullianm wants to merge 4 commits into
developfrom
chore/replace-repo-by-usecases-in-viewmodels
Open

chore: replace repository dependencies with use cases in Files view models - WPB-26913#4986
jullianm wants to merge 4 commits into
developfrom
chore/replace-repo-by-usecases-in-viewmodels

Conversation

@jullianm

@jullianm jullianm commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
TaskWPB-26913 [iOS] Inject use cases instead of repositories in view models

Issue

FilesViewModel, FilesItemViewModel, and the MoveToFolder view models held direct references to WireDriveNodesRepositoryProtocol / WireDriveLocalAssetRepositoryProtocol alongside their use cases, and the use case wiring for FilesViewContainer, RecycleBinContainer, and WireMessagingFactory was duplicated verbatim across all three call sites. This PR removes the repository dependencies from the view models so they only talk to use cases, and centralizes use case construction.

Technical approach:

  • Added FilesViewModel.Dependencies and FilesViewModel.makeUseCases(dependencies:) to build the full UseCases struct in one place, replacing the copy-pasted initializer previously duplicated in FilesViewContainer, RecycleBinContainer, and WireMessagingFactory.
  • Removed localAssetRepository and nodesRepository from FilesViewModel; it now depends solely on UseCases.
  • WireDriveFetchNodesPageUseCase now receives its configuration per call (invoke(configuration:...)) instead of at init, since FilesViewModel computes the configuration dynamically from isBrowsing/isRecycleBin/navigationPath.
  • WireDriveFetchNodesUseCase is now @MainActor, exposes a nodes Combine publisher (backed by its internal WireDriveNodesCollection), and adds a clearNodes() method to reset and restart observation — used by MoveToFolderPageViewModel instead of owning its own WireDriveNodesCollection.
  • Added WireDriveObserveAssetUseCase and a synchronous WireDriveGetAssetUseCase.asset(nodeID:), replacing direct localAssetRepository.observeAsset/asset calls in FilesItemViewModel.
  • MoveToFolderViewModel/MoveToFolderPageViewModel now take an injected moveNodeUseCase/fetchNodesUseCase instead of building their own repository-backed instances per navigation step.
  • Removed a #if DEBUG deleteAsset() helper in FilesItemViewModel that reached into the repository directly.

No behavior change intended; this is a dependency-direction cleanup ahead of further refactoring.

Testing

  • Existing unit and UI tests updated to construct view models via the new use-case-only APIs (WireDriveFetchNodesPageUseCaseTests, FilesViewModelTests, FilesItemViewModelTests, FilesBrowserViewTests, FilesViewTests).
  • Run the WireMessaging test target and manually exercise Files browsing, recycle bin, and Move to Folder flows to confirm listing, search, and offline-asset state still behave as before.

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

No UI changes in this PR — internal dependency refactor only.

@jullianm jullianm changed the title [WPB-26913] chore: replace repository dependencies with use cases in Files view models chore: replace repository dependencies with use cases in Files view models - WPB-26913 Jul 9, 2026
@jullianm
jullianm requested review from a team, David-Henner and johnxnguyen and removed request for a team July 9, 2026 07:48
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Test Results

315 tests   315 ✅  1m 47s ⏱️
 62 suites    0 💤
  1 files      0 ❌

Results for commit 12e3159.

♻️ This comment has been updated with latest results.

Summary: workflow run #29003514028
Allure report (download zip): html-report-31697-chore_replace-repo-by-usecases-in-viewmodels

@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

return fileURL
}

@MainActor

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why does this need to be main actor?

package import Combine
package import Foundation

@MainActor

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: also why does this need to be main actor? I would expect that the view model is main actor but use cases are concurrent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants