From faac601f93a069998ba04d13ccc712cd98a48c81 Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 16 Mar 2023 12:44:14 +0800 Subject: [PATCH] ui: problemconfig: add testlib builtin checkers --- .../components/monaco/schema/problemconfig.ts | 13 +++- .../components/problemconfig/ProblemType.tsx | 70 ++++++++++++++----- .../problemconfig/reducer/config.ts | 2 +- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/packages/ui-default/components/monaco/schema/problemconfig.ts b/packages/ui-default/components/monaco/schema/problemconfig.ts index af20f714a..86c9bcb70 100644 --- a/packages/ui-default/components/monaco/schema/problemconfig.ts +++ b/packages/ui-default/components/monaco/schema/problemconfig.ts @@ -1,5 +1,11 @@ import type { JSONSchema7 } from 'json-schema'; +export const testlibCheckers = [ + 'acmp', 'caseicmp', 'casencmp', 'casewcmp', 'dcmp', 'fcmp', 'hcmp', + 'icmp', 'lcmp', 'ncmp', 'nyesno', 'pointscmp', 'pointsinfo', + 'rcmp', 'rcmp4', 'rcmp6', 'rcmp9', 'rncmp', 'uncmp', 'wcmp', 'yesno', +]; + const problemConfigSchema: JSONSchema7 = { type: 'object', definitions: { @@ -43,7 +49,12 @@ const problemConfigSchema: JSONSchema7 = { langs: { type: 'array', items: { type: 'string' } }, target: { type: 'string' }, checker_type: { enum: ['default', 'lemon', 'syzoj', 'hustoj', 'testlib', 'strict', 'qduoj'] }, - checker: { type: 'string', pattern: '\\.' }, + checker: { + oneOf: [ + { type: 'string', pattern: '\\.' }, + { type: 'string', enum: testlibCheckers }, + ], + }, interactor: { type: 'string', pattern: '\\.' }, validator: { type: 'string', pattern: '\\.' }, user_extra_files: { type: 'array', items: { type: 'string' } }, diff --git a/packages/ui-default/components/problemconfig/ProblemType.tsx b/packages/ui-default/components/problemconfig/ProblemType.tsx index a89ccbf90..2781d605e 100644 --- a/packages/ui-default/components/problemconfig/ProblemType.tsx +++ b/packages/ui-default/components/problemconfig/ProblemType.tsx @@ -4,6 +4,7 @@ import { import React from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { i18n } from 'vj/utils'; +import { testlibCheckers } from '../monaco/schema/problemconfig'; import { FormItem, ManagedSelect, SingleFileSelect } from './BasicForm'; import type { RootState } from './reducer/index'; @@ -12,6 +13,8 @@ export default function ProblemType() { const checkerType = useSelector((state: RootState) => state.config.checker_type); const filename = useSelector((state: RootState) => state.config.filename); const subType = useSelector((state: RootState) => state.config.subType); + const checker = useSelector((state: RootState) => state.config.checker); + const [category, setCategory] = React.useState(checker?.includes('.') ? 'preset' : 'custom'); const dispatch = useDispatch(); const dispatcher = (base) => (value) => dispatch({ ...base, value }); return ( @@ -58,25 +61,56 @@ export default function ProblemType() { )} /> - {['testlib', 'other'].map((i) => ( - - {i === 'other' && ( - - - - )} - - + + + + + {category === 'preset' + ? + - - )} - /> - ))} + : + + } + + )} + /> + + + + + + + + + )} + /> )} /> diff --git a/packages/ui-default/components/problemconfig/reducer/config.ts b/packages/ui-default/components/problemconfig/reducer/config.ts index d8c834fbb..ee7d31e2e 100644 --- a/packages/ui-default/components/problemconfig/reducer/config.ts +++ b/packages/ui-default/components/problemconfig/reducer/config.ts @@ -28,7 +28,7 @@ export default function reducer(state = { for (const subtask of subtasks) { if (typeof subtask.id !== 'number') { for (let i = 1; ; i++) { - if (!subtasks.find((s) => s.id === s)) { + if (!subtasks.find((s) => s.id === i)) { subtask.id = i; break; }