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

[Tabs][Carousel] The Json export doesn't work properly for nested Tabs and Carousels #298

Closed
andreeadracea opened this issue Sep 26, 2018 · 4 comments
Labels
bug Unexpected problem or unintended behavior that impairs normal functioning of the product.
Milestone

Comments

@andreeadracea
Copy link
Contributor

andreeadracea commented Sep 26, 2018

The items elements are not exported properly in Json when having nested tabs.
(CQ-4253492)

@gabrielwalt gabrielwalt added the bug Unexpected problem or unintended behavior that impairs normal functioning of the product. label Oct 26, 2018
@gabrielwalt gabrielwalt added this to the 2.2.2 milestone Oct 26, 2018
@jckautzmann
Copy link
Contributor

We should first define how the JSON should look like. I see the following options:

Option 1

We introduce a tabs object with the tab item specific properties (for now only the tab title).
The :items object consists of all the nested models JSON.

The JSON would look as follows:

{
    "tabs": [
        {
            "title": "Tab 1"
        },
        {
            "title": "Tab 2"
        }
    ],
    ":itemsOrder": [
        "item_1",
        "item_2"
    ],
    ":type": "weretail/components/content/tabs",
    ":items": {
        "item_1": {
            "columnCount": 12,
            "columnClassNames": {},
            "gridClassNames": "aem-Grid aem-Grid--12 aem-Grid--default--12",
            ":items": {},
            ":itemsOrder": [],
            ":type": "wcm/foundation/components/responsivegrid"
        },
        "item_2": {
            "columnCount": 12,
            "columnClassNames": {},
            "gridClassNames": "aem-Grid aem-Grid--12 aem-Grid--default--12",
            ":items": {},
            ":itemsOrder": [],
            ":type": "wcm/foundation/components/responsivegrid"
        }
    }
}

Advantages:

  • minimal implementation effort
  • tab item specific properties are nicely isolated from the other nested models JSON.

Disadvantages:

  • it might be confusing to read: which title belongs to which item?

Option 2

We introduce a specific node for the tab item which:

  • stores the tab item specific properties (today only the title).
  • has a specific resource type (e.g. core/wcm/components/tabs/v1/tabs/item) and a dedicated model

The JCR structure would look as follows:

tabs
    item1
        responsivegrid
            text
            image
…

The JSON would look as follows:

{
    ":itemsOrder": [
        "item_1",
        "item_2"
    ],
    ":type": "weretail/components/content/tabs",
    ":items": {
        "item_1": {
            ":type": "weretail/components/content/tabs/item",
            "title": "Tab 1",
            "container": {
                "columnCount": 12,
                "columnClassNames": {},
                "gridClassNames": "aem-Grid aem-Grid--12 aem-Grid--default--12",
                ":items": {},
                ":itemsOrder": [],
                ":type": "wcm/foundation/components/responsivegrid"
            }
        },
        "item_2": {
            ":type": "weretail/components/content/tabs/item",
            "title": "Tab 2",
            "container": {
                "columnCount": 12,
                "columnClassNames": {},
                "gridClassNames": "aem-Grid aem-Grid--12 aem-Grid--default--12",
                ":items": {},
                ":itemsOrder": [],
                ":type": "wcm/foundation/components/responsivegrid"
            }
        }
    }
}

Advantages:

  • tab item specific properties are nicely isolated from the other models
  • easy to read and to find out which title belongs to which item
  • nicely maps the JCR structure

Disadvantages:

  • big implementation effort

WDYT?

@vladbailescu
Copy link
Member

Another option would be to wrap the exported items in a class that adds the extra properties we need and inline/unwrap the original exported model.

The JSON would look like

{
    [..],
    ":itemsOrder": [
        "item_1",
        "item_2"
    ],
    ":type": "weretail/components/content/tabs",
    ":items": {
        "item_1": {
            // These are coming from the wrapper
            "title": "Tab 1",
            // These are coming from the wrapped model
            "columnCount": 12,
            "columnClassNames": {},
            "gridClassNames": "aem-Grid aem-Grid--12 aem-Grid--default--12",
            ":items": {},
            ":itemsOrder": [],
            ":type": "wcm/foundation/components/responsivegrid"
        },
        "item_2": {
            "title": "Tab 2",
            "columnCount": 12,
            "columnClassNames": {},
            "gridClassNames": "aem-Grid aem-Grid--12 aem-Grid--default--12",
            ":items": {},
            ":itemsOrder": [],
            ":type": "wcm/foundation/components/responsivegrid"
        }
    }
}

We could use @JsonUnwrapped to inline wrapped model properties.

@gabrielwalt
Copy link
Member

gabrielwalt commented Nov 9, 2018

TLDR: I'm for Option 3.

Option 1
I like the simplicity of this option, but the way the tabs and the items work is not very consistent: one is an array and the other an object. Would it make sense that we use the same indexes for the tabs?

{
    ":itemsOrder": [
        "item_1",
        "item_2"
    ],
    ":items": {
        "item_1": {...},
        "item_2": {...}
    },
    "tabs": {
        "item_1": {
            "title": "Tab 1"
        },
        "item_2": {
            "title": "Tab 2"
        }
    ],
    ":type": "weretail/components/content/tabs"
}

Option 2
I like the clarity of this option, but it's adding one more resource type. It would require customers to create a relatively useless proxy component just for the items. Would it make sense to skip that resource type property?

{
    ":itemsOrder": [
        "item_1",
        "item_2"
    ],
    ":items": {
        "item_1": {
            "title": "Tab 1",
            "container": {...}
        },
        "item_2": {
            "title": "Tab 2",
            "container": {...}
        }
    },
    ":type": "weretail/components/content/tabs"
}

Option 3
I like the compromise between simplicity and clarity, and it's consistent with the fact that the Tabs are adding the title property to the Layout Container component. Theoretically, it should be the model of the Layout Container that should provide the title in its JSON, but for the components that don't provide a title, it's good if the model of the Tabs can inject that. However, that should only happen when the component's model doesn't output any title, in case the component's model implemented some business logic for the title.

Finally, we should also apply the same architectural concept to the Carousel component.

@jckautzmann
Copy link
Contributor

jckautzmann commented Nov 9, 2018

The following commit implements option 3 with item specific properties (itemTitleand itemPath):
adb1ecb

vladbailescu added a commit that referenced this issue Nov 20, 2018
…s and Carousels #298

* Updated Tabs and Carousel to implement ContainerExporter
richardhand added a commit that referenced this issue Nov 20, 2018
…s and Carousels #298

- panel select, only append subtitle it available
vladbailescu pushed a commit that referenced this issue Nov 21, 2018
…s and Carousels #298

- panel select, only append subtitle it available
vladbailescu added a commit that referenced this issue Nov 21, 2018
…s and Carousels #298

* Updated Tabs and Carousel to also adapt to ContainerExporter
richardhand added a commit that referenced this issue Nov 21, 2018
…s and Carousels #298

- panel select, only append subtitle it available
vladbailescu added a commit that referenced this issue Nov 21, 2018
…s and Carousels #298 (#390)

* Updated Tabs and Carousel to also adapt to ContainerExporter
richardhand pushed a commit that referenced this issue Nov 21, 2018
…s and Carousels #298 (#390)

* Updated Tabs and Carousel to also adapt to ContainerExporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problem or unintended behavior that impairs normal functioning of the product.
Projects
None yet
Development

No branches or pull requests

5 participants