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

♻️ button follows topbar #1773

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 26 additions & 4 deletions src/js_modules/syllabus/ProjectBoardGuidedExperience.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState, useRef, useEffect } from 'react';
import { Box, useColorModeValue } from '@chakra-ui/react';
import useTranslation from 'next-translate/useTranslation';
import PropTypes from 'prop-types';
import useCohortHandler from '../../common/hooks/useCohortHandler';
import SubtasksPill from './SubtasksPill';
import StatusPill from './StatusPill';
import Topbar from './Topbar';
Expand All @@ -14,8 +15,9 @@ import ReactPlayerV2 from '../../common/components/ReactPlayerV2';
import Heading from '../../common/components/Heading';
import Text from '../../common/components/Text';
import Icon from '../../common/components/Icon';
import bc from '../../common/services/breathecode';

function ProjectHeading({ currentAsset, isDelivered, handleStartLearnpack }) {
function ProjectHeading({ currentAsset, isDelivered, handleStartLearnpack, provisioningVendors }) {
const { backgroundColor4, hexColor } = useStyle();

const title = currentAsset?.title;
Expand Down Expand Up @@ -60,7 +62,7 @@ function ProjectHeading({ currentAsset, isDelivered, handleStartLearnpack }) {
)}
</Box>
<Box>
<ProjectInstructions variant={includesVideo ? 'small' : 'extra-small'} currentAsset={currentAsset} handleStartLearnpack={handleStartLearnpack} />
<ProjectInstructions variant={includesVideo ? 'small' : 'extra-small'} currentAsset={currentAsset} handleStartLearnpack={handleStartLearnpack} provisioningVendors={provisioningVendors} />
</Box>
</Box>
</Box>
Expand Down Expand Up @@ -90,10 +92,28 @@ function ProjectBoardGuidedExperience({ currentAsset, handleStartLearnpack }) {
const headerRef = useRef(null);
const [isHeaderVisible, setIsHeaderVisible] = useState(true);
const { hexColor, backgroundColor, featuredLight } = useStyle();
const [vendors, setVendors] = useState([]);
const { state } = useCohortHandler();
const { cohortSession } = state;

// const isDelivered = false;
const isDelivered = currentTask?.task_status === 'DONE' && currentAsset?.delivery_formats !== 'no_delivery';

const fetchProvisioningVendors = async () => {
try {
const { data } = await bc.provisioning().academyVendors(cohortSession.academy.id);
setVendors(data);
} catch (e) {
console.log(e);
}
};

useEffect(() => {
if (cohortSession) {
fetchProvisioningVendors();
}
}, [cohortSession]);

useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
Expand Down Expand Up @@ -127,7 +147,7 @@ function ProjectBoardGuidedExperience({ currentAsset, handleStartLearnpack }) {
flexDirection={{ base: 'column', md: 'row' }}
>
<Box display="flex" flexDirection="column" gap="20px" width="100%">
<ProjectHeading currentAsset={currentAsset} isDelivered={isDelivered} handleStartLearnpack={handleStartLearnpack} />
<ProjectHeading currentAsset={currentAsset} isDelivered={isDelivered} handleStartLearnpack={handleStartLearnpack} provisioningVendors={vendors} />
{isDelivered && (
<Box padding="16px" background={backgroundColor} borderRadius="16px" height="100%">
<Heading size="18px" mb="16px">
Expand Down Expand Up @@ -156,7 +176,7 @@ function ProjectBoardGuidedExperience({ currentAsset, handleStartLearnpack }) {
<TaskCodeRevisions />
)}
</Box>
<Topbar currentAsset={currentAsset} display={isHeaderVisible ? 'none' : 'flex'} />
<Topbar currentAsset={currentAsset} display={isHeaderVisible ? 'none' : 'flex'} handleStartLearnpack={handleStartLearnpack} provisioningVendors={vendors} buttonsHandlerVariant="extra-small" />
</>
);
}
Expand All @@ -173,10 +193,12 @@ ProjectHeading.propTypes = {
currentAsset: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.any])),
isDelivered: PropTypes.bool,
handleStartLearnpack: PropTypes.func.isRequired,
provisioningVendors: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.any])),
};
ProjectHeading.defaultProps = {
currentAsset: null,
isDelivered: false,
provisioningVendors: [],
};

