editor: don't create a champ by default

Before the editor attempted to create a default champ as soon as the
list became empty.

This created many race conditions, which made the tests flaky.

Remove this behavior, and add an empty label instead.
This commit is contained in:
Pierre de La Morinerie 2019-11-26 16:57:03 +01:00
parent d0cd875e91
commit 7ed649dfca
3 changed files with 24 additions and 27 deletions

View file

@ -12,13 +12,6 @@ function TypeDeChamps({ state: rootState, typeDeChamps }) {
typeDeChamps typeDeChamps
}); });
if (state.typeDeChamps.length === 0) {
dispatch({
type: 'addFirstTypeDeChamp',
done: () => dispatch({ type: 'refresh' })
});
}
return ( return (
<div className="champs-editor"> <div className="champs-editor">
<SortableContainer <SortableContainer
@ -39,6 +32,13 @@ function TypeDeChamps({ state: rootState, typeDeChamps }) {
/> />
))} ))}
</SortableContainer> </SortableContainer>
{state.typeDeChamps.length === 0 && (
<h2>
<FontAwesomeIcon icon="arrow-circle-down" />
&nbsp;&nbsp;Cliquez sur le bouton «&nbsp;Ajouter un champ&nbsp;» pour
créer votre premier champ.
</h2>
)}
<div className="footer">&nbsp;</div> <div className="footer">&nbsp;</div>
<div className="buttons"> <div className="buttons">
<button <button

View file

@ -5,6 +5,7 @@ import {
faArrowDown, faArrowDown,
faArrowsAltV, faArrowsAltV,
faArrowUp, faArrowUp,
faArrowCircleDown,
faPlus, faPlus,
faTrash faTrash
} from '@fortawesome/free-solid-svg-icons'; } from '@fortawesome/free-solid-svg-icons';
@ -13,7 +14,14 @@ import Flash from './Flash';
import OperationsQueue from './OperationsQueue'; import OperationsQueue from './OperationsQueue';
import TypeDeChamps from './components/TypeDeChamps'; import TypeDeChamps from './components/TypeDeChamps';
library.add(faArrowDown, faArrowsAltV, faArrowUp, faPlus, faTrash); library.add(
faArrowDown,
faArrowsAltV,
faArrowUp,
faArrowCircleDown,
faPlus,
faTrash
);
class TypesDeChampEditor extends Component { class TypesDeChampEditor extends Component {
constructor(props) { constructor(props) {

View file

@ -11,8 +11,6 @@ export default function typeDeChampsReducer(state, { type, params, done }) {
switch (type) { switch (type) {
case 'addNewTypeDeChamp': case 'addNewTypeDeChamp':
return addNewTypeDeChamp(state, state.typeDeChamps, done); return addNewTypeDeChamp(state, state.typeDeChamps, done);
case 'addFirstTypeDeChamp':
return addFirstTypeDeChamp(state, state.typeDeChamps, done);
case 'addNewRepetitionTypeDeChamp': case 'addNewRepetitionTypeDeChamp':
return addNewRepetitionTypeDeChamp( return addNewRepetitionTypeDeChamp(
state, state,
@ -98,19 +96,6 @@ function addNewRepetitionTypeDeChamp(state, typeDeChamps, typeDeChamp, done) {
); );
} }
function addFirstTypeDeChamp(state, typeDeChamps, done) {
const typeDeChamp = { ...state.defaultTypeDeChampAttributes, order_place: 0 };
createTypeDeChampOperation(typeDeChamp, state.queue)
.then(() => done())
.catch(message => state.flash.error(message));
return {
...state,
typeDeChamps: [...typeDeChamps, typeDeChamp]
};
}
function updateTypeDeChamp( function updateTypeDeChamp(
state, state,
typeDeChamps, typeDeChamps,
@ -223,10 +208,14 @@ function getUpdateHandler(typeDeChamp, { queue, flash }) {
function findItemToInsertAfter() { function findItemToInsertAfter() {
const target = getLastVisibleTypeDeChamp(); const target = getLastVisibleTypeDeChamp();
if (target) {
return { return {
target, target,
index: parseInt(target.dataset.index) + 1 index: parseInt(target.dataset.index) + 1
}; };
} else {
return null;
}
} }
function getLastVisibleTypeDeChamp() { function getLastVisibleTypeDeChamp() {