Skip to content

Commit

Permalink
fix(client): set editor submission filename based on selected language (
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar authored Sep 30, 2023
1 parent c420701 commit e39c04a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { ContentCard } from '../../../ContentCard/ContentCard';
import { MaxCodeLength50KB, Required, composeValidators } from '../../../forms/validations';
import FormAceEditor from '../../../forms/FormAceEditor/FormAceEditor';
import { FormSelect2 } from '../../../forms/FormSelect2/FormSelect2';
import { getAllowedGradingLanguages, gradingLanguageNamesMap } from '../../../../modules/api/gabriel/language.js';
import {
getAllowedGradingLanguages,
getGradingLanguageEditorSubmissionFilename,
getGradingLanguageEditorSubmissionHint,
gradingLanguageNamesMap,
} from '../../../../modules/api/gabriel/language.js';

import './ProblemSubmissionEditor.scss';

Expand All @@ -20,7 +25,9 @@ export function ProblemSubmissionEditor({
const onSubmitEditor = data => {
const sourceFiles = {};
Object.keys(sourceKeys).forEach(key => {
sourceFiles[key] = new File([data.editor], 'solution.cpp', { type: 'text/plain' });
sourceFiles[key] = new File([data.editor], getGradingLanguageEditorSubmissionFilename(data.gradingLanguage), {
type: 'text/plain',
});
});

return onSubmit({
Expand Down Expand Up @@ -71,21 +78,30 @@ export function ProblemSubmissionEditor({

return (
<Form onSubmit={onSubmitEditor} initialValues={initialValues}>
{({ values, handleSubmit, submitting }) => (
<form onSubmit={handleSubmit}>
<div className="editor-heading">
<Field component={FormSelect2} {...gradingLanguageField} />
<p>
<Tag intent={Intent.WARNING}>BETA</Tag>
</p>
<p>
<small>Type or paste your code here</small>
</p>
</div>
<Field component={FormAceEditor} {...editorField} gradingLanguage={values.gradingLanguage} />
<Button type="submit" text="Submit" intent={Intent.PRIMARY} loading={submitting} />
</form>
)}
{({ values, handleSubmit, submitting }) => {
const submissionHint = getGradingLanguageEditorSubmissionHint(values.gradingLanguage);

return (
<form onSubmit={handleSubmit}>
<div className="editor-heading">
<Field component={FormSelect2} {...gradingLanguageField} />
<p>
<Tag intent={Intent.WARNING}>BETA</Tag>
</p>
<p>
<small>Type or paste your code here</small>
</p>
</div>
{submissionHint && (
<p>
<small>{submissionHint}</small>
</p>
)}
<Field component={FormAceEditor} {...editorField} gradingLanguage={values.gradingLanguage} />
<Button type="submit" text="Submit" intent={Intent.PRIMARY} loading={submitting} />
</form>
);
}}
</Form>
);
};
Expand Down
25 changes: 25 additions & 0 deletions judgels-client/src/modules/api/gabriel/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ export const gradingLanguageSyntaxHighlighterValueMap = {
OutputOnly: '',
};

export const gradingLanguageEditorSubmissionFilenamesMap = {
C: 'solution.c',
Cpp11: 'solution.cpp',
Cpp17: 'solution.cpp',
Cpp20: 'solution.cpp',
Go: 'solution.go',
Java: 'Solution.java',
Pascal: 'solution.pas',
Python3: 'solution.py',
PyPy3: 'solution.py',
Rust2021: 'solution.rs',
};

export const gradingLanguageEditorSubmissionHintsMap = {
Java: 'Public class name must be Solution',
};

export const gradingLanguages = Object.keys(gradingLanguageNamesMap)
.filter(l => l !== OutputOnlyOverrides.KEY)
.sort();
Expand All @@ -78,6 +95,14 @@ export function getGradingLanguageSyntaxHighlighterValue(code) {
return gradingLanguageSyntaxHighlighterValueMap[code] || code;
}

export function getGradingLanguageEditorSubmissionFilename(code) {
return gradingLanguageEditorSubmissionFilenamesMap[code];
}

export function getGradingLanguageEditorSubmissionHint(code) {
return gradingLanguageEditorSubmissionHintsMap[code];
}

export function getAllowedGradingLanguages(gradingEngine, restriction) {
if (gradingEngine.startsWith(OutputOnlyOverrides.KEY)) {
return [OutputOnlyOverrides.KEY];
Expand Down

0 comments on commit e39c04a

Please sign in to comment.