Refacto du type pour les radio block

pull/2077/head
Jérémy Rialland 2022-03-09 12:03:41 +01:00 committed by Johan Girod
parent 8ed5e7eb3c
commit bf9afdd5db
2 changed files with 3 additions and 18 deletions

View File

@ -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'

View File

@ -65,22 +65,11 @@ export const binaryQuestion = [
{ value: 'non', label: 'Non' },
] as const
interface RuleWithMetadata<T> extends Rule {
metadata: T
}
const isMetadata = <T extends RuleWithMetadata<unknown>>(
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<Names extends string = DottedName>({
dottedName,
onChange,
showSuggestions = true,
@ -116,10 +105,7 @@ export default function RuleInput<
/>
)
}
if (
isMetadata<RuleWithMetadata<Metadata>>(rule.rawNode) &&
rule.rawNode.metadata.component === 'ToggleRadioBlock'
) {
if (rule.rawNode.type === 'radio block') {
return (
<MultipleAnswerInput
{...commonProps}