Skip to content

Commit

Permalink
feat(bench): add maxCyclomaticComplexity
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 28, 2021
1 parent 777affd commit 4ecb295
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/components/Benchmarks/BenchmarkDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ const BenchmarkDetail = ({
editorRef.current = editor;
}

const {
isLoading: isBenchmarkLoading,
isError: isBenchmarkError,
data: benchmarkData,
error,
} = useBenchmarkDetail(match.params.id);

let lastSubmission;
const {
isLoading: isLastSubmissionLoading,
Expand Down Expand Up @@ -89,17 +96,11 @@ const BenchmarkDetail = ({
lintScore={jobData.lintScore}
lintErrors={jobData.lintErrors}
isLoading={isProcessing}
maxCyclomaticComplexity={benchmarkData?.maxCyclomaticComplexity}
/>
);
}

const {
isLoading: isBenchmarkLoading,
isError: isBenchmarkError,
data: benchmarkData,
error,
} = useBenchmarkDetail(match.params.id);

if (isBenchmarkLoading) {
return <span>Loading....</span>;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Benchmarks/BenchmarkModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class benchmarkModel {
gitUrl: null | undefined;
createdAt: string | undefined;
difficulty: string | undefined;
maxCyclomaticComplexity: number | undefined;
creator:
| {
id: string | undefined;
Expand Down
20 changes: 19 additions & 1 deletion src/components/Benchmarks/CreateBenchmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ const CreateBenchmark: React.FC = () => {
const title = event.target.title.value;
const subject = event.target.subject.value;
const difficulty = event.target.difficulty.value;
const maxCyclomaticComplexity = event.target.maxCylomaticComplexity.value;

if (title === '' || subject === '') {
setMessage('At least one field is blank');
setStatus('Error');
return;
}

mutate({ title, subject, difficulty });
mutate({ title, subject, difficulty, maxCyclomaticComplexity });
};

return (
Expand Down Expand Up @@ -75,6 +76,23 @@ const CreateBenchmark: React.FC = () => {
/>
</div>
</div>
<div className="flex flex-wrap -mx-3 mb-6">
<div className="w-full px-3">
<label
className="block dark:text-gray-100 uppercase tracking-wide text-gray-700 text-xs font-bold mb-2"
htmlFor="grid-password"
>
Max cyclomatic complexity
</label>
<input
className="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
type="number"
id="maxCylomaticComplexity"
min="1"
max="10"
/>
</div>
</div>
<div className="flex flex-wrap -mx-3 mb-6">
<div className="w-full px-3">
<label
Expand Down
13 changes: 12 additions & 1 deletion src/components/Benchmarks/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface LayoutProps {
lintScore?: number;
lintErrors?: LintErrorDTO[];
isLoading: boolean;
maxCyclomaticComplexity?: number;
}

const Result: React.FC<LayoutProps> = ({
Expand All @@ -29,6 +30,7 @@ const Result: React.FC<LayoutProps> = ({
lintErrors,
isLoading,
cyclomaticComplexity,
maxCyclomaticComplexity,
}) => {
if (status !== 'done' && status !== 'failed') {
return (
Expand All @@ -53,6 +55,7 @@ const Result: React.FC<LayoutProps> = ({
memUsage={memUsage}
execDuration={execDuration}
cyclomaticComplexity={cyclomaticComplexity}
maxCyclomaticComplexity={maxCyclomaticComplexity}
/>
</div>
<div className="w-3/5 pl-6">
Expand Down Expand Up @@ -139,6 +142,7 @@ interface ScoresComponentProps {
memUsage: number | undefined;
execDuration: number | undefined;
cyclomaticComplexity: number | undefined;
maxCyclomaticComplexity: number | undefined;
}

const ScoresComponent: React.FC<ScoresComponentProps> = ({
Expand All @@ -148,6 +152,7 @@ const ScoresComponent: React.FC<ScoresComponentProps> = ({
memUsage,
execDuration,
cyclomaticComplexity,
maxCyclomaticComplexity,
}) => {
return (
<div className="relative flex flex-col min-w-0 mb-4 lg:mb-0 break-words bg-gray-50 dark:bg-gray-800 w-full shadow-lg rounded">
Expand Down Expand Up @@ -236,7 +241,13 @@ const ScoresComponent: React.FC<ScoresComponentProps> = ({
</th>
<td className="border-t-0 px-4 align-middle border-l-0 border-r-0 text-sm whitespace-nowrap p-3">
<div className="flex items-center">
<span className="mr-2">{cyclomaticComplexity}</span>
<span className="mr-2">
{cyclomaticComplexity} / {maxCyclomaticComplexity}{' '}
{(cyclomaticComplexity ?? 0) >
(maxCyclomaticComplexity ?? 0)
? '❌'
: '✅'}
</span>
</div>
</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions src/hooks/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function createBenchmark(bench: {
title: string;
subject: string;
difficulty: string;
maxCyclomaticComplexity: number;
}): Promise<benchmarkModel> {
const { data } = await authenticatedRequest({
url: `/benchmarks`,
Expand Down

0 comments on commit 4ecb295

Please sign in to comment.