Skip to content

Commit

Permalink
feat: BFF integration
Browse files Browse the repository at this point in the history
Feat/bff integration 2
  • Loading branch information
muselesscreator authored Nov 20, 2023
2 parents 375496e + 2c62661 commit d81f1e2
Show file tree
Hide file tree
Showing 41 changed files with 402 additions and 327 deletions.
45 changes: 37 additions & 8 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
import React from 'react';
import { Routes, Route } from 'react-router-dom';
import {
AuthenticatedPageRoute,
ErrorPage,
} from '@edx/frontend-platform/react';
import { useIntl } from '@edx/frontend-platform/i18n';

import PeerAssessmentView from 'views/AssessmentView/PeerAssessmentView';
import SelfAssessmentView from 'views/AssessmentView/SelfAssessmentView';
import StudentTrainingView from 'views/AssessmentView/StudentTrainingView';
import AssessmentView from 'views/AssessmentView';
import SubmissionView from 'views/SubmissionView';
import XBlockView from 'views/XBlockView';
import GradeView from 'views/GradeView';

import AppContainer from 'components/AppContainer';
import ModalContainer from 'components/ModalContainer';

import { useRefreshPageData } from 'hooks/app';

Check failure on line 17 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test

'useRefreshPageData' is defined but never used
import { useRefreshUpstream } from 'hooks/modal';

Check failure on line 18 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test

'useRefreshUpstream' is defined but never used
import { useUpdateTestProgressKey } from 'hooks/test';

import messages from './messages';
import routes from './routes';

