From 31e67f5bb95974b5be0a310878bec4c66af4a29d Mon Sep 17 00:00:00 2001 From: edvinstava <136808756+edvinstava@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:48:21 +0200 Subject: [PATCH] feat: [CGC-37] Explore solutions for custom growth references (#40) --- .../ChartSelector/ChartSelector.cy.js | 3 +- docs/using-capture-growth-charts.md | 218 +++++++++++++----- i18n/en.pot | 22 +- src/Plugin.tsx | 11 +- src/UI/GenericError/CustomReferencesError.tsx | 33 +++ src/components/GrowthChart/GrowthChart.tsx | 8 +- .../ChartSelectorDropdown.tsx | 2 +- .../DataFetching/Hooks/useChartConfig.ts | 2 +- .../DataFetching/Hooks/useCustomReferences.ts | 21 ++ .../Sorting/useChartDataForGender.ts | 6 +- 10 files changed, 249 insertions(+), 77 deletions(-) create mode 100644 src/UI/GenericError/CustomReferencesError.tsx create mode 100644 src/utils/DataFetching/Hooks/useCustomReferences.ts diff --git a/cypress/component/ChartSelector/ChartSelector.cy.js b/cypress/component/ChartSelector/ChartSelector.cy.js index 13132b7..8508a36 100644 --- a/cypress/component/ChartSelector/ChartSelector.cy.js +++ b/cypress/component/ChartSelector/ChartSelector.cy.js @@ -1,11 +1,12 @@ import React, { useState, useEffect } from 'react'; import { useChartDataForGender } from '../../../src/utils/DataFetching/Sorting/useChartDataForGender'; import { ChartSelector } from '../../../src/components/GrowthChart/GrowthChartSelector'; +import { chartData as chartDataWHO } from '../../../src/DataSets/WhoStandardDataSets/ChartData'; describe('ChartSelector', () => { const TestComponent = () => { const [gender, setGender] = useState('Boy'); - const { chartDataForGender } = useChartDataForGender({ gender: 'Boy' }); + const { chartDataForGender } = useChartDataForGender({ gender: 'Boy', chartData: chartDataWHO }); const [chartData, setChartData] = useState(null); const [category, setCategory] = useState(null); const [dataset, setDataset] = useState(null); diff --git a/docs/using-capture-growth-charts.md b/docs/using-capture-growth-charts.md index 19c5426..6e38f58 100644 --- a/docs/using-capture-growth-charts.md +++ b/docs/using-capture-growth-charts.md @@ -195,70 +195,176 @@ The structure of the config has to be the same as the one in the example below; } ``` -#### Custom references (Future functionality) +#### Custom references ##### Create custom references -1. Create a new key in the `capture-growth-chart` namespace with the key `customReferences` -2. Add the custom references you want to use. The structure of the custom references has to be the same as the one in the example below. But the **datasetValues** should be changed to fit your own references. +1. Create a new key in the `capture-growth-chart` namespace with the key `customReferences`. +2. Here is the format for the custom references: ```json { - "hcfa_b": { - "categoryMetadata": { - "gender": "Boy", - "label": "Head circumference for age" + "": { + "categoryMetadata": { + "gender": "", + "label": "" + }, + "datasets": { + "