ui: problemconfig: force set subtaskId

This commit is contained in:
undefined committed 2023-03-16 11:16:53 +08:00
1 parent eeeae604eb
commit cf69ef8c1c
3 files changed
+60 -19

No files matched your search

@@ -19,7 +19,28 @@ export default function reducer(state = {
} as State, action: any = {}): State { } as State, action: any = {}): State {
switch (action.type) { switch (action.type) {
case 'CONFIG_LOAD_FULFILLED': { case 'CONFIG_LOAD_FULFILLED': {
return { ...state, ...yaml.load(action.payload.config) as object, __loaded: true }; try {
const data = yaml.load(action.payload.config) as any;
if (!validate(data)) {
return { ...state, __valid: false, __errors: validate.errors.map((i) => `${i.instancePath}: ${i.message}`) };
}
const subtasks = (data as any).subtasks;
for (const subtask of subtasks) {
if (typeof subtask.id !== 'number') {
for (let i = 1; ; i++) {
if (!subtasks.find((s) => s.id === s)) {
subtask.id = i;
break;
}
}
}
}
return {
...state, ...data as any, __valid: true, __errors: [], __loaded: true,
};
} catch (e) {
return { ...state, __valid: false, __errors: [e.message] };
}
} }
case 'CONFIG_FORM_UPDATE': { case 'CONFIG_FORM_UPDATE': {
const next = { ...state, [action.key]: action.value }; const next = { ...state, [action.key]: action.value };
@@ -32,13 +53,20 @@ export default function reducer(state = {
try { try {
const data = yaml.load(action.payload); const data = yaml.load(action.payload);
if (!validate(data)) { if (!validate(data)) {
return { ...state, __valid: false, __errors: validate.errors.map((i) => `${i.instancePath}: ${i.message}`) }; return {
...state,
__valid: false,
__errors: validate.errors.map((i) => `${i.instancePath}: ${i.message}`),
__loaded: true,
};
} }
return { return {
...state, ...data as object, __valid: true, __errors: [], ...state, ...data as object, __valid: true, __errors: [], __loaded: true,
}; };
} catch (e) { } catch (e) {
return { ...state, __valid: false, __errors: [e.message] }; return {
...state, __valid: false, __errors: [e.message], __loaded: true,
};
} }
} }
case 'CONFIG_AUTOCASES_UPDATE': { case 'CONFIG_AUTOCASES_UPDATE': {
@@ -49,6 +77,14 @@ export default function reducer(state = {
if (subtask.memory === parseMemoryMB(state.memory || '256m')) delete subtask.memory; if (subtask.memory === parseMemoryMB(state.memory || '256m')) delete subtask.memory;
if (subtask.time) subtask.time += 'ms'; if (subtask.time) subtask.time += 'ms';
if (subtask.memory) subtask.memory += 'MB'; if (subtask.memory) subtask.memory += 'MB';
if (typeof subtask.id !== 'number') {
for (let i = 1; ; i++) {
if (!subtasks.find((s) => s.id === s)) {
subtask.id = i;
break;
}
}
}
} }
if (subtasks.length === 0) next.subtasks = []; if (subtasks.length === 0) next.subtasks = [];
else { else {
@@ -1,8 +1,9 @@
import { import {
Button, ControlGroup, Button, ControlGroup,
Dialog, DialogBody, DialogFooter, Dialog, DialogBody, DialogFooter,
Icon, InputGroup, Icon, InputGroup, Tag,
} from '@blueprintjs/core'; } from '@blueprintjs/core';
import { parseMemoryMB, parseTimeMS } from '@hydrooj/utils/lib/common';
import React from 'react'; import React from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { i18n } from 'vj/utils'; import { i18n } from 'vj/utils';
@@ -47,15 +48,17 @@ export function SubtaskSettings(props: SubtaskSettingsProps) {
<ControlGroup fill={true} vertical={false}> <ControlGroup fill={true} vertical={false}>
<InputGroup <InputGroup
leftElement={<Icon icon="time" />} leftElement={<Icon icon="time" />}
onChange={dispatcher(setTime, 'time')} rightElement={<Tag minimal>ms</Tag>}
placeholder={`Inherit (${props.time || '1s'})`} onChange={(ev) => setTime(`${ev.currentTarget.value}ms`)}
value={ctime || ''} placeholder={`Inherit (${parseTimeMS(props.time, false) || '1000'})`}
value={ctime ? parseTimeMS(ctime, false).toString() || '' : ''}
/> />
<InputGroup <InputGroup
leftElement={<Icon icon="comparison" />} leftElement={<Icon icon="comparison" />}
onChange={dispatcher(setMemory, 'memory')} rightElement={<Tag minimal>MB</Tag>}
placeholder={`Inherit (${props.memory || '256m'})`} onChange={(ev) => setMemory(`${ev.currentTarget.value}MB`)}
value={cmemory || ''} placeholder={`Inherit (${parseMemoryMB(props.memory, false) || '256'})`}
value={cmemory ? parseMemoryMB(cmemory, false).toString() || '' : ''}
/> />
<InputGroup <InputGroup
leftElement={<Icon icon="star" />} leftElement={<Icon icon="star" />}
@@ -112,15 +115,17 @@ export function GlobalSettings() {
<ControlGroup fill={true} vertical={false}> <ControlGroup fill={true} vertical={false}>
<InputGroup <InputGroup
leftElement={<Icon icon="time" />} leftElement={<Icon icon="time" />}
onChange={(ev) => setTime(ev.currentTarget.value)} rightElement={<Tag minimal>ms</Tag>}
placeholder="1s" onChange={(ev) => setTime(`${ev.currentTarget.value}ms`)}
value={ctime || ''} placeholder="1000"
value={ctime ? parseTimeMS(ctime, false).toString() || '' : ''}
/> />
<InputGroup <InputGroup
leftElement={<Icon icon="comparison" />} leftElement={<Icon icon="comparison" />}
onChange={(ev) => setMemory(ev.currentTarget.value)} rightElement={<Tag minimal>MB</Tag>}
placeholder="256m" onChange={(ev) => setMemory(`${ev.currentTarget.value}MB`)}
value={cmemory || ''} placeholder="256"
value={cmemory ? parseMemoryMB(cmemory, false).toString() || '' : ''}
/> />
</ControlGroup> </ControlGroup>
</DialogBody> </DialogBody>
@@ -133,7 +138,7 @@ export function GlobalSettings() {
<span className={`bp4-tree-node-label${time ? '' : ' text-gray'}`}>{time || '1s'}</span> <span className={`bp4-tree-node-label${time ? '' : ' text-gray'}`}>{time || '1s'}</span>
<Icon icon="comparison" /> <Icon icon="comparison" />
{' '} {' '}
<span className={`bp4-tree-node-secondary-label${memory ? '' : ' text-gray'}`}>{memory || '256m'}</span> <span className={`bp4-tree-node-secondary-label${memory ? '' : ' text-gray'}`}>{memory || '256MB'}</span>
</div> </div>
</li> </li>
</>); </>);
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.48.1", "version": "4.48.2",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "index.ts", "main": "index.ts",