const RouterRoot = () => {
const App = () => {
/*
const { body } = document;
const refreshPageData = useRefreshPageData();
const refreshUpstream = useRefreshUpstream();
React.useEffect(() => {
const resizeEvent = () => {
// const { clientHeight, scrollHeight, offsetHeight } = body;
const height = body.scrollHeight;
if (document.referrer !== '' && height !== 0) {
window.parent.postMessage(
{ type: 'ora-resize', payload: { height } },
document.referrer,
);
}
};
resizeEvent();
window.addEventListener('resize', resizeEvent);
}, [body.scrollHeight]);
React.useEffect(() => {
window.addEventListener('message', (event) => {
if (event.data.type === 'plugin.modal-close') {
refreshPageData();
}
});
}, []);
*/

const { formatMessage } = useIntl();

// test
Expand Down Expand Up @@ -69,9 +98,9 @@ const RouterRoot = () => {
*/
const baseRoutes = [
appRoute(routes.xblock, XBlockView),
modalRoute(routes.peerAssessment, PeerAssessmentView, 'Assess your peers'),
modalRoute(routes.selfAssessment, SelfAssessmentView, 'Assess yourself'),
modalRoute(routes.studentTraining, StudentTrainingView, 'Practice grading'),
modalRoute(routes.peerAssessment, AssessmentView, 'Assess your peers'),
modalRoute(routes.selfAssessment, AssessmentView, 'Assess yourself'),
modalRoute(routes.studentTraining, AssessmentView, 'Practice grading'),
modalRoute(routes.submission, SubmissionView, 'Your response'),
modalRoute(routes.graded, GradeView, 'My Grade'),
<Route key="error" path={routes.root} element={<ErrorPage message={formatMessage(messages.error404Message)} />} />,
Expand All @@ -85,4 +114,4 @@ const RouterRoot = () => {
);
};

export default RouterRoot;
export default App;
18 changes: 9 additions & 9 deletions src/components/FileUpload/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export const useUploadConfirmModalHooks = ({
closeHandler,
uploadHandler,
}) => {
const [description, setDescription] = useKeyedState(
stateKeys.description,
''
);
const [description, setDescription] = useKeyedState(stateKeys.description, '');
const [shouldShowError, setShouldShowError] = useKeyedState(
stateKeys.shouldShowError,
false
false,
);

const confirmUploadClickHandler = () => {
console.log({ confirmUploadClick: { description } });

Check warning on line 25 in src/components/FileUpload/hooks.js

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
if (description !== '') {
uploadHandler(file, description);
} else {
Expand Down Expand Up @@ -54,13 +52,15 @@ export const useFileUploadHooks = ({ onFileUploaded }) => {
const [uploadArgs, setUploadArgs] = useKeyedState(stateKeys.uploadArgs, {});
const [isModalOpen, setIsModalOpen] = useKeyedState(
stateKeys.isModalOpen,
false
false,
);

const confirmUpload = useCallback(async () => {
const confirmUpload = useCallback(async (file, description) => {
console.log({ confirmUpload: { file, description } });

Check warning on line 59 in src/components/FileUpload/hooks.js

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
setIsModalOpen(false);
if (onFileUploaded) {
await onFileUploaded(uploadArgs);
console.log({ uploadArgs });

Check warning on line 62 in src/components/FileUpload/hooks.js

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
await onFileUploaded({ ...uploadArgs, description });
}
setUploadArgs({});
}, [uploadArgs, onFileUploaded, setIsModalOpen, setUploadArgs]);
Expand All @@ -75,7 +75,7 @@ export const useFileUploadHooks = ({ onFileUploaded }) => {
setIsModalOpen(true);
setUploadArgs({ fileData, handleError, requestConfig });
},
[setIsModalOpen, setUploadArgs]
[setIsModalOpen, setUploadArgs],
);

return {
Expand Down
9 changes: 5 additions & 4 deletions src/components/FileUpload/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { useIntl } from '@edx/frontend-platform/i18n';

import { nullMethod } from 'utils';
import { useFileUploadEnabled } from 'hooks/app';
import { useViewStep } from 'hooks/routing';
import FilePreview from 'components/FilePreview';
import { stepNames } from 'constants';

import UploadConfirmModal from './UploadConfirmModal';
import ActionCell from './ActionCell';
Expand Down Expand Up @@ -35,11 +37,10 @@ const FileUpload = ({
isModalOpen,
onProcessUpload,
uploadArgs,
} = useFileUploadHooks({
onFileUploaded,
});
} = useFileUploadHooks({ onFileUploaded });
const viewStep = useViewStep();

if ( !useFileUploadEnabled() ) {
if (!useFileUploadEnabled() || viewStep === stepNames.studentTraining) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const useActiveSubmissionConfig = ({
formatMessage,
}) => {
const saveAndClose = React.useCallback(
() => (options.saveResponse ? options.saveResponse().then(closeModal) : null),
() => (options.finishLater ? options.finishLater().then(closeModal) : null),
[options, closeModal],
);

if (!options) { return null; }

const { submit, submitStatus, saveResponseStatus } = options;
const { submit, submitStatus, finishLaterStatus } = options;

return {
primary: {
Expand All @@ -28,9 +28,9 @@ const useActiveSubmissionConfig = ({
},
secondary: {
onClick: saveAndClose,
state: saveResponseStatus,
state: finishLaterStatus,
labels: {
[MutationStatus.idle]: formatMessage(messages.finishLater),
default: formatMessage(messages.finishLater),
[MutationStatus.loading]: formatMessage(messages.savingResponse),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const useFinishedStateActions = () => {
}
console.log("?");
// submission finished state
console.log({ startStepAction });
return { primary: startStepAction, secondary: finishLaterAction };
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/ModalActions/hooks/useModalActionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const useModalActionConfig = ({ options }) => {

const exitAction = useExitAction();

// console.log({ useModalActionConfig: { step, globalState, hasSubmitted } });
// finished state
if (hasSubmitted) {
if (globalState.activeStepState !== stepStates.inProgress) {
return { primary: exitAction };
}
return finishedStateActions;
}

Expand Down
9 changes: 0 additions & 9 deletions src/components/PageDataProvider.jsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/ProgressBar/ProgressStep.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ProgressStep = ({
} else if (isComplete) {
iconSrc = CheckCircle;
if (step === stepNames.done && myGrade) {
subLabel = `${myGrade.earned} / ${myGrade.possible}`;
subLabel = `${myGrade.stepScore.earned} / ${myGrade.stepScore.possible}`;
}
}
return (
Expand Down
10 changes: 5 additions & 5 deletions src/components/ProgressBar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ export const ProgressBar = ({ className }) => {
return null;
}

const stepEl = (curStep) =>
stepLabels[curStep] ? (
const stepEl = (curStep) => stepLabels[curStep]
? (
<ProgressStep
step={curStep}
key={curStep}
label={formatMessage(stepLabels[curStep])}
canRevisit={(curStep === 'done' && hasReceivedFinalGrade) || !!stepInfo[curStep]}
canRevisit={(curStep === 'done' && hasReceivedFinalGrade) || stepCanRevisit[curStep]}
/>
) : null;

return (
<Navbar className={classNames('px-0', className)}>
<Navbar.Collapse className='ora-progress-nav-group bg-white'>
<hr className='ora-progress-divider' />
<Navbar.Collapse className="ora-progress-nav-group bg-white">
<hr className="ora-progress-divider" />
{stepOrders.map(stepEl)}
</Navbar.Collapse>
</Navbar>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Rubric/Rubric.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
}

.rubric-body {
overflow-y: scroll;
overflow-y: hide;
padding: map-get($spacers, 3);
}

.rubric-footer {
Expand Down
7 changes: 4 additions & 3 deletions src/components/Rubric/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ export const Rubric = ({ isCollapsible }) => {
return (
<Layout
title={<h3>{formatMessage(messages.rubric)}</h3>}
className='rubric-card'
className="rubric-card"
defaultOpen
>
<Card.Section className='rubric-body'>
<Card.Section className="rubric-body">
{!isCollapsible && (
<>
<h3>{formatMessage(messages.rubric)}</h3>
<hr className='m-2.5' />
<hr className="m-2.5" />
</>
)}
{criteria.map((criterion) => (
Expand Down
1 change: 0 additions & 1 deletion src/components/StatusAlert/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,3 @@ export default {
},
...messages,
};

16 changes: 16 additions & 0 deletions src/components/StatusAlert/useStatusAlertData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const useStatusAlertData = ({
const { formatMessage } = useIntl();
const {
activeStepName,
activeStepState,
cancellationInfo,
stepState,
} = useGlobalState({ step });
Expand Down Expand Up @@ -102,6 +103,15 @@ const useStatusAlertData = ({
heading: messages.headings[viewStep].submitted,
...alertTypes.success,
}));
if (activeStepState !== stepStates.inProgress) {
out.push(alertConfig({
message: messages.alerts[activeStepName][activeStepState],
heading: messages.headings[activeStepName][activeStepState],
actions: [
<Button onClick={closeModal}>{formatMessage(messages.exit)}</Button>,
],
}));
}
if (activeStepName === stepNames.staff) {
out.push(alertConfig({
message: messages.alerts[activeStepName].staffAssessment,
Expand Down Expand Up @@ -141,6 +151,12 @@ const useStatusAlertData = ({
heading: messages.headings.peer.finished,
})];
}
if (stepName === stepNames.staff) {
return [alertConfig({
message: messages.alerts[activeStepName].staffAssessment,
heading: messages.headings[activeStepName].staffAssessment,
})];
}
return [alertConfig({
message: messages.alerts[stepName][stepState],
heading: messages.headings[stepName][stepState],
Expand Down
2 changes: 0 additions & 2 deletions src/components/StepProgressIndicator/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import messages from './messages';
import './index.scss';

const StepProgressIndicator = ({ step }) => {
console.log("Step Progress Indicator");
const { formatMessage } = useIntl();
const configInfo = useAssessmentStepConfig();
const stepInfo = useStepInfo();
const globalState = useGlobalState();
const hasSubmitted = useHasSubmitted();
const { activeStepName } = globalState;
console.log({ globalState, stepInfo });
const loadNextAction = useLoadNextAction();
if (![stepNames.peer, stepNames.studentTraining].includes(step)) {
return null;
Expand Down
4 changes: 3 additions & 1 deletion src/data/redux/app/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const initialState = {
submittedAssessment: null,
showTrainingError: false,
},
response: null,
formFields: {
criteria: [],
overallFeedback: '',
Expand All @@ -26,8 +27,9 @@ const app = createSlice({
reducers: {
loadAssessment: (state, { payload }) => ({
...state,
assessment: { ...initialState.assessment, submittedAssessment: payload },
assessment: { ...initialState.assessment, submittedAssessment: payload.data },
}),
loadResponse: (state, { payload }) => ({ ...state, response: payload }),
setHasSubmitted: (state, { payload }) => ({
...state,
hasSubmitted: payload,
Expand Down
2 changes: 2 additions & 0 deletions src/data/redux/app/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const selectors = {
formFieldsData(state).criteria[criterionIndex]?.selectedOption
),

response: createSelector(rootSelector, ({ response }) => response),

hasSubmitted: createSelector(rootSelector, ({ hasSubmitted }) => hasSubmitted),

overallFeedback: (state) => formFieldsData(state).overallFeedback,
Expand Down
2 changes: 2 additions & 0 deletions src/data/redux/hooks/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const useHasSubmitted = () => useSelector(selectors.hasSubmitted);
export const useShowValidation = () => useSelector(selectors.showValidation);
export const useShowTrainingError = () => useSelector(selectors.showTrainingError);
export const useOverallFeedbackValue = () => useSelector(selectors.overallFeedback);
export const useResponse = () => useSelector(selectors.response);

/* special selectors */
export const useCriterionOption = criterionIndex => (
Expand All @@ -31,6 +32,7 @@ export const useSetShowTrainingError = () => useActionHook(actions.setShowTraini
export const useSetFormFields = () => useActionHook(actions.setFormFields);
export const useResetAssessment = () => useActionHook(actions.resetAssessment);
export const useSetOverallFeedback = () => useActionHook(actions.setOverallFeedback);
export const useSetResponse = () => useActionHook(actions.loadResponse);

export const useSetCriterionFeedback = (criterionIndex) => {
const dispatch = useDispatch();
Expand Down
Loading

0 comments on commit d81f1e2

Please sign in to comment.