diff --git a/site/source/components/App.tsx b/site/source/components/App.tsx index 2bc8412d4..c023d98f4 100644 --- a/site/source/components/App.tsx +++ b/site/source/components/App.tsx @@ -4,17 +4,10 @@ import { useLazyPromise, usePromise, useWorkerEngine, - WorkerEngine, } from '@publicodes/worker-react' import { ErrorBoundary } from '@sentry/react' import { FallbackRender } from '@sentry/react/types/errorboundary' -import React, { - ComponentProps, - StrictMode, - Suspense, - useEffect, - useState, -} from 'react' +import { ComponentProps, StrictMode, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { Route, Routes } from 'react-router-dom' import { css, styled } from 'styled-components' @@ -59,8 +52,6 @@ const TestWorkerEngine = () => { { defaultValue: 'loading...' } ) - // const date = useAsyncGetRule('date', { defaultValue: 'loading...' }) - // const SMIC = useAsyncGetRule('SMIC', { defaultValue: 'loading...' }) const date = workerEngine.getRule('date') const SMIC = workerEngine.getRule('SMIC') diff --git a/site/source/components/Notifications.tsx b/site/source/components/Notifications.tsx index ccca2db05..e7af279f0 100644 --- a/site/source/components/Notifications.tsx +++ b/site/source/components/Notifications.tsx @@ -1,6 +1,6 @@ import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react' import { DottedName } from 'modele-social' -import Engine, { RuleNode } from 'publicodes' +import { RuleNode } from 'publicodes' import { useTranslation } from 'react-i18next' import { useDispatch, useSelector } from 'react-redux' import { styled } from 'styled-components' @@ -32,17 +32,16 @@ type Notification = { async function getNotifications(workerEngine: WorkerEngine) { return ( await Promise.all( - Object.values(await workerEngine.asyncGetParsedRules()).map( - async (rule) => - rule.rawNode.type === 'notification' && - !!(await workerEngine.asyncEvaluate(rule.dottedName)).nodeValue - ? { - dottedName: rule.dottedName, - sévérité: rule.rawNode.sévérité, - résumé: rule.rawNode.résumé, - description: rule.rawNode.description, - } - : null + Object.values(workerEngine.getParsedRules()).map(async (rule) => + rule.rawNode.type === 'notification' && + !!(await workerEngine.asyncEvaluate(rule.dottedName)).nodeValue + ? { + dottedName: rule.dottedName, + sévérité: rule.rawNode.sévérité, + résumé: rule.rawNode.résumé, + description: rule.rawNode.description, + } + : null ) ) ).filter(isNotNull) diff --git a/site/source/components/References.tsx b/site/source/components/References.tsx index ea2597598..8656aed4a 100644 --- a/site/source/components/References.tsx +++ b/site/source/components/References.tsx @@ -17,19 +17,7 @@ export function References({ references?: Record dottedName?: DottedName | undefined }): JSX.Element | null { - return null const workerEngine = useWorkerEngine() - const parentRefences = usePromise(async () => { - if (!dottedName && !references) { - return null - } - const parentRule = utils.ruleParent(dottedName as string) as DottedName - if (!parentRule) { - return null - } - - return (await workerEngine.asyncGetRule(parentRule)).rawNode.références - }, [dottedName, references, workerEngine]) if (!dottedName && !references) { return null @@ -46,11 +34,11 @@ export function References({ } // If no reference, check if parent has some that we could use - // const parentRule = utils.ruleParent(dottedName as string) as DottedName - // if (!parentRule) { - // return null - // } - // const parentRefences = engine.getRule(parentRule).rawNode.références + const parentRule = utils.ruleParent(dottedName as string) as DottedName + if (!parentRule) { + return null + } + const parentRefences = workerEngine.getRule(parentRule).rawNode.références if (!parentRefences) { return null } @@ -144,12 +132,13 @@ const getDomain = (link: string) => ) export function RuleReferences({ dottedNames }: { dottedNames: DottedName[] }) { + const workerEngine = useWorkerEngine() const references = usePromise( async () => { const values = await Promise.all( dottedNames.map( async (dottedName) => - (await asyncEvaluate(`${dottedName} != non`)).nodeValue + (await workerEngine.asyncEvaluate(`${dottedName} != non`)).nodeValue ) ) @@ -158,7 +147,7 @@ export function RuleReferences({ dottedNames }: { dottedNames: DottedName[] }) { .filter(isNotNullOrUndefined) .map(async (dottedName) => Object.entries( - (await asyncGetRule(dottedName as DottedName)).rawNode + workerEngine.getRule(dottedName as DottedName).rawNode .références ?? {} ) ) diff --git a/site/source/components/Simulation/SimulationGoal.tsx b/site/source/components/Simulation/SimulationGoal.tsx index 0edc0f6bb..38c61f30a 100644 --- a/site/source/components/Simulation/SimulationGoal.tsx +++ b/site/source/components/Simulation/SimulationGoal.tsx @@ -60,7 +60,6 @@ export function SimulationGoal({ }), [workerEngine, dottedName, round, isTypeBoolean, currentUnit] ) - // const rule = useAsyncGetRule(dottedName) const rule = workerEngine.getRule(dottedName) const initialRender = useInitialRender() const [isFocused, setFocused] = useState(false) diff --git a/site/source/components/conversation/Conversation.tsx b/site/source/components/conversation/Conversation.tsx index f4942fdc2..a78cb0067 100644 --- a/site/source/components/conversation/Conversation.tsx +++ b/site/source/components/conversation/Conversation.tsx @@ -1,6 +1,6 @@ import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react' import { DottedName } from 'modele-social' -import Engine, { PublicodesExpression, RuleNode } from 'publicodes' +import { PublicodesExpression, RuleNode } from 'publicodes' import React, { useCallback, useEffect, useState } from 'react' import { Trans, useTranslation } from 'react-i18next' import { useDispatch, useSelector } from 'react-redux' @@ -88,7 +88,6 @@ export default function Conversation({ const formRef = React.useRef(null) const workerEngine = useWorkerEngine() - // const rule = useAsyncGetRule(currentQuestion) const rule = workerEngine.getRule(currentQuestion) const question = usePromise( diff --git a/site/source/components/conversation/RuleInput.tsx b/site/source/components/conversation/RuleInput.tsx index c39a9e72b..120e336e1 100644 --- a/site/source/components/conversation/RuleInput.tsx +++ b/site/source/components/conversation/RuleInput.tsx @@ -12,20 +12,14 @@ import { reduceAST, RuleNode, } from 'publicodes' -import React, { useEffect } from 'react' +import React from 'react' import NumberInput from '@/components/conversation/NumberInput' import SelectCommune from '@/components/conversation/select/SelectCommune' -import { DateFieldProps } from '@/design-system/field/DateField' import { getMeta, isNotNull } from '@/utils' import { Choice, MultipleAnswerInput, OuiNonInput } from './ChoicesInput' -import DateInput from './DateInput' import { MultipleChoicesInput } from './MulipleChoicesInput' -import ParagrapheInput from './ParagrapheInput' -import SelectPaysDétachement from './select/SelectPaysDétachement' -import SelectAtmp from './select/SelectTauxRisque' -import TextInput from './TextInput' type InputType = 'radio' | 'card' | 'toggle' | 'select' diff --git a/site/source/components/simulationExplanation/InstitutionsPartenaires.tsx b/site/source/components/simulationExplanation/InstitutionsPartenaires.tsx index 8d580ebcb..4fecf6eed 100644 --- a/site/source/components/simulationExplanation/InstitutionsPartenaires.tsx +++ b/site/source/components/simulationExplanation/InstitutionsPartenaires.tsx @@ -183,11 +183,12 @@ const caisses = [ function CaisseRetraite({ role }: { role?: string }) { const unit = useSelector(targetUnitSelector) + const workerEngine = useWorkerEngine() const rules = usePromiseOnSituationChange( () => Promise.all( caisses.map((caisse) => - asyncGetRule( + workerEngine.getRule( `dirigeant . indépendant . PL . ${caisse} . cotisations` as DottedName ) ) @@ -255,9 +256,6 @@ function CaisseRetraite({ role }: { role?: string }) { export function InstitutionsPartenairesArtisteAuteur() { const unit = useSelector(targetUnitSelector) const workerEngine = useWorkerEngine() - // const descriptionIRCEC = useAsyncGetRule( - // 'artiste-auteur . cotisations . IRCEC' as DottedName - // )?.rawNode.description const descriptionIRCEC = workerEngine.getRule( 'artiste-auteur . cotisations . IRCEC' as DottedName )?.rawNode.description