Skip to content

Commit

Permalink
Merge pull request #321 from ls1intum/code-cleanup
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
fabian-emilius authored Oct 22, 2024
2 parents a7a0462 + d965219 commit bce7660
Show file tree
Hide file tree
Showing 18 changed files with 484 additions and 479 deletions.
557 changes: 266 additions & 291 deletions client/package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"@mantine/hooks": "7.13.3",
"@mantine/notifications": "7.13.3",
"@mantine/tiptap": "7.13.3",
"@tiptap/extension-highlight": "2.8.0",
"@tiptap/extension-subscript": "2.8.0",
"@tiptap/extension-superscript": "2.8.0",
"@tiptap/extension-text-align": "2.8.0",
"@tiptap/extension-underline": "2.8.0",
"@tiptap/starter-kit": "2.8.0",
"@tiptap/extension-highlight": "2.9.0",
"@tiptap/extension-subscript": "2.9.0",
"@tiptap/extension-superscript": "2.9.0",
"@tiptap/extension-text-align": "2.9.0",
"@tiptap/extension-underline": "2.9.0",
"@tiptap/starter-kit": "2.9.0",
"i18n-iso-countries": "7.12.0",
"jszip": "3.10.1",
"jwt-decode": "4.0.0",
Expand All @@ -45,8 +45,8 @@
"@types/react": "18.3.11",
"@types/react-avatar-editor": "^13.0.3",
"@types/react-dom": "18.3.1",
"@typescript-eslint/eslint-plugin": "8.10.0",
"@typescript-eslint/parser": "8.10.0",
"@typescript-eslint/eslint-plugin": "8.11.0",
"@typescript-eslint/parser": "8.11.0",
"clean-webpack-plugin": "4.0.0",
"compression-webpack-plugin": "11.1.0",
"copy-webpack-plugin": "12.0.2",
Expand Down
2 changes: 2 additions & 0 deletions client/public/generate-runtime-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const ALLOWED_ENVIRONMENT_VARIABLES = [
'STUDY_DEGREES',
'STUDY_PROGRAMS',
'LANGUAGES',
'THESIS_TYPES',
'CUSTOM_DATA',
'THESIS_FILES',
'CALDAV_URL',
]

