Skip to content

Commit

Permalink
Merge pull request #339 from ls1intum/code-cleanup
Browse files Browse the repository at this point in the history
Improve request changes form
  • Loading branch information
fabian-emilius authored Oct 31, 2024
2 parents 8e247f3 + 1d2f840 commit 4e5a07d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import {
useLoadedThesisContext,
useThesisUpdateAction,
} from '../../../../providers/ThesisProvider/hooks'
import { ActionIcon, Button, Checkbox, Group, Modal, Stack, TextInput } from '@mantine/core'
import {
Button,
Checkbox,
Modal,
Stack,
Textarea,
} from '@mantine/core'
import { doRequest } from '../../../../requests/request'
import { IThesis } from '../../../../requests/responses/thesis'
import { ApiError } from '../../../../requests/handler'
import { randomId } from '@mantine/hooks'
import { X } from 'phosphor-react'

interface IThesisFeedbackRequestButtonProps {
type: string
Expand All @@ -20,12 +24,7 @@ const ThesisFeedbackRequestButton = (props: IThesisFeedbackRequestButtonProps) =
const { thesis } = useLoadedThesisContext()

const [opened, setOpened] = useState(false)
const [newChanges, setNewChanges] = useState<
Array<{
id: string
feedback: string
}>
>([])
const [changes, setChanges] = useState('')
const [editChanges, setEditChanges] = useState<
Array<{
feedbackId: string
Expand All @@ -34,10 +33,12 @@ const ThesisFeedbackRequestButton = (props: IThesisFeedbackRequestButtonProps) =
>([])

useEffect(() => {
setNewChanges([{ feedback: '', id: randomId() }])
setChanges('')
setEditChanges([])
}, [opened])

const newChanges = changes.split('\n').filter((x) => x.trim())

const [loading, onSave] = useThesisUpdateAction(async () => {
for (const editChange of editChanges) {
await doRequest<IThesis>(
Expand All @@ -55,7 +56,7 @@ const ThesisFeedbackRequestButton = (props: IThesisFeedbackRequestButtonProps) =
data: {
type,
requestedChanges: newChanges.map((newChange) => ({
feedback: newChange.feedback,
feedback: newChange,
completed: false,
})),
},
Expand All @@ -77,6 +78,7 @@ const ThesisFeedbackRequestButton = (props: IThesisFeedbackRequestButtonProps) =
opened={opened}
onClose={() => setOpened(false)}
onClick={(e) => e.stopPropagation()}
size='xl'
>
<Stack>
{thesis.feedback
Expand All @@ -103,41 +105,16 @@ const ThesisFeedbackRequestButton = (props: IThesisFeedbackRequestButtonProps) =
}}
/>
))}
{newChanges.map((change) => (
<Group key={change.id} style={{ width: '100%' }}>
<TextInput
style={{ flexGrow: 1 }}
value={change.feedback}
onChange={(e) => {
change.feedback = e.target.value
setNewChanges([...newChanges])
}}
/>
<ActionIcon
onClick={() =>
setNewChanges((prev) => prev.filter((item) => item.id !== change.id))
}
>
<X />
</ActionIcon>
</Group>
))}
<Group>
<Button
variant='outline'
ml='auto'
onClick={() => setNewChanges((prev) => [...prev, { id: randomId(), feedback: '' }])}
>
+ Add Item
</Button>
</Group>
<Textarea
label='New Change Requests (split multiple requests by lines)'
rows={10}
value={changes}
onChange={(e) => setChanges(e.target.value)}
/>
<Button
fullWidth
loading={loading}
disabled={
(editChanges.length === 0 && newChanges.length === 0) ||
newChanges.some((change) => !change.feedback)
}
disabled={editChanges.length === 0 && newChanges.length === 0}
onClick={onSave}
>
Request Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public enum StringLimits {
THESIS_TITLE(500),
THESIS_GRADE(10),
SHORTTEXT(100),
LONGTEXT(3000);
LONGTEXT(2000),
UNLIMITED_TEXT(10000);

private final int limit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ public ResponseEntity<ThesisDto> updateThesisInfo(

thesis = thesisService.updateThesisInfo(
thesis,
RequestValidator.validateStringMaxLength(payload.abstractText(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.infoText(), StringLimits.LONGTEXT.getLimit())
RequestValidator.validateStringMaxLength(payload.abstractText(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.infoText(), StringLimits.UNLIMITED_TEXT.getLimit())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
Expand Down Expand Up @@ -654,9 +654,9 @@ public ResponseEntity<ThesisDto> createAssessment(
thesis = thesisService.submitAssessment(
authenticatedUser,
thesis,
RequestValidator.validateStringMaxLength(payload.summary(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.positives(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.negatives(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.summary(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.positives(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.negatives(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.gradeSuggestion(), StringLimits.THESIS_GRADE.getLimit())
);

Expand All @@ -681,7 +681,7 @@ public ResponseEntity<ThesisDto> addGrade(
thesis = thesisService.gradeThesis(
thesis,
RequestValidator.validateStringMaxLength(payload.finalGrade(), StringLimits.THESIS_GRADE.getLimit()),
RequestValidator.validateStringMaxLength(payload.finalFeedback(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.finalFeedback(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateNotNull(payload.visibility())
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public ResponseEntity<TopicDto> createTopic(
authenticatedUser,
RequestValidator.validateStringMaxLength(payload.title(), StringLimits.THESIS_TITLE.getLimit()),
RequestValidator.validateStringSetItemMaxLengthAllowNull(payload.thesisTypes(), StringLimits.SHORTTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.problemStatement(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.requirements(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.goals(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.references(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.problemStatement(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.requirements(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.goals(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.references(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateNotNull(payload.supervisorIds()),
RequestValidator.validateNotNull(payload.advisorIds())
);
Expand All @@ -104,10 +104,10 @@ public ResponseEntity<TopicDto> updateTopic(
topic,
RequestValidator.validateStringMaxLength(payload.title(), StringLimits.THESIS_TITLE.getLimit()),
RequestValidator.validateStringSetItemMaxLengthAllowNull(payload.thesisTypes(), StringLimits.SHORTTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.problemStatement(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.requirements(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.goals(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.references(), StringLimits.LONGTEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.problemStatement(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.requirements(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.goals(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateStringMaxLength(payload.references(), StringLimits.UNLIMITED_TEXT.getLimit()),
RequestValidator.validateNotNull(payload.supervisorIds()),
RequestValidator.validateNotNull(payload.advisorIds())
);
Expand Down

0 comments on commit 4e5a07d

Please sign in to comment.