Skip to content

Conversation

JonasLudwig1998
Copy link
Contributor

Q A
Bug fix? (use the a.b branch) ✔️
New feature/enhancement? (use the a.x branch)
Deprecations?
BC breaks? (use the c.x branch)
Automated tests included?
Related user documentation PR URL mautic/user-documentation#...
Related developer documentation PR URL mautic/developer-documentation-new#...
Issue(s) addressed Fixes #...

Description

This PR solves #14855
It makes sure that in the update contact/company campaign action bool values can be changed to not only true but also false.


📋 Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)
  2. Create some bool fields (for both contact and company)
  3. Create a campaign with the update contact and update contact's primary company action
  4. Check if with the actions you are able to change bool fields to both yes and no
  5. Check if when you select X both bool fields with the value yes or no stay unchanged
    image

@JonasLudwig1998
Copy link
Contributor Author

@escopecz It's my first time doing some design stuff in Mautic, so I'd be grateful to get some suggestions for improving the code to have a more Mautic-like solution. Also, I was not sure which parts of the solution to test and how. Any suggestions?

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 15 lines in your changes missing coverage. Please review.

Project coverage is 63.68%. Comparing base (47e8dee) to head (88f1c12).
Report is 11 commits behind head on 5.2.

Files with missing lines Patch % Lines
...dBundle/Form/Type/NullableYesNoButtonGroupType.php 0.00% 11 Missing ⚠️
...eadBundle/Form/Type/EntityFieldsBuildFormTrait.php 50.00% 2 Missing ⚠️
...s/LeadBundle/Form/Type/UpdateCompanyActionType.php 0.00% 1 Missing ⚠️
...dles/LeadBundle/Form/Type/UpdateLeadActionType.php 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                5.2   #14888      +/-   ##
============================================
- Coverage     63.69%   63.68%   -0.01%     
- Complexity    34663    34676      +13     
============================================
  Files          2273     2274       +1     
  Lines        103710   103729      +19     
============================================
+ Hits          66054    66058       +4     
- Misses        37656    37671      +15     
Files with missing lines Coverage Δ
...es/LeadBundle/EventListener/CampaignSubscriber.php 74.57% <100.00%> (+0.26%) ⬆️
...s/LeadBundle/Form/Type/UpdateCompanyActionType.php 0.00% <0.00%> (ø)
...dles/LeadBundle/Form/Type/UpdateLeadActionType.php 0.00% <0.00%> (ø)
...eadBundle/Form/Type/EntityFieldsBuildFormTrait.php 82.35% <50.00%> (-1.11%) ⬇️
...dBundle/Form/Type/NullableYesNoButtonGroupType.php 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@patrykgruszka patrykgruszka left a comment

Choose a reason for hiding this comment

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

Consider adding a functional test to verify that the boolean lead field is correctly updated in the campaign. Here is an example: https://github.com/mautic/mautic/blob/5.2/app/bundles/LeadBundle/Tests/EventListener/CampaignSubscriberFunctionalTest.php#L82

It is important to test all options: no change, false, true.

@patrykgruszka patrykgruszka added bug Issues or PR's relating to bugs needs-automated-tests PR's that need automated tests before they can be merged campaigns Anything related to campaigns and campaign builder labels Apr 17, 2025
@escopecz escopecz requested a review from andersonjeccel April 17, 2025 13:01
Copy link
Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

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

I noticed a few changes that would improve the code. Please take a look.

@andersonjeccel
Copy link
Contributor

In terms of design, I think changing the field type is the path for situations like these

Buttons are adequate, thank you for the fix

@patrykgruszka
Copy link
Member

@andersonjeccel I was wondering if something like No change would be more descriptive than just x. What do you think?

@andersonjeccel
Copy link
Contributor

@patrykgruszka sounds great!

@JonasLudwig1998
Copy link
Contributor Author

@escopecz I have two issues with the code that I'm not able to solve:

First of all, I didn't manage to get the overall button responsive. So when the window gets to small it overlaps with other stuff
image
I tried a few different approaches but none of them worked. Do you have any best practice in your mind to solve the problem?

Number two is regarding my functions tests. After adding bool custom fields, I don't mange to set them to the desired value. Do you have an explanation for that?

 $lead       = $this->contactRepository->getEntity($id);

public function createBoolField(string $alias, string $label): void
{
    $field = new LeadField();
    $field->setAlias($alias);
    $field->setLabel($label);
    $field->setType('bool');
    $field->setIsVisible(true);
    $this->em->persist($field);
    $this->em->flush();
}

$this->createBoolField('bool1', 'Bool 1');
$lead->addUpdatedField('bool1', 1);

@escopecz escopecz self-requested a review April 22, 2025 13:34
@escopecz
Copy link
Member

@JonasLudwig1998 I'm not sure about the responsiveness. @andersonjeccel may give a better advise here. I'd look into the columns and make them into a single column before the button group overflow. And the "x" was there for this reason too, I'd think.

For the test, you have to use the FieldModel to create a new field as it's doing also DB schema migrations. Check other tests how it's being done. For example the CampaignDecisionTest::makeField() method. You can extract that to a trait so we don't duplicate the field creation in so many places. But it doesn't matter if you do, it makes tests more readable if it's all in 1 file.

