Update imports

engine-in-web-worker
Jérémy Rialland 2023-09-05 15:24:43 +02:00
parent 7b2c44575f
commit d33d7db5ed
27 changed files with 92 additions and 84 deletions

View File

@ -1,3 +1,4 @@
import { useAsyncGetRule, useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { PublicodesExpression, serializeEvaluation } from 'publicodes'
import { useCallback } from 'react'
@ -11,10 +12,6 @@ import { batchUpdateSituation } from '@/store/actions/actions'
import { situationSelector } from '@/store/selectors/simulationSelectors'
import { ReplaceReturnType } from '@/types/utils'
import { catchDivideByZeroError } from '@/utils'
import {
useAsyncGetRule,
useWorkerEngine,
} from '@/worker/workerEngineClientReact'
import { ExplicableRule } from './conversation/Explicable'
import { Condition, WhenApplicable } from './EngineValue'

View File

@ -1,3 +1,4 @@
import { useAsyncParsedRules, useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import {
ASTNode,
@ -11,10 +12,6 @@ import { useTranslation } from 'react-i18next'
import { keyframes, styled } from 'styled-components'
import { usePromise } from '@/hooks/usePromise'
import {
useAsyncParsedRules,
useWorkerEngine,
} from '@/worker/workerEngineClientReact'
import RuleLink from './RuleLink'

View File

@ -1,3 +1,4 @@
import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import Engine, { RuleNode } from 'publicodes'
import { useTranslation } from 'react-i18next'
@ -12,7 +13,6 @@ import { usePromise } from '@/hooks/usePromise'
import { hideNotification } from '@/store/actions/actions'
import { RootState } from '@/store/reducers/rootReducer'
import { isNotNull } from '@/utils'
import { useWorkerEngine, WorkerEngine } from '@/worker/workerEngineClientReact'
import { ExplicableRule } from './conversation/Explicable'
import { Appear } from './ui/animate'

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { utils } from 'publicodes'
import { useContext } from 'react'
@ -17,7 +18,19 @@ export function References({
references?: Record<string, string>
dottedName?: DottedName | undefined
}): JSX.Element | null {
const engine = useEngine()
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
@ -34,11 +47,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 = engine.getRule(parentRule).rawNode.références
if (!parentRefences) {
return null
}

View File

@ -1,24 +1,21 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { RuleLink as EngineRuleLink } from 'publicodes-react'
import React, { ReactNode } from 'react'
import React from 'react'
import { Link } from '@/design-system/typography/link'
import { usePromise } from '@/hooks/usePromise'
import { useSitePaths } from '@/sitePaths'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
// TODO : quicklink -> en cas de variations ou de somme avec un seul élément actif, faire un lien vers cet élément
export default function RuleLink(
props: {
dottedName: DottedName
displayIcon?: boolean
children?: React.ReactNode
documentationPath?: string
linkComponent?: ReactNode
engineId?: number
} & Omit<React.ComponentProps<typeof Link>, 'to' | 'children'>
) {
const engineId = props.engineId ?? 0
const { dottedName, documentationPath, ...linkProps } = props
const { absoluteSitePaths } = useSitePaths()
const [loading, setLoading] = React.useState(true)
const [error, setError] = React.useState(false)
@ -29,26 +26,23 @@ export default function RuleLink(
setError(false)
return workerEngine
.asyncGetRule(props.dottedName)
.asyncGetRule(dottedName)
.catch(() => setError(true))
.then(() => setLoading(false))
}, [props.dottedName, workerEngine])
}, [dottedName, workerEngine])
if (loading || error) {
return null
}
return <>EngineRuleLink</>
// TODO : publicodes-react ne supporte pas encore les engines dans un worker
return (
<EngineRuleLink
{...props}
{...linkProps}
// @ts-ignore
linkComponent={props?.linkComponent || Link}
engine={engineUsed}
linkComponent={Link}
engine={workerEngine}
documentationPath={
props.documentationPath ?? absoluteSitePaths.documentation.index
documentationPath ?? absoluteSitePaths.documentation.index
}
/>
)

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { Evaluation } from 'publicodes'
import { Trans } from 'react-i18next'
import { useDispatch } from 'react-redux'
@ -7,7 +8,6 @@ import Banner from '@/components/Banner'
import { Link as DesignSystemLink } from '@/design-system/typography/link'
import { usePromise } from '@/hooks/usePromise'
import { updateSituation } from '@/store/actions/actions'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
const Bold = styled.span<{ $bold: boolean }>`
${({ $bold }) => ($bold ? 'font-weight: bold;' : '')}

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { Evaluation } from 'publicodes'
import { Trans } from 'react-i18next'
import { styled } from 'styled-components'
@ -8,7 +9,6 @@ import { Li, Ul } from '@/design-system/typography/list'
import { Body } from '@/design-system/typography/paragraphs'
import { usePromise } from '@/hooks/usePromise'
import { AbsoluteSitePaths } from '@/sitePaths'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
type SimulateurWarningProps = {
simulateur: Exclude<keyof AbsoluteSitePaths['simulateurs'], 'index'>

View File

@ -1,3 +1,4 @@
import { useAsyncGetRule, useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { formatValue, PublicodesExpression } from 'publicodes'
import React, { useCallback, useState } from 'react'
@ -11,10 +12,6 @@ import { Body, SmallBody } from '@/design-system/typography/paragraphs'
import { usePromise } from '@/hooks/usePromise'
import { updateSituation } from '@/store/actions/actions'
import { targetUnitSelector } from '@/store/selectors/simulationSelectors'
import {
useAsyncGetRule,
useWorkerEngine,
} from '@/worker/workerEngineClientReact'
import { ExplicableRule } from '../conversation/Explicable'
import RuleInput, { InputProps } from '../conversation/RuleInput'

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { EvaluatedNode } from 'publicodes'
import React, { useContext } from 'react'
@ -10,7 +11,6 @@ import RuleLink from '@/components/RuleLink'
import useDisplayOnIntersecting from '@/components/utils/useDisplayOnIntersecting'
import { usePromise } from '@/hooks/usePromise'
import { targetUnitSelector } from '@/store/selectors/simulationSelectors'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
import { DisableAnimationContext } from './utils/DisableAnimationContext'

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { PublicodesExpression, RuleNode, utils } from 'publicodes'
import { useCallback, useMemo } from 'react'
@ -25,7 +26,6 @@ import {
companySituationSelector,
situationSelector,
} from '@/store/selectors/simulationSelectors'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
import Value from '../EngineValue'
import { JeDonneMonAvis } from '../JeDonneMonAvis'

View File

@ -1,3 +1,8 @@
import {
useAsyncGetRule,
useWorkerEngine,
WorkerEngine,
} from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import Engine, { PublicodesExpression, RuleNode } from 'publicodes'
import React, { useCallback, useEffect, useState } from 'react'
@ -19,11 +24,6 @@ import {
answeredQuestionsSelector,
situationSelector,
} from '@/store/selectors/simulationSelectors'
import {
useAsyncGetRule,
useWorkerEngine,
WorkerEngine,
} from '@/worker/workerEngineClientReact'
import { TrackPage } from '../ATInternetTracking'
import { JeDonneMonAvis } from '../JeDonneMonAvis'

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { useContext, useEffect } from 'react'
@ -7,7 +8,6 @@ import HelpButtonWithPopover from '@/design-system/buttons/HelpButtonWithPopover
import { Spacing } from '@/design-system/layout'
import { H3 } from '@/design-system/typography/heading'
import { usePromise } from '@/hooks/usePromise'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
import { References } from '../References'
import RuleLink from '../RuleLink'

View File

@ -1,3 +1,4 @@
import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { PublicodesExpression, RuleNode } from 'publicodes'
import { Fragment } from 'react'
@ -6,7 +7,6 @@ import { useTranslation } from 'react-i18next'
import { Checkbox } from '@/design-system'
import { Emoji } from '@/design-system/emoji'
import { usePromise } from '@/hooks/usePromise'
import { useWorkerEngine, WorkerEngine } from '@/worker/workerEngineClientReact'
import { ExplicableRule } from './Explicable'
import { InputProps, RuleWithMultiplePossibilities } from './RuleInput'

View File

@ -1,3 +1,8 @@
import {
useAsyncGetRule,
useWorkerEngine,
WorkerEngine,
} from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import {
ASTNode,
@ -14,11 +19,6 @@ import SelectCommune from '@/components/conversation/select/SelectCommune'
import { DateFieldProps } from '@/design-system/field/DateField'
import { usePromise } from '@/hooks/usePromise'
import { getMeta, isNotNull } from '@/utils'
import {
useAsyncGetRule,
useWorkerEngine,
WorkerEngine,
} from '@/worker/workerEngineClientReact'
import { Choice, MultipleAnswerInput, OuiNonInput } from './ChoicesInput'
import DateInput from './DateInput'
@ -100,10 +100,6 @@ export default function RuleInput({
const rule = useAsyncGetRule(dottedName)
useEffect(() => {
console.log('update', workerEngine.situationVersion)
}, [workerEngine.situationVersion])
// const evaluation = engineValue.evaluate({ valeur: dottedName, ...modifiers })
// async
const evaluation = usePromise(
@ -187,11 +183,13 @@ export default function RuleInput({
}
if (rule.rawNode.API && rule.rawNode.API === 'commune') {
return `<SelectCommune
return (
<SelectCommune
{...commonProps}
onChange={(c) => commonProps.onChange({ batchUpdate: c })}
value={value as Evaluation<string>}
/>`
/>
)
}
if (rule.rawNode.API && rule.rawNode.API.startsWith('pays détachement')) {

View File

@ -2,7 +2,7 @@ import React from 'react'
import { Appear } from '@/components/ui/animate'
// We add a animation for all coponents displayed on the client only but not on
// We add a animation for all components displayed on the client only but not on
// the SSR to avoid augment the CLS (Cumulative Layout Shift).
export default function BrowserOnly({
children,

View File

@ -1,3 +1,4 @@
import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import Engine, {
EvaluatedNode,
@ -6,7 +7,7 @@ import Engine, {
Rule,
RuleNode,
} from 'publicodes'
import { createContext, useContext, useEffect, useMemo } from 'react'
import React, { createContext, useContext, useEffect, useMemo } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { deleteFromSituation } from '@/store/actions/actions'
@ -16,7 +17,6 @@ import {
situationSelector,
} from '@/store/selectors/simulationSelectors'
import { omit } from '@/utils'
import { useWorkerEngine, WorkerEngine } from '@/worker/workerEngineClientReact'
import i18n from '../../locales/i18n'
@ -158,13 +158,13 @@ export const useSetupSafeSituation = (workerEngine?: WorkerEngine) => {
// const workerEngine = useWorkerEngine()
const rawSituation = useRawSituation()
const simulatorSituation = useSelector(situationSelector)
const configSituation = useSelector(configSituationSelector)
const companySituation = useSelector(companySituationSelector)
// const simulatorSituation = useSelector(situationSelector)
// const configSituation = useSelector(configSituationSelector)
// const companySituation = useSelector(companySituationSelector)
const { asyncSetSituation } = workerEngine ?? {}
useEffect(() => {
if (!asyncSetSituation) {
if (!asyncSetSituation || Object.keys(rawSituation).length === 0) {
return
}
console.log('set rawSituation', rawSituation, workerEngine)

View File

@ -1,3 +1,8 @@
import {
useAsyncParsedRules,
useWorkerEngine,
WorkerEngine,
} from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { ParsedRules, serializeEvaluation } from 'publicodes'
import { useEffect, useMemo, useState } from 'react'
@ -13,11 +18,6 @@ import {
configObjectifsSelector,
situationSelector,
} from '@/store/selectors/simulationSelectors'
import {
useAsyncParsedRules,
useWorkerEngine,
WorkerEngine,
} from '@/worker/workerEngineClientReact'
type ShortName = string
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents

View File

@ -1,3 +1,4 @@
import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import Engine, { RuleNode } from 'publicodes'
import { useMemo } from 'react'
@ -10,7 +11,6 @@ import {
useMissingVariables,
} from '@/store/selectors/simulationSelectors'
import { ImmutableType } from '@/types/utils'
import { useWorkerEngine, WorkerEngine } from '@/worker/workerEngineClientReact'
import { usePromise } from './usePromise'

View File

@ -1,6 +1,7 @@
import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react'
import rules, { DottedName } from 'modele-social'
import Engine from 'publicodes'
import { getDocumentationSiteMap, RulePage } from 'publicodes-react'
import { RulePage, useDocumentationSiteMap } from 'publicodes-react'
import { ComponentProps, useMemo, useRef } from 'react'
import { Helmet } from 'react-helmet-async'
import { Trans, useTranslation } from 'react-i18next'
@ -38,20 +39,27 @@ export default function Documentation({
engine,
}: {
documentationPath: string
engine: Engine
engine: WorkerEngine
}) {
const { t } = useTranslation()
const location = useLocation()
const pathname = decodeURI(location?.pathname ?? '')
const documentationSitePaths = useMemo(
() => getDocumentationSiteMap({ engine, documentationPath }),
[engine, documentationPath]
const workerEngine = useWorkerEngine()
const documentationSitePaths = useDocumentationSiteMap(
workerEngine,
documentationPath
)
if (!documentationSitePaths) {
return <>documentationSitePaths loading...</>
}
return (
<Routes>
<Route index element={<DocumentationLanding />} />
<Route path="dev" element={<DocumentationRulesList />} />
{IS_DEVELOPMENT && (
<Route path="dev" element={<DocumentationRulesList />} />
)}
<Route
path="*"
element={
@ -97,6 +105,10 @@ const StyledAccordion = styled(Accordion)`
font-weight: bold;
}
}
button {
border-radius: ${({ theme }) => theme.box.borderRadius};
}
`
type Renderers = ComponentProps<typeof RulePage>['renderers']
@ -117,7 +129,7 @@ function DocumentationPageBody({
engine,
}: {
documentationPath: string
engine: Engine
engine: WorkerEngine
}) {
const { absoluteSitePaths } = useSitePaths()
const { i18n } = useTranslation()

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { useCallback, useEffect } from 'react'
import { Trans, useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
@ -22,7 +23,6 @@ import { useSetEntreprise } from '@/hooks/useSetEntreprise'
import { useSitePaths } from '@/sitePaths'
import { getCookieValue } from '@/storage/readCookie'
import { resetCompany } from '@/store/actions/companyActions'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
// import { RootState } from '@/store/reducers/rootReducer'

View File

@ -1,8 +1,8 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { useTranslation } from 'react-i18next'
import { Article } from '@/design-system/card'
import { usePromise } from '@/hooks/usePromise'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
export function AnnuaireEntreprises() {
const { t } = useTranslation()

View File

@ -1,3 +1,4 @@
import { useWorkerEngine } from '@publicodes/worker-react'
import { Trans, useTranslation } from 'react-i18next'
import { Condition, WhenAlreadyDefined } from '@/components/EngineValue'
@ -11,7 +12,6 @@ import { usePromise } from '@/hooks/usePromise'
import { GuideURSSAFCard } from '@/pages/simulateurs/cards/GuideURSSAFCard'
import { IframeIntegrationCard } from '@/pages/simulateurs/cards/IframeIntegrationCard'
import { useSitePaths } from '@/sitePaths'
import { useWorkerEngine } from '@/worker/workerEngineClientReact'
import { AnnuaireEntreprises } from '../assistants/pour-mon-entreprise/AnnuaireEntreprises'
import { AutoEntrepreneurCard } from '../assistants/pour-mon-entreprise/AutoEntrepeneurCard'

View File

@ -1,7 +1,7 @@
import { DottedName } from 'modele-social'
import Engine from 'publicodes'
import { useTranslation } from 'react-i18next'
import { DottedName } from '@/../../modele-social'
import { EngineDocumentationRoutes } from '@/components/EngineDocumentationRoutes'
import PeriodSwitch from '@/components/PeriodSwitch'
import Simulation, {

View File

@ -1,8 +1,8 @@
import { DottedName } from 'modele-social'
import Engine, { PublicodesExpression } from 'publicodes'
import { ReactNode } from 'react'
import { styled } from 'styled-components'
import { DottedName } from '@/../../modele-social'
import Value, { Condition, WhenNotApplicable } from '@/components/EngineValue'
import RuleLink from '@/components/RuleLink'
import { HelpIcon } from '@/design-system/icons'

View File

@ -1,7 +1,7 @@
import { DottedName } from 'modele-social'
import Engine from 'publicodes'
import { ComponentProps } from 'react'
import { DottedName } from '@/../../modele-social'
import Value from '@/components/EngineValue'
import { H3 } from '@/design-system/typography/heading'

View File

@ -1,6 +1,6 @@
import { DottedName } from 'modele-social'
import Engine, { Evaluation } from 'publicodes'
import { DottedName } from '@/../../modele-social'
import { StatutType } from '@/components/StatutTag'
export type OptionType = {

View File

@ -1,3 +1,4 @@
import { useWorkerEngine, WorkerEngine } from '@publicodes/worker-react'
import { DottedName } from 'modele-social'
import { utils } from 'publicodes'
import { useSelector } from 'react-redux'
@ -6,7 +7,6 @@ import { createSelector } from 'reselect'
import { usePromise } from '@/hooks/usePromise'
// import { useEngine } from '@/components/utils/EngineContext'
import { RootState, Situation } from '@/store/reducers/rootReducer'
import { useWorkerEngine, WorkerEngine } from '@/worker/workerEngineClientReact'
export const configSelector = (state: RootState) =>
state.simulation?.config ?? {}