Expand Down
6 changes: 3 additions & 3 deletions client/src/components/ApplicationData/ApplicationData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const ApplicationData = (props: IApplicationDataProps) => {
{application.user.hasCv && (
<AuthenticatedFilePreview
url={`/v2/users/${application.user.userId}/cv`}
filename={`${formatApplicationFilename(application, 'Application CV')}.pdf`}
filename={formatApplicationFilename(application, 'CV', 'file.pdf')}
type='pdf'
aspectRatio={16 / 11}
key={application.user.userId}
Expand All @@ -166,7 +166,7 @@ const ApplicationData = (props: IApplicationDataProps) => {
{application.user.hasExaminationReport && (
<AuthenticatedFilePreview
url={`/v2/users/${application.user.userId}/examination-report`}
filename={`${formatApplicationFilename(application, 'Application Examination Report')}.pdf`}
filename={formatApplicationFilename(application, 'Examination Report', 'file.pdf')}
type='pdf'
aspectRatio={16 / 11}
key={application.user.userId}
Expand All @@ -175,7 +175,7 @@ const ApplicationData = (props: IApplicationDataProps) => {
{application.user.hasDegreeReport && (
<AuthenticatedFilePreview
url={`/v2/users/${application.user.userId}/degree-report`}
filename={`${formatApplicationFilename(application, 'Application Degree Report')}.pdf`}
filename={formatApplicationFilename(application, 'Degree Report', 'file.pdf')}
type='pdf'
aspectRatio={16 / 11}
key={application.user.userId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getApiResponseErrorMessage } from '../../requests/handler'
import ApplicationRejectButton from '../ApplicationRejectButton/ApplicationRejectButton'
import { useLoggedInUser } from '../../hooks/authentication'
import AvatarUser from '../AvatarUser/AvatarUser'
import { formatDate } from '../../utils/format'
import { formatDate, formatThesisType } from '../../utils/format'

interface IApplicationReviewFormProps {
application: IApplication
Expand Down Expand Up @@ -252,9 +252,9 @@ const ApplicationReviewForm = (props: IApplicationReviewFormProps) => {
<Select
label='Thesis Type'
required={true}
data={Object.entries(GLOBAL_CONFIG.thesis_types).map(([key, value]) => ({
data={Object.keys(GLOBAL_CONFIG.thesis_types).map((key) => ({
value: key,
label: value,
label: formatThesisType(key),
}))}
{...form.getInputProps('type')}
/>
Expand Down
80 changes: 36 additions & 44 deletions client/src/components/PresentationsTable/PresentationsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useState } from 'react'
import { DataTable, DataTableColumn } from 'mantine-datatable'
import {
hasAdvisorAccess,
hasStudentAccess,
IPublishedPresentation,
IPublishedThesis,
isPublishedPresentation,
Expand All @@ -20,6 +18,7 @@ import { useThesisUpdateAction } from '../../providers/ThesisProvider/hooks'
import { doRequest } from '../../requests/request'
import { ApiError } from '../../requests/handler'
import { useUser } from '../../hooks/authentication'
import { hasAdvisorAccess, hasStudentAccess, isThesisClosed } from '../../utils/thesis'

type PresentationColumn =
| 'state'
Expand Down Expand Up @@ -159,18 +158,18 @@ const PresentationsTable = <T extends IThesisPresentation | IPublishedPresentati
textAlign: 'center',
width: 180,
ellipsis: true,
render: (presentation) => (
<Center onClick={(e) => e.stopPropagation()}>
{hasStudentAccess(
theses.find((thesis) => thesis.thesisId === presentation.thesisId),
user,
) && (
<Group gap='xs'>
{presentation.state === 'DRAFTED' &&
hasAdvisorAccess(
theses.find((thesis) => thesis.thesisId === presentation.thesisId),
user,
) && (
render: (presentation) => {
const thesis = theses.find((row) => row.thesisId === presentation.thesisId)

if (!thesis || isThesisClosed(thesis)) {
return null
}

return (
<Center onClick={(e) => e.stopPropagation()}>
{hasStudentAccess(thesis, user) && (
<Group gap='xs'>
{presentation.state === 'DRAFTED' && hasAdvisorAccess(thesis, user) && (
<Button
loading={loading}
size='xs'
Expand All @@ -179,36 +178,29 @@ const PresentationsTable = <T extends IThesisPresentation | IPublishedPresentati
<Check />
</Button>
)}
{(presentation.state === 'DRAFTED' ||
hasAdvisorAccess(
theses.find((thesis) => thesis.thesisId === presentation.thesisId),
user,
)) && (
<Button
loading={loading}
size='xs'
onClick={() => setEditPresentationModal(presentation)}
>
<Pencil />
</Button>
)}
{(presentation.state === 'DRAFTED' ||
hasAdvisorAccess(
theses.find((thesis) => thesis.thesisId === presentation.thesisId),
user,
)) && (
<Button
loading={loading}
size='xs'
onClick={() => deletePresentation(presentation)}
>
<Trash />
</Button>
)}
</Group>
)}
</Center>
),
{(presentation.state === 'DRAFTED' || hasAdvisorAccess(thesis, user)) && (
<Button
loading={loading}
size='xs'
onClick={() => setEditPresentationModal(presentation)}
>
<Pencil />
</Button>
)}
{(presentation.state === 'DRAFTED' || hasAdvisorAccess(thesis, user)) && (
<Button
loading={loading}
size='xs'
onClick={() => deletePresentation(presentation)}
>
<Trash />
</Button>
)}
</Group>
)}
</Center>
)
},
},
...(extraColumns ?? {}),
}
Expand Down
32 changes: 8 additions & 24 deletions client/src/components/ThesisCommentsList/ThesisCommentsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { downloadFile } from '../../utils/blob'
import { doRequest } from '../../requests/request'
import { showSimpleError } from '../../utils/notification'
import { getApiResponseErrorMessage } from '../../requests/handler'
import AuthenticatedFileDownloadButton from '../AuthenticatedFileDownloadButton/AuthenticatedFileDownloadButton'

const ThesisCommentsList = () => {
const { thesis, comments, deleteComment, limit, page, setPage } = useThesisCommentsContext()
Expand All @@ -17,27 +18,6 @@ const ThesisCommentsList = () => {

const commentBackgroundColor = useHighlightedBackgroundColor(false)

const downloadCommentFile = async (comment: IThesisComment) => {
if (!comment.uploadName) {
return
}

const response = await doRequest<Blob>(
`/v2/theses/${thesis.thesisId}/comments/${comment.commentId}/file`,
{
method: 'GET',
requiresAuth: true,
responseType: 'blob',
},
)

if (response.ok) {
downloadFile(new File([response.data], comment.uploadName))
} else {
showSimpleError(getApiResponseErrorMessage(response))
}
}

return (
<Stack>
{!comments &&
Expand All @@ -49,10 +29,14 @@ const ThesisCommentsList = () => {
<Paper p='md' radius='sm' style={{ backgroundColor: commentBackgroundColor }}>
<Group style={{ width: '100%' }}>
<Text>{comment.message}</Text>
{comment.filename && (
<Button onClick={() => downloadCommentFile(comment)} ml='auto'>
{comment.uploadName && (
<AuthenticatedFileDownloadButton
url={`/v2/theses/${thesis.thesisId}/comments/${comment.commentId}/file`}
filename={comment.uploadName}
ml='auto'
>
<Download />
</Button>
</AuthenticatedFileDownloadButton>
)}
</Group>
</Paper>
Expand Down
25 changes: 20 additions & 5 deletions client/src/config/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,23 @@ export const GLOBAL_CONFIG: IGlobalConfig = {
OTHER: 'Other',
},

thesis_types: getEnvironmentVariable<Record<string, string>>('THESIS_TYPES', true) || {
BACHELOR: 'Bachelor Thesis',
MASTER: 'Master Thesis',
INTERDISCIPLINARY_PROJECT: 'Interdisciplinary Project',
GUIDED_RESEARCH: 'Guided Research',
thesis_types: getEnvironmentVariable<IGlobalConfig['thesis_types']>('THESIS_TYPES', true) || {
BACHELOR: {
long: 'Bachelor Thesis',
short: 'BA',
},
MASTER: {
long: 'Master Thesis',
short: 'MA',
},
INTERDISCIPLINARY_PROJECT: {
long: 'Interdisciplinary Project',
short: 'IDP',
},
GUIDED_RESEARCH: {
long: 'Guided Research',
short: 'GR',
},
},

languages: getEnvironmentVariable<Record<string, string>>('LANGUAGES', true) || {
Expand All @@ -64,16 +76,19 @@ export const GLOBAL_CONFIG: IGlobalConfig = {
thesis_files: getEnvironmentVariable<IGlobalConfig['thesis_files']>('THESIS_FILES', true) || {
PRESENTATION: {
label: 'Presentation',
description: 'Presentation (PDF)',
accept: 'pdf',
required: true,
},
PRESENTATION_SOURCE: {
label: 'Presentation Source',
description: 'Presentation Source (KEY, PPTX)',
accept: 'any',
required: false,
},
FEEDBACK_LOG: {
label: 'Feedback Log',
description: 'Feedback Log (PDF)',
accept: 'pdf',
required: false,
},
Expand Down
10 changes: 9 additions & 1 deletion client/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ export interface IGlobalConfig {
genders: Record<string, string>
study_programs: Record<string, string>
study_degrees: Record<string, string>
thesis_types: Record<string, string>
languages: Record<string, string>

thesis_types: Record<
string,
{
long: string
short: string
}
>

custom_data: Record<
string,
{
Expand All @@ -26,6 +33,7 @@ export interface IGlobalConfig {
string,
{
label: string
description: string
accept: UploadFileType
required: boolean
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { Link } from 'react-router-dom'
import { ApiError } from '../../../../requests/handler'
import DownloadAllFilesButton from './components/DownloadAllFilesButton/DownloadAllFilesButton'
import { isThesisClosed } from '../../../../utils/thesis'

const ThesisInfoSection = () => {
const { thesis, access } = useLoadedThesisContext()
Expand Down Expand Up @@ -75,14 +76,14 @@ const ThesisInfoSection = () => {
</Grid.Col>
<Grid.Col span={{ md: 6 }}>
<Flex justify='flex-end'>
{access.student && !editMode && (
<Group>
<DownloadAllFilesButton />
<Group>
<DownloadAllFilesButton />
{access.student && !editMode && !isThesisClosed(thesis) && (
<Button ml='auto' onClick={() => setEditMode(true)}>
Edit
</Button>
</Group>
)}
)}
</Group>
{editMode && (
<Group>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const DownloadAllFilesButton = () => {
if (thesisFile) {
data.push({
url: `/v2/theses/${thesis.thesisId}/files/${thesisFile.fileId}`,
filename: formatThesisFilename(thesis, 'Final', thesisFile.filename, 0),
filename: formatThesisFilename(thesis, 'Thesis', thesisFile.filename, 0),
})
}

Expand Down
Loading

0 comments on commit bce7660

Please sign in to comment.