Skip to content
Snippets Groups Projects
Commit 22e4d05e authored by borzechof99's avatar borzechof99 :whale2:
Browse files

Bug Fix: Incomplete Sport Criterion name stays, Reference Fields

parent b63f048f
No related branches found
No related tags found
No related merge requests found
...@@ -2,25 +2,21 @@ ...@@ -2,25 +2,21 @@
export const criterionEditValidator = val => { export const criterionEditValidator = val => {
if (val % 1 != 0) { if (val % 1 != 0 || !Number.isInteger(val)) {
return "Muss ganzzahlig sein!"; return "Muss ganzzahlig sein!";
// return "Must be an Integer!"; };
}
if (val > 9) { if (val > 9) {
return "Darf nicht größer als 9 sein." return "Darf nicht größer als 9 sein.";
// return "Must not be larger than 9" };
}
if (val < -1) { if (val < -1) {
return "Nur -1 ist als negativer Wert erlaubt!" return "Nur -1 ist als negativer Wert erlaubt!";
// return "Only allowed negative value is -1" };
}
if (val === 0) { if (val === 0) {
return "Muss entweder -1 oder zwischen 1 und 9 liegen!" return "Muss entweder -1 oder zwischen 1 und 9 liegen!";
// return "Must be either -1 or between 1 and 9" };
}
return undefined; return undefined;
}; };
......
...@@ -10,7 +10,9 @@ import { ...@@ -10,7 +10,9 @@ import {
SimpleForm, SimpleForm,
SaveButton, SaveButton,
Toolbar, Toolbar,
FormDataConsumer FormDataConsumer,
ReferenceField,
ChipField
} from 'react-admin'; } from 'react-admin';
import { criterionEditValidator } from './criterionEditValidator.js'; import { criterionEditValidator } from './criterionEditValidator.js';
...@@ -27,7 +29,15 @@ export const incompleteList = props => ( ...@@ -27,7 +29,15 @@ export const incompleteList = props => (
<List {...props}> <List {...props}>
{/* rowClick expand means that no edit page is opened, but instead shown below the data row itself without reloading */} {/* rowClick expand means that no edit page is opened, but instead shown below the data row itself without reloading */}
<Datagrid rowClick="expand" expand={incompleteEdit} > <Datagrid rowClick="expand" expand={incompleteEdit} >
<TextField source="id" />
{/* Reference Field fetches every Sport object if a reference field to it exists.
This means that n GETs are made for one load of the incomplete-list.
Could probably be improved in the future.
*/}
<ReferenceField label="ID" source="id" reference="sport" >
<ChipField source="id" />
</ReferenceField>
<TextField source="name" /> <TextField source="name" />
</Datagrid> </Datagrid>
</List> </List>
...@@ -57,8 +67,8 @@ export const incompleteEdit = props => ( ...@@ -57,8 +67,8 @@ export const incompleteEdit = props => (
</FormDataConsumer> </FormDataConsumer>
{/* Bug Here: TextField changes to either None or name of the sport when an invalid string or a number are entered respectively */}
<NumberInput <NumberInput
source="value"
label="Wertung" label="Wertung"
validate={[criterionEditValidator]} validate={[criterionEditValidator]}
/> />
......
...@@ -96,6 +96,18 @@ export default ( ...@@ -96,6 +96,18 @@ export default (
data = cached_incomplete.find((data) => data.id == params.id); data = cached_incomplete.find((data) => data.id == params.id);
} }
let formatted_criteria = [];
data.criteria.forEach(criterion => {
formatted_criteria.push(
{
"id": criterion.id,
"name": criterion.name,
"value": -1
}
);
});
data.criteria = formatted_criteria;
return { return {
data data
}; };
...@@ -128,20 +140,14 @@ export default ( ...@@ -128,20 +140,14 @@ export default (
const verbose_criteria_list = []; const verbose_criteria_list = [];
// Filter the criteria that were filled out // Filter the criteria that were filled out
for (let i = 0; i < params.data.criteria.length; i++) { params.data.criteria.forEach(criterion => {
const element = params.data.criteria[i]; if (criterion.value !== -1) {
verbose_criteria_list.push({
if (Number.isInteger(element)) { "id": criterion.id,
"value": criterion.value
verbose_criteria_list.push( });
{ };
"id": params.previousData.criteria[i].id, });
"value": element
}
);
}
}
// Send criteria that were filled out // Send criteria that were filled out
const data = { const data = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment