Skip to content

Commit

Permalink
Merge branch 'main' into DOP-4247-build-artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Feb 1, 2024
2 parents 7d6fc3f + 044be80 commit 0f3647f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
20 changes: 20 additions & 0 deletions src/components/Heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import { cx, css } from '@leafygreen-ui/emotion';
import { H2, H3, Subtitle, Body } from '@leafygreen-ui/typography';
import Button from '@leafygreen-ui/button';
import Icon from '@leafygreen-ui/icon';
import useScreenSize from '../hooks/useScreenSize';
import ComponentFactory from './ComponentFactory';
import TabSelectors from './Tabs/TabSelectors';
import { TabContext } from './Tabs/tab-context';
import { InstruqtContext } from './Instruqt/instruqt-context';
import ConditionalWrapper from './ConditionalWrapper';
import Contents from './Contents';
import Permalink from './Permalink';
Expand All @@ -21,6 +24,10 @@ const headingStyles = css`
margin-bottom: 8px;
`;

const labButtonStyling = css`
margin-left: 18px;
`;

const determineHeading = (sectionDepth) => {
if (sectionDepth === 1) {
return H2;
Expand All @@ -39,7 +46,9 @@ const Heading = ({ sectionDepth, nodeData, page, ...rest }) => {
const isPageTitle = sectionDepth === 1;
const { isMobile, isTabletOrMobile } = useScreenSize();
const { selectors } = useContext(TabContext);
const { hasDrawer, isOpen, setIsOpen } = useContext(InstruqtContext);
const hasSelectors = selectors && Object.keys(selectors).length > 0;
const shouldShowLabButton = process.env.GATSBY_FEATURE_LAB_DRAWER === 'true' && isPageTitle && hasDrawer;
const shouldShowMobileHeader = !!(isPageTitle && isTabletOrMobile && hasSelectors);

return (
Expand All @@ -62,6 +71,17 @@ const Heading = ({ sectionDepth, nodeData, page, ...rest }) => {
return <ComponentFactory {...rest} nodeData={element} key={index} />;
})}
<Permalink id={id} description="heading" />
{shouldShowLabButton && (
<Button
role="button"
className={cx(labButtonStyling)}
disabled={isOpen}
onClick={() => setIsOpen(true)}
leftGlyph={<Icon glyph="Code" />}
>
{'Open Interactive Tutorial'}
</Button>
)}
</HeadingTag>
</ConditionalWrapper>
{isPageTitle && <Contents />}
Expand Down
12 changes: 7 additions & 5 deletions src/components/Instruqt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Instruqt = ({ nodeData }) => {
const embedValue = nodeData?.argument[0]?.value;
const title = nodeData?.options?.title;
const iframeRef = useRef(null);
const { setIsOpen, hasLab } = useContext(InstruqtContext);
const { setIsOpen, isOpen, hasDrawer } = useContext(InstruqtContext);

const onFullScreen = useCallback(() => {
if (iframeRef) {
Expand All @@ -47,10 +47,12 @@ const Instruqt = ({ nodeData }) => {

return (
<>
{process.env.GATSBY_FEATURE_LAB_DRAWER === 'true' && hasLab ? (
<>
<LabDrawer embedValue={embedValue} title={title} />
</>
{process.env.GATSBY_FEATURE_LAB_DRAWER === 'true' && hasDrawer ? (
isOpen && (
<>
<LabDrawer embedValue={embedValue} title={title} />
</>
)
) : (
<>
<InstruqtFrame title={title} embedValue={embedValue} ref={iframeRef} />
Expand Down
10 changes: 5 additions & 5 deletions src/components/Instruqt/instruqt-context.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React, { useState } from 'react';

const defaultContextValue = {
hasLab: false,
hasDrawer: false,
isOpen: false,
setIsOpen: () => {},
};

const InstruqtContext = React.createContext(defaultContextValue);

const InstruqtProvider = ({ children, hasInstruqtLab }) => {
const hasLab = hasInstruqtLab;
const InstruqtProvider = ({ children, hasLabDrawer }) => {
const hasDrawer = hasLabDrawer;
const [isOpen, setIsOpen] = useState(false);

return <InstruqtContext.Provider value={{ hasLab, isOpen, setIsOpen }}>{children}</InstruqtContext.Provider>;
return <InstruqtContext.Provider value={{ hasDrawer, isOpen, setIsOpen }}>{children}</InstruqtContext.Provider>;
};

InstruqtProvider.defaultProps = {
hasInstruqtLab: false,
hasLabDrawer: false,
};

export { InstruqtContext, InstruqtProvider };
4 changes: 2 additions & 2 deletions src/components/RootProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const RootProvider = ({
selectors,
slug,
repoBranches,
hasInstruqtLab,
hasLabDrawer,
remoteMetadata,
project,
}) => {
Expand All @@ -30,7 +30,7 @@ const RootProvider = ({
<VersionContextProvider repoBranches={repoBranches} slug={slug}>
<TocContextProvider remoteMetadata={remoteMetadata}>
<SidenavContextProvider>
<InstruqtProvider hasInstruqtLab={hasInstruqtLab}>
<InstruqtProvider hasLabDrawer={hasLabDrawer}>
<SearchContextProvider showFacets={SHOW_FACETS}>{children}</SearchContextProvider>
</InstruqtProvider>
</SidenavContextProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const DefaultLayout = ({ children, pageContext: { page, slug, repoBranches, temp
selectors={page?.options?.selectors}
remoteMetadata={remoteMetadata}
project={project}
hasInstruqtLab={page?.options?.instruqt}
hasLabDrawer={page?.options?.instruqt}
>
<GlobalGrid isInPresentationMode={isInPresentationMode}>
{!isInPresentationMode ? <Header sidenav={sidenav} eol={eol} slug={slug} template={template} /> : <div />}
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/preview-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const DefaultLayout = ({
associatedReposInfo={associatedReposInfo}
headingNodes={page?.options?.headings}
selectors={page?.options?.selectors}
hasInstruqtLab={page?.options?.instruqt}
hasLabDrawer={page?.options?.instruqt}
isAssociatedProduct={isAssociatedProduct}
>
<GlobalGrid>
Expand Down
1 change: 0 additions & 1 deletion tests/unit/Instruqt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('Instruqt', () => {
const hasLabDrawer = true;
const wrapper = renderComponent(mockData.example, hasLabDrawer);
expect(wrapper.queryByTitle('Instruqt', { exact: false })).toBeTruthy();
expect(wrapper.queryByText('MongoDB Interactive Lab')).toBeTruthy();
});
});
});

0 comments on commit 0f3647f

Please sign in to comment.