Expose all optional layers in TypeDeChamp editor
This commit is contained in:
parent
cad8ee31d8
commit
eaa9b1c071
5 changed files with 99 additions and 28 deletions
|
@ -137,14 +137,13 @@ const TypeDeChamp = sortableElement(
|
|||
url={typeDeChamp.piece_justificative_template_url}
|
||||
/>
|
||||
<TypeDeChampCarteOptions isVisible={isCarte}>
|
||||
<TypeDeChampCarteOption
|
||||
label="Cadastres"
|
||||
handler={updateHandlers.cadastres}
|
||||
/>
|
||||
<TypeDeChampCarteOption
|
||||
label="Zones naturelles protégées"
|
||||
handler={updateHandlers.mnhn}
|
||||
/>
|
||||
{Object.entries(OPTIONS_FIELDS).map(([field, label]) => (
|
||||
<TypeDeChampCarteOption
|
||||
key={field}
|
||||
label={label}
|
||||
handler={updateHandlers[field]}
|
||||
/>
|
||||
))}
|
||||
</TypeDeChampCarteOptions>
|
||||
<TypeDeChampRepetitionOptions
|
||||
isVisible={isRepetition}
|
||||
|
@ -182,7 +181,7 @@ function createUpdateHandler(dispatch, typeDeChamp, field, index, prefix) {
|
|||
return {
|
||||
id: `${prefix ? `${prefix}-` : ''}champ-${index}-${field}`,
|
||||
name: field,
|
||||
value: typeDeChamp[field],
|
||||
value: getValue(typeDeChamp, field),
|
||||
onChange: ({ target }) =>
|
||||
dispatch({
|
||||
type: 'updateTypeDeChamp',
|
||||
|
@ -196,6 +195,14 @@ function createUpdateHandler(dispatch, typeDeChamp, field, index, prefix) {
|
|||
};
|
||||
}
|
||||
|
||||
function getValue(obj, path) {
|
||||
const [, optionsPath] = path.split('.');
|
||||
if (optionsPath) {
|
||||
return (obj.editable_options || {})[optionsPath];
|
||||
}
|
||||
return obj[path];
|
||||
}
|
||||
|
||||
function createUpdateHandlers(dispatch, typeDeChamp, index, prefix) {
|
||||
return FIELDS.reduce((handlers, field) => {
|
||||
handlers[field] = createUpdateHandler(
|
||||
|
@ -209,19 +216,30 @@ function createUpdateHandlers(dispatch, typeDeChamp, index, prefix) {
|
|||
}, {});
|
||||
}
|
||||
|
||||
const OPTIONS_FIELDS = {
|
||||
'options.cadastres': 'Cadastres',
|
||||
'options.unesco': 'UNESCO',
|
||||
'options.arretes_protection': 'Arrêtés de protection',
|
||||
'options.conservatoire_littoral': 'Conservatoire du Littoral',
|
||||
'options.reserves_chasse_faune_sauvage':
|
||||
'Réserves nationales de chasse et de faune sauvage',
|
||||
'options.reserves_biologiques': 'Réserves biologiques',
|
||||
'options.reserves_naturelles': 'Réserves naturelles',
|
||||
'options.natura_2000': 'Natura 2000',
|
||||
'options.zones_humides': 'Zones humides d’importance internationale',
|
||||
'options.znieff': 'ZNIEFF'
|
||||
};
|
||||
|
||||
export const FIELDS = [
|
||||
'cadastres',
|
||||
'mnhn',
|
||||
'description',
|
||||
'drop_down_list_value',
|
||||
'libelle',
|
||||
'mandatory',
|
||||
'parcelles_agricoles',
|
||||
'parent_id',
|
||||
'piece_justificative_template',
|
||||
'private',
|
||||
'quartiers_prioritaires',
|
||||
'type_champ'
|
||||
'type_champ',
|
||||
...Object.keys(OPTIONS_FIELDS)
|
||||
];
|
||||
|
||||
function readValue(input) {
|
||||
|
|
|
@ -113,7 +113,13 @@ function updateTypeDeChamp(
|
|||
}
|
||||
}
|
||||
|
||||
typeDeChamp[field] = value;
|
||||
if (field.startsWith('options.')) {
|
||||
const [, optionsField] = field.split('.');
|
||||
typeDeChamp.editable_options = typeDeChamp.editable_options || {};
|
||||
typeDeChamp.editable_options[optionsField] = value;
|
||||
} else {
|
||||
typeDeChamp[field] = value;
|
||||
}
|
||||
|
||||
getUpdateHandler(typeDeChamp, state)(done);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue