Problem/Motivation

Display overview of the styles and layouts.

Proposed resolution

So the starting point here is some "Paragraphs Collection" admin - reports page. That page will have two tabs: Layouts, Styles.
And later more with more discoveries. We need this for better design consistency.
Columns should be:
- Style icon
- Style name
- Style description
Provide UI screenshots

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#23 layout_and_styles-2860820-23.patch22.67 KBVladimirMarko
#23 interdiff-2860820-21-23.txt893 bytesVladimirMarko
#23 layout_and_styles-2860820-23-test-only.patch2.75 KBVladimirMarko
#21 layout_and_styles-2860820-21.patch22.64 KBVladimirMarko
#20 layout_and_styles-2860820-20.patch22.63 KBVladimirMarko
#20 interdiff-2860820-17-20.txt33.01 KBVladimirMarko
#17 layout_and_styles-2860820-17.patch21.72 KBVladimirMarko
#17 interdiff-2860820-14-17.txt21.3 KBVladimirMarko
#17 layout_and_styles-2860820-17-test-only.patch2.72 KBVladimirMarko
#14 Layouts overview 2.png55.91 KBVladimirMarko
#14 layout_and_styles-2860820-14.patch17.69 KBVladimirMarko
#14 interdiff-2860820-13-14.txt1.5 KBVladimirMarko
#13 Styles overview.png35.99 KBVladimirMarko
#13 Layouts overview.png47.58 KBVladimirMarko
#13 layout_and_styles-2860820-13.patch17.25 KBVladimirMarko
#13 interdiff-2860820-11-13.txt15.08 KBVladimirMarko
#11 Styles overview WIP 2.png40.52 KBVladimirMarko
#11 layout_and_styles-2860820-11.patch18.66 KBVladimirMarko
#11 interdiff-2860820-9-11.txt10.55 KBVladimirMarko
#9 Styles overview WIP.png44.07 KBVladimirMarko
#9 layout_and_styles-2860820-9.patch16.75 KBVladimirMarko
#9 interdiff-2860820-7-9.txt16.78 KBVladimirMarko
#7 layout_and_styles-2860820-7.patch9.79 KBVladimirMarko
#7 interdiff-2860820-6-7.txt10.76 KBVladimirMarko
#6 layout_and_styles-2860820-6.patch10.3 KBVladimirMarko
#6 interdiff-2860820-5-6.txt2.77 KBVladimirMarko
#5 layout_and_styles-2860820-5.patch8.18 KBVladimirMarko

Comments

Ginovski created an issue. See original summary.

ginovski’s picture

Issue summary: View changes
ginovski’s picture

Issue summary: View changes
VladimirMarko’s picture

Assigned: Unassigned » VladimirMarko
VladimirMarko’s picture

Status: Active » Needs work
StatusFileSize
new8.18 KB

This is my progress thus far.

VladimirMarko’s picture

StatusFileSize
new2.77 KB
new10.3 KB

Added functions to get from grid layouts to entities in which those layouts are being used.

VladimirMarko’s picture

StatusFileSize
new10.76 KB
new9.79 KB

Deleted all Paragraph entities stuff. Added functions for styles.

miro_dietiker’s picture

This is an admin UI feature, please provide a screenshot of the UI.

+++ b/src/Controller/OverviewController.php
@@ -0,0 +1,229 @@
+  public function getParagraphsTypesLayoutsEnabled() {
...
+  public function getParagraphsTypesStyleGroupsUsed() {

I think we should generalise this method to getParagraphTypesWithPlugin($plugin_id)

VladimirMarko’s picture

StatusFileSize
new16.78 KB
new16.75 KB
new44.07 KB

Work in progress. I still need to add the right classes to the table entries.

Styles overview WIP

ginovski’s picture

  1. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,351 @@
    +    $build['filters']['category'] = [
    +      '#type' => 'select',
    ...
    +    $build['filters']['text'] = [
    

    There is a followup for this #2860830: Add group filter in the layout and style overview page, we can move everything associated with filters in that issue and keep it simple here.

  2. +++ b/paragraphs_collection.links.menu.yml
    @@ -0,0 +1,6 @@
    +  description: 'Overview of all layouts and styles for the respective plugins.'
    

    The description should be more general, since there might be some new plugins in the overview. Maybe something like:
    "Overview of the behavior plugins"

  3. +++ b/paragraphs_collection.routing.yml
    @@ -0,0 +1,18 @@
    +    _title: 'Available layouts (grid layout plugin)'
    ...
    +    _title: 'Available Styles (styles plugin)'
    

    We can drop the (grid layout plugin) and (styles plugin)

VladimirMarko’s picture

StatusFileSize
new10.55 KB
new18.66 KB
new40.52 KB

Work in progress. The styles overview is now working nicely. I will work on refactoring the grid layout overview code into the working styles code now.

@Ginovski
I will make the generalization changes later. Everything #2860830: Add group filter in the layout and style overview page wants is already in this patch, however. I am not going to split it anymore. That would mean far too much useless refactoring.

Styles overview WIP 2

miro_dietiker’s picture

Yeah, let's try to avoid changing the goal. Just complete the current scope properly.
Basic test coverage is still a must to get this in. To speedup, we could do JS tests in a follow-up.

  1. +++ b/js/overview.js
    @@ -0,0 +1,74 @@
    +      function filterSensorList() {
    ...
    +        $rows.each(showSensorRow);
    

    Eliminate the term Sensor.

  2. +++ b/paragraphs_collection.routing.yml
    @@ -0,0 +1,18 @@
    +    _permission: 'administer paragraphs types' # @todo Change this?
    ...
    +    _permission: 'administer paragraphs types' # @todo Change this?
    

    IMHO these permissions are pretty fine.

VladimirMarko’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new15.08 KB
new17.25 KB
new47.58 KB
new35.99 KB

The styles and the layouts overview now both look nice and the search is functional everywhere.
Completed styles overview

Moving on to writing the tests.

VladimirMarko’s picture

StatusFileSize
new1.5 KB
new17.69 KB
new55.91 KB

Fixed wrong labeling in the layouts overview.
Layouts overview with fixed labeling

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,389 @@
    +   * ['<plugin ID>' => ['<Paragraphs Type ID>' => <item(s) (plugin-specific)>]]
    

    Better make an example.

  2. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,389 @@
    +   * Lists Paragraphs Types with discoverable items they allow for a plugin.
    ...
    +   *   Discoverable items keyed by by Paragraphs Type IDs. The form of the items
    ...
    +  public function getItemsPerParagraphsTypesPerPlugin($plugin_id) {
    

    What are discoverable items?

  3. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,389 @@
    +  public function layouts() {
    +    return self::content('grid_layout');
    

    This method calls a different method that delivers two pretty much different things based on a string argument.
    Instead, the called method should deliver what is uniform and the caller should do the specific things.

  4. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,389 @@
    +    switch ($plugin_id) {
    ...
    +    switch ($plugin_id) {
    ...
    +      switch ($plugin_id) {
    ...
    +      switch ($plugin_id) {
    ...
    +    switch ($plugin_id) {
    ...
    +    switch ($plugin_id) {
    

    All these switches should not exist.

    Do not create methods that do two different things based on an argument.
    Instead, put parts that are similar code-wise and outsource them in a method you call.

VladimirMarko’s picture

VladimirMarko’s picture

Status: Needs work » Needs review
StatusFileSize
new2.72 KB
new21.3 KB
new21.72 KB

Added a test. Removed all the switch statements and broke up both affected methods into two methods each.

The last submitted patch, 17: layout_and_styles-2860820-17-test-only.patch, failed testing.

primsi’s picture

Status: Needs review » Needs work
  1. --- /dev/null
    +++ b/css/overview.css
    
    @@ -0,0 +1,10 @@
    diff --git a/js/overview.js b/js/overview.js
    

    Both this files are actually used in admin context, so I would do overview.admin.js

  2. +++ b/js/overview.js
    @@ -0,0 +1,67 @@
    +      // var $selects = $
    

    Commented out code.

  3. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +   * The first level is keyed by Paragraphs Type IDs. The second-level keys have
    +   * no meaning. The second-level values are machine names of the grid layouts
    +   * that the first-level key Paragraphs Type has enabled.
    +   * Exception: An empty second-level array means that all layouts are enabled
    +   * for that Paragraphs Type.
    

    IMHO we could just add an example and shorten this text.

  4. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +  protected $gridLayoutsOrderedByParagraphsTypes;
    ...
    +  protected $styleGroupsOrderedByParagraphsTypes;
    

    Ordered or grouped?

  5. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +   *   A nested array. The first level is keyed by Paragraphs Type IDs. The
    +   *   second-level keys have no meaning. The second-level values are machine
    +   *   names of the grid layouts that the first-level key Paragraphs Type has
    +   *   enabled.
    

    Same here, an example would be helpful.

  6. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +    $paragraph_type_ids = \Drupal::entityQuery('paragraphs_type')->execute();
    

    I think ParagraphsType::loadMultiple() should do it here.

  7. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +      $paragraphs_type_ids = $this->getParagraphsTypesPerLayout($layout_id);
    ...
    +      foreach ($paragraphs_type_ids as $paragraphs_type_id) {
    +        $paragraphs_type = ParagraphsType::load($paragraphs_type_id);
    

    Maybe I am not getting something but, do we need the list built by get*OrderedBy... elsewhere too? If it's only here shouldn't we rather have a list of behavior ids as keys and paragraph types that use them as values? If that's the case we could get rid of a some of the above methods. Also if we load multiple and store them there I think we wont need to load them separately here.

  8. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +        if($paragraphs_type_link_list != []) {
    +          $paragraphs_type_link_list[] = ['#plain_text' => ', '];
    +        }
    

    Just implode the list where you use it.

  9. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +        '#type' => 'markup',
    ...
    +        '#prefix' => '<span class="table-filter-text-source">',
    +        '#suffix' => '</span>',
    

    I think you could use container instead of markup.

  10. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +        '#markup' => Html::escape($layout['title']),
    

    Not sure if this needs escaping, doesn't twig do that for us already?

  11. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +        '#title' => $this->t($layout['description']) ?: $this->t('Details'),
    

    Description should be translatable elsewhere. If it's not an issue should be opened. Also Details should probably be "Description not available" imho.

  12. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +        '#type' => 'item',
    +        '#title' => $this->t('ID'),
    +        '#markup' => '<span class="table-filter-text-source">'. Html::escape($layout_id) . '</span>',
    +        '#prefix' => '<div class="container-inline">',
    +        '#suffix' => '</div>',
    

    Same remark about escaping and use of container as above

  13. +++ b/src/Controller/OverviewController.php
    @@ -0,0 +1,427 @@
    +    $filters = [
    +      '#type' => 'fieldset',
    +      '#attributes' => [
    +        'class' => ['table-filter', 'js-show', 'form--inline'],
    +        'data-table' => '.paragraphs-collection-overview-table',
    +      ],
    +      '#weight' => -10,
    

    If that's meant to be above, let's move filters to the top of this method.

Given that the styles method is quite similar same remarks as for the grid one apply.

VladimirMarko’s picture

Status: Needs work » Needs review
StatusFileSize
new33.01 KB
new22.63 KB

8. That wouldn't work. I need the '#plain_text' keys for it to be rendered correctly inside the table.

10.'#markup' always needs escaping. However, it's no longer an issue here, as I removed all the occurrences from the current patch.

11. I have created a new issue to make the descriptions (and titles) translatable: #2867856: Titles and descriptions of grid layouts and styles are not being translated

I implemented all the other suggestions.

VladimirMarko’s picture

StatusFileSize
new22.64 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 21: layout_and_styles-2860820-21.patch, failed testing.

VladimirMarko’s picture

Status: Needs work » Needs review
StatusFileSize
new2.75 KB
new893 bytes
new22.67 KB

Adjusted the test to accommodate a change to the present grid layouts.

The last submitted patch, 23: layout_and_styles-2860820-23-test-only.patch, failed testing.

primsi’s picture

Status: Needs review » Fixed
primsi’s picture

Status: Fixed » Needs work

Overlooked "To speedup, we could do JS tests in a follow-up.", re-opening. Please close when the follow up is created

miro_dietiker’s picture

Looks pretty nice. Committed as is.

Back to needs-work to discuss the missing steps and create all follow-ups. Then plz close.

Follow-up: If i limit the grid paragraph type in paragraphs_collection_demo to two layouts, all others disappear. Layouts without usage should also be listed. Same for the group.

Follow-up: Should we remove the term "Grid" completely from the layout plugin? Can we really only handle grids? Not yet sure.
If not, i think we should be clear that the tab list Grid layouts, not layouts in general.

We need a meta about evolving the management UI of layout and grid. All related features should be grouped there. For instance, also the creating of new groups through the UI.

ginovski’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.