Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues in course analysis statistics tool #387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions domain/statistics/seasons.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
const i18n = require('../../i18n')

// eslint-disable-next-line no-unused-vars
const seasonConstants = {
SPRING_TERM_NUMBER: 1, // Minimum possible term number.
AUTUMN_TERM_NUMBER: 2, // Maximum possible term number.
SUMMER_TERM_NUMBER: 0,
SPRING_TERM_NUMBER: 1,
AUTUMN_TERM_NUMBER: 2,
}
const orderedSeasons = () => [
seasonConstants.AUTUMN_TERM_NUMBER,
seasonConstants.SPRING_TERM_NUMBER,
seasonConstants.SUMMER_TERM_NUMBER,
]
const orderedSeasons = () => [seasonConstants.AUTUMN_TERM_NUMBER, seasonConstants.SPRING_TERM_NUMBER]
/**
* @param {number} seasonNumber
* @param {number} langIndex
Expand All @@ -21,8 +15,6 @@ function labelSeason(seasonNumber, langIndex) {
const { statisticsLabels: labels } = i18n.messages[langIndex]

switch (Number(seasonNumber)) {
case seasonConstants.SUMMER_TERM_NUMBER:
return labels.seasonSummer
case seasonConstants.AUTUMN_TERM_NUMBER:
return labels.seasonAutumn
case seasonConstants.SPRING_TERM_NUMBER:
Expand Down
4 changes: 2 additions & 2 deletions i18n/messages.en.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ module.exports = {
documentType: 'Area',
periods: 'Study period',
school: 'School',
seasons: 'Semester',
semester: 'Semester',
year: 'Year',
},
formShortIntro: {
documentType: 'Select the area you would like to see statistics for ',
periods: 'Choose one or more option(s)',
school: 'Select school',
seasons: 'Choose one or more option(s)',
semester: 'Choose one semester',
year: 'Select year',
},
missingParameters: { text: extra => `You have to select a ${extra} to view statistics.` },
Expand Down
4 changes: 2 additions & 2 deletions i18n/messages.se.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ module.exports = {
documentType: 'Område',
periods: 'Läsperiod',
school: 'Skola',
seasons: 'Termin',
semester: 'Termin',
year: 'År',
},
formShortIntro: {
documentType: 'Välj det område du vill se statistik för',
periods: 'Kryssa i ett eller flera val',
school: 'Välj skola',
seasons: 'Kryssa i ett eller flera val',
semester: 'Välj en termin',
year: 'Välj år',
},
missingParameters: {
Expand Down
24 changes: 12 additions & 12 deletions public/js/app/components/statistics/AnalysesSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useLanguage } from '../../hooks/useLanguage'
import { TableSummary } from './TableSummaryRows'
import { seasons as seasonLib } from './domain/index'
import { Charts } from './Chart'
import { Results } from './index'
import { Results, StatisticsAlert } from './index'

function getSchoolNumbers(school) {
const { numberOfCourses, numberOfUniqAnalyses } = school
Expand All @@ -25,7 +25,7 @@ function addAllSchoolsData({ totalCourses, totalUniqPublishedAnalyses }) {
return allSchools
}

function Captions({ school, year, seasons }) {
function Captions({ school, year, semester }) {
const {
languageIndex,
translation: {
Expand All @@ -41,7 +41,7 @@ function Captions({ school, year, seasons }) {
return schoolName
}

const seasonsStr = seasons.map(season => seasonLib.labelSeason(season, languageIndex)).join(', ')
const semesterStr = seasonLib.labelSeason(semester, languageIndex)
return (
<Row>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
Expand All @@ -53,8 +53,8 @@ function Captions({ school, year, seasons }) {
{`: ${year}`}
</Col>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{formSubHeaders.seasons}</label>
{`: ${seasonsStr}`}
<label>{formSubHeaders.semester}</label>
{`: ${semesterStr}`}
</Col>
</Row>
)
Expand All @@ -63,12 +63,12 @@ function Captions({ school, year, seasons }) {
function AnalysesNumbersTable({ statisticsResult }) {
const { translation } = useLanguage()
const { analysesNumbersTable } = translation.statisticsLabels.summaryLabels
const { combinedAnalysesPerSchool, year, seasons, school } = statisticsResult
const { combinedAnalysesPerSchool, year, semester, school } = statisticsResult
const cellNames = ['totalCourses', 'totalUniqPublishedAnalyses']

return (
<>
<Captions school={school} year={year} seasons={seasons} />
<Captions school={school} year={year} semester={semester} />

<TableSummary
docsPerSchool={combinedAnalysesPerSchool}
Expand All @@ -83,32 +83,32 @@ function AnalysesNumbersTable({ statisticsResult }) {

function AnalysesNumbersCharts({ statisticsResult }) {
const chartNames = ['numberOfUniqAnalyses']
const { combinedAnalysesPerSchool: docsPerSchool, seasons, year, school } = statisticsResult
const { combinedAnalysesPerSchool: docsPerSchool, semester, year, school } = statisticsResult
const { schools = {} } = docsPerSchool
if (school === 'allSchools') {
schools.allSchools = addAllSchoolsData(docsPerSchool)
}

return (
<>
<Captions school={school} year={year} seasons={seasons} />
<Captions school={school} year={year} semester={semester} />

<Charts chartNames={chartNames} schools={schools} />
</>
)
}
function AnalysesNumbersChartsYearAgo({ statisticsResult }) {
const { school, documentType, seasons, year } = statisticsResult
const { school, documentType, semester, year } = statisticsResult

if (!documentType) return null
const oneYearAgo = Number(year) - 1

const state = useStatisticsAsync({ seasons, year: oneYearAgo, documentType, school }, 'once')
const state = useStatisticsAsync({ semester, year: oneYearAgo, documentType, school }, 'once')

const { data: statisticsResultYearAgo, status: statisticsStatus, error = {} } = state || {}

return (
<>
{error?.errorType && <StatisticsAlert alertType={error.errorType}>{error.errorExtraText}</StatisticsAlert>}
<Results statisticsStatus={statisticsStatus} error={error}>
<AnalysesNumbersCharts statisticsResult={statisticsResultYearAgo} />
</Results>
Expand Down
2 changes: 1 addition & 1 deletion public/js/app/components/statistics/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Charts({ chartNames = [], schools = {} }) {

function Chart({ data = [], label = '' }) {
const styles = {
font: { fontFamily: 'Open Sans', fontSize: 'font-heading-xs' },
font: { fontFamily: 'Figtree, sans-serif', fontSize: 16 },
}
return (
<VictoryChart height={405} width={405} theme={VictoryTheme.material} domainPadding={20} style={styles.font}>
Expand Down
6 changes: 3 additions & 3 deletions public/js/app/components/statistics/MemosSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useLanguage } from '../../hooks/useLanguage'
import { TableSummary } from './TableSummaryRows'
import { Charts } from './Chart'
import { periods as periodsLib } from './domain/index'
import { Results } from './index'
import { Results, StatisticsAlert } from './index'

function getSchoolNumbers(school = {}) {
return [
Expand Down Expand Up @@ -145,7 +145,6 @@ function MemosNumbersCharts({ statisticsResult }) {
function MemosNumbersChartsYearAgo({ statisticsResult }) {
const { school, documentType, periods, year } = statisticsResult

if (!documentType) return null
const oneYearAgo = Number(year) - 1

const state = useStatisticsAsync({ periods, year: oneYearAgo, documentType, school }, 'once')
Expand All @@ -154,6 +153,8 @@ function MemosNumbersChartsYearAgo({ statisticsResult }) {

return (
<>
{error?.errorType && <StatisticsAlert alertType={error.errorType}>{error.errorExtraText}</StatisticsAlert>}

<Results statisticsStatus={statisticsStatus} error={error}>
<MemosNumbersCharts statisticsResult={statisticsResultYearAgo} />
</Results>
Expand Down Expand Up @@ -182,5 +183,4 @@ function MemosSummary({ statisticsResult }) {
)
}

MemosSummary.defaultProps = {}
export default MemosSummary
2 changes: 1 addition & 1 deletion public/js/app/components/statistics/RadioboxOption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function RadioboxOption({ paramName, onChange }) {
}

RadioboxOption.propTypes = {
paramName: PropTypes.oneOf(['documentType', 'school']).isRequired,
paramName: PropTypes.oneOf(['documentType', 'school', 'semester']).isRequired,
onChange: PropTypes.func.isRequired,
}

Expand Down
18 changes: 7 additions & 11 deletions public/js/app/components/statistics/ResultNumbersSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@ function ResultNumbersSummary({ statisticsResult }) {
}

ResultNumbersSummary.propTypes = {
statisticsResult: PropTypes.oneOf([
PropTypes.shape({
combinedMemosPerSchool: PropTypes.shape({}),
documentType: PropTypes.oneOf(documentTypes()),
koppsApiBasePath: PropTypes.string,
documentsApiBasePath: PropTypes.string,
school: PropTypes.oneOf(schools.orderedSchoolsFormOptions()),
}),
]),
statisticsResult: PropTypes.shape({
combinedMemosPerSchool: PropTypes.shape({}),
documentType: PropTypes.oneOf(documentTypes()),
koppsApiBasePath: PropTypes.string,
documentsApiBasePath: PropTypes.string,
school: PropTypes.oneOf(schools.orderedSchoolsFormOptions()),
}),
}

ResultNumbersSummary.defaultProps = {}
export default ResultNumbersSummary
7 changes: 1 addition & 6 deletions public/js/app/components/statistics/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const errorItalicParagraph = (error = {}, labels) => {
)
}

function Results({ statisticsStatus, error = {}, children }) {
function Results({ statisticsStatus = null, error = {}, children }) {
const {
translation: { statisticsLabels },
} = useLanguage()
Expand Down Expand Up @@ -57,9 +57,4 @@ Results.propTypes = {
}),
}

Results.defaultProps = {
error: {},
statisticsStatus: null,
}

export default Results
10 changes: 5 additions & 5 deletions public/js/app/components/statistics/StatisticsAlert.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import PropTypes from 'prop-types'
import Alert from '../../components-shared/Alert'
import React from 'react'
import i18n from '../../../../../i18n'
import Alert from '../../components-shared/Alert'
import { ERROR_ASYNC } from '../../hooks/statisticsUseAsync'
import { useLanguage } from '../../hooks/useLanguage'

function StatisticsAlert({ alertType, languageIndex, children }) {
// We cannot use useLanguage or useWebContext here, as this component will be rendered outside of our component tree
function StatisticsAlert({ alertType, children }) {
const { languageIndex } = useLanguage()
const { statisticsLabels } = i18n.messages[languageIndex]
const { header = '', help = '', text = '' } = statisticsLabels[alertType] || {}

Expand All @@ -20,7 +21,6 @@ function StatisticsAlert({ alertType, languageIndex, children }) {

StatisticsAlert.propTypes = {
alertType: PropTypes.oneOf([...Object.values(ERROR_ASYNC), null]).isRequired,
languageIndex: PropTypes.oneOf([0, 1]).isRequired,
}

export default StatisticsAlert
8 changes: 5 additions & 3 deletions public/js/app/components/statistics/StatisticsDataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function StatisticsDataTable({ statisticsResult }) {
(statisticsResult.offeringsWithAnalyses && statisticsResult.offeringsWithAnalyses.length === 0)
)
return <NoDataMessage labels={sortableTable} />
const { year, offeringsWithMemos, periods = [], seasons = [], offeringsWithAnalyses } = statisticsResult
const { year, offeringsWithMemos, periods = [], semester = '', offeringsWithAnalyses } = statisticsResult
const isMemoPage = offeringsWithMemos && offeringsWithMemos.length > 0 ? true : false
const isAnalysisPage = offeringsWithAnalyses && offeringsWithAnalyses.length > 0 ? true : false

Expand Down Expand Up @@ -342,7 +342,9 @@ function StatisticsDataTable({ statisticsResult }) {
selector: group => group[columnName],
sortable: true,
wrap: true,
minWidth: '137px',
style: {
minWidth: '137px',
},
}))
let dataRows = []
if (isMemoPage) {
Expand Down Expand Up @@ -402,7 +404,7 @@ function StatisticsDataTable({ statisticsResult }) {
fileName={
isMemoPage
? `course-information-statistics-memos-${year}-periods-${periods.join('-')}`
: `course-information-statistics-analyses-${year}-periods-${seasons.join('-')}`
: `course-information-statistics-analyses-${year}-periods-${semester}`
}
></StatisticsExport>
</Row>
Expand Down
26 changes: 16 additions & 10 deletions public/js/app/components/statistics/StatisticsForm.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import PropTypes from 'prop-types'
import React, { useReducer } from 'react'
import { Col, Row } from 'reactstrap'
import PropTypes from 'prop-types'
import { useLanguage } from '../../hooks/useLanguage'
import { DOCS, studyLengthParamName } from './domain/formConfigurations'

import { CheckboxOption, DropdownOption, RadioboxOption } from './index'
import { CheckboxOption, DropdownOption, RadioboxOption, StatisticsAlert } from './index'

const paramsReducer = (state, action) => {
const { value, type } = action
Expand All @@ -24,7 +24,7 @@ const paramsReducer = (state, action) => {
}
}

function StatisticsForm({ onSubmit }) {
function StatisticsForm({ onSubmit, resultError }) {
const [state, setState] = useReducer(paramsReducer, {})
const [stateMode, setStateMode] = React.useState('init')
const { documentType = null } = state
Expand Down Expand Up @@ -85,19 +85,24 @@ function StatisticsForm({ onSubmit }) {
</Row>
<Row key={`row-for-periods-or-seasons-choice`} className={`row-for-periods-or-seasons-choice`}>
<Col>
{/* depends on type of document to dropdown */}
<CheckboxOption
paramName={studyLengthParamName(documentType)}
onChange={handleParamChange}
stateMode={stateMode}
/>
{documentType === 'courseAnalysis' ? (
<RadioboxOption paramName={studyLengthParamName(documentType)} onChange={handleParamChange} />
) : (
<CheckboxOption
paramName={studyLengthParamName(documentType)}
onChange={handleParamChange}
stateMode={stateMode}
/>
)}
</Col>
</Row>
</>
)}
<Row>
<Col>
<div id="alert-placeholder" />
{resultError?.errorType && (
<StatisticsAlert alertType={resultError.errorType}>{resultError.errorExtraText}</StatisticsAlert>
)}
</Col>
</Row>
<Row>
Expand All @@ -113,6 +118,7 @@ function StatisticsForm({ onSubmit }) {

StatisticsForm.propTypes = {
onSubmit: PropTypes.func.isRequired,
resultError: PropTypes.object,
}

export default StatisticsForm
Loading
Loading