Another thing is that if an ALTER TABLE query is executed then the test cannot roll back. So make sure you turn that off with

protected $useCleanupRollback = false;

One more thing I'd recommend is to create a new contact with new Lead() instead of using API, getting ID and fetching it. It speeds up the test by a lot. I hope that's all that's needed to make the test work.

And please order the methods from public to protected to private so the public methods are at the top and private at the bottom of the classes.

@patrykgruszka
Copy link
Member

This field type is stored in the database as boolean, so it should be:

$field->setType('boolean');

@andersonjeccel
Copy link
Contributor

@JonasLudwig1998 the columns rendering each field, use classes "col-md-6 col-xs-12" (both together, will generate 2 columns on desktop and one above the other on mobile)

@matbcvo matbcvo added this to the 5.2.5 milestone Apr 23, 2025
@JonasLudwig1998
Copy link
Contributor Author

@andersonjeccel I changed _updatelead_action_widget.html.twig and _updatecompany_action_widget.html.twig to make the campaign action forms responsive (by adding col-md-6 col-xs-12").
Is this a good solution or is there a smarter and cleaner solution?

@JonasLudwig1998
Copy link
Contributor Author

@escopecz Your suggestions are implemented now

@JonasLudwig1998 I'm not sure about the responsiveness. @andersonjeccel may give a better advise here. I'd look into the columns and make them into a single column before the button group overflow. And the "x" was there for this reason too, I'd think.

For the test, you have to use the FieldModel to create a new field as it's doing also DB schema migrations. Check other tests how it's being done. For example the CampaignDecisionTest::makeField() method. You can extract that to a trait so we don't duplicate the field creation in so many places. But it doesn't matter if you do, it makes tests more readable if it's all in 1 file.

Another thing is that if an ALTER TABLE query is executed then the test cannot roll back. So make sure you turn that off with

protected $useCleanupRollback = false;

One more thing I'd recommend is to create a new contact with new Lead() instead of using API, getting ID and fetching it. It speeds up the test by a lot. I hope that's all that's needed to make the test work.

And please order the methods from public to protected to private so the public methods are at the top and private at the bottom of the classes.

@matbcvo matbcvo requested a review from patrykgruszka April 23, 2025 13:51
@matbcvo matbcvo moved this to 🦸🏻 Needs 2 tests in Open Source Fridays Apr 23, 2025
@matbcvo matbcvo added ready-to-test PR's that are ready to test code-review-needed PR's that require a code review before merging labels Apr 23, 2025
@matbcvo matbcvo linked an issue Apr 23, 2025 that may be closed by this pull request
1 task
@matbcvo matbcvo changed the title Enable saving bool field value false in update contact action Restore "No change" option for boolean fields in Campaign Update Contact/Company action Apr 23, 2025
@matbcvo matbcvo removed the needs-automated-tests PR's that need automated tests before they can be merged label Apr 26, 2025
Copy link
Member

@RCheesley RCheesley left a comment

Choose a reason for hiding this comment

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

This fixes the issue by introducing the 'no change' option - I agree with @matbcvo that we need this to be a translatable string, @JonasLudwig1998 could you action that?

@andersonjeccel I was a little concerned that perhaps these should have some colour indications but perhaps thinking about it we don't want to assume which is positive or negative?

These were the ones I was thinking perhaps should have colour indicators:
New-Campaign-Mautic-04-28-2025_12_37_PM

Note: This can be followed up in a separate PR if necessary and shouldn't block the merging of this PR providing the translation string is fixed.

@RCheesley RCheesley added pending-test-confirmation PR's that require one test before they can be merged pending-feedback PR's and issues that are awaiting feedback from the author and removed ready-to-test PR's that are ready to test labels Apr 28, 2025
@RCheesley RCheesley moved this from 🦸🏻 Needs 2 tests to ⏳︎ Needs 1 more test in Open Source Fridays Apr 28, 2025
@RCheesley RCheesley added code-review-passed PRs which have passed code review and removed pending-feedback PR's and issues that are awaiting feedback from the author code-review-needed PR's that require a code review before merging labels Apr 28, 2025
@RCheesley
Copy link
Member

Note: I realised I had not tested the company boolean field updates in campaigns which I've just done - and this works too.

@matbcvo matbcvo added user-testing-passed PRs which have been successfully tested by the required number of people. and removed pending-test-confirmation PR's that require one test before they can be merged labels Apr 28, 2025
Copy link
Contributor

@matbcvo matbcvo left a comment

Choose a reason for hiding this comment

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

I’ve tested the PR and found no issues. Thank you!

Copy link
Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

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

I see no issues in the code changes 👍

@escopecz escopecz added the ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged label Apr 28, 2025
@matbcvo matbcvo merged commit 26b614d into mautic:5.2 Apr 28, 2025
16 of 17 checks passed
@github-project-automation github-project-automation bot moved this from ⏳︎ Needs 1 more test to 🥳 Done in Open Source Fridays Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs campaigns Anything related to campaigns and campaign builder code-review-passed PRs which have passed code review ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged user-testing-passed PRs which have been successfully tested by the required number of people.
Projects
Status: 🥳 Done
Development

Successfully merging this pull request may close these issues.

Regression: Handling of Bool-fields of Campaign-Action "Update Contact"
6 participants