Skip to content

WCProductTagModel to Room #14003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun List<ProductTag>.addTags(product: Product?): List<ProductTag> {

fun WCProductTagModel.toProductTag(): ProductTag {
return ProductTag(
remoteTagId = this.remoteTagId,
remoteTagId = this.remoteTagId.value,
name = this.name,
slug = this.slug,
description = this.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2404,13 +2404,15 @@ class ProductDetailViewModel @Inject constructor(
fun onProductTagAdded(tagName: String) {
// verify if the entered tagName exists for the site
// It so, the tag should be added to the product directly
productTagsRepository.getProductTagByName(tagName)?.let {
onProductTagSelected(it)
} ?: run {
// Since the tag does not exist for the site, add the tag to
// a list of newly added tags
_addedProductTags.addNewItem(ProductTag(name = tagName))
loadProductTags()
viewModelScope.launch {
productTagsRepository.getProductTagByName(tagName)?.let {
onProductTagSelected(it)
} ?: run {
// Since the tag does not exist for the site, add the tag to
// a list of newly added tags
_addedProductTags.addNewItem(ProductTag(name = tagName))
loadProductTags()
}
}
}

Expand Down Expand Up @@ -2464,12 +2466,13 @@ class ProductDetailViewModel @Inject constructor(
*/
fun setProductTagsFilter(filter: String) {
productTagsViewState = productTagsViewState.copy(currentFilter = filter)
val productTags = productTagsRepository.getProductTags()
filterProductTagList(productTags)

// fetch from the backend when a filter exists in case not all tags have been fetched yet
if (filter.isNotEmpty()) {
launch {
launch {
val productTags = productTagsRepository.getProductTags()
filterProductTagList(productTags)

// fetch from the backend when a filter exists in case not all tags have been fetched yet
if (filter.isNotEmpty()) {
fetchProductTags(searchQuery = filter)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ProductTagsRepository @Inject constructor(
/**
* Returns all product tags for the current site that are in the database
*/
fun getProductTags(): List<ProductTag> {
suspend fun getProductTags(): List<ProductTag> {
return productStore.getTagsForSite(selectedSite.get())
.map { it.toProductTag() }
}
Expand All @@ -80,9 +80,9 @@ class ProductTagsRepository @Inject constructor(
}
}

fun getProductTagsByNames(names: List<String>) =
private suspend fun getProductTagsByNames(names: List<String>) =
productStore.getProductTagsByNames(selectedSite.get(), names).map { it.toProductTag() }

fun getProductTagByName(name: String) =
suspend fun getProductTagByName(name: String) =
productStore.getProductTagByName(selectedSite.get(), name)?.toProductTag()
}
Loading
Loading