diff --git a/3a b/3a deleted file mode 100644 index 98232c64fc..0000000000 --- a/3a +++ /dev/null @@ -1 +0,0 @@ -{ diff --git a/;a b/;a deleted file mode 100644 index a475eb159d..0000000000 --- a/;a +++ /dev/null @@ -1,291 +0,0 @@ -import React, { - useState, - useMemo, - useCallback, -} from 'react'; -import { - Tab, - TabList, - TabPanel, - Tabs, - KeyFigure, - KeyFigureProps, - ListView, - PendingAnimation, -} from '@the-deep/deep-ui'; -import { - EntriesAsList, - Error, - getErrorObject, -} from '@togglecorp/toggle-form'; -import { - gql, - useQuery, -} from '@apollo/client'; -import { - isDefined, - isNotDefined, - sum, - listToMap, - median, - compareString, - _cs, -} from '@togglecorp/fujs'; - -import { - AssessmentRegistryScoreAnalyticalStatementTypeEnum, - GetQualityScoreListQuery, - GetQualityScoreListQueryVariables, -} from '#generated/types'; - -import QualityScoreForm from './QualityScoreForm'; -import AnalyticalDensityForm from './AnalyticalDensityForm'; -import { - PartialFormType, -} from '../formSchema'; - -import styles from './styles.css'; - -type TabOptions = 'qualityScores' | 'analyticalDensity' | undefined; - -const scoring = { - VERY_POOR: 0, - POOR: 0.5, - FAIR: 1, - GOOD: 1.5, - VERY_GOOD: 2, -}; - -const GET_QUALITY_SCORE_LIST = gql` - query GetQualityScoreList( - $projectId: ID!, - ) { - project(id: $projectId) { - id - assessmentRegistryOptions { - scoreOptions { - scoreCriteriaDisplay - scoreCriteria - analyticalStatementDisplay - analyticalStatement - } - } - } - } -`; - -interface ScoreStatsValue { - key: string; - label: string; - score: number; -} - -const keySelector = (d: ScoreStatsValue) => d.key; - -interface Props { - projectId: string; - value: PartialFormType, - setFieldValue: (...entries: EntriesAsList) => void; - error: Error - loading?: boolean; -} - -function ScoreForm(props: Props) { - const { - projectId, - value, - setFieldValue, - error: riskyError, - loading, - } = props; - - const error = getErrorObject(riskyError); - - const [activeTab, setActiveTab] = useState('qualityScores'); - - const { - loading: scorePending, - data: qualityScoreList, - } = useQuery( - GET_QUALITY_SCORE_LIST, - { - variables: { - projectId, - }, - }, - ); - - const scoreOptions = qualityScoreList?.project?.assessmentRegistryOptions?.scoreOptions; - - const scoreStatsValue = useMemo(() => { - // NOTE: Analytical Density Value - const sectorWiseDensityValue = value.scoreAnalyticalDensity?.map( - (density) => { - const figureProvideValue = density.figureProvided?.length ?? 0; - const analysisLevelValue = density.analysisLevelCovered?.length ?? 0; - return (figureProvideValue * analysisLevelValue) / 10; - }, - ).filter(isDefined); - - const analyticalDensityValue = { - key: 'ANALYTICAL_DENSITY', - label: 'Analytical density', - score: Math.round((median(sectorWiseDensityValue ?? []) ?? 0) * 100) / 100, - }; - - const scoreToScoreGroupMap = listToMap( - scoreOptions, - (k) => k.scoreCriteria, - (d) => d.analyticalStatement, - ); - - // TODO: Replace string to enum - interface Accumulator { - [key: string]: number; - } - - interface ScoreStatsAccumulator { - [key: string]: { - label: string; - key: AssessmentRegistryScoreAnalyticalStatementTypeEnum; - score: number; - }; - } - - const scoreRatingValue = value.scoreRatings?.reduce( - (acc, scoreRating) => { - if (isNotDefined(scoreRating.rating) || isNotDefined(scoreRating.scoreType)) { - return acc; - } - const key = scoreToScoreGroupMap?.[scoreRating.scoreType]; - const score = scoring?.[scoreRating.rating]; - - if (isNotDefined(key) || isNotDefined(score)) { - return acc; - } - const currentValueForGroup = acc?.[key]; - - acc[key] = (currentValueForGroup ?? 0) + score; - - return acc; - }, - {}, - ); - - const scoreStatsList = scoreOptions?.reduce( - (acc, elem) => { - acc[elem.analyticalStatement] = { - key: elem.analyticalStatement, - label: elem.analyticalStatementDisplay, - score: scoreRatingValue?.[elem.analyticalStatement] ?? 0, - }; - - return acc; - }, - {}, - ); - - const scoreGroupScores = [...Object.values(scoreStatsList ?? [])].sort( - (a, b) => (compareString(a.label, b.label)), - ); - - return [ - ...scoreGroupScores, - analyticalDensityValue, - { - key: 'FINAL_SCORE', - label: 'Final Score', - score: Math.round((( - sum( - scoreGroupScores.map((item) => item.score), - ) + analyticalDensityValue.score) / 5) * 100) / 100, - }, - ]; - }, [ - scoreOptions, - value.scoreRatings, - value.scoreAnalyticalDensity, - ]); - - const scoreStatsValueParams = useCallback( - (_: string, data: ScoreStatsValue): KeyFigureProps => ({ - label: data.label, - value: data.score, - }), [], - ); - - if (loading || scorePending) { - return ( -
- -
- ); - } - - console.log('------stats value', scoreStatsValue); - - return ( -
- - - - - Quality Scores - - - Analytical Density - -
- - - - - - - - -
- ); -} - -export default ScoreForm;