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

feat: migrates Container to TypeScript; Container without max-width on docs site [FC-0062] #3216

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Sep 5, 2024

Description

This PR allows the size property of the Container to be undefined, removing the maximum width in this case

Deploy Preview

https://deploy-preview-3216--paragon-openedx.netlify.app/components/container/

More information

Part of:

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Netlify deploy preview, if applicable.
  • Does your change adhere to the documented style conventions?
  • Do any prop types have missing descriptions in the Props API tables in the documentation site (check deploy preview)?
  • Were your changes tested using all available themes (see theme switcher in the header of the deploy preview, under the "Settings" icon)?
  • Were your changes tested in the example app?
  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please request an a11y review for the PR in the #wg-paragon Open edX Slack channel.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

Private ref: FAL-3820

@openedx-webhooks
Copy link

openedx-webhooks commented Sep 5, 2024

Thanks for the pull request, @rpenido!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/paragon-working-group. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 5, 2024
Copy link

netlify bot commented Sep 5, 2024

Deploy Preview for paragon-openedx ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7a03d83
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx/deploys/66df513b5bad7a0008eb3ffe
😎 Deploy Preview https://deploy-preview-3216--paragon-openedx.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.27%. Comparing base (4b63a24) to head (7a03d83).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3216      +/-   ##
==========================================
+ Coverage   93.25%   93.27%   +0.01%     
==========================================
  Files         249      249              
  Lines        4388     4401      +13     
  Branches     1037     1037              
==========================================
+ Hits         4092     4105      +13     
  Misses        290      290              
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rpenido rpenido force-pushed the rpenido/fal-3820-add-full-width-container-option branch from 0dfd9d8 to 4a206ae Compare September 5, 2024 22:48
@rpenido rpenido changed the title feat: allow Container render without a max width feat: allow Container render without a max width [FC-0062] Sep 6, 2024
Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

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

@rpenido Some comments for you -- I still need to test this too.

And in future, could you separate out converting from JSX -> TSX into a separate commit? That would help me see what's changed :)

