Skip to content

Commit

Permalink
fixed hasSamplingPointData hook
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Oct 9, 2023
1 parent 4f385fb commit 2f9e1e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions core/i18n/resources/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ Thank you and enjoy **$t(common.appNameFull)**!`,
availableSpace: 'Available ({{size}})',
usedSpace: 'Used ({{size}})',
},
samplingPointDataCompletion: 'Sampling Point Data Completion',
step: {
entry: 'Data Entry',
cleansing: 'Data Cleansing',
analysis: 'Data Analysis',
},
},
surveyDeleted: 'Survey {{surveyName}} has been deleted',
surveyInfo: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, { useEffect, useRef, useContext } from 'react'
import * as d3 from 'd3'

import { countSamplingPointData } from '@webapp/service/api/categories'
import { useI18n } from '@webapp/store/system'

import { RecordsSummaryContext } from '../RecordsSummaryContext'

const SamplingDataChart = (surveyInfo) => {
const ref = useRef()
const { dataEntry, dataCleansing } = useContext(RecordsSummaryContext)
const i18n = useI18n()

useEffect(() => {
const fetchData = async () => {
Expand Down Expand Up @@ -43,7 +47,9 @@ const SamplingDataChart = (surveyInfo) => {
.attr('d', arcGenerator1)
.attr('fill', (d, i) => color(i))

d3.select('#tooltip1').style('visibility', 'visible').html(`Data Entry: ${dataEntry} / ${totalRows}`)
d3.select('#tooltip1')
.style('visibility', 'visible')
.html(`${i18n.t('homeView.dashboard.step.entry')}: ${dataEntry} / ${totalRows}`)

// Create second pie
const data_ready2 = pie(data2)
Expand All @@ -56,14 +62,16 @@ const SamplingDataChart = (surveyInfo) => {
.attr('d', arcGenerator2)
.attr('fill', (d, i) => color2(i))

d3.select('#tooltip2').style('visibility', 'visible').html(`Data Cleansing: ${dataCleansing} / ${totalRows}`)
d3.select('#tooltip2')
.style('visibility', 'visible')
.html(`${i18n.t('homeView.dashboard.step.cleansing')}: ${dataCleansing} / ${totalRows}`)
}
fetchData()
}, [])

return (
<div ref={ref} style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', flexDirection: 'column' }}>
<h4 style={{ textAlign: 'center' }}>Sampling Datapoint Completion</h4>
<h4 style={{ textAlign: 'center' }}>{i18n.t('homeView.dashboard.samplingPointDataCompletion')}</h4>
<div id="tooltip1" style={{ visibility: 'visible' }}></div>
<div id="tooltip2" style={{ visibility: 'visible' }}></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useState, useEffect } from 'react'

import * as Survey from '@core/survey/survey'
import * as NodeDef from '@core/survey/nodeDef'

import { useSurvey } from '@webapp/store/survey'

export const useHasSamplingPointData = () => {
Expand All @@ -8,7 +11,16 @@ export const useHasSamplingPointData = () => {

useEffect(() => {
const samplingPointDataNodeDefs = Survey.getSamplingPointDataNodeDefs(survey)
setHasSamplingPointData(samplingPointDataNodeDefs.length > 0)
if (samplingPointDataNodeDefs.length === 0) {
setHasSamplingPointData(false)
return
}
const rootKeyDefs = Survey.getNodeDefRootKeys(survey)
const samplingPointDataNodeDefUuids = samplingPointDataNodeDefs.map(NodeDef.getUuid)
const allKeysUseSamplingPointData = rootKeyDefs.every((rootKeyDef) =>
samplingPointDataNodeDefUuids.includes(NodeDef.getUuid(rootKeyDef))
)
setHasSamplingPointData(allKeysUseSamplingPointData)
}, [survey])

return hasSamplingPointData
Expand Down

0 comments on commit 2f9e1e2

Please sign in to comment.