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

[To Main] DESENG-632: Add engagement content tabs #2545

Merged
merged 7 commits into from
Jun 20, 2024

Conversation

NatSquared
Copy link
Contributor

@NatSquared NatSquared commented Jun 20, 2024

Issue #: 🎟️ DESENG-632

Description of changes:

  • Feature Add a new tabbed content view to the new engagement page
    • Added a new tabbed content view to the new engagement page
    • Tabs are pulled from the engagement's summary and custom content sections (to be revisited when redoing authoring flow)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the met-public license (Apache 2.0).

@NatSquared NatSquared marked this pull request as ready for review June 20, 2024 01:43
@NatSquared NatSquared requested a review from Baelx June 20, 2024 01:44
Copy link
Collaborator

@Baelx Baelx 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! Thanks for your work :)

No changes to request per se, but I'd like to just double-check a keyboard users experience when it comes to the fade being applied to the tablist. Let's discuss

@@ -81,3 +81,9 @@ export const isDarkColor = (color: string, sensitivity = 0.5) => {
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return luminance < sensitivity;
};

export function combinePromises<T>(promises: { [K in keyof T]: Promise<T[K]> }): Promise<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export function combinePromises<T>(promises: { [K in keyof T]: Promise<T[K]> }): Promise<T> {
export function combinePromisesAsObject<T>(promises: { [K in keyof T]: Promise<T[K]> }): Promise<T> {

When I see the name combinePromises I think "why not just use Promise.all?" I'm a fan of longer variable/function names that provide more description, which I think could be something to consider here. Especially since we don't use doc blocks in this code base

resizeObserver.disconnect();
};
} else {
setTimeout(attachFade, 100); // try again in 100ms
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you help me understand the timeout for attaching the fade? I'm guessing this would run when tabListRef no longer has a current ref but wouldn't the whole component be unmounted by then?

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'm attaching the fade to a child of the ref (can't find a way to get a ref for the scroller directly) so the timeout is a workaround to let me wait until the ref is loaded before attaching. Note that attachFade is scheduling itself here, so this can be read as "if there is nothing to attach to, try this again in 100 ms"

Copy link
Collaborator

Choose a reason for hiding this comment

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

We discussed offline and Nat may try useCallback instead of useRef

const checkFade = () => {
if (!tabListRef.current) return;
const scroller = tabListRef.current.getElementsByClassName('MuiTabs-scroller')[0];
const scrollPosition = scroller.scrollLeft; // distance from left edge
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the comments so we can follow along more easily!

const scroller = tabListRef.current.getElementsByClassName('MuiTabs-scroller')[0];
const scrollPosition = scroller.scrollLeft; // distance from left edge
const maxScroll = scroller.scrollWidth - scroller.clientWidth; // distance from right edge
const fadeMargin = 64; // pixels
Copy link
Collaborator

Choose a reason for hiding this comment

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

The fade is a nice idea to make it clear to users that there's more to the tablist if they scroll. As keyboard users tab to the right, will it be clear where their focus is at all times? Will focus ever be obscured by the fade?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed this offline: keyboard users should be ok

display: 'flex',
justifyContent: 'center',
height: '6px',
// backgroundColor: 'transparent',
Copy link
Collaborator

Choose a reason for hiding this comment

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

👀

height: '100%',
background:
'linear-gradient(to left, rgba(255,255,255,1) 0%, rgba(255,255,255,0.8) 5%, rgba(255,255,255,0.8) 50%, rgba(255,255,255,0) 100%)',
pointerEvents: 'none', //allow clicking on faded tabs
Copy link
Collaborator

Choose a reason for hiding this comment

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

I never knew about this CSS attribute! Neat

useEffect(attachFade, [tabListRef]);

return (
<section id="content-tabs" aria-label="Engagement content tabs">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice aria label for this region! We don't have a heading tag to lean on so I think this is adequately descriptive of the content to follow :)

import { getWidgets } from 'services/widgetService';

const castCustomContentToSummaryContent = (customContent: EngagementCustomContent[]): EngagementSummaryContent[] => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice descriptive function name

Copy link

sonarcloud bot commented Jun 20, 2024

Copy link
Collaborator

@Baelx Baelx 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 my comments!

@NatSquared NatSquared merged commit 18b019d into main Jun 20, 2024
8 checks passed
@NatSquared NatSquared deleted the feature/DESENG-632-engagement-dynamic-pages branch June 20, 2024 20:59
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.

2 participants