Skip to content

fix(site): display correct user_limit on license ui #8118

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

Merged
merged 2 commits into from
Jun 23, 2023

Conversation

rodrimaia
Copy link
Contributor

@rodrimaia rodrimaia commented Jun 20, 2023

Fixes #7671

So, when the license UI was created, we used to have a bug on the backend that would return each license's user_limit as the same as the maximum number of users allowed on all licenses. For that reason we only displayed that max value. The bug was fixed, but we never updated the UI to display the correct value of each license. This PR fixes that.

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Could you please describe in the issue description what is the root cause of the problem?

@@ -30,6 +30,9 @@ export const LicenseCard = ({
number | undefined
>(undefined)

const currentUserLimit =
license.claims.features["user_limit"] || userLimitLimit
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 probably out of scope of this PR, but userLimitLimit sounds weird.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I find it weird as well

@@ -72,7 +75,7 @@ export const LicenseCard = ({
<Stack direction="column" spacing={0} alignItems="center">
<span className={styles.secondaryMaincolor}>Users</span>
<span className={styles.userLimit}>
{userLimitActual} {` / ${userLimitLimit || "Unlimited"}`}
{userLimitActual} {` / ${currentUserLimit || "Unlimited"}`}
Copy link
Member

Choose a reason for hiding this comment

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

Should we move the condition || "Unlimited" to currentUserLimit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally would rather not doing it since the user limit is a number and here we are dealing with "presentational" logic

Copy link
Member

Choose a reason for hiding this comment

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

Killer argument 👍

Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

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

Just small things that @mtojek already mentioned

@rodrimaia
Copy link
Contributor Author

Could you please describe in the issue description what is the root cause of the problem?

So, when the license UI was created, we used to have a bug on the backend that would return each license's user_limit as the same as the maximum number of users allowed on all licenses. For that reason we only displayed that max value. The bug was fixed, but we never updated the UI to display the correct value of each license. This PR fixes that.

@@ -1006,7 +1006,7 @@ export const getWorkspaceBuildParameters = async (
return response.data
}
type Claims = {
license_expires?: number
license_expires: number
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this type not returned from the typesGenerated.ts? Usually, the API endpoints and resources have generated types that are more trustable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BrunoQuaresma No, the type returned from the typesGenerated is not that strict, check the claims type:

image

Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

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

Just one minor thing.

Comment on lines +20 to +22
await screen.findByText("#1")
await screen.findByText("1 / 10")
await screen.findByText("Enterprise")
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't make sense to look at the entire screen for #1 as I'm sure that you will find something else. Same for Enterprise. Could we limit it only to the rendered element?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is ok and a common practice for JS tests when using react testing library

Copy link
Member

@mtojek mtojek Jun 22, 2023

Choose a reason for hiding this comment

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

The practice is fine, but we should limit/scope it to the element under test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean it is safe because if the matcher finds it in multiple elements, it will raise an error.

Copy link
Member

Choose a reason for hiding this comment

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

What if it finds a static label placed somewhere else on the page, and our license card didn't render at all?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The storybook should get that. IMO, integration tests should be used to catch network and "actionable" things. Check if things are rendered correctly should be on Storybook but I get your point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is usually a recommendation to use screen: https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen

And also in this case we are only rendering the component, there isn't anything else in the screen that could be matched. I have printed the result of a screen.debug() and this is the result:

<body>
        <div>
          <div
            class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation2 makeStyles-licenseCard-27 css-19zg6r2-MuiPaper-root"
          >
            <div
              class="makeStyles-stack-39 makeStyles-stack-40  makeStyles-cardContent-28"
            >
              <span
                class="makeStyles-licenseId-29"
              >
                #
                1
              </span>
              <span
                class="makeStyles-accountType-30"
              >
                Enterprise
              </span>
              <div
                class="makeStyles-stack-39 makeStyles-stack-41"
                style="flex: 1;"
              >
                <div
                  class="makeStyles-stack-39 makeStyles-stack-42"
                >
                  <span
                    class="makeStyles-secondaryMaincolor-33"
                  >
                    Users
                  </span>
                  <span
                    class="makeStyles-userLimit-26"
                  >
                    1

                     / Unlimited
                  </span>
                </div>
                <div
                  class="makeStyles-stack-39 makeStyles-stack-43"
                  width="134px"
                >
                  <span
                    class="makeStyles-secondaryMaincolor-33"
                  >
                    Valid Until
                  </span>
                  <span
                    class="makeStyles-licenseExpires-31"
                  >
                    May 20, 2078
                  </span>
                </div>
                <div
                  class="makeStyles-stack-39 makeStyles-stack-44"
                >
                  <button
                    class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textNeutral MuiButton-sizeSmall MuiButton-textSizeSmall MuiButton-root MuiButton-text MuiButton-textNeutral MuiButton-sizeSmall MuiButton-textSizeSmall makeStyles-removeButton-34 css-1sr08q4-MuiButtonBase-root-MuiButton-root"
                    tabindex="0"
                    type="button"
                  >
                    Remove
                  </button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </body>

as you can see, just the component is being rendered.

@mtojek mtojek self-requested a review June 22, 2023 12:44
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

I left some comments, but defer the final decision to Bruno as frontend expert.

@mtojek mtojek merged commit c594f02 into main Jun 23, 2023
@mtojek mtojek deleted the show_correct_user_count branch June 23, 2023 06:38
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

License UI incorrectly show the user count
3 participants