Skip to content

feat(site): move resources into the sidebar #11456

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 3 commits into from
Jan 8, 2024
Merged

Conversation

BrunoQuaresma
Copy link
Collaborator

Screen.Recording.2024-01-05.at.14.34.35.mov

@BrunoQuaresma BrunoQuaresma requested a review from a team January 5, 2024 17:38
@BrunoQuaresma BrunoQuaresma self-assigned this Jan 5, 2024
@BrunoQuaresma BrunoQuaresma requested review from aslilac and Parkreiner and removed request for a team January 5, 2024 17:38
@BrunoQuaresma
Copy link
Collaborator Author

Related to #11491

Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

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

Looks good! Just had a few suggestions for improving some of the markup, and caught one tiny, React-specific bug

// These resources (i.e. docker_image, kubernetes_deployment) map to Terraform
// resource types. These are the most used ones and are based on user usage.
// We may want to update from time-to-time.
const BUILT_IN_ICON_PATHS: Record<string, string> = {
Copy link
Member

Choose a reason for hiding this comment

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

Is it safe to assume that all the icons should start with /icon/? I'm wondering if there might be value in redefining the record type as

Record<string, `/icon/${string}`>

Just to help catch accidental typos

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

love the idea

</p>
)}
{resources.length === 0 &&
!failed &&
Copy link
Member

Choose a reason for hiding this comment

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

Is this condition strictly for handling loading states?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

display: "flex",
alignItems: "center",
justifyContent: "center",
lineHeight: 0,
Copy link
Member

@Parkreiner Parkreiner Jan 8, 2024

Choose a reason for hiding this comment

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

Do you want a lineHeight of 0, or a lineHeight of 1? I've had issues where a value of 0 broke a lot of text rendering and made text invisible the moment something accidentally overflowed to a new line

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think 1 🤔 but let me check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh in this case, it is an image wrapper so it is ok to use 0... I'm going to replace those wrappers - we have a few in the codebase - with the new @aslilac component ExternalIcon


export const ResourceSidebarItemSkeleton = () => {
return (
<div css={[styles.root, { pointerEvents: "none" }]}>
Copy link
Member

Choose a reason for hiding this comment

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

Does pointerEvents do anything here? Divs aren't interactive by default, and turning on the style rule would just make clicks on the div hit the parent directly, which wouldn't be that different from the events firing on the div, and then bubbling up to the parent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is because it has the root style which applies a "hover" style. I just found it easier to set pointerEvents to none to remove that. Do you see better ways?

padding: 2,
}}
>
<img
Copy link
Member

Choose a reason for hiding this comment

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

Can you add role="presentation" here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeap.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Empty alt has similar behavior to the presentation role.

In these cases, a null (empty) alt text should be provided (alt="") so that they can be ignored by assistive technologies, such as screen readers. Text values for these types of images would add audible clutter to screen reader output or could distract users if the topic is different from that in adjacent text. Leaving out the alt attribute is also not an option because when it is not provided, some screen readers will announce the file name of the image instead.

https://www.w3.org/WAI/tutorials/images/decorative/

};

const selectedResourceId = useTab("resources", "");
const resources = workspace.latest_build.resources.sort(
Copy link
Member

Choose a reason for hiding this comment

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

Accidental mutation here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if I got it 🤔

Copy link
Member

Choose a reason for hiding this comment

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

So, the .sort method is mutating the underlying array, even though that array is globally available throughout the app through the query cache. That could cause bugs for any other components that need the data in its original form

I don't think the .toSorted method is supported enough to swap that in, but you should be able to rewrite this as

 const resources = [...workspace.latest_build.resources].sort()

@BrunoQuaresma BrunoQuaresma merged commit 6145086 into main Jan 8, 2024
@BrunoQuaresma BrunoQuaresma deleted the bq/refactor-resources branch January 8, 2024 16:14
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2024
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.

2 participants