export default ProjectBoardGuidedExperience;
Expand Down
33 changes: 9 additions & 24 deletions src/js_modules/syllabus/ProjectInstructions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function ProvisioningPopover({ openInLearnpackAction, provisioningLinks }) {
);
}

function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartLearnpack, isForOpenLocaly, startWithLearnpack, variant }) {
export function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartLearnpack, isForOpenLocaly, startWithLearnpack, variant, ...rest }) {
const { t } = useTranslation('common');
const { state } = useCohortHandler();
const { cohortSession } = state;
Expand All @@ -89,13 +89,13 @@ function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartL
markdownBody.scrollIntoView({ block: 'start', behavior: 'smooth' });
};

const showProvisioningLinks = vendors.length > 0 && currentAsset?.gitpod && !cohortSession.available_as_saas;
const showProvisioningLinks = vendors?.length > 0 && currentAsset?.gitpod && !cohortSession.available_as_saas;
const isExternalExercise = currentAsset.external && currentAsset.asset_type === 'EXERCISE';
const canSeeInstructions = variant !== 'small' || variant !== 'extra-small';

if (isExternalExercise) {
return (
<Button cursor="pointer" as="a" href={currentAsset.url} target="_blank" size="sm" padding="4px 8px" fontSize="14px" fontWeight="500" background="gray.200" color="blue.default">
<Button cursor="pointer" as="a" href={currentAsset.url} target="_blank" size="sm" padding="4px 8px" fontSize="14px" fontWeight="500" background="gray.200" color="blue.default" {...rest}>
{t('common:learnpack.start-exercise')}
</Button>
);
Expand All @@ -114,7 +114,7 @@ function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartL
</Popover>
)}
{startWithLearnpack ? (
<Button cursor="pointer" as="a" onClick={handleStartLearnpack} size="sm" padding="4px 8px" fontSize="14px" fontWeight="500" background="gray.200" color="blue.default">
<Button cursor="pointer" as="a" onClick={handleStartLearnpack} size="sm" padding="4px 8px" fontSize="14px" fontWeight="500" background="gray.200" color="blue.default" {...rest}>
{t('common:learnpack.start-asset', { asset_type: t(`common:learnpack.asset_types.${currentAsset?.asset_type?.toLowerCase() || ''}`) })}
</Button>
) : (
Expand All @@ -133,6 +133,7 @@ function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartL
if (isForOpenLocaly) setShowCloneModal(true);
else scrollToMarkdown();
}}
{...rest}
>
{t('asset-button.project')}
</Button>
Expand All @@ -141,30 +142,14 @@ function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartL
);
}

