diff --git a/publicodes/source/components/mecanisms/Somme.js b/publicodes/source/components/mecanisms/Somme.js
deleted file mode 100644
index fc315b52d..000000000
--- a/publicodes/source/components/mecanisms/Somme.js
+++ /dev/null
@@ -1,147 +0,0 @@
-import { path } from 'ramda'
-import { useState } from 'react'
-import Explanation from '../Explanation'
-import { Mecanism, NodeValuePointer } from './common'
-import styled from 'styled-components'
-
-const SommeNode = ({ explanation, nodeValue, unit }) => (
-
-
-
-
-
-)
-export default SommeNode
-
-// We want to put non applicable rules a the bottom of list #1055
-function sortByApplicability(a, b) {
- const isApplicable = (x) => x.nodeValue === false
- if (isApplicable(a) === isApplicable(b)) {
- return 0
- }
- return isApplicable(a) ? 1 : -1
-}
-
-let Table = ({ explanation, unit }) => (
-
-
- {explanation.sort(sortByApplicability).map((v, i) => (
-
- ))}
-
-
-)
-
-/* La colonne peut au clic afficher une nouvelle colonne qui sera une autre somme imbriquée */
-function Row({ v, i, unit }) {
- let [folded, setFolded] = useState(true),
- rowFormula = path(['explanation', 'formule', 'explanation'], v),
- isSomme = rowFormula && rowFormula.name == 'somme'
-
- return [
- setFolded(!folded)}
- >
-
-
- {isSomme && (
-
- {folded ? 'déplier' : 'replier'}
-
- )}
-
- {v.nodeValue != null && (
-
-
-
- )}
- ,
- ...(isSomme && !folded
- ? [
- ,
- ]
- : []),
- ]
-}
-
-const StyledSomme = styled.div`
- /* mécanisme somme */
- table {
- width: 100%;
- border-collapse: collapse;
- }
- tr .element {
- text-align: left;
- padding: 0.2rem 0.4rem;
- }
- tr .value span {
- text-align: right;
- }
- .nested {
- padding: 0;
- }
-`
-const StyledRow = styled.div`
- display: flex;
- align-items: center;
- flex-flow: row nowrap;
- :nth-child(2n) {
- background-color: var(--lightestColor);
- }
-
- &.notApplicable {
- opacity: 0.6;
- }
-
- .element .result,
- .element > .variable > .nodeHead > .nodeValue {
- display: none;
- }
- :first-child {
- border-top: none;
- }
-
- .element {
- flex: 1;
- max-width: 100%;
- display: flex;
- align-items: baseline;
- padding: 0.1em 0.4em;
- padding-top: 0.2em;
- overflow: hidden;
- }
- .element .unfoldIndication {
- text-transform: capitalize;
- flex: 1;
- margin-left: 0.6rem;
- text-align: left;
- }
-
- .element .variable,
- .element .nodeHead {
- overflow: hidden;
- text-overflow: ellipsis;
- max-width: 100%;
- }
-
- .element .situationValue {
- display: none !important;
- }
-
- /* Nested Mecanism */
- + .nested {
- padding-left: 2em;
- border-top: 1px dashed rgba(51, 51, 80, 0.15);
- }
-`
diff --git a/publicodes/source/components/mecanisms/Somme.tsx b/publicodes/source/components/mecanisms/Somme.tsx
new file mode 100644
index 000000000..72b9ea781
--- /dev/null
+++ b/publicodes/source/components/mecanisms/Somme.tsx
@@ -0,0 +1,104 @@
+import styled from 'styled-components'
+import { EvaluatedNode } from '../..'
+import Explanation from '../Explanation'
+import { Mecanism, NodeValuePointer, UnfoldIsEnabledContext } from './common'
+
+const SommeNode = ({ explanation, nodeValue, unit }) => (
+
+
+
+
+
+)
+export default SommeNode
+
+// We want to put non applicable rules a the bottom of list #1055
+function sortByApplicability(a: EvaluatedNode, b: EvaluatedNode): 1 | 0 | -1 {
+ const isApplicable = (x) => x.nodeValue === false
+ if (isApplicable(a) === isApplicable(b)) {
+ return 0
+ }
+ return isApplicable(a) ? 1 : -1
+}
+
+const Table = ({ explanation }) => (
+
+
+ {explanation.sort(sortByApplicability).map((node: EvaluatedNode, i) => (
+
+ ))}
+
+
+)
+
+/* La colonne peut au clic afficher une nouvelle colonne qui sera une autre somme imbriquée */
+function Row({ node }: { node: EvaluatedNode }) {
+ return (
+
+
+
+
+
+
+
+ )
+}
+
+const StyledSomme = styled.div`
+ /* mécanisme somme */
+ table {
+ width: 100%;
+ border-collapse: collapse;
+ }
+ tr .element {
+ text-align: left;
+ padding: 0.2rem 0.4rem;
+ }
+ tr .value span {
+ text-align: right;
+ }
+ .nested {
+ padding: 0;
+ }
+`
+const StyledRow = styled.div`
+ display: flex;
+ align-items: center;
+ flex-flow: row nowrap;
+ :nth-child(2n) {
+ background-color: var(--lightestColor);
+ }
+
+ &.notApplicable {
+ opacity: 0.6;
+ }
+
+ .element .result,
+ :first-child {
+ border-top: none;
+ }
+
+ .element {
+ flex: 1;
+ display: flex;
+ max-width: 100%;
+ align-items: baseline;
+
+ padding: 0.1em 0.4em;
+ padding-top: 0.2em;
+ overflow: hidden;
+ flex-wrap: wrap;
+ }
+
+ .element > * {
+ flex: 1;
+ display: flex;
+ text-overflow: ellipsis;
+ }
+`
diff --git a/publicodes/source/components/mecanisms/common.tsx b/publicodes/source/components/mecanisms/common.tsx
index 8efbd2a1c..d01349e1c 100644
--- a/publicodes/source/components/mecanisms/common.tsx
+++ b/publicodes/source/components/mecanisms/common.tsx
@@ -1,4 +1,4 @@
-import React, { useContext, useState } from 'react'
+import React, { createContext, useContext, useState } from 'react'
import { Trans } from 'react-i18next'
import styled from 'styled-components'
import mecanismsDoc from '../../../docs/mecanisms.yaml'
@@ -266,16 +266,43 @@ export function Leaf(
if (!rule) {
throw new InternalError(node)
}
- const inlineRule =
+
+ const [folded, setFolded] = useState(true)
+ const foldButton = useContext(UnfoldIsEnabledContext) ? (
+ setFolded(!folded)}
+ css={`
+ text-transform: none !important;
+ flex: 1 !important;
+ margin-left: 0.4rem !important;
+ text-align: left !important;
+ `}
+ className="ui__ notice small static simple button"
+ >
+ {folded ? 'déplier' : 'replier'}
+
+ ) : null
+
+ if (
node.dottedName === node.contextDottedName + ' . ' + node.name &&
!node.name.includes(' . ') &&
rule.virtualRule
- if (inlineRule) {
- return
+ ) {
+ return
}
return (
-
-
+
+
{rule.rawNode.acronyme ? (
@@ -285,11 +312,25 @@ export function Leaf(
)}
+ {foldButton}
- {nodeValue != null && unit && (
+ {nodeValue !== null && unit && (
)}
-
-
+ {' '}
+ {!folded && (
+
+
+
+
+
+ )}
+
)
}
+
+export const UnfoldIsEnabledContext = createContext(false)