Skip to content

Add a way to clear parent category #11428

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 2 commits into from
May 8, 2024
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 @@ -106,6 +106,10 @@ class AddProductCategoryFragment :
}
}

binding.clearParentCategory.setOnClickListener {
viewModel.onClearParentCategoryClicked()
}

with(binding.productCategoryParent) {
viewModel.getSelectedParentCategoryName()?.let { setText(it) }
setClickListener {
Expand Down Expand Up @@ -160,11 +164,18 @@ class AddProductCategoryFragment :
}
new.selectedParentId.takeIfNotEqualTo(old?.selectedParentId) {
val parentCategoryName = viewModel.getSelectedParentCategoryName()
parentCategoryName?.let { binding.productCategoryParent.setHtmlText(it) }
if (parentCategoryName != null) {
binding.productCategoryParent.setHtmlText(parentCategoryName)
} else {
binding.productCategoryParent.setHtmlText("")
}
Comment on lines +167 to +171
Copy link
Member

Choose a reason for hiding this comment

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

very minor np, we could shorten this with something like:

            binding.productCategoryParent.setHtmlText(parentCategoryName.orEmpty())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, good call 👍

}
new.isEditingMode.takeIfNotEqualTo(old?.isEditingMode) {
deleteMenuItem?.isVisible = it
}
new.selectedParentId.takeIfNotEqualTo(old?.selectedParentId) {
binding.clearParentCategory.isEnabled = it != 0L && it != null
}
}

viewModel.event.observe(viewLifecycleOwner) { event ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class AddProductCategoryViewModel @Inject constructor(
}
}

fun onClearParentCategoryClicked() {
addProductCategoryViewState = addProductCategoryViewState.copy(selectedParentId = 0L)
}

fun onCategoryNameChanged(categoryName: String) {
addProductCategoryViewState = if (categoryName.isEmpty()) {
addProductCategoryViewState.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/major_100"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">
Expand Down Expand Up @@ -53,5 +52,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/product_category_name" />


<com.google.android.material.button.MaterialButton
style="@style/Woo.Button.TextButton.TextStart"
android:id="@+id/clear_parent_category"
android:paddingStart="@dimen/major_100"
android:paddingEnd="@dimen/minor_100"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/product_category_clear_parent"/>

</com.woocommerce.android.widgets.WCElevatedLinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions WooCommerce/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,7 @@
<string name="product_variation_no_price_set">No price set</string>
<string name="product_categories">Categories</string>
<string name="product_category_empty">Add category</string>
<string name="product_category_clear_parent">Clear parent category</string>
<string name="product_category_list_empty_title">Add your first category</string>
<string name="product_category_list_empty_message">Organise your products in categories</string>
<string name="product_add_category">Add category</string>
Expand Down