Skip to content

Commit

Permalink
Identify tests by their ids
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Dec 9, 2017
1 parent d71995d commit d175e9f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
16 changes: 5 additions & 11 deletions src/components/forms/EditSimpleLimitsForm/EditSimpleLimitsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import FormBox from '../../widgets/FormBox';
import Button from '../../widgets/FlatButton';
import { RefreshIcon } from '../../icons';

import {
encodeTestName,
encodeEnvironmentId
} from '../../../redux/modules/simpleLimits';
import { encodeEnvironmentId } from '../../../redux/modules/simpleLimits';
import prettyMs from 'pretty-ms';

import styles from './styles.less';
Expand Down Expand Up @@ -129,10 +126,7 @@ const EditSimpleLimitsForm = ({
</th>

{environments.map(environment => {
const id =
encodeTestName(test.name) +
'.' +
encodeEnvironmentId(environment.id);
const id = test.id + '.' + encodeEnvironmentId(environment.id);
return (
<td
key={`td.${id}`}
Expand All @@ -145,17 +139,17 @@ const EditSimpleLimitsForm = ({
environmentsCount={environments.length}
cloneVertically={cloneVertically(
'editSimpleLimits',
test.name,
test.id,
environment.id
)}
cloneHorizontally={cloneHorizontally(
'editSimpleLimits',
test.name,
test.id,
environment.id
)}
cloneAll={cloneAll(
'editSimpleLimits',
test.name,
test.id,
environment.id
)}
/>
Expand Down
22 changes: 15 additions & 7 deletions src/helpers/exerciseSimpleForm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import yaml from 'js-yaml';
import {
endpointDisguisedAsIdFactory,
encodeTestName,
encodeEnvironmentId
} from '../redux/modules/simpleLimits';

Expand Down Expand Up @@ -83,8 +82,12 @@ export const transformAndSendTestsValues = (

export const getSimpleConfigInitValues = (config, tests, locale) => {
const confTests =
config[0] && config[0].tests
? config[0].tests.sort((a, b) => a.name.localeCompare(b.name, locale))
tests && config[0] && config[0].tests
? config[0].tests.sort((a, b) => {
const aName = tests.find(test => test.id === a.name).name;
const bName = tests.find(test => test.id === b.name).name;
return aName.localeCompare(bName, locale);
})
: [];

let res = [];
Expand Down Expand Up @@ -171,6 +174,11 @@ export const getSimpleConfigInitValues = (config, tests, locale) => {
res.push(testObj);
}

// fill new tests with default judge
for (let i = confTests.length; i < tests.length; ++i) {
res.push({ judgeBinary: 'recodex-judge-normal' });
}

return { config: res };
};

Expand All @@ -184,7 +192,7 @@ export const transformAndSendConfigValues = (
let testVars = [];
for (let testIndex = 0; testIndex < sortedTests.length; ++testIndex) {
const test = formData.config[testIndex];
const testName = sortedTests[testIndex].name;
const testName = sortedTests[testIndex].id;
let variables = [];

variables.push({
Expand Down Expand Up @@ -306,7 +314,7 @@ export const getLimitsInitValues = (
let res = {};

tests.forEach(test => {
const testId = encodeTestName(test.name);
const testId = test.id;
res[testId] = {};
environments.forEach(environment => {
const envId = encodeEnvironmentId(environment.id);
Expand All @@ -316,7 +324,7 @@ export const getLimitsInitValues = (
runtimeEnvironmentId: environment.id
}),
'data',
test.name
String(testId)
]);
if (lim) {
lim = lim.toJS();
Expand Down Expand Up @@ -348,7 +356,7 @@ export const transformAndSendLimitsValues = (
const envId = encodeEnvironmentId(environment.id);
const data = {
limits: tests.reduce((acc, test) => {
acc[test.name] = formData.limits[encodeTestName(test.name)][envId];
acc[test.id] = formData.limits[test.id][envId];
return acc;
}, {})
};
Expand Down
16 changes: 8 additions & 8 deletions src/redux/modules/simpleLimits.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ export const editEnvironmentSimpleLimits = (
* Special functions for cloning buttons
*/

// Encoding function which help us avoid problems with some characters in test names and env ids (e.g., character '.').
export const encodeTestName = testName => 'test' + btoa(testName);
// Encoding function which help us avoid problems with some characters in env ids (e.g., character '.').
export const encodeEnvironmentId = envId => 'env' + btoa(envId);

// Get a single value by its test name, environment ID, and field identifier
const getSimpleLimitsOf = (
{ form },
formName,
testName,
testId,
runtimeEnvironmentId,
field
) => {
const testEnc = encodeTestName(testName);
const envEnc = encodeEnvironmentId(runtimeEnvironmentId);
console.log(testId);
console.log(form[formName].values.limits);
return (
form[formName].values.limits[testEnc][envEnc][field] ||
form[formName].initial.limits[testName][envEnc][field] ||
form[formName].values.limits[testId][envEnc][field] ||
form[formName].initial.limits[testId][envEnc][field] ||
null
);
};
Expand All @@ -78,11 +78,11 @@ const getSimpleLimitsOf = (
const getTargetFormKeys = (
{ form }, // form key in the store
formName, // form identifier
testName, // test name or null (if all test should be targetted)
testId, // test id or null (if all test should be targetted)
environmentId, // environment ID or null (if all environments should be targetted)
field // field identifier (memory or wall-time)
) => {
const testEnc = testName ? encodeTestName(testName) : null;
const testEnc = testId || null;
const envEnc = environmentId ? encodeEnvironmentId(environmentId) : null;
return form && form[formName] && form[formName].registeredFields
? Object.keys(form[formName].registeredFields).filter(key => {
Expand Down

0 comments on commit d175e9f

Please sign in to comment.