Skip to content

Commit

Permalink
🚨 fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemog committed Dec 24, 2024
1 parent a9e912d commit 2edde66
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { safeEvaluateHelper } from '@/publicodes-state/helpers/safeEvaluateHelpe
import type { Situation } from '@/publicodes-state/types'
import { encodeRuleName } from '@/utils/publicodes/encodeRuleName'
import type { DottedName } from '@incubateur-ademe/nosgestesclimat'
import type { Evaluation } from 'publicodes';
import type { Evaluation } from 'publicodes'
import Engine from 'publicodes'
import { useEffect, useMemo, useState } from 'react'

Expand Down Expand Up @@ -86,7 +86,7 @@ export default function ModeleDemoBlock() {
onChange(el, e.target.value === '' ? '' : e.target.value)
}
/>
 {rules?.[el]?.unité}
 {rules?.[el]?.unité as string}
</span>
</label>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function ActionPlusList({ actions }: Props) {
<div className="mb-8 text-2xl">{rule.icônes || '🎯'}</div>
<div className="text-center">
{getRuleTitle(
rule as NGCRule & { dottedName: DottedName; titre: string }
rule as NGCRule & { dottedName: DottedName; titre?: string }
)}
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import MessageIcon from '@/components/icons/MessageIcon'
import Trans from '@/components/translation/Trans'
import Card from '@/design-system/layout/Card'
import Markdown from '@/design-system/utils/Markdown'
import type { Rule } from 'publicodes'
import type { NGCRule } from '@incubateur-ademe/nosgestesclimat'

export default function QuestionSection({ rule }: { rule: Rule }) {
export default function QuestionSection({ rule }: { rule: NGCRule }) {
if (!rule.question) return null
return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Link from '@/components/Link'
import { capitalizeString } from '@/utils/capitalizeString'
import { encodeRuleName } from '@/utils/publicodes/encodeRuleName'
import type { DottedName, NGCRules } from '@incubateur-ademe/nosgestesclimat'
import type { Rule} from 'publicodes';
import type {
DottedName,
NGCRule,
NGCRules,
} from '@incubateur-ademe/nosgestesclimat'
import { utils } from 'publicodes'

const KEYS_TO_OMIT = [
Expand All @@ -24,7 +27,7 @@ const KEYS_TO_OMIT = [
'mosaique',
]

const getRuleFormatted = (rule: Rule): Rule => {
const getRuleFormatted = (rule: NGCRule): NGCRule => {
const ruleFormatted = { ...rule }

for (const key in ruleFormatted) {
Expand All @@ -40,7 +43,7 @@ export default function RuleDetail({
ruleData,
context,
}: {
ruleData: Rule | string | number
ruleData: NGCRule | string | number
context: {
dottedName: DottedName
rules: NGCRules
Expand Down
12 changes: 11 additions & 1 deletion src/publicodes-state/hooks/useRule/useContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ export default function useContent({ dottedName, rule }: Props) {
[rule]
)

const plancher = useMemo<number>(() => rule?.rawNode['plancher'] ?? 0, [rule])
const plancher = useMemo<number>(() => {
// By default, the plancher is 0
const plancherValue = rule?.rawNode['plancher']

// TODO: Deal with the case where the plancher needs to be evaluated.
if (typeof plancherValue === 'string') {
return 0
}

return plancherValue ?? 0
}, [rule])

const warning = useMemo<string | undefined>(
() => rule?.rawNode['avertissement'],
Expand Down

0 comments on commit 2edde66

Please sign in to comment.