Skip to content

Commit

Permalink
Merge branch 'preprod' into NGC-998
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlaa authored Aug 26, 2024
2 parents cdac6d1 + 210249a commit 5cb4195
Show file tree
Hide file tree
Showing 171 changed files with 1,031 additions and 683 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Link from '@/components/Link'
import { formatCarbonFootprint } from '@/helpers/formatters/formatCarbonFootprint'
import { useRules } from '@/hooks/useRules'
import { safeEvaluateHelper } from '@/publicodes-state/helpers/safeEvaluateHelper'
import { DottedName, Rules, Situation } from '@/publicodes-state/types'
import { Situation } from '@/publicodes-state/types'
import { encodeRuleName } from '@/utils/publicodes/encodeRuleName'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import Engine, { Evaluation } from 'publicodes'
import { useEffect, useMemo, useState } from 'react'

const demoDottedNames = [
const demoDottedNames: DottedName[] = [
'commun . intensité électricité',
'transport . voiture . thermique . empreinte au litre',
"logement . construction . durée d'amortissement",
]

const indicatorsKeys = ['bilan', 'transport', 'logement']
Expand All @@ -25,10 +25,10 @@ export default function ModeleDemoBlock() {

const { data: rules } = useRules({ isOptim: false })

const engine = useMemo<Engine | null>(
const engine = useMemo(
() =>
rules
? new Engine(rules as Rules, {
? new Engine<DottedName>(rules, {
strict: {
situation: false,
noOrphanRule: false,
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function ModeleDemoBlock() {

return obj
},
{} as { [key: (typeof demoDottedNames)[number]]: Evaluation }
{} as Record<(typeof demoDottedNames)[number], Evaluation>
)

return (
Expand All @@ -85,7 +85,7 @@ export default function ModeleDemoBlock() {
onChange(el, e.target.value === '' ? '' : e.target.value)
}
/>
&nbsp;{(rules as Rules)?.[el]?.unité}
&nbsp;{rules?.[el]?.unité}
</span>
</label>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
useTempEngine,
useUser,
} from '@/publicodes-state'
import { DottedName, NGCRuleNode } from '@/publicodes-state/types'
import { trackEvent } from '@/utils/matomo/trackEvent'
import { DottedName, NGCRuleNode } from '@incubateur-ademe/nosgestesclimat'
import { utils } from 'publicodes'
import ActionForm from '../../_components/actions/_components/ActionForm'

Expand All @@ -33,16 +33,18 @@ export default function ActionDetail({
?.map(decodeURIComponent)
?.join(' . ')

const { rules, getRuleObject, extendedFoldedSteps } = useTempEngine()
const { rules, getSpecialRuleObject, extendedFoldedSteps } = useTempEngine()

const { toggleActionChoice } = useUser()

const { actionChoices } = useCurrentSimulation()

const dottedName = decodeRuleName(formattedDottedName ?? '')
const dottedName = decodeRuleName(formattedDottedName ?? '') as DottedName

const remainingQuestions = filterRelevantMissingVariables(
Object.keys(getRuleObject(dottedName).missingVariables || {}),
Object.keys(
getSpecialRuleObject(dottedName).missingVariables || {}
) as DottedName[],
extendedFoldedSteps
)

Expand All @@ -57,14 +59,15 @@ export default function ActionDetail({

const { description, icônes: icons } = rules[dottedName]

const flatActions = rules['actions']
// Typing is shit here but it's the `actions` rule from model.
const flatActions = rules['actions'] as { formule: { somme: DottedName[] } }

const relatedActions: NGCRuleNode[] = flatActions?.formule?.somme
.filter(
(action: DottedName) =>
action !== dottedName && getCategory(dottedName) === getCategory(action)
)
.map((name: string) => getRuleObject(name))
.map((name: DottedName) => getSpecialRuleObject(name))

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Trans from '@/components/translation/Trans'
import ButtonLink from '@/design-system/inputs/ButtonLink'
import { getServerTranslation } from '@/helpers/getServerTranslation'
import { getMetadataObject } from '@/helpers/metadata/getMetadataObject'
import { DottedName } from '@/publicodes-state/types'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import ActionDetail from './_components/ActionDetail'

export async function generateMetadata({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
useTempEngine,
useUser,
} from '@/publicodes-state'
import { DottedName } from '@/publicodes-state/types'
import { trackEvent } from '@/utils/matomo/trackEvent'
import { encodeRuleName } from '@/utils/publicodes/encodeRuleName'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import { useCallback } from 'react'
import ActionValue from './ActionValue'

Expand Down Expand Up @@ -59,7 +59,7 @@ export default function ActionCard({
const { icônes: icons } = rule || action

const remainingQuestions = filterRelevantMissingVariables(
Object.keys(missingVariables || {}),
Object.keys(missingVariables || {}) as DottedName[],
extendedFoldedSteps
)

Expand All @@ -85,7 +85,7 @@ export default function ActionCard({
return key === dottedName && actionChoices?.[key]
})

const flatRule = rules?.[dottedName]
const flatRule = (rules as any)?.[dottedName]

const hasFormula = flatRule?.formule
const isDisabled =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import Navigation from '@/components/form/Navigation'
import Question from '@/components/form/Question'
import { useForm } from '@/publicodes-state'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import { motion } from 'framer-motion'
import { useEffect } from 'react'

type Props = {
category: string
category: DottedName
onComplete: () => void
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
useEngine,
useUser,
} from '@/publicodes-state'
import { DottedName } from '@/publicodes-state/types'
import { trackEvent } from '@/utils/matomo/trackEvent'
import ActionCard from './ActionCard'
import ActionForm from './ActionForm'
Expand All @@ -19,7 +18,7 @@ type Props = {
rules: any
bilan: any
focusedAction: string
setFocusedAction: (dottedName: DottedName) => void
setFocusedAction: (dottedName: string) => void
}

export default function ActionList({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getCarbonFootprint } from '@/helpers/actions/getCarbonFootprint'
import { useClientTranslation } from '@/hooks/useClientTranslation'
import { useRule } from '@/publicodes-state'
import { DottedName, NodeValue } from '@/publicodes-state/types'
import { TranslationFunctionType } from '@/types/translation'
import { getCorrectedValue } from '@/utils/getCorrectedValue'
import { DottedName, NodeValue } from '@incubateur-ademe/nosgestesclimat'

const getFormattedActionValue = (
{ t, i18n }: { t: TranslationFunctionType; i18n: any },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function CategoryFilters({ actions }: Props) {

return (
<ul className="flex list-none flex-wrap justify-center gap-1 pl-0">
{categories?.map((category: string) => {
{categories?.map((category) => {
return (
<Filter
key={category}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
getTextDarkColor,
} from '@/helpers/getCategoryColorClass'
import { useRule } from '@/publicodes-state'
import { DottedName } from '@/publicodes-state/types'
import { trackEvent } from '@/utils/matomo/trackEvent'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import { useRouter, useSearchParams } from 'next/navigation'

type Props = {
Expand Down
4 changes: 2 additions & 2 deletions src/app/(simulation)/(large-layout)/actions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function ActionsPage({

const { actionChoices, progression } = useCurrentSimulation()

const { rules, getRuleObject } = useTempEngine()
const { rules, getSpecialRuleObject } = useTempEngine()

const { safeEvaluate } = useSimulation()

Expand All @@ -42,7 +42,7 @@ export default function ActionsPage({
rules,
radical,
safeEvaluate,
getRuleObject,
getSpecialRuleObject,
actionChoices,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Markdown from '@/design-system/utils/Markdown'
import { getServerTranslation } from '@/helpers/getServerTranslation'
import { getPost } from '@/helpers/markdown/getPost'
import { getMetadataObject } from '@/helpers/metadata/getMetadataObject'
import { DottedName } from '@/publicodes-state/types'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'

export async function generateMetadata() {
const { t } = await getServerTranslation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import Link from '@/components/Link'
import Card from '@/design-system/layout/Card'
import { getRuleTitle } from '@/helpers/publicodes/getRuleTitle'
import { useTempEngine } from '@/publicodes-state'
import { DottedName } from '@/publicodes-state/types'
import { NGCRule, NGCRules } from '@incubateur-ademe/nosgestesclimat'

import { Post } from '@/types/posts'
import { encodeRuleName } from '@/utils/publicodes/encodeRuleName'
import {
DottedName,
NGCRule,
NGCRules,
} from '@incubateur-ademe/nosgestesclimat'

type Props = {
actions: Post[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Badge from '@/design-system/layout/Badge'
import Emoji from '@/design-system/utils/Emoji'
import { useRule } from '@/publicodes-state'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import { formatValue } from 'publicodes'
import ValueDiff from './pointsListItem/ValueDiff'

type PointsListItemProps = {
name: string
name: DottedName
value: number
difference: number
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Emoji from '@/design-system/utils/Emoji'
import { useRule } from '@/publicodes-state'
import { ValueObject } from '@/types/groups'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import { formatValue } from 'publicodes'
import ValueDiff from '../pointsFortsFaibles/pointsListItem/ValueDiff'

type Props = {
category: string
category: DottedName
categoryFootprint?: ValueObject
membersLength: number
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Trans from '@/components/translation/Trans'
import { carboneMetric } from '@/constants/metric'
import Separator from '@/design-system/layout/Separator'
import { SimulationRecap } from '@/types/organisations'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import { useMemo } from 'react'
import CategoryListItem from './pollStatisticsCharts/CategoryListItem'
import MainFootprintChart from './pollStatisticsCharts/MainFootprintChart'
Expand All @@ -19,8 +20,10 @@ export default function PollStatisticsCharts({
const maxValueOfAllCategories = useMemo(
() =>
simulationRecaps?.reduce((acc, obj) => {
Object.keys(
obj.computedResults[carboneMetric].categories ?? {}
;(
Object.keys(
obj.computedResults[carboneMetric].categories ?? {}
) as DottedName[]
).forEach((category) => {
const roundedValue = Math.round(
obj.computedResults[carboneMetric].categories[category] / 1000
Expand Down Expand Up @@ -51,8 +54,10 @@ export default function PollStatisticsCharts({
// Calculate the mean for each category
const meanCategories = useMemo(
() =>
Object.keys(
simulationRecaps?.[0]?.computedResults[carboneMetric].categories ?? {}
(
Object.keys(
simulationRecaps?.[0]?.computedResults[carboneMetric].categories ?? {}
) as DottedName[]
).map((category) => {
const mean = simulationRecaps?.reduce(
(acc, obj) =>
Expand Down Expand Up @@ -123,8 +128,10 @@ export default function PollStatisticsCharts({
</div>
<ul>
{simulationRecaps?.length > 0 &&
Object.keys(
simulationRecaps[0].computedResults[carboneMetric].categories
(
Object.keys(
simulationRecaps[0].computedResults[carboneMetric].categories
) as DottedName[]
).map((category, index) => (
<CategoryListItem
key={index}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import Emoji from '@/design-system/utils/Emoji'
import { formatCarbonFootprint } from '@/helpers/formatters/formatCarbonFootprint'
import { useRule } from '@/publicodes-state'
import { SimulationRecap } from '@/types/organisations'
import { DottedName } from '@incubateur-ademe/nosgestesclimat'
import { t } from 'i18next'
import RepartitionChart from './RepartitionChart'

type Props = {
simulationsRecap: SimulationRecap[]
value: number
category: string
category: DottedName
maxValue: number
}

Expand Down
Loading

0 comments on commit 5cb4195

Please sign in to comment.