diff --git a/source/components/conversation/Explicable.tsx b/source/components/conversation/Explicable.tsx
index 4f2d41c18..edb1e3503 100644
--- a/source/components/conversation/Explicable.tsx
+++ b/source/components/conversation/Explicable.tsx
@@ -1,10 +1,9 @@
import { explainVariable } from 'Actions/actions'
-import { findRuleByDottedName } from 'Engine/rules'
import React, { useContext } from 'react'
import emoji from 'react-easy-emoji'
import { useDispatch, useSelector } from 'react-redux'
import { RootState } from 'Reducers/rootReducer'
-import { flatRulesSelector } from 'Selectors/analyseSelectors'
+import { parsedRulesSelector } from 'Selectors/analyseSelectors'
import { DottedName } from 'Types/rule'
import { TrackerContext } from '../utils/withTracker'
import './Explicable.css'
@@ -13,12 +12,12 @@ export default function Explicable({ dottedName }: { dottedName: DottedName }) {
const tracker = useContext(TrackerContext)
const dispatch = useDispatch()
const explained = useSelector((state: RootState) => state.explainedVariable)
- const flatRules = useSelector(flatRulesSelector)
+ const rules = useSelector(parsedRulesSelector)
// Rien à expliquer ici, ce n'est pas une règle
if (dottedName == null) return null
- let rule = findRuleByDottedName(flatRules, dottedName)
+ let rule = rules[dottedName]
if (rule.description == null) return null
diff --git a/source/components/conversation/FormDecorator.tsx b/source/components/conversation/FormDecorator.tsx
index 73a0d434f..4137fb5ea 100644
--- a/source/components/conversation/FormDecorator.tsx
+++ b/source/components/conversation/FormDecorator.tsx
@@ -1,11 +1,10 @@
import { updateSituation } from 'Actions/actions'
import Explicable from 'Components/conversation/Explicable'
-import { findRuleByDottedName } from 'Engine/rules'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import {
- flatRulesSelector,
+ parsedRulesSelector,
situationSelector
} from 'Selectors/analyseSelectors'
@@ -21,7 +20,7 @@ export default function FormDecorator(RenderField) {
return function FormStep({ dottedName }) {
const dispatch = useDispatch()
const situation = useSelector(situationSelector)
- const flatRules = useSelector(flatRulesSelector)
+ const rules = useSelector(parsedRulesSelector)
const language = useTranslation().i18n.language
const submit = source =>
@@ -38,8 +37,7 @@ export default function FormDecorator(RenderField) {
return (
- {findRuleByDottedName(flatRules, dottedName).question}{' '}
-
+ {rules[dottedName].question}
diff --git a/source/components/rule/Namespace.tsx b/source/components/rule/Namespace.tsx
index 427f7bbe2..cab50267a 100644
--- a/source/components/rule/Namespace.tsx
+++ b/source/components/rule/Namespace.tsx
@@ -1,5 +1,4 @@
import { SitePathsContext } from 'Components/utils/withSitePaths'
-import { findRuleByDottedName } from 'Engine/rules'
import React, { useContext } from 'react'
import emoji from 'react-easy-emoji'
import { Link } from 'react-router-dom'
@@ -22,7 +21,7 @@ export default function Namespace({ dottedName, flatRules, color }) {
)
.map(fragments => {
let ruleName = fragments.join(' . '),
- rule = findRuleByDottedName(flatRules, ruleName)
+ rule = flatRules[ruleName]
if (!rule) {
throw new Error(
`Attention, il se peut que la règle ${ruleName}, ait été définie avec un namespace qui n'existe pas.`
diff --git a/source/components/rule/Rule.js b/source/components/rule/Rule.js
index 57e36d469..a7cabf5b9 100644
--- a/source/components/rule/Rule.js
+++ b/source/components/rule/Rule.js
@@ -2,8 +2,7 @@ import { ThemeColorsContext } from 'Components/utils/colors'
import { SitePathsContext } from 'Components/utils/withSitePaths'
import Value from 'Components/Value'
import mecanisms from 'Engine/mecanisms.yaml'
-import { findRuleByDottedName, findRuleByNamespace } from 'Engine/rules'
-import { isEmpty } from 'ramda'
+import { filter, isEmpty } from 'ramda'
import React, { Suspense, useContext, useState } from 'react'
import emoji from 'react-easy-emoji'
import { Helmet } from 'react-helmet'
@@ -12,8 +11,8 @@ import { useSelector } from 'react-redux'
import { Link } from 'react-router-dom'
import {
exampleAnalysisSelector,
- flatRulesSelector,
noUserInputSelector,
+ parsedRulesSelector,
ruleAnalysisSelector
} from 'Selectors/analyseSelectors'
import Animate from 'Ui/animate'
@@ -30,7 +29,7 @@ let LazySource = React.lazy(() => import('./RuleSource'))
export default AttachDictionary(mecanisms)(function Rule({ dottedName }) {
const currentExample = useSelector(state => state.currentExample)
- const flatRules = useSelector(flatRulesSelector)
+ const rules = useSelector(parsedRulesSelector)
const valuesToShow = !useSelector(noUserInputSelector)
const analysedRule = useSelector(state =>
ruleAnalysisSelector(state, { dottedName })
@@ -42,9 +41,15 @@ export default AttachDictionary(mecanisms)(function Rule({ dottedName }) {
const [viewSource, setViewSource] = useState(false)
const { t } = useTranslation()
- let flatRule = findRuleByDottedName(flatRules, dottedName)
- let { type, name, acronyme, title, description, question, icon } = flatRule,
- namespaceRules = findRuleByNamespace(flatRules, dottedName)
+ let rule = rules[dottedName]
+ let { type, name, acronyme, title, description, question, icon } = rule,
+ namespaceRules = filter(
+ rule =>
+ rule.dottedName.startsWith(dottedName) &&
+ rule.dottedName.split(' . ').length ===
+ dottedName.split(' . ').length + 1,
+ rules
+ )
let displayedRule = analysedExample || analysedRule
const renderToggleSourceButton = () => {
return (
@@ -99,8 +104,8 @@ export default AttachDictionary(mecanisms)(function Rule({ dottedName }) {
type,
description,
question,
- flatRule,
- flatRules,
+ flatRule: rule,
+ flatRules: rules,
name,
acronyme,
title,
@@ -183,10 +188,10 @@ export default AttachDictionary(mecanisms)(function Rule({ dottedName }) {
)}
- {flatRule.note && (
+ {rule.note && (
)}
)}
- {renderReferences(flatRule)}
+ {renderReferences(rule)}
{renderToggleSourceButton()}
@@ -216,7 +221,7 @@ function NamespaceRulesList({ namespaceRules }) {
Pages associées
- {namespaceRules.map(r => (
+ {Object.values(namespaceRules).map(r => (
-
{dottedName}
-
+
)
}
diff --git a/source/engine/RuleInput.tsx b/source/engine/RuleInput.tsx
index 141bd1cfd..bd9432eb4 100644
--- a/source/engine/RuleInput.tsx
+++ b/source/engine/RuleInput.tsx
@@ -6,12 +6,10 @@ import SendButton from 'Components/conversation/SendButton'
import CurrencyInput from 'Components/CurrencyInput/CurrencyInput'
import PercentageField from 'Components/PercentageField'
import ToggleSwitch from 'Components/ui/ToggleSwitch'
-import { is, prop, unless } from 'ramda'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { DottedName, Rule } from 'Types/rule'
import DateInput from '../components/conversation/DateInput'
-import { findRuleByDottedName, queryRule } from './rules'
export const binaryOptionChoices = [
{ value: 'non', label: 'Non' },
@@ -20,7 +18,7 @@ export const binaryOptionChoices = [
type Value = string | number | object | boolean
type Props = {
- rules: Array