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