fields icon indicating copy to clipboard operation
fields copied to clipboard

Fixed issue with hiding conditions not hiding containers in simple ticket view

Open akstis-typer opened this issue 10 months ago • 17 comments

  • It fixes #847

akstis-typer avatar Apr 10 '25 12:04 akstis-typer

Just to clarify: in my fresh installation (latest versions of everything), I had to place the code inside the showForTab function below the line:

$display_condition = new PluginFieldsContainerDisplayCondition();

like this:

...
$display_condition = new PluginFieldsContainerDisplayCondition();

// @akstis-typer code starts here ------
if($item->fields['type'] == "")
{
    $item->fields['type'] = $params['options']['type'];
}
if($item->fields['itilcategories_id'] == "")
{
    $item->fields['itilcategories_id'] = $params['options']['itilcategories_id'];
}
// @akstis-typer code ends here ------

if ($display_condition->computeDisplayContainer($item, $c_id)) {
...

Otherwise, it didn’t work properly in my environment

DaviidMM avatar Apr 11 '25 09:04 DaviidMM

I've been testing this code and works correctly except for one more issue: When a custom field is shown and you edit another field (e.g. title), the custom field's alignment breaks again. My solution was to add echo "<div class='offset-md-1 col-md-8 col-xxl-6'>"; into the ajax/container.php file, inside the if ($display_condition->computeDisplayContainer($item, $containers_id)) { condition:

$display_condition = new PluginFieldsContainerDisplayCondition();
    if ($display_condition->computeDisplayContainer($item, $containers_id)) {
        $field_options = [
            'label_class' => 'col-lg-3',
            'input_class' => 'col-lg-9',
        ];
        echo "<div class='offset-md-1 col-md-8 col-xxl-6'>";
        PluginFieldsField::showDomContainer(
            $containers_id,
            $item,
            $type,
            $subtype,
            $field_options
        );
        echo "</div>";
    } else {
        echo '';
    }

After the showDomContainer method i close the created div with echo "</div>";

DaviidMM avatar May 05 '25 09:05 DaviidMM

Hi @akstis-typer

can you rebase ?

stonebuzz avatar May 06 '25 07:05 stonebuzz

Hi @akstis-typer

can you rebase ?

Hi, you mean I need to add last changes of original repository? Or something else? I'm not so good at git so I didn't get it :0

akstis-typer avatar May 06 '25 07:05 akstis-typer

git fetch upstream (github repo)
git pull --rebase upstream main
git push --force 

That should be sufficient.

stonebuzz avatar May 20 '25 07:05 stonebuzz

I think I did it right. The next step is unit tests - how do I make them? Or can I run yours? I launched php-fixer and php-stan analyzer - this showed me that all is OK

akstis-typer avatar May 23 '25 06:05 akstis-typer

I've done poorly last time and accidentally revert changes in twig files. Now I reverted all back how it should be and removed spaces and new lines I added.

akstis-typer avatar May 23 '25 07:05 akstis-typer

Finally I got it

akstis-typer avatar May 23 '25 08:05 akstis-typer

The next step is unit tests - how do I make them? Or can I run yours?

We currently have no tests on this plugin; but we will work on adding some quickly. For now, you cannot add tests for your changes; we'll ping you.

Until that, we asked feedback from several users to know if their issues are resolved by your changes.

Thanks a lot for your worK.

trasher avatar May 23 '25 09:05 trasher

=

I've been testing this code and works correctly except for one more issue: When a custom field is shown and you edit another field (e.g. title), the custom field's alignment breaks again. My solution was to add echo "<div class='offset-md-1 col-md-8 col-xxl-6'>"; into the ajax/container.php file, inside the if ($display_condition->computeDisplayContainer($item, $containers_id)) { condition:

$display_condition = new PluginFieldsContainerDisplayCondition();
    if ($display_condition->computeDisplayContainer($item, $containers_id)) {
        $field_options = [
            'label_class' => 'col-lg-3',
            'input_class' => 'col-lg-9',
        ];
        echo "<div class='offset-md-1 col-md-8 col-xxl-6'>";
        PluginFieldsField::showDomContainer(
            $containers_id,
            $item,
            $type,
            $subtype,
            $field_options
        );
        echo "</div>";
    } else {
        echo '';
    }

After the showDomContainer method i close the created div with echo "</div>";

I tested it and in my environment it only worked correctly this way.

Thank you very much everyone!

leeopereira avatar Jun 05 '25 20:06 leeopereira

It seems that there are many unrelated changes included in this PR. Translation files do not need to be committed, as we have a dedicated CI process to push and pull translations from Transifex. Also, adding conditions on the field looks more like a new feature than a fix. This should be handled in a separate PR to keep the reviews focused and easier to follow.

stonebuzz avatar Aug 18 '25 08:08 stonebuzz

My bad. I'll get rid of unnecessary changes

akstis-typer avatar Aug 18 '25 15:08 akstis-typer

Great, congratulations! You updated the plugin, but when I applied the update, not only did it not fix this problem, but the fix from the colleague above no longer works. Great!

leeopereira avatar Aug 27 '25 23:08 leeopereira

Hi, @leeopereira, my fix doesn't work on the nightly version of the plugin?

akstis-typer avatar Aug 28 '25 04:08 akstis-typer

Hi, @leeopereira, my fix doesn't work on the nightly version of the plugin?

Oi @akstis-typer , Unfortunately not, I had to restore a backup of the previous version of the files. When I updated, the deleted files were replaced with the originals from the new version, and the problem returned. The hide condition stopped working, and the custom fields became misaligned. :/

leeopereira avatar Aug 28 '25 04:08 leeopereira

@leeopereira , this happened because this changes are not in the main branch of fields plugin repo, so when you update using glpi - they getting overriden by update that developers made. But, if you pull changes from this branch and merge it with updated branch - it'll still work :) I may update my branch to the nightly one, and you'll be able to pull it without problem.

akstis-typer avatar Aug 28 '25 04:08 akstis-typer

@akstis-typer After updating, I tried editing the files and inserting the corrections here in the topic, but it still didn't work. I don't know if they changed something in the code that impacted the correction. But I just returned the two old edited files and it worked.

leeopereira avatar Aug 28 '25 05:08 leeopereira