function ProjectInstructions({ currentAsset, variant, handleStartLearnpack }) {
function ProjectInstructions({ currentAsset, variant, handleStartLearnpack, provisioningVendors }) {
const { t } = useTranslation('common');
const { currentTask } = useModuleHandler();
const { state } = useCohortHandler();
const { cohortSession } = state;
const [vendors, setVendors] = useState([]);
const [showCloneModal, setShowCloneModal] = useState(false);
const noLearnpackIncluded = noLearnpackAssets['no-learnpack'];

const fetchProvisioningVendors = async () => {
try {
const { data } = await bc.provisioning().academyVendors(cohortSession.academy.id);
setVendors(data);
} catch (e) {
console.log(e);
}
};

useEffect(() => {
if (cohortSession) {
fetchProvisioningVendors();
}
}, [cohortSession]);

const templateUrl = currentAsset?.template_url;
const isInteractive = currentAsset?.interactive;
const isForOpenLocaly = isInteractive || templateUrl;
Expand Down Expand Up @@ -193,7 +178,7 @@ function ProjectInstructions({ currentAsset, variant, handleStartLearnpack }) {
currentAsset={currentAsset}
handleStartLearnpack={handleStartLearnpack}
setShowCloneModal={setShowCloneModal}
vendors={vendors}
vendors={provisioningVendors}
isForOpenLocaly={isForOpenLocaly}
startWithLearnpack={startWithLearnpack}
variant={variant}
Expand Down Expand Up @@ -229,7 +214,7 @@ function ProjectInstructions({ currentAsset, variant, handleStartLearnpack }) {
currentAsset={currentAsset}
handleStartLearnpack={handleStartLearnpack}
setShowCloneModal={setShowCloneModal}
vendors={vendors}
vendors={provisioningVendors}
isForOpenLocaly={isForOpenLocaly}
startWithLearnpack={startWithLearnpack}
variant={variant}
Expand Down Expand Up @@ -276,7 +261,7 @@ function ProjectInstructions({ currentAsset, variant, handleStartLearnpack }) {
setShowCloneModal={setShowCloneModal}
startWithLearnpack={startWithLearnpack}
isForOpenLocaly={isForOpenLocaly}
vendors={vendors}
vendors={provisioningVendors}
variant={variant}
/>
</Box>
Expand Down
35 changes: 34 additions & 1 deletion src/js_modules/syllabus/Topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@ import SubtasksPill from './SubtasksPill';
import useStyle from '../../common/hooks/useStyle';
import Heading from '../../common/components/Heading';
import Icon from '../../common/components/Icon';
import ModalToCloneProject from './ModalToCloneProject';
import noLearnpackAssets from '../../../public/no-learnpack-in-cloud.json';
import { ButtonsHandler } from './ProjectInstructions';
import useCohortHandler from '../../common/hooks/useCohortHandler';

function TopBar({ currentAsset, ...rest }) {
function TopBar({ currentAsset, handleStartLearnpack, provisioningVendors, buttonsHandlerVariant, ...rest }) {
const { t } = useTranslation('syllabus');
const { backgroundColor4, hexColor } = useStyle();
const [isVisible, setIsVisible] = useState(false);
const [showCloneModal, setShowCloneModal] = useState(false);
const { state } = useCohortHandler();
const { cohortSession } = state;

const title = currentAsset?.title;
const assetType = currentAsset?.asset_type;
const noLearnpackIncluded = noLearnpackAssets['no-learnpack'];

const templateUrl = currentAsset?.template_url;
const isInteractive = currentAsset?.interactive;
const isForOpenLocaly = isInteractive || templateUrl;
const learnpackDeployUrl = currentAsset?.learnpack_deploy_url;
const startWithLearnpack = learnpackDeployUrl && cohortSession.available_as_saas && !noLearnpackIncluded.includes(currentAsset.slug);

const assetTypeIcons = {
LESSON: 'book',
Expand Down Expand Up @@ -69,6 +83,19 @@ function TopBar({ currentAsset, ...rest }) {
<Box display="flex" alignItems="center" gap="5px">
{currentAsset?.asset_type === 'PROJECT' && (
<>
<ButtonsHandler
currentAsset={currentAsset}
handleStartLearnpack={handleStartLearnpack}
setShowCloneModal={setShowCloneModal}
vendors={provisioningVendors}
isForOpenLocaly={isForOpenLocaly}
startWithLearnpack={startWithLearnpack}
variant={buttonsHandlerVariant}
background="blue.1000"
color="white"
_hover="none"
_active="none"
/>
<StatusPill />
<SubtasksPill />
</>
Expand All @@ -79,15 +106,21 @@ function TopBar({ currentAsset, ...rest }) {
</Button>
</Box>
</Box>
<ModalToCloneProject currentAsset={currentAsset} isOpen={showCloneModal} onClose={setShowCloneModal} />
</>
);
}

TopBar.propTypes = {
currentAsset: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.any])),
handleStartLearnpack: PropTypes.func.isRequired,
buttonsHandlerVariant: PropTypes.string,
provisioningVendors: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.any])),
};
TopBar.defaultProps = {
currentAsset: null,
buttonsHandlerVariant: 'extra-small',
provisioningVendors: [],
};

export default TopBar;