Skip to content

Commit d330b84

Browse files
authored
Merge pull request #4875 from UniversityOfHelsinkiCS/OOD-90-config-json
[FRONTEND] OOD-90: fetching frontend config from json
2 parents de8a090 + ae393fa commit d330b84

File tree

4 files changed

+90
-23
lines changed

4 files changed

+90
-23
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "sisUrl": "https://sis-qa.funidata.fi" }
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1+
import { useState, useEffect } from 'react'
12
import { Icon, Item } from 'semantic-ui-react'
2-
import { sisUrl } from '@/conf'
3+
import { sisUrl, serviceProvider } from '@/conf'
34

45
interface SisuLinkItemProps {
56
id: string
67
}
78

8-
export const SisuLinkItem = ({ id }: SisuLinkItemProps) => (
9-
<div data-cy="sisulink">
10-
<Item as="a" href={`${sisUrl}/tutor/role/staff/student/${id}/basic/basic-info`} target="_blank">
11-
<Icon name="external alternate" />
12-
Sisu
13-
</Item>
14-
</div>
15-
)
9+
export const SisuLinkItem = ({ id }: SisuLinkItemProps) => {
10+
const [runtimeConfiguredSisUrl, setRuntimeConfiguredSisUrl] = useState(sisUrl)
11+
useEffect(() => {
12+
fetch('/frontend-config.json')
13+
.then(response => {
14+
if (!response.ok) {
15+
throw new Error('Json response was not ok')
16+
}
17+
return response.json()
18+
})
19+
.then(data => {
20+
if (data.sisUrl) setRuntimeConfiguredSisUrl(data.sisUrl)
21+
})
22+
.catch(error => {
23+
throw new Error(error)
24+
})
25+
}, [])
26+
27+
const usableSisUrl = serviceProvider === 'fd' ? runtimeConfiguredSisUrl : sisUrl
28+
29+
return (
30+
<div data-cy="sisulink">
31+
<Item as="a" href={`${usableSisUrl}/tutor/role/staff/student/${id}/basic/basic-info`} target="_blank">
32+
<Icon name="external alternate" />
33+
Sisu
34+
</Item>
35+
</div>
36+
)
37+
}

services/frontend/src/components/material/StudentInfoItem.tsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,42 @@ import IconButton from '@mui/material/IconButton'
33
import Stack from '@mui/material/Stack'
44
import Typography from '@mui/material/Typography'
55

6+
import { useState, useEffect } from 'react'
67
import { Link } from 'react-router'
78

8-
import { sisUrl } from '@/conf'
9+
import { sisUrl, serviceProvider } from '@/conf'
910
import { ExternalLink } from './ExternalLink'
1011

11-
export const StudentInfoItem = ({ sisPersonId, studentNumber }: { sisPersonId: string; studentNumber: string }) => (
12-
<Stack direction="row" justifyContent="space-between">
13-
<Typography component="span" sx={{ alignContent: 'center', padding: '0 0.25em' }} variant="body2">
14-
{studentNumber}
15-
</Typography>
16-
<IconButton component={Link} target="_blank" to={`/students/${studentNumber}`}>
17-
<PersonIcon color="primary" fontSize="small" />
18-
</IconButton>
19-
<ExternalLink href={`${sisUrl}/tutor/role/staff/student/${sisPersonId}/basic/basic-info`} text="Sisu" />
20-
</Stack>
21-
)
12+
export const StudentInfoItem = ({ sisPersonId, studentNumber }: { sisPersonId: string; studentNumber: string }) => {
13+
const [runtimeConfiguredSisUrl, setRuntimeConfiguredSisUrl] = useState(sisUrl)
14+
15+
useEffect(() => {
16+
fetch('/frontend-config.json')
17+
.then(response => {
18+
if (!response.ok) {
19+
throw new Error('Json response was not ok')
20+
}
21+
return response.json()
22+
})
23+
.then(data => {
24+
if (data.sisUrl) setRuntimeConfiguredSisUrl(data.sisUrl)
25+
})
26+
.catch(error => {
27+
throw new Error(error)
28+
})
29+
}, [])
30+
31+
const usableSisUrl = serviceProvider === 'fd' ? runtimeConfiguredSisUrl : sisUrl
32+
33+
return (
34+
<Stack direction="row" justifyContent="space-between">
35+
<Typography component="span" sx={{ alignContent: 'center', padding: '0 0.25em' }} variant="body2">
36+
{studentNumber}
37+
</Typography>
38+
<IconButton component={Link} target="_blank" to={`/students/${studentNumber}`}>
39+
<PersonIcon color="primary" fontSize="small" />
40+
</IconButton>
41+
<ExternalLink href={`${usableSisUrl}/tutor/role/staff/student/${sisPersonId}/basic/basic-info`} text="Sisu" />
42+
</Stack>
43+
)
44+
}

services/frontend/src/pages/Students/StudentDetails/StudentInfoCard.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,43 @@ import CardContent from '@mui/material/CardContent'
66
import Stack from '@mui/material/Stack'
77
import Typography from '@mui/material/Typography'
88

9+
import { useState, useEffect } from 'react'
10+
911
import { callApi } from '@/apiConnection'
1012
import { ExternalLink } from '@/components/material/ExternalLink'
1113
import { useStudentNameVisibility } from '@/components/material/StudentNameVisibilityToggle'
12-
import { sisUrl } from '@/conf'
14+
import { sisUrl, serviceProvider } from '@/conf'
1315
import { DateFormat } from '@/constants/date'
1416
import { useGetAuthorizedUserQuery } from '@/redux/auth'
1517
import { reformatDate } from '@/util/timeAndDate'
1618
import { StudentPageStudent } from '@oodikone/shared/types/studentData'
1719
import { EnrollmentAccordion } from './EnrollmentAccordion'
1820

1921
export const StudentInfoCard = ({ student }: { student: StudentPageStudent }) => {
22+
const [runtimeConfiguredSisUrl, setRuntimeConfiguredSisUrl] = useState(sisUrl)
2023
const { visible: showName } = useStudentNameVisibility()
2124
const { isAdmin } = useGetAuthorizedUserQuery()
2225
const name = showName ? `${student.name}, ` : ''
2326
const email = showName && student.email ? `${student.email}` : ''
2427

28+
useEffect(() => {
29+
fetch('/frontend-config.json')
30+
.then(response => {
31+
if (!response.ok) {
32+
throw new Error('Json response was not ok')
33+
}
34+
return response.json()
35+
})
36+
.then(data => {
37+
if (data.sisUrl) setRuntimeConfiguredSisUrl(data.sisUrl)
38+
})
39+
.catch(error => {
40+
throw new Error(error)
41+
})
42+
}, [])
43+
44+
const usableSisUrl = serviceProvider === 'fd' ? runtimeConfiguredSisUrl : sisUrl
45+
2546
const formattedTimestamp = reformatDate(
2647
student.updatedAt,
2748
isAdmin ? DateFormat.DISPLAY_DATE_DEV : DateFormat.DISPLAY_DATE
@@ -41,7 +62,7 @@ export const StudentInfoCard = ({ student }: { student: StudentPageStudent }) =>
4162
</Typography>
4263
<ExternalLink
4364
cypress="sisu-link"
44-
href={`${sisUrl}/tutor/role/staff/student/${student.sisPersonId}/basic/basic-info`}
65+
href={`${usableSisUrl}/tutor/role/staff/student/${student.sisPersonId}/basic/basic-info`}
4566
text="Sisu"
4667
variant="h6"
4768
/>

0 commit comments

Comments
 (0)