Skip to content

Commit

Permalink
Fixing minor issues with review comment forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Dec 31, 2023
1 parent 64ed481 commit 03a4167
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/components/Solutions/SourceCodeBox/SourceCodeBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ const SourceCodeBox = ({
</div>
) : (
<SourceCodeViewer
id={id}
content={content.content}
name={name}
solutionId={solutionId}
Expand Down
3 changes: 2 additions & 1 deletion src/components/forms/Fields/CheckboxField.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CheckboxField = ({
return (
<FormGroup
className={error ? 'text-danger' : warning ? 'text-warning' : dirty && !ignoreDirty ? 'text-primary' : undefined}
controlId={input.name}>
controlId={props.id || input.name}>
<Component
{...props}
{...input}
Expand All @@ -34,6 +34,7 @@ const CheckboxField = ({
};

CheckboxField.propTypes = {
id: PropTypes.string,
input: PropTypes.shape({
name: PropTypes.string.isRequired,
value: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
Expand Down
18 changes: 15 additions & 3 deletions src/components/forms/OnOffCheckbox/OnOffCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,32 @@ import { WarningIcon } from '../../icons';
import 'react-toggle/style.css';
import './OnOffCheckbox.css'; // eslint-disable-line import/no-deprecated

const OnOffCheckbox = ({ children, name, className, disabled, checked, error, warning, dirty, ...props }) => (
const OnOffCheckbox = ({
children,
name,
className,
disabled,
checked,
error,
warning,
dirty,
id = name,
...props
}) => (
<FormLabel
className={classnames({
[className]: className && className.length > 0,
onOffCheckboxLabelDisabled: disabled,
onOffCheckboxLabel: !disabled,
})}>
<Toggle {...props} checked={checked} name={name} id={name} value={checked ? 'true' : 'false'} disabled={disabled} />
<Toggle {...props} checked={checked} name={name} id={id} value={checked ? 'true' : 'false'} disabled={disabled} />
<span className="onOffCheckboxLabelText">
{children}
{Boolean(error || warning) && (
<OverlayTrigger
placement="bottom"
overlay={
<Tooltip id={name} className="wider-tooltip">
<Tooltip id={`${id}-tooltip`} className="wider-tooltip">
{error || warning}
</Tooltip>
}>
Expand All @@ -40,6 +51,7 @@ OnOffCheckbox.propTypes = {
error: PropTypes.any,
warning: PropTypes.any,
dirty: PropTypes.bool,
id: PropTypes.string,
name: PropTypes.string,
className: PropTypes.string,
};
Expand Down
4 changes: 4 additions & 0 deletions src/components/forms/ReviewCommentForm/ReviewCommentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const newCommentFormInitialValues = {
};

const ReviewCommentForm = ({
form,
authorId = null,
createdAt = null,
onCancel = null,
Expand Down Expand Up @@ -77,6 +78,7 @@ const ReviewCommentForm = ({
<Row>
<Col>
<Field
id={`${form}-issue`}
name="issue"
component={CheckboxField}
onOff
Expand All @@ -97,6 +99,7 @@ const ReviewCommentForm = ({
{showSuppressor && (
<Col sm="auto">
<Field
id={`${form}-suppressNotification`}
name="suppressNotification"
component={CheckboxField}
onOff
Expand Down Expand Up @@ -155,6 +158,7 @@ const ReviewCommentForm = ({
);

ReviewCommentForm.propTypes = {
form: PropTypes.string,
createdAt: PropTypes.number,
authorId: PropTypes.string,
onCancel: PropTypes.func,
Expand Down
11 changes: 9 additions & 2 deletions src/components/helpers/SourceCodeViewer/SourceCodeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ class SourceCodeViewer extends React.Component {
};

linesRenderer = ({ rows, stylesheet, useInlineStyles }) => {
const { authorView = false, updateComment = null, removeComment = null, restrictCommentAuthor = null } = this.props;
const {
id,
authorView = false,
updateComment = null,
removeComment = null,
restrictCommentAuthor = null,
} = this.props;
const comments = groupCommentsByLine(this.props.comments || []);
return rows.map((node, i) => {
const lineNumber = i + 1;
Expand Down Expand Up @@ -128,7 +134,7 @@ class SourceCodeViewer extends React.Component {

{this.state.newComment && this.state.newComment === lineNumber && (
<ReviewCommentForm
form="review-comment-new"
form={`review-comment-new-${id}`}
initialValues={newCommentFormInitialValues}
onCancel={this.closeForms}
onSubmit={this.createNewComment}
Expand Down Expand Up @@ -171,6 +177,7 @@ class SourceCodeViewer extends React.Component {
}

SourceCodeViewer.propTypes = {
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
content: PropTypes.string,
solutionId: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SourceCodeViewerContainer extends Component {

<Modal.Body className={styles.modalBody}>
<div>
<SourceCodeViewer content="" name="loading" solutionId={solutionId} />
<SourceCodeViewer id={fileId} content="" name="loading" solutionId={solutionId} />
</div>
</Modal.Body>
</Modal>
Expand Down Expand Up @@ -163,7 +163,7 @@ class SourceCodeViewerContainer extends Component {
{content.malformedCharacters ? (
<pre className="border-top">{content.content}</pre>
) : (
<SourceCodeViewer content={content.content} name={fileName} solutionId={solutionId} />
<SourceCodeViewer id={fileId} content={content.content} name={fileName} solutionId={solutionId} />
)}
<div className="border-top pt-1 bg-light rounded-bottom"></div>
</Modal.Body>
Expand Down

0 comments on commit 03a4167

Please sign in to comment.