Enlève les dernières références à asyncGetRule et asyncGetParsedRules
parent
529158bbb9
commit
731b3f208a
|
@ -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')
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -17,19 +17,7 @@ export function References({
|
|||
references?: Record<string, string>
|
||||
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 ?? {}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<HTMLFormElement>(null)
|
||||
const workerEngine = useWorkerEngine()
|
||||
// const rule = useAsyncGetRule(currentQuestion)
|
||||
const rule = workerEngine.getRule(currentQuestion)
|
||||
|
||||
const question = usePromise(
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue