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] Feature - DESENG 631: Add Engagement Description Block #2541

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## June 17, 2024

- **Feature** Add engagement description to the engagement page [🎟️ DESENG-631](https://apps.itsm.gov.bc.ca/jira/browse/DESENG-631)
- Display engagement description on the new engagement page
- Display first widget of the engagement beside the description
- Limit text editor to remove disruptive formatting options

## June 11, 2024

- **Feature** Add new header to "new look" engagement page [🎟️ DESENG-630](https://apps.itsm.gov.bc.ca/jira/browse/DESENG-630)
Expand Down
42 changes: 30 additions & 12 deletions met-web/src/components/appLayouts/PublicLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,38 @@ import { FeedbackModal } from 'components/feedback/FeedbackModal';
import Footer from 'components/layout/Footer';
import DocumentTitle from 'DocumentTitle';
import ScrollToTop from 'components/scrollToTop';
import { WidthLimiter } from 'components/common/Layout';
import { Box } from '@mui/material';
import { colors } from 'components/common';

export const PublicLayout = () => {
return (
<WidthLimiter>
<DocumentTitle />
<PageViewTracker />
<Notification />
<NotificationModal />
<PublicHeader />
<ScrollToTop />
<Outlet />
<FeedbackModal />
<Footer />
</WidthLimiter>
<Box
sx={{
width: '100%',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'transparent',
padding: 0,
margin: 0,
}}
>
<Box
sx={{
maxWidth: '1926px',
margin: '0 auto',
background: colors.surface.white,
}}
>
<DocumentTitle />
<PageViewTracker />
<Notification />
<NotificationModal />
<PublicHeader />
<ScrollToTop />
<Outlet />
<FeedbackModal />
<Footer />
</Box>
</Box>
);
};
28 changes: 0 additions & 28 deletions met-web/src/components/common/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,5 @@ export const ResponsiveWrapper: React.FC = () => {
);
};

export const WidthLimiter: React.FC<BoxProps & { innerProps?: BoxProps }> = ({ children, innerProps, ...props }) => {
return (
<Box
sx={{
width: '100%',
alignItems: 'center',
justifyContent: 'center',
background: 'transparent',
padding: 0,
margin: 0,
...props.sx,
}}
{...props}
>
<Box
sx={{
maxWidth: '1920px',
margin: '0 auto',
...innerProps?.sx,
}}
{...innerProps}
>
{children}
</Box>
</Box>
);
};

export { Table, TableHead, TableHeadRow, TableHeadCell, TableBody, TableRow, TableCell, TableContainer } from './Table';
export { DetailsContainer, Detail } from './Details';
13 changes: 1 addition & 12 deletions met-web/src/components/common/RichTextEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@ const RichTextEditor = ({
error = false,
helperText = '',
toolbar = {
options: [
'inline',
'blockType',
'fontSize',
'list',
'colorPicker',
'link',
'embedded',
'emoji',
'image',
'history',
],
options: ['inline', 'list', 'link', 'history'],
inline: {
options: ['bold', 'italic', 'underline', 'superscript', 'subscript'],
},
Expand Down
13 changes: 12 additions & 1 deletion met-web/src/components/common/Typography/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { colors } from '../../common';

export const BodyText = ({
bold,
thin,
size = 'regular',
children,
...props
}: {
bold?: boolean;
thin?: boolean;
size?: 'small' | 'regular' | 'large';
children: React.ReactNode;
} & TypographyProps) => {
Expand All @@ -22,13 +24,22 @@ export const BodyText = ({
regular: '24px',
large: '24px',
}[size];
const fontWeight = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you foresee us needing additional font weight customization as time goes on? You could just expose a prop that accepts a valid fontWeight attribute and feeds it right to the corresponding Material UI typography property

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 don't honestly forsee us needing this - if a specific numeric font weight is needed it can be overridden with sx.fontWeight

if (bold) {
return 700;
}
if (thin) {
return 300;
}
return 400;
};
return (
<Typography
{...props}
sx={{
fontSize,
lineHeight,
fontWeight: bold ? 700 : 400,
fontWeight: fontWeight(),
color: colors.type.regular.primary,
...props.sx,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const EngagementForm = () => {
<Grid item xs={12}>
<TextField
title="Call to Action URL"
instructions="This where the main button on the engagement page will link to."
instructions="This is where the main button on the engagement page will link to."
id="call-to-action-url"
data-testid="engagement-form/call-to-action-url"
name="cta_url"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import TreeItem, { treeItemClasses, TreeItemProps } from '@mui/lab/TreeItem';
import { MetBodyOld } from 'components/common';
import { BodyText } from 'components/common/Typography';
import { If, Then, Else } from 'react-if';
import { Box } from '@mui/material';
import { IconProp } from '@fortawesome/fontawesome-svg-core';
Expand Down Expand Up @@ -87,7 +87,7 @@ export function StyledTreeItem(props: StyledTreeItemProps & DocumentTreeItemProp
{LabelIcon && (
<FontAwesomeIcon icon={LabelIcon} style={{ fontSize: '20px', paddingRight: '8px' }} />
)}
<MetBodyOld bold>{labelText}</MetBodyOld>
<BodyText bold>{labelText}</BodyText>
</Else>
</If>
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const RichTextToolbarConfig = {
options: ['inline', 'fontSize', 'list'],
options: ['inline', 'list', 'history'],
inline: {
options: ['bold', 'italic', 'underline'],
options: ['bold', 'italic', 'underline', 'superscript', 'subscript'],
},
list: { options: ['unordered', 'ordered'] },
};
Expand Down
105 changes: 105 additions & 0 deletions met-web/src/components/engagement/new/view/EngagementDescription.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React, { Suspense } from 'react';
import { BodyText, Header2 } from 'components/common/Typography';
import { Link } from 'components/common/Navigation';
import { Engagement } from 'models/engagement';
import { Grid, Skeleton } from '@mui/material';
import { colors } from 'components/common';
import { Await, useLoaderData } from 'react-router-dom';
import { Editor } from 'react-draft-wysiwyg';
import { getEditorStateFromRaw } from 'components/common/RichTextEditor/utils';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faArrowLeftLong } from '@fortawesome/pro-light-svg-icons';
import { Widget } from 'models/widget';
import { WidgetSwitch } from 'components/engagement/view/widgets/WidgetSwitch';

export const EngagementDescription = ({ engagement }: { engagement: Engagement }) => {
const { widgets } = useLoaderData() as { widgets: Widget[] };
return (
<section id="cta-section">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we label this accessibility region? In the last PR, we used an aria-label directly for something descriptive of the section. In this case, I think we can use the H2 below. You'd reference it with an aria-labelledby attribute

See here for the relevant technique: https://www.w3.org/WAI/ARIA/apg/patterns/landmarks/examples/region.html

<Grid
container
justifyContent="space-between"
sx={{
width: '100%',
margin: 0,
background: colors.surface.blue[90],
color: colors.surface.white,
borderRadius: '0px 24px 0px 0px' /* upper right corner */,
padding: { xs: '43px 16px 75px 16px', md: '32px 5vw 88px 5vw', lg: '32px 156px 88px 156px' },
marginTop: '-56px',
zIndex: 10,
position: 'relative',
flexDirection: { xs: 'column', md: 'row' },
}}
>
<Grid
item
sx={{
width: '100%',
display: 'flex',
flexDirection: 'row',
marginBottom: { xs: '24px', md: '48px' },
}}
>
<Grid item component={Link} to={'/'} alignItems="center" display="flex">
<FontAwesomeIcon
icon={faArrowLeftLong}
color={colors.surface.white}
fontSize={'24px'}
style={{ paddingRight: '8px' }}
/>
<BodyText thin size="small" sx={{ color: colors.surface.white }}>
All engagements
</BodyText>
</Grid>
</Grid>
<Grid
item
sx={{
width: { xs: '100%', md: '47.5%' },
display: 'flex',
flexDirection: 'column',
minHeight: '120px',
}}
>
<Header2 decorated weight="thin" sx={{ color: colors.surface.white }}>
Engagement Description
</Header2>
<BodyText
sx={{
color: colors.surface.white,
'& .rdw-link-decorator-icon': { display: 'none' },
'& a': {
color: colors.surface.white,
textDecoration: 'underline',
},
}}
>
<Editor
editorState={getEditorStateFromRaw(engagement.rich_description)}
readOnly={true}
toolbarHidden
/>
</BodyText>
</Grid>
<Grid
item
sx={{
width: { xs: '100%', md: '47.5%' },
display: 'flex',
minHeight: '360px',
}}
>
<Suspense fallback={<Skeleton variant="rectangular" sx={{ width: '100%', height: '360px' }} />}>
<Await resolve={widgets}>
{(resolvedWidgets: Widget[]) => {
const widget = resolvedWidgets?.[0];
return widget && <WidgetSwitch widget={widget} />;
}}
</Await>
</Suspense>
</Grid>
</Grid>
</section>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const EngagementHero = ({ engagement }: { engagement: Engagement }) => {
<Button
href={engagement.cta_url || '#cta-section'}
variant="primary"
size="large"
icon={<FontAwesomeIcon fontSize={24} icon={faChevronRight} />}
iconPosition="right"
sx={{ borderRadius: '8px' }}
Expand Down
11 changes: 11 additions & 0 deletions met-web/src/components/engagement/new/view/EngagementLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Params, defer } from 'react-router-dom';
import { getEngagement } from 'services/engagementService';
import { getEngagementIdBySlug } from 'services/engagementSlugService';
import { getWidgets } from 'services/widgetService';

export const engagementLoader = async ({ params }: { params: Params<string> }) => {
const { slug } = params;
const engagement = getEngagementIdBySlug(slug ?? '').then((response) => getEngagement(response.engagement_id));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you meaning to run all these in series? I think without the await keyword, some of these will run asynchronously

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, these promises are intentionally not resolved within the loader - it would cause the route to be slow during navigation. This method is only to construct and gather the relevant promises in one place. The defer() pattern allows us to choose what data we want to await vs. not, finding the right tradeoff between loading time and CLS. Deferred variables (promises) are awaited inside the route itself, using the element from react-router-dom in combination with with a MUI Skeleton fallback.
More reading: Deferred Data

const widgets = engagement.then((response) => getWidgets(response.id));
return defer({ engagement, slug, widgets });
};
Loading
Loading