From bf9afdd5dbf43bc1c18d68d3ddc8aa9a27a81172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 9 Mar 2022 12:03:41 +0100 Subject: [PATCH] Refacto du type pour les radio block --- .../règles/exonération-covid.yaml | 3 +-- .../components/conversation/RuleInput.tsx | 18 ++---------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/exoneration-covid/règles/exonération-covid.yaml b/exoneration-covid/règles/exonération-covid.yaml index d0710eff4..6a8f4f46c 100644 --- a/exoneration-covid/règles/exonération-covid.yaml +++ b/exoneration-covid/règles/exonération-covid.yaml @@ -3,8 +3,7 @@ secteur: une possibilité: choix obligatoire: oui possibilités: [S1, S1bis, S2] - metadata: - component: ToggleRadioBlock + type: radio block secteur . S1: valeur: secteur = 'S1' diff --git a/site/source/components/conversation/RuleInput.tsx b/site/source/components/conversation/RuleInput.tsx index 8fd3785f5..baa0f12cc 100644 --- a/site/source/components/conversation/RuleInput.tsx +++ b/site/source/components/conversation/RuleInput.tsx @@ -65,22 +65,11 @@ export const binaryQuestion = [ { value: 'non', label: 'Non' }, ] as const -interface RuleWithMetadata extends Rule { - metadata: T -} - -const isMetadata = >( - rule: Rule -): rule is T => 'metadata' in rule - // This function takes the unknown rule and finds which React component should // be displayed to get a user input through successive if statements // That's not great, but we won't invest more time until we have more diverse // input components and a better type system. -export default function RuleInput< - Names extends string = DottedName, - Metadata extends { component?: string } = { component?: string } ->({ +export default function RuleInput({ dottedName, onChange, showSuggestions = true, @@ -116,10 +105,7 @@ export default function RuleInput< /> ) } - if ( - isMetadata>(rule.rawNode) && - rule.rawNode.metadata.component === 'ToggleRadioBlock' - ) { + if (rule.rawNode.type === 'radio block') { return (