Skip to content
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

IBX-6750/IBX-6754/IBX-6839: Implementation of smart/expert mode #1017

Merged
merged 17 commits into from
Dec 4, 2023

Conversation

adamwojs
Copy link
Member

@adamwojs adamwojs commented Nov 30, 2023

Question Answer
Tickets IBX-6750/IBX-6754/IBX-6839
Bug fix? no
New feature? yes
BC breaks? no
Tests pass? yes
Doc needed? yes
License GPL-2.0

Changes summary:

  • New APIs to interact with smart/expert mode

    • Twig functions: ibexa_is_smart_mode, ibexa_is_expert_mode
    • Ibexa\AdminUi\Specification\UserMode\IsUserModeEnabled specification (internal)
  • Added mode switcher to user context menu
    image

  • Applied user mode to main menu item & tabs visibility

  • Renamed "Quick preview" tab to "Data"

  • Hidden "Language Code" column in "Translations tab" when smart mode is active

  • Fixed sub-items list initialization which rely on forms from "Technical Details" tab

  • Added missing "Modified" and "Published" field to the "Authors" tab

Smart / Expert mode comparison

Smart mode

image

Expert mode

image

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

]) %}

{% if ibexa_is_expert_mode() %}
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend utilizing ibexa_user_settings['user_mode'] instead of a dedicated Twig function.

If we name the function with the "expert" keyword, this designation will remain with us for the upcoming years. If we decide to change the name or introduce additional user modes, we will need to implement extra logic

Copy link
Contributor

Choose a reason for hiding this comment

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

Or ibexa_mode(...) function if we cannot rely on user settings being present in the template.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even, we can use wildcards in twig function names and do it like ibexa_is_*_mode and handle it that way.

Copy link
Contributor

@Steveb-p Steveb-p Dec 1, 2023

Choose a reason for hiding this comment

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

One issue with wildcards is that you cannot use mode value as a variable.

You have to use the full function name immediately.

{% set expected_mode = 'expert' %}
{{ expected_mode is same as 'expert' ? ibexa_is_expert_mode() : ibexa_is_smart_mode() }}

Using an argument does not have this limitation.

Copy link
Member Author

Choose a reason for hiding this comment

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

ibexa_user_settings['user_mode'] or ibexa_mode(...) is a no go for me. It's simply bad DX:

{% if ibexa_user_settings['user_mode'] === constant('\\Ibexa\\AdminUi\\UserSetting\\UserMode::SMART') %}
    Do something
{% endif %}

Wildcard function is a good idea, but we don't need it at the moment.

@adamwojs adamwojs changed the title Implemntation of smart/expert mode Implementation of smart/expert mode Nov 30, 2023
if ($form->isSubmitted() && $form->isValid()) {
$this->userSettingService->setUserSetting(
UserMode::IDENTIFIER,
$data->getMode() ? UserMode::EXPERT : UserMode::SMART
Copy link
Contributor

Choose a reason for hiding this comment

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

Why aren't we using UserMode::EXPERT and UserMode::SMART directly, instead of relying on a straight up boolean?

For me myself, it would make sense to use the same value as user settings. It would be also a lot easier to work with in case a third setting is introduced.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I commented on the same issue. Fully agree, user setting was prepared to accept more user modes in the future. We could maybe even make it extendable by developers, especially with suggestions like #1017 (comment) Data format should reflect values from the user setting.

]) %}

{% if ibexa_is_expert_mode() %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Or ibexa_mode(...) function if we cannot rely on user settings being present in the template.


final class UserModeChangeData
{
private ?bool $mode;
Copy link
Contributor

@webhdx webhdx Dec 1, 2023

Choose a reason for hiding this comment

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

Why don't you use UserMode class constants for the value? It makes more sense since the setting is prepared to handle more user modes if there is ever a need. If your data class could reflect it, introducing more user modes will be easier as you would only need to change the form type.

Copy link
Member Author

@adamwojs adamwojs Dec 1, 2023

Choose a reason for hiding this comment

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

At the moment is checkbox (rendered as switcher) on the user menu (expert mode is enabled or no). I could add data transformer if need.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't even need a Data Transformer. You can use arbitrary string values in data class and do some magic with false_values and value on CheckboxType (ref. https://symfony.com/doc/5.4/reference/forms/types/checkbox.html).

@mnocon mnocon force-pushed the smart_expert_mode branch 3 times, most recently from b3623d7 to 58c890d Compare December 1, 2023 23:57
@mnocon
Copy link
Contributor

mnocon commented Dec 4, 2023

58c890d contains the Behat changes (together with https://github.com/ibexa/version-comparison/pull/62 and https://github.com/ibexa/product-catalog/pull/1103 it's enough to make tests pass)

@webhdx
Copy link
Contributor

webhdx commented Dec 4, 2023

@mnocon There are some left over var_dumps in the Behat code.

{{ ibexa_location_sort_order_as_rest_value(location_asc) }}
{{ ibexa_location_sort_order_as_rest_value(location_desc) }}
--DATA--
use \Ibexa\Contracts\Core\Repository\Values\Content\Location;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the import required?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it does, SORT_ORDER_ASC and SORT_ORDER_DESC constants reference Location.

@webhdx webhdx requested review from ViniTou, Steveb-p and a team December 4, 2023 08:50
@mnocon mnocon force-pushed the smart_expert_mode branch from 58c890d to d31a7f1 Compare December 4, 2023 08:51
@mnocon
Copy link
Contributor

mnocon commented Dec 4, 2023

@mnocon There are some left over var_dumps in the Behat code.

Thanks, already removed 😅

Copy link

sonarqubecloud bot commented Dec 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
1.7% 1.7% Duplication

{{ ibexa_location_sort_order_as_rest_value(location_asc) }}
{{ ibexa_location_sort_order_as_rest_value(location_desc) }}
--DATA--
use \Ibexa\Contracts\Core\Repository\Values\Content\Location;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it does, SORT_ORDER_ASC and SORT_ORDER_DESC constants reference Location.

{{ ibexa_location_sort_field_as_rest_sort_clause(location) }}
{% endfor %}
--DATA--
use \Ibexa\Contracts\Core\Repository\Values\Content\Location;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this import needed?

@adamwojs adamwojs merged commit 438ba7c into main Dec 4, 2023
22 of 23 checks passed
@adamwojs adamwojs deleted the smart_expert_mode branch December 4, 2023 09:41
@adamwojs adamwojs changed the title Implementation of smart/expert mode IBX-6750/IBX-6754/IBX-6839: Implementation of smart/expert mode Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.