Skip to content

Commit

Permalink
Keep tests pane open (display: none) so that we don't lose collapse s…
Browse files Browse the repository at this point in the history
…tate of the accordions
  • Loading branch information
SebastienTainon committed Aug 11, 2023
1 parent 34c2ef3 commit 906c086
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
29 changes: 16 additions & 13 deletions frontend/submission/TestsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {faClock} from '@fortawesome/free-solid-svg-icons';
import {faTimes} from '@fortawesome/free-solid-svg-icons/faTimes';
import {TaskSubmission, TaskSubmissionEvaluateOn, TaskSubmissionServer} from './submission_types';

export function TestsPane() {
export interface TestsPaneProps {
open: boolean,
}

export function TestsPane(props: TestsPaneProps) {
const submissionResults = useAppSelector(state => state.submission.taskSubmissions);
const dispatch = useDispatch();
const currentSubmission = useAppSelector(state => null !== state.submission.currentSubmissionId ? submissionResults[state.submission.currentSubmissionId] : null);
Expand Down Expand Up @@ -69,7 +73,7 @@ export function TestsPane() {
};

return (
<div className="submission-results">
<div className="submission-results" style={{display: props.open ? 'block' : 'none'}}>
<div className="submission-results__header">
<div className="submission-results__title">{getMessage(currentSubmission ? 'SUBMISSION_RESULTS_TITLE' : 'SUBMISSION_RESULTS_TESTS_TITLE')}</div>
<div className="submission-results__close" onClick={closePane}>
Expand All @@ -94,25 +98,24 @@ export function TestsPane() {
</Dropdown.Menu>
</Dropdown>
</div>}
{null !== currentSubmission && <div className="submission-results__submission">
{currentSubmission.evaluated ?

<div className="submission-results__submission">
<div style={{display: !currentSubmission || currentSubmission.evaluated ? 'block' : 'none'}}>
<TestsPaneList
submission={currentSubmission}
/>
:
(currentSubmission.crashed ? <div className="submission-results__submission-crashed">
</div>

{(currentSubmission && !currentSubmission.evaluated) && (
currentSubmission.crashed ? <div className="submission-results__submission-crashed">
{getMessage('SUBMISSION_RESULTS_CRASHED')}
</div>
: <div className="submission-results__submission-loader">
<FontAwesomeIcon icon={faSpinner} className="fa-spin mr-2"/>
{getMessage('SUBMISSION_RESULTS_EVALUATING')}
</div>)
}
</div>}
{null === currentSubmission && <div className="submission-results__submission">
<TestsPaneList
/>
</div>}
</div>
)}
</div>
</div>
)
}
6 changes: 3 additions & 3 deletions frontend/submission/TestsPaneList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function TestsPaneList(props: SubmissionResultProps) {
const currentTask = useAppSelector(state => state.task.currentTask);
const testsOrdered = useAppSelector(selectTaskTests);
const submission = props.submission;
const subTasksOrdered = currentTask.subTasks ? [...currentTask.subTasks] : [];
const subTasksOrdered = currentTask?.subTasks ? [...currentTask.subTasks] : [];
subTasksOrdered.sort((a, b) => a.rank - b.rank);
const submissionDisplayedError = useAppSelector(state => state.submission.submissionDisplayedError);
const context = quickAlgoLibraries.getContext(null, 'main');
Expand Down Expand Up @@ -73,7 +73,7 @@ export function TestsPaneList(props: SubmissionResultProps) {

return (
<div className="submission-result">
{submission && isServerSubmission(submission) && TaskSubmissionMode.UserTest === submission.result.mode && <div>
{submission && isServerSubmission(submission) && TaskSubmissionMode.UserTest === submission.result?.mode && <div>
<Alert intent={Intent.WARNING}>{getMessage('SUBMISSION_USER_TEST_WARNING')}</Alert>
</div>}
{submission && !submission.evaluated && <div>
Expand All @@ -83,7 +83,7 @@ export function TestsPaneList(props: SubmissionResultProps) {
<React.Fragment>
{compilationResult}

{submission && (!isServerSubmission(submission) || !submission.result.compilationError) && submission.result.tests.length === 0 && <div>
{submission && (!isServerSubmission(submission) || !submission.result?.compilationError) && submission.result?.tests.length === 0 && <div>
{getMessage('SUBMISSION_NO_TESTS')}
</div>}

Expand Down
4 changes: 2 additions & 2 deletions frontend/submission/TestsPaneListSubTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export interface SubmissionResultSubTaskProps {
export function TestsPaneListSubTask(props: SubmissionResultSubTaskProps) {
const taskTests = useAppSelector(selectTaskTests);
const subTask = props.subTask;
const subTaskResult = props.submission && props.submission.result.subTasks ? props.submission.result.subTasks.find(submissionSubTask => submissionSubTask.subtaskId === subTask.id) : null;
const subTaskResult = props.submission && props.submission.result?.subTasks ? props.submission.result.subTasks.find(submissionSubTask => submissionSubTask.subtaskId === subTask.id) : null;
const [open, setOpen] = useState(false);

const testsOrdered = [...taskTests.filter(test => test.subtaskId === subTask.id)];

const testsByIcon: {[key: number]: number} = {};
let testsByIconValues: {errorCodeData: ErrorCodeData, count: number}[];
if (props.submission) {
if (props.submission && props.submission.result) {
for (let test of testsOrdered) {
const testResult = props.submission.result.tests.find(submissionTest => submissionTest.testId === test.id);
if (testResult && null !== testResult.errorCode && undefined !== testResult.errorCode) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/submission/TestsPaneListTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const testErrorCodeData: {[property in SubmissionTestErrorCode]: ErrorCod
export function TestsPaneListTest(props: SubmissionResultTestProps) {
const test = props.test;
const currentTestId = useAppSelector(state => state.task.currentTestId);
const testResult = props.submission ? props.submission.result.tests.find(otherTest => otherTest.testId === test.id) : null;
const testResult = props.submission && props.submission.result ? props.submission.result.tests.find(otherTest => otherTest.testId === test.id) : null;
const testIndex = useAppSelector(state => selectTaskTests(state).findIndex(otherTest => otherTest.id === test.id));

const hasRelativeScore = testResult && testResult.score > 0 && testResult.score < 1;
Expand Down
4 changes: 2 additions & 2 deletions frontend/submission/TestsPaneListUserTests.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState} from "react";
import React, {useEffect, useState} from "react";
import {useAppSelector} from "../hooks";
import {Collapse} from 'react-bootstrap';
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
Expand Down Expand Up @@ -27,7 +27,7 @@ export function TestsPaneListUserTests(props: SubmissionResultSubTaskProps) {

const testsByIcon: {[key: number]: number} = {};
let testsByIconValues: {errorCodeData: ErrorCodeData, count: number}[];
if (props.submission) {
if (props.submission && props.submission.result) {
for (let test of testsOrdered) {
const testResult = props.submission.result.tests.find(submissionTest => submissionTest.testId === test.id);
if (testResult && null !== testResult.errorCode && undefined !== testResult.errorCode) {
Expand Down
5 changes: 4 additions & 1 deletion frontend/task/TaskApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export function TaskApp() {
<Container key={language} fluid className={`task ${fullScreenActive ? 'full-screen' : ''} layout-${layoutType} task-player-${layoutPlayerMode} platform-${options.platform}`}>
<div className="layout-general">
<div className={`task-section`}>
{submissionsPaneOpen && <TestsPane/>}
<TestsPane
open={submissionsPaneOpen}
/>

<div className="task-section-container">
<div className="task-header">
<span className="task-header__quick">QUICK</span>
Expand Down
2 changes: 0 additions & 2 deletions frontend/task/libs/printer/printer_lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,6 @@ export class PrinterLib extends QuickAlgoLibrary {
},
};

console.log('the test', test);

let unknownInput = true;
let initial = '';
if (undefined !== log.remainingInput) {
Expand Down

0 comments on commit 906c086

Please sign in to comment.