Skip to content

Commit

Permalink
[CourseStatistics, StudyProgramme, Teachers] Added serviceProvider ch…
Browse files Browse the repository at this point in the history
…ecks to hide some tables, tabs and routes when not running in toska enviroment (#4685)

* [CourseStatistics, StudyProgramme, Teachers] Added serviceProvider checks to hide some tables and tabs when not running in toska enviroment

* [StudentsTable] Use cloneDeep for toskaColumns to prevent mutation

* [Frontend] Replace serviceProvider checks with isDefaultServiceProvider function for consistency

---------

Co-authored-by: Valtteri Kantanen <[email protected]>
  • Loading branch information
mattirasanen and valtterikantanen authored Nov 25, 2024
1 parent 3b0ccb5 commit dad7ddc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { uniq } from 'lodash'
import { cloneDeep, uniq } from 'lodash'
import qs from 'query-string'
import { useMemo } from 'react'
import { useSelector } from 'react-redux'
import { Link } from 'react-router-dom'
import { Header, Icon, Item } from 'semantic-ui-react'

import { isDefaultServiceProvider } from '@/common'
import { defineCellColor, getSortableColumn, resolveGrades } from '@/components/CourseStatistics/ResultTabs/panes/util'
import { SortableTable, row } from '@/components/SortableTable'
import { getCourseAlternatives } from '@/selectors/courseStats'
Expand Down Expand Up @@ -35,8 +36,7 @@ const getColumns = (stats, showGrades, userHasAccessToAllStats, alternatives, se
const searchString = qs.stringify(queryObject)
return `/coursepopulation?${searchString}`
}

const columns = [
const toskaColumns = [
{
key: 'TIME_PARENT',
merge: true,
Expand Down Expand Up @@ -155,6 +155,13 @@ const getColumns = (stats, showGrades, userHasAccessToAllStats, alternatives, se
},
]

const fdColums = cloneDeep(toskaColumns)
const index = fdColums.findIndex(o => o.key === 'TIME_PARENT')
if (index !== -1) {
fdColums[index].children = fdColums[index].children.filter(o => o.key === 'TIME')
}

const columns = isDefaultServiceProvider() ? toskaColumns : fdColums
return columns.filter(column => {
if (showGrades && column.onlyInGradeView) return true
if (showGrades && column.hideWhenGradesVisible) return false
Expand Down
18 changes: 10 additions & 8 deletions services/frontend/src/components/Routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ export const Routes = () => (
requireUserHasRights
requiredRoles={['fullSisuAccess', 'courseStatistics']}
/>
<ProtectedRoute component={Users} path={routes.users} requiredRoles={['admin']} />
<ProtectedRoute component={Teachers} path={routes.teachers} requiredRoles={['teachers']} />
<ProtectedRoute
component={CoursePopulation}
path={routes.coursepopulation}
requireUserHasRights
requiredRoles={['fullSisuAccess']}
/>
<ProtectedRoute component={Users} exact path={routes.users} requiredRoles={['admin']} />
<ProtectedRoute component={Teachers} exact path={routes.teachers} requiredRoles={['teachers']} />
{isDefaultServiceProvider() && (
<ProtectedRoute
component={CoursePopulation}
path={routes.coursepopulation}
requireUserHasRights
requiredRoles={['fullSisuAccess']}
/>
)}
<ProtectedRoute
component={CustomPopulation}
path={routes.custompopulation}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { Divider, Loader, Message } from 'semantic-ui-react'

import { getGraduationGraphTitle } from '@/common'
import { getGraduationGraphTitle, isDefaultServiceProvider } from '@/common'
import { studyProgrammeToolTips } from '@/common/InfoToolTips'
import { CreditsProduced } from '@/components/common/CreditsProduced'
import { InfoBox } from '@/components/InfoBox'
Expand Down Expand Up @@ -187,7 +187,7 @@ export const BasicOverview = ({
</div>
</>
)}
{credits?.data?.stats?.[studyprogramme]?.stats && (
{credits?.data?.stats?.[studyprogramme]?.stats && isDefaultServiceProvider() && (
<>
{getDivider('Credits produced by the study programme', 'creditsProducedByTheStudyProgramme')}
<CreditsProduced
Expand Down
26 changes: 14 additions & 12 deletions services/frontend/src/components/StudyProgramme/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react'
import { useHistory, useParams } from 'react-router-dom'
import { Container, Header, Menu, Segment, Tab } from 'semantic-ui-react'

import { getFullStudyProgrammeRights, getUnifiedProgrammeName } from '@/common'
import { getFullStudyProgrammeRights, getUnifiedProgrammeName, isDefaultServiceProvider } from '@/common'
import { useTabs, useTitle } from '@/common/hooks'
import { useLanguage } from '@/components/LanguagePicker/useLanguage'
import { useGetAuthorizedUserQuery } from '@/redux/auth'
Expand Down Expand Up @@ -87,17 +87,19 @@ export const StudyProgramme = () => {
fullStudyProgrammeRights.includes(programmeId) ||
fullStudyProgrammeRights.includes(secondProgrammeId)
) {
panes.push({
menuItem: <Menu.Item key="Programme courses">Programme courses</Menu.Item>,
render: () => (
<ProgrammeCourses
academicYear={academicYear}
combinedProgramme={secondProgrammeId}
setAcademicYear={setAcademicYear}
studyProgramme={programmeId}
/>
),
})
if (isDefaultServiceProvider()) {
panes.push({
menuItem: <Menu.Item key="Programme courses">Programme courses</Menu.Item>,
render: () => (
<ProgrammeCourses
academicYear={academicYear}
combinedProgramme={secondProgrammeId}
setAcademicYear={setAcademicYear}
studyProgramme={programmeId}
/>
),
})
}
panes.push({
menuItem: 'Degree courses',
render: () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react'
import { Link } from 'react-router-dom'
import { Segment, Icon, Item } from 'semantic-ui-react'

import { calculatePercentage } from '@/common'
import { calculatePercentage, isDefaultServiceProvider } from '@/common'
import { SortableTable } from '@/components/SortableTable'

const createColumnWithTitle = title => ({
Expand Down Expand Up @@ -39,9 +39,11 @@ export const TeacherStatisticsTable = ({ statistics, variant }) => {
getRowContent: row => (
<div style={{ display: 'flex', justifyContent: 'space-between', gap: '0.5em' }}>
{row.name}
<Item as={Link} target="_blank" to={`/teachers/${row.id}`}>
<Icon name="level up alternate" />
</Item>
{isDefaultServiceProvider() && (
<Item as={Link} target="_blank" to={`/teachers/${row.id}`}>
<Icon name="level up alternate" />
</Item>
)}
</div>
),
})
Expand Down

0 comments on commit dad7ddc

Please sign in to comment.