@@ -19,6 +19,10 @@ The base container to contain, pad, and center content in the viewport. This com
```jsx live
<div style={{ overflowX: 'auto' }}>
<div style={{ width: '1500px', border: 'solid 3px red' }}>
<Container size="full" className="bg-danger-300 my-4">
The content in this container don't have a max width
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
The content in this container don't have a max width
The content in this container doesn't have a max width

Copy link
Contributor Author

@rpenido rpenido Sep 6, 2024

Choose a reason for hiding this comment

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

Fixed: a55d28b

Comment on lines 31 to 32
bsPrefix="container"
fluid
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Do we need these lines when these properties are overridden by the prop defaults below?

I'm more concerned with the fluid one, since I'm unsure how overriding these boolean values works in Typescript, and don't want to break anyone else's UI.

Suggested change
bsPrefix="container"
fluid

Copy link
Contributor Author

@rpenido rpenido Sep 6, 2024

Choose a reason for hiding this comment

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

You're right. We don't need this.
Removed here: a55d28b

As information only, because the spread {...props} was after these props, the spread would override it. The boolean fluid is a syntax sugar for fluid={true}. This is the transpiled JS code:

image

Comment on lines +34 to +35
it('does not add a size class when size is not specified', () => {
const { container } = render(<Container>Content</Container>);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather use an explicit size="full" than assume that omitting the size means "full width".. Omitting a size should make the container fit its contents, just like a <div> without a max-width.
I think the bootstrap class mw-100 does this?

Copy link
Contributor Author

@rpenido rpenido Sep 6, 2024

Choose a reason for hiding this comment

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

I agree with you and tried this approach first.

The problem is that the current component allows the size props to be omitted, and it behaves like "full width". You can check it here, removing the size from one example: https://paragon-openedx.netlify.app/components/container/

We have many containers in our code base without size that probably rely on this, so I don't think we can change that.
So I pushed back the size={full} option.

We can add both options, but I think the ambiguity will not help us here.

Copy link
Contributor Author

@rpenido rpenido Sep 6, 2024

Choose a reason for hiding this comment

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

I tried to update the API docs here: 47cbcb1

Copy link
Contributor

@pomegranited pomegranited Sep 10, 2024

Choose a reason for hiding this comment

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

The problem is that the current component allows the size props to be omitted, and it behaves like "full width". You can check it here, removing the size from one example: https://paragon-openedx.netlify.app/components/container/

Passing in size="" gives us the fullscreen behaviour you're adding here.. so do we need this change?

Edit: ah yes, this is what Adam said 😄

@rpenido rpenido marked this pull request as ready for review September 6, 2024 14:25
@adamstankiewicz
Copy link
Member

Thanks for the contribution! Just as a heads up, I believe the primary change here is the TypeScript migration and adding the docs site example for Container without a max-width. The current implementation of Container supports the intended behavior today when omitting the size prop: Playground Example.

The first instance of Container is the above example renders with max-width: none;, when size is omitted or an invalid size is passed:

image

@@ -0,0 +1,64 @@
/* eslint-disable react/require-default-props */
Copy link
Member

Choose a reason for hiding this comment

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

[optional] With a recent update to @edx/eslint-config, we might be able to upgrade to v4.2.0 in this repo and remove the need for default params in this file without disabling the ESLint rule 👀 openedx/eslint-config#156

While this repo is currently using v3 of @edx/eslint-config, the v4 breaking changes don't seem to apply to this repo at the moment, per the release notes, so the upgrade should be fairly trivial:

Drops support for eslint ^6.8.0; @edx/eslint-config must now be used with at least eslint versions ^7.32.0 or ^8.2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adamstankiewicz I tried to update but got the following error on linting (which prevents the commit).
Did you already experienced this error before?

> @openedx/[email protected] lint
> npm run stylelint && eslint --ext .js --ext .jsx --ext .ts --ext .tsx . && npm run lint --workspaces --if-present


> @openedx/[email protected] stylelint
> stylelint "src/**/*.scss" "scss/**/*.scss" "www/src/**/*.scss" --config .stylelintrc.json


Oops! Something went wrong! :(

ESLint: 8.18.0

Error: Error while loading rule '@typescript-eslint/naming-convention': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting /home/rpenido/Projects/opencraft/paragon/.eslintrc.js
...

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I have not. Thanks for flagging. I am able to reproduce the issue on my end as well. Unless you want to investigate the error further, feel free to defer on the upgrade and continue with your existing solution using default props and the disabled ESLint rule. If you do defer on the investigation/resolution, do you mind filing a new Paragon issue to document the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue created: #3230

size?: ContainerSize;
}

type ContainerType = ComponentWithAsProp<'div', ContainerProps> & { Deprecated?: any };
Copy link
Member

Choose a reason for hiding this comment

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

Is the Deprecated property necessary here? Container doesn't have a deprecated sub-component (e.g., Container.Deprecated) as Button.Deprecated does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's not needed. Thank you for catching this.
Fixed here: 641dd15


type ContainerType = ComponentWithAsProp<'div', ContainerProps> & { Deprecated?: any };

const Container: ContainerType = React.forwardRef<HTMLDivElement, ContainerProps>(({
Copy link
Member

Choose a reason for hiding this comment

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

Could Container be used with a non-div element, e.g. with as="span"? I wonder if this should be more generic, e.g. HTMLElement or even Element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I changed it to Element as our property of interest (className) exists.
Here: 7e0fb5c

/** Fill all available space at any breakpoint */
fluid: PropTypes.bool,
/** Set the maximum width for the container. Omiting the prop will remove the max-width */
size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', undefined]),
Copy link
Member

Choose a reason for hiding this comment

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

I believe the undefined is implied by the lack of .isRequired on the prop type definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. It was there to show in the docs, but it isn't necessary with the docstring change.
Fixed: 7a03d83

@@ -12,7 +12,7 @@ export interface IDefaultValue {
theme?: string,
direction?: string,
language?: string,
containerWidth?: string,
containerWidth?: ContainerSize,
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the ContainerSize type here, too! 🙌

@rpenido
Copy link
Contributor Author

rpenido commented Sep 9, 2024

Just as a heads up, I believe the primary change here is the TypeScript migration and adding the docs site example for Container without a max-width.

Absolutely. Do you think I should change anything in the PR to make it clear?

@adamstankiewicz
Copy link
Member

adamstankiewicz commented Sep 9, 2024

Absolutely. Do you think I should change anything in the PR to make it clear?

I might just recommend amending your PR title / commit message to more closely reflect the TypeScript migration and the additional example on the docs site, e.g.

feat: migrates Container to TypeScript; Container without max-width on docs site

Edit: typically we squash+merge when merging PRs, so this refactored commit message can actually be provided at the time the PR merges without you needing to amend/squash the commits yourself! Perhaps just modifying the PR title for now would suffice 😄

@rpenido rpenido changed the title feat: allow Container render without a max width [FC-0062] refactor: migrates Container to TypeScript; Container without max-width on docs site [FC-0062] Sep 9, 2024
@adamstankiewicz
Copy link
Member

adamstankiewicz commented Sep 9, 2024

@rpenido When this merges, to ensure it gets published to NPM via semantic-release, the commit type prefix will be feat.

semantic-release, by default (as configured), only triggers NPM releases for fix, feat, and perf. Given your contribution is exposing new TypeScript types to consumers, I want to be sure merging triggers a new release feat :)

@rpenido rpenido changed the title refactor: migrates Container to TypeScript; Container without max-width on docs site [FC-0062] feat: migrates Container to TypeScript; Container without max-width on docs site [FC-0062] Sep 9, 2024
@rpenido
Copy link
Contributor Author

rpenido commented Sep 9, 2024

Thank you, @adamstankiewicz! I updated the PR title again.
When you and @pomegranited think this is good for merge, just ping me, and I can squash it (if needed) to ensure we have the correct commit message.

@adamstankiewicz
Copy link
Member

LGTM! If either you or @pomegranited don't have the ability to merge, let me know and I'll happily merge it, too :)

@pomegranited
Copy link
Contributor

Thanks @adamstankiewicz could you merge? We don't have access.

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

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

👍

@adamstankiewicz adamstankiewicz merged commit 65bb39b into openedx:master Sep 10, 2024
10 checks passed
@openedx-semantic-release-bot

🎉 This PR is included in version 22.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Sep 10, 2024
@rpenido rpenido deleted the rpenido/fal-3820-add-full-width-container-option branch September 10, 2024 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U released
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants