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

Refactor Page Layout components to render correctly in Custom Views panels #3353

Merged
merged 15 commits into from
Jan 22, 2024

Conversation

CarlosCortizasCT
Copy link
Contributor

Summary

Refactor Page Layout components to render correctly in Custom Views panels

Description

When rendering this kind of component (eg: InfoMainPage, we noticed we were introducing a "double padding" effect since the Custom Views panel itself already contains some paddings to make sure, no matter what content is rendered inside, the contents have some white space around and these kind of components also render some surrounding paddings/margins.

To avoid this unwanted UI, we now add an attribute to the body element of the Custom View panel iFrame we render inside it and use it to adjust the CSS rules of those components when they are rendered in such context.

BEFORE:
image

AFTER:
image

Copy link

changeset-bot bot commented Dec 18, 2023

🦋 Changeset detected

Latest commit: 82a180e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 38 packages
Name Type
@commercetools-frontend/application-components Patch
@commercetools-frontend/application-shell Patch
@commercetools-frontend/codemod Patch
@commercetools-frontend/mc-scripts Patch
@commercetools-applications/merchant-center-template-starter-typescript Patch
@commercetools-applications/merchant-center-template-starter Patch
@commercetools-applications/merchant-center-custom-view-template-starter-typescript Patch
@commercetools-applications/merchant-center-custom-view-template-starter Patch
@commercetools-local/playground Patch
@commercetools-local/visual-testing-app Patch
@commercetools-website/components-playground Patch
@commercetools-frontend/cypress Patch
@commercetools-backend/eslint-config-node Patch
@commercetools-backend/express Patch
@commercetools-backend/loggers Patch
@commercetools-frontend/actions-global Patch
@commercetools-frontend/application-config Patch
@commercetools-frontend/application-shell-connectors Patch
@commercetools-frontend/assets Patch
@commercetools-frontend/babel-preset-mc-app Patch
@commercetools-frontend/browser-history Patch
@commercetools-frontend/constants Patch
@commercetools-frontend/create-mc-app Patch
@commercetools-frontend/eslint-config-mc-app Patch
@commercetools-frontend/i18n Patch
@commercetools-frontend/jest-preset-mc-app Patch
@commercetools-frontend/jest-stylelint-runner Patch
@commercetools-frontend/l10n Patch
@commercetools-frontend/mc-dev-authentication Patch
@commercetools-frontend/mc-html-template Patch
@commercetools-frontend/notifications Patch
@commercetools-frontend/permissions Patch
@commercetools-frontend/react-notifications Patch
@commercetools-frontend/sdk Patch
@commercetools-frontend/sentry Patch
@commercetools-frontend/url-utils Patch
@commercetools-website/custom-applications Patch
@commercetools-website/custom-views Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -140,6 +142,13 @@ function CustomViewShell(props: TCustomViewShellProps) {
[]
);

useLayoutEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the simplest solution.

I think I would prefer to update how we generate the HTML document when running/building the application to already include this attribute but I was worried that end-users would need to make sure they update all app-kit dependencies at the same time, and last year we learnt that's not always the case.

Pelase, let me know waht you think 🙏

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to avoid using an effect for this case.

Do we need to target the body? I think it would be enough to define the data attribute in one of the wrapping containers of CustomViewShell, for example

<ContentWrapper data-extension-type="custom-view">

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. That's a better approach for our current use case.

Updated here: 5694676

@@ -19,6 +20,9 @@ const DetailPageContainer = styled.div`
background-color: ${appKitDesignTokens.backgroundColorForPageHeader};
padding: ${appKitDesignTokens.paddingForDetailPageHeader};
border-bottom: 1px ${appKitDesignTokens.colorForPageHeaderBottomBorder} solid;
body[data-extension-type='${CUSTOM_EXTENSION_TYPES.CUSTOM_VIEW}'] & {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically we overwrite the paddings or margins in all the relevant components if they are rendered within a Custom View.

Copy link
Contributor

github-actions bot commented Dec 18, 2023

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-6mp70dhdx-commercetools.vercel.app
https://appkit-sha-2b6c4099815d559e2e021e486cd1685ac3de7de5.commercetools.vercel.app
https://appkit-pr-3353.commercetools.vercel.app

Built with commit 82a180e.
This pull request is being automatically deployed with vercel-action

Copy link
Contributor

github-actions bot commented Dec 18, 2023

Deploy preview for application-kit-custom-views ready!

✅ Preview
https://application-kit-custom-views-miiz825dg-commercetools.vercel.app
https://appkit-cv-sha-2b6c4099815d559e2e021e486cd1685ac3de7de5.commercetools.vercel.app
https://appkit-cv-pr-3353.commercetools.vercel.app

Built with commit 82a180e.
This pull request is being automatically deployed with vercel-action

@CarlosCortizasCT CarlosCortizasCT marked this pull request as ready for review December 18, 2023 16:16
@CarlosCortizasCT CarlosCortizasCT requested a review from a team December 18, 2023 16:16
@CarlosCortizasCT
Copy link
Contributor Author

We decided to block this PR as the proposed change is not agreed by the team and we need to have a discussion between engineers and designers in order to come to an alignment.

@CarlosCortizasCT
Copy link
Contributor Author

We decided to block this PR as the proposed change is not agreed by the team and we need to have a discussion between engineers and designers in order to come to an alignment.

@emmenko and I have been discussing about the current approach and, although he's concern on the maintainability costs this implementation might have in the future, we agreed that the balance in terms of added complexity and developer experience is fair enough as we also don't see better approaches that do not imply either degrading DX or including some complexity anyway.

We discussed options like:

  • remove default paddings for Custom Views panels: will force users to add them somehow and we have the problem with the positioning of the close icon and its integration with notifications or even modals
  • remove the paddings only for large Custom Views panels: we would still have the problems as before and DX will be a little more degraded as developers would need to learn different approaches based on the Custom View panel size.

At the end of the day, we think adding this extra complexity it worth the DX os developers not needing to do anything special in terms of what components and paddings to use no matter the Custom View panel they's using (or if they are using page layout components in Custom Applications or Custom Views).

@CarlosCortizasCT CarlosCortizasCT requested review from emmenko and removed request for a team January 15, 2024 17:50
@CarlosCortizasCT CarlosCortizasCT marked this pull request as ready for review January 15, 2024 17:50
@CarlosCortizasCT CarlosCortizasCT requested a review from a team January 15, 2024 17:51
Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Some suggestions, otherwise (as you mentioned) I'm ok with the approach. 🤗

@@ -140,6 +142,13 @@ function CustomViewShell(props: TCustomViewShellProps) {
[]
);

useLayoutEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to avoid using an effect for this case.

Do we need to target the body? I think it would be enough to define the data attribute in one of the wrapping containers of CustomViewShell, for example

<ContentWrapper data-extension-type="custom-view">

Comment on lines 9 to 11
// Bear in mind the margins are dependant on the context the component
// is rendered in. For example, when rendered in a custom view, its panel
// already contains default paddings, so we don't need to add margins here.
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to keep the comments out of the CSS, as otherwise they will be bundled with the styles

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated here: cf1c6e5

However, I checked the built bundles and I couldn't find those comments, although I could have missed something.

<div
css={css`
margin: ${appKitDesignTokens.marginForModalPageHeader};
padding: ${appKitDesignTokens.paddingForModalPageHeader};
border-bottom: 1px solid
${appKitDesignTokens.borderColorForModalPageHeaderDivider};
body[data-extension-type='${CUSTOM_EXTENSION_TYPES.CUSTOM_VIEW}'] & {
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit "surprising" to me that we can target global elements within a scoped style.

I would suggest to follow this approach (@ByronDWall actually proposed it 😅): emotion-js/emotion#2836 (comment)

css`
  * :where([data-extension-type="custom-view"]) & {
    margin: ${appKitDesignTokens.paddingForModalPageHeaderInCustomView};
  }
`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated here: cf1c6e5

Copy link
Contributor

@kark kark left a comment

Choose a reason for hiding this comment

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

Appreciate you providing insights into the decision-making process; everything looks good. Just a friendly reminder to include a changeset before merging. Thanks!

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Thanks for the improvements, glad that it worked! 🤗

Comment on lines 70 to 72
// Bear in mind the margins are dependant on the context the component
// is rendered in. For example, when rendered in a custom view, its panel
// already contains default paddings, so we don't need to add margins here.
Copy link
Member

Choose a reason for hiding this comment

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

Move comments outsides of CSS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot about that one. Sorry.

Updated here: 64f6bef

Comment on lines 74 to 76
body[data-extension-type='custom-view'] & {
margin: ${appKitDesignTokens.marginForCustomViewsSelectorAsTabularInCustomView};
}
Copy link
Member

Choose a reason for hiding this comment

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

I guess this also needs to be adjusted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot about that one. Sorry.

Updated here: 129d8b9

Comment on lines 26 to 28
// Bear in mind the margins are dependant on the context the component
// is rendered in. For example, when rendered in a custom view, its panel
// already contains default paddings, so we don't need to add margins here.
Copy link
Member

Choose a reason for hiding this comment

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

Here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot about that one. Sorry.

Updated here: 64f6bef

marginForDialogContainerContents: `${uiKitDesignTokens.spacing30} 0 ${uiKitDesignTokens.spacing50} 0`,
marginForModalPageHeader: `0 ${appKitSpacing55}`,
marginForUserMenuItem: `${uiKitDesignTokens.spacing10} 0`,
marginLeftForModalPageHeaderControls: uiKitDesignTokens.spacing50,
marginRightForAppbar: appKitSpacing55,
marginTopForDialogFooter: uiKitDesignTokens.spacing50,
marginForPageContent: `${uiKitDesignTokens.spacing50} ${appKitSpacing55}`,
marginForPageContentInCustomView: `${uiKitDesignTokens.spacing50} 0`,
Copy link
Member

@emmenko emmenko Jan 17, 2024

Choose a reason for hiding this comment

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

As an alternative idea / approach, would it work if we override the css variables (theming) to change the margins instead of doing that explicitly in each component? 🤔

So basically in the CustomViewShell we inject styles in the wrapper and override the css variables.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @emmenko. That's a great idea 🔝

The only drawback that I can see is that maybe it's a little more complicated to spot where things are happening in terms of maintanability.
With the new approach, the Page Layout components have a different UI when they are rendered within a Custom View Panel but it is not pretty straightforward why as the code which makes that happen is not in those components but in a new file (custom-view-shell.styles.ts).

I've opened this PR with the refactoring so we can all take a look at how it would look like before applying those changes here.

@commercetools/shield-team-fe it would be great to read your thoughts 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Thanks Carlos. I left a review in the other PR 🤗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I merged the other PR into this one so we have your idea implemented here.

…w panels (#3378)

* refactor(application-components): refactor how we manage double padding when page layout components are used within custom views panels

* refactor(application-shell): remove unnecessary styles
Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Thanks for looking into different options and for the constructive discussions ❤️

I feel more confident now with this approach, so good to go from my side 🚀

@@ -15,6 +15,5 @@ export const MainPageContent = styled.div`
flex: 1;
flex-basis: 0;
overflow: auto;
// NOTE: do not change to "padding" as this breaks sticky DataTable styles
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could you keep and move this comment outside of the styles (L13)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restored here: 82a180e

@CarlosCortizasCT CarlosCortizasCT merged commit 05dfdef into main Jan 22, 2024
20 checks passed
@CarlosCortizasCT CarlosCortizasCT deleted the cm-page-layout-components-in-custom-views branch January 22, 2024 12:10
@ct-changesets ct-changesets bot mentioned this pull request Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants