Skip to content

Commit

Permalink
♻️ Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlaa committed Sep 2, 2024
1 parent 014c1a7 commit c9f6723
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build:debug-memory": "next build --experimental-debug-memory-usage",
"start": "next start",
"lint": "next lint",
"lint:types": "npx tsc --noEmit",
"lint:types": "tsc --noEmit",
"e2e": "cypress open --e2e",
"e2e:generate": "node cypress/scripts/generateSpecsFromPersonas.mjs",
"ui:parse": "node scripts/i18n/generate-ui.js",
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/RavijenChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CategoryChart from './ravijenChart/CategoryChart'

type Props = {
categories: DottedName[]
subcategories: Record<DottedName, DottedName[]> | undefined
subcategories?: Record<DottedName, DottedName[]> | undefined
squashLimitPercentage?: number
isInverted?: boolean
shouldAlwaysDisplayValue?: boolean
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/ravijenChart/CategoryChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TotalCategoryBlock from './categoryChart/TotalCategoryBlock'

type Props = {
category: DottedName
subcategories: DottedName[] | undefined
subcategories?: DottedName[] | undefined
maxValue: number
squashLimitPercentage?: number
isInverted?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export const getUserCategoryFootprintsSortedByDifference = ({

const { positiveDifferenceCategories, negativeDifferenceCategories } =
formattedResult.reduce(
(acc, item) => {
(
acc: {
positiveDifferenceCategories: PointsFortsFaiblesType[]
negativeDifferenceCategories: PointsFortsFaiblesType[]
},
item: PointsFortsFaiblesType
) => {
const { resultObject } = item
if (!!resultObject?.difference && resultObject?.difference < 0) {
acc.positiveDifferenceCategories.push(item)
Expand All @@ -54,9 +60,6 @@ export const getUserCategoryFootprintsSortedByDifference = ({
{
positiveDifferenceCategories: [],
negativeDifferenceCategories: [],
} as {
positiveDifferenceCategories: PointsFortsFaiblesType[]
negativeDifferenceCategories: PointsFortsFaiblesType[]
}
)

Expand Down
10 changes: 8 additions & 2 deletions src/hooks/groups/__tests__/fixtures/createGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ export function createGroup({
carbone: {
bilan: faker.number.float(),
categories: {} as Record<DottedName, number>,
subcategories: {} as Record<DottedName, Record<DottedName, number>>,
subcategories: {} as Record<
DottedName,
Record<DottedName, number | undefined>
>,
},
eau: {
bilan: faker.number.float(),
categories: {} as Record<DottedName, number>,
subcategories: {} as Record<DottedName, Record<DottedName, number>>,
subcategories: {} as Record<
DottedName,
Record<DottedName, number | undefined>
>,
},
},

Expand Down
2 changes: 1 addition & 1 deletion src/publicodes-state/helpers/getSubcategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function getSubcategories({
dottedName: DottedName
getRule: (dottedName: DottedName) => NGCRuleNode | null
parsedRules: Record<string, NGCRuleNode>
}): DottedName[] | undefined {
}): DottedName[] {
const ruleNode = getRule(dottedName)

if (!ruleNode || !ruleNode.rawNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,35 @@ export function useSetComputedResults({
// Set the computed results object (after engine init only)
const computedResults: ComputedResults = useMemo(
() =>
metrics.reduce((acc, metric) => {
acc[metric] = categories.reduce(
(acc, category) => {
acc.categories[category] = getNumericValue(category, metric)
metrics.reduce((metricsAcc: ComputedResults, metric: Metric) => {
metricsAcc[metric] = categories.reduce(
(categoriesAcc: ComputedResultsFootprint, category: DottedName) => {
categoriesAcc.categories[category] = getNumericValue(
category,
metric
)

const subcategories = getSubcategories(category)

if (!subcategories) return acc

acc.subcategories[category] = subcategories.reduce(
(subAcc, subcategory) => {
subAcc[subcategory] = getNumericValue(subcategory, metric)
if (!subcategories) return categoriesAcc

categoriesAcc.subcategories[category] = subcategories.reduce(
(subAcc: Record<DottedName, number>, subcategory: DottedName) => {
subAcc[subcategory] = getNumericValue(subcategory, metric) || 0
return subAcc
},
{} as { [key in DottedName]: number }
{} as Record<DottedName, number>
)

return acc
return categoriesAcc
},
{
categories: {},
subcategories: {},
bilan: getNumericValue('bilan', metric),
} as ComputedResultsFootprint
)
return acc
return metricsAcc
}, {} as ComputedResults),
// eslint-disable-next-line react-hooks/exhaustive-deps
[categories, getNumericValue, situation]
Expand Down

0 comments on commit c9f6723

Please sign in to comment.