Skip to content

Commit

Permalink
Merge pull request #12995 from woocommerce/issue/12994-custom-fields-…
Browse files Browse the repository at this point in the history
…code-cleanup

[Custom Fields] Code cleanup
  • Loading branch information
hichamboushaba authored Dec 3, 2024
2 parents 2b78305 + 19e4eea commit cd1d38c
Show file tree
Hide file tree
Showing 15 changed files with 5 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.woocommerce.android.ui.orders.details.OrderDetailFragmentDirections
import com.woocommerce.android.ui.orders.shippinglabels.PrintShippingLabelFragmentDirections
import com.woocommerce.android.ui.orders.tracking.AddOrderShipmentTrackingFragmentDirections
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam
import com.woocommerce.android.util.FeatureFlag
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -208,15 +207,9 @@ class OrderNavigator @Inject constructor() {
}

is ViewCustomFields -> {
val action = if (FeatureFlag.CUSTOM_FIELDS.isEnabled()) {
OrderDetailFragmentDirections.actionOrderDetailFragmentToCustomFieldsFragment(
parentItemId = target.orderId
)
} else {
OrderDetailFragmentDirections.actionOrderDetailFragmentToCustomOrderFieldsFragment(
orderId = target.orderId
)
}
val action = OrderDetailFragmentDirections.actionOrderDetailFragmentToCustomFieldsFragment(
parentItemId = target.orderId
)
fragment.findNavController().navigateSafely(action)
}
is AIThankYouNote -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,6 @@ class OrderDetailFragment :
new.wcShippingBannerVisible?.takeIfNotEqualTo(old?.wcShippingBannerVisible) {
showInstallWcShippingBanner(it)
}
new.isCustomFieldsButtonShown?.takeIfNotEqualTo(old?.isCustomFieldsButtonShown) {
binding.customFieldsCard.root.isVisible = it
if (it && !FeatureFlag.CUSTOM_FIELDS.isEnabled()) {
// When the feature flag is disabled, keep the original text and hide the icon
with(binding.customFieldsCard.customFieldsButton) {
icon = null
text = getString(R.string.orderdetail_view_custom_fields)
}
}
}
new.isAIThankYouNoteButtonShown.takeIfNotEqualTo(old?.isAIThankYouNoteButtonShown) {
binding.orderDetailsAICard.isVisible = it
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.woocommerce.android.ui.orders.details

import android.content.Context
import androidx.annotation.StringRes
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LiveData
Expand Down Expand Up @@ -59,7 +58,6 @@ import com.woocommerce.android.ui.orders.creation.shipping.GetShippingMethodsWit
import com.woocommerce.android.ui.orders.creation.shipping.RefreshShippingMethods
import com.woocommerce.android.ui.orders.creation.shipping.ShippingLineDetails
import com.woocommerce.android.ui.orders.creation.shipping.ShippingMethodsRepository
import com.woocommerce.android.ui.orders.details.customfields.CustomOrderFieldsHelper
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam
import com.woocommerce.android.ui.payments.cardreader.payment.CardReaderPaymentCollectibilityChecker
import com.woocommerce.android.ui.payments.receipt.PaymentReceiptHelper
Expand Down Expand Up @@ -87,9 +85,7 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.withIndex
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.wordpress.android.fluxc.model.OrderAttributionInfo
import org.wordpress.android.fluxc.model.metadata.WCMetaData
import org.wordpress.android.fluxc.store.WCOrderStore.UpdateOrderResult.OptimisticUpdateResult
import org.wordpress.android.fluxc.store.WCOrderStore.UpdateOrderResult.RemoteUpdateResult
import org.wordpress.android.fluxc.store.WooCommerceStore
Expand Down Expand Up @@ -269,7 +265,6 @@ class OrderDetailViewModel @Inject constructor(
loadOrderNotes()
displayProductAndShippingDetails()
displayCustomAmounts()
checkOrderMetaData()
}

private suspend fun fetchOrder(showSkeleton: Boolean) {
Expand Down Expand Up @@ -313,13 +308,6 @@ class OrderDetailViewModel @Inject constructor(
}
}

private suspend fun checkOrderMetaData() {
viewState = viewState.copy(
isCustomFieldsButtonShown = FeatureFlag.CUSTOM_FIELDS.isEnabled() ||
orderDetailRepository.orderHasMetadata(navArgs.orderId)
)
}

/**
* User clicked the button to view custom fields
*/
Expand All @@ -328,21 +316,10 @@ class OrderDetailViewModel @Inject constructor(
triggerEvent(OrderNavigationTarget.ViewCustomFields(navArgs.orderId))
}

/**
* User tapped an actionable custom field
*/
fun onCustomFieldClicked(context: Context, value: String) {
CustomOrderFieldsHelper.handleMetadataValue(context, value)
}

fun onBackPressed() {
triggerEvent(MultiLiveEvent.Event.Exit)
}

fun getOrderMetadata(): List<WCMetaData> = runBlocking {
orderDetailRepository.getOrderMetadata(navArgs.orderId)
}

fun onRefreshRequested() {
tracker.trackOrderDetailPulledToRefresh()
viewState = viewState.copy(isRefreshing = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ data class OrderDetailViewState(
val areShippingLabelsVisible: Boolean? = null,
val isProductListMenuVisible: Boolean? = null,
val wcShippingBannerVisible: Boolean? = null,
val isCustomFieldsButtonShown: Boolean? = null,
val isAIThankYouNoteButtonShown: Boolean = false,
val isOrderDetailEmpty: Boolean = false,
) : Parcelable {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit cd1d38c

Please sign in to comment.