Skip to content

Commit

Permalink
Changes for comment report settings (#2149)
Browse files Browse the repository at this point in the history
* Changes to show all survey results to superusers

* removing hard coded values

* fixing linting

* splitting to seperate end points

* fixing auth check

* fixing linting

* merging method in service

* Handle no data error for graphs

* adding new nodata component

* adding new email for submission response

* fixing linting and testing

* Changes for comment report settings

* fixing linting

* changing conditional check to react-if
  • Loading branch information
VineetBala-AOT authored Sep 8, 2023
1 parent 0f62b05 commit 4cf9bde
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 13 deletions.
29 changes: 26 additions & 3 deletions met-api/src/met_api/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

from sqlalchemy import and_, asc, desc
from sqlalchemy.sql import text
from sqlalchemy.sql.expression import true
from sqlalchemy.sql.schema import ForeignKey
from sqlalchemy.ext.hybrid import hybrid_property

from met_api.constants.comment_status import Status as CommentStatus
from met_api.constants.engagement_status import Status as EngagementStatus
from met_api.models.pagination_options import PaginationOptions
from met_api.models.engagement import Engagement
from met_api.models.report_setting import ReportSetting
from met_api.models.submission import Submission
from met_api.models.survey import Survey
from met_api.schemas.comment import CommentSchema
Expand All @@ -35,6 +38,21 @@ class Comment(BaseModel):
submission_id = db.Column(db.Integer, ForeignKey('submission.id', ondelete='SET NULL'), nullable=True)
component_id = db.Column(db.String(10))

@hybrid_property
def is_displayed(self):
"""Get report settings."""
return self._display()

def _display(self):
"""Return report settings for single/multi line comment type questions."""
report_setting = db.session.query(ReportSetting).filter(
ReportSetting.question_key == self.component_id,
ReportSetting.survey_id == self.survey_id).one_or_none()
if report_setting:
return f'{report_setting.display}'

return None

@classmethod
def get_by_submission(cls, submission_id):
"""Get comments by submission id."""
Expand All @@ -48,7 +66,9 @@ def get_comments_by_survey_id_paginated(cls, survey_id, pagination_options: Pagi
"""Get comments paginated."""
query = db.session.query(Comment)\
.join(Survey)\
.filter(Comment.survey_id == survey_id)\
.join(ReportSetting, and_(Comment.survey_id == ReportSetting.survey_id,
Comment.component_id == ReportSetting.question_key))\
.filter(and_(Comment.survey_id == survey_id, ReportSetting.display == true()))

if search_text:
query = query.filter(Comment.text.ilike('%' + search_text + '%'))
Expand Down Expand Up @@ -76,12 +96,15 @@ def get_accepted_comments_by_survey_id_where_engagement_closed_paginated(
.join(CommentStatusModel, Submission.comment_status_id == CommentStatusModel.id)\
.join(Survey, Survey.id == Submission.survey_id)\
.join(Engagement, Engagement.id == Survey.engagement_id)\
.join(ReportSetting, and_(Comment.survey_id == ReportSetting.survey_id,
Comment.component_id == ReportSetting.question_key))\
.filter(
and_(
Comment.survey_id == survey_id,
CommentStatusModel.id == CommentStatus.Approved.value,
Engagement.status_id == EngagementStatus.Closed.value
))\
Engagement.status_id == EngagementStatus.Closed.value,
ReportSetting.display == true()
))

query = query.order_by(Comment.id.desc())

Expand Down
1 change: 1 addition & 0 deletions met-api/src/met_api/schemas/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Meta: # pylint: disable=too-few-public-methods
status_id = fields.Int(data_key='status_id')
survey_id = fields.Int(data_key='survey_id')
submission_id = fields.Int(data_key='submission_id')
is_displayed = fields.Bool(data_key='is_displayed')
status_id = fields.Method('get_comment_status_id')
reviewed_by = fields.Method('get_comment_reviewed_by')
label = fields.Method('get_comment_label')
Expand Down
49 changes: 44 additions & 5 deletions met-web/src/components/comments/admin/review/CommentReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
MetHeader3,
MetHeader4,
MetSmallText,
MetTooltip,
} from 'components/common';
import { CommentStatus } from 'constants/commentStatus';
import { StaffNoteType } from 'constants/staffNoteType';
Expand All @@ -39,6 +40,8 @@ import { RejectEmailTemplate } from './emailPreview/EmailTemplates';
import EmailPreview from './emailPreview/EmailPreview';
import { Survey, createDefaultSurvey } from 'models/survey';
import { getSurvey } from 'services/surveyService';
import CommentIcon from '@mui/icons-material/Comment';
import CommentsDisabledIcon from '@mui/icons-material/CommentsDisabled';

const CommentReview = () => {
const [submission, setSubmission] = useState<SurveySubmission>(createDefaultSubmission());
Expand Down Expand Up @@ -270,11 +273,47 @@ const CommentReview = () => {
return (
<Grid key={comment.id} item xs={12}>
<Divider />
<Grid xs={12} item paddingTop={2}>
<MetLabel>{comment.label ?? 'Label not available.'}</MetLabel>
</Grid>
<Grid xs={12} item>
<MetParagraph>{comment.text}</MetParagraph>
<Grid container direction="row" alignItems={'flex-start'} justifyContent="flex-start">
<Grid item xs={1} paddingTop={3}>
<If condition={comment.is_displayed}>
<Then>
<Grid xs={12} item>
<MetTooltip
disableInteractive
title={'Displayed to the public'}
placement="top"
arrow
>
<span>
<CommentIcon color="info" />
</span>
</MetTooltip>
</Grid>
</Then>
<Else>
<Grid xs={12} item>
<MetTooltip
disableInteractive
title={'Not displayed to the public'}
placement="top"
arrow
>
<span>
<CommentsDisabledIcon color="info" />
</span>
</MetTooltip>
</Grid>
</Else>
</If>
</Grid>
<Grid item xs={11}>
<Grid xs={12} item paddingTop={2}>
<MetLabel>{comment.label ?? 'Label not available.'}</MetLabel>
</Grid>
<Grid xs={12} item>
<MetParagraph>{comment.text}</MetParagraph>
</Grid>
</Grid>
</Grid>
</Grid>
);
Expand Down
46 changes: 41 additions & 5 deletions met-web/src/components/comments/admin/textListing/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React, { useState, useEffect } from 'react';
import MetTable from 'components/common/Table';
import { Link, useLocation, useParams } from 'react-router-dom';
import { MetPageGridContainer, PrimaryButton, MetParagraph, MetLabel } from 'components/common';
import { MetPageGridContainer, PrimaryButton, MetParagraph, MetLabel, MetTooltip } from 'components/common';
import { HeadCell, PageInfo, PaginationOptions } from 'components/common/Table/types';
import { Link as MuiLink, Grid, Stack, TextField } from '@mui/material';
import SearchIcon from '@mui/icons-material/Search';
import { useAppDispatch, useAppSelector } from 'hooks';
import { openNotification } from 'services/notificationService/notificationSlice';
import { CommentStatusChip } from '../../status';
import { CommentStatus } from 'constants/commentStatus';
import { When } from 'react-if';
import { If, Then, Else, When } from 'react-if';
import { getSubmissionPage } from 'services/submissionService';
import { SurveySubmission } from 'models/surveySubmission';
import { formatDate } from 'components/common/dateHelper';
import { USER_ROLES } from 'services/userService/constants';
import { USER_GROUP } from 'models/user';
import { updateURLWithPagination } from 'components/common/Table/utils';
import CommentIcon from '@mui/icons-material/Comment';
import CommentsDisabledIcon from '@mui/icons-material/CommentsDisabled';

const CommentTextListing = () => {
const { roles, userDetail, assignedEngagements } = useAppSelector((state) => state.user);
Expand Down Expand Up @@ -122,9 +124,43 @@ const CommentTextListing = () => {
{row.comments?.map((comment, index) => {
return (
<Grid key={index} item xs={12}>
<Grid xs={12} item>
<MetLabel>{comment.label ?? 'Label not available.'} </MetLabel>
<MetParagraph>{' ' + comment.text}</MetParagraph>
<Grid container direction="row" alignItems={'flex-start'} justifyContent="flex-start">
<Grid item xs={1} paddingTop={1}>
<If condition={comment.is_displayed}>
<Then>
<Grid xs={12} item>
<MetTooltip
disableInteractive
title={'Displayed to the public'}
placement="top"
arrow
>
<span>
<CommentIcon color="info" />
</span>
</MetTooltip>
</Grid>
</Then>
<Else>
<Grid xs={12} item>
<MetTooltip
disableInteractive
title={'Not displayed to the public'}
placement="top"
arrow
>
<span>
<CommentsDisabledIcon color="info" />
</span>
</MetTooltip>
</Grid>
</Else>
</If>
</Grid>
<Grid item xs={11}>
<MetLabel>{comment.label ?? 'Label not available.'} </MetLabel>
<MetParagraph>{' ' + comment.text}</MetParagraph>
</Grid>
</Grid>
</Grid>
);
Expand Down
2 changes: 2 additions & 0 deletions met-web/src/models/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Comment {
label: string;
status_id: number;
reviewed_by: string;
is_displayed: boolean;
}

export const createDefaultComment = (): Comment => {
Expand All @@ -21,5 +22,6 @@ export const createDefaultComment = (): Comment => {
label: '',
status_id: 1,
reviewed_by: '',
is_displayed: true,
};
};

0 comments on commit 4cf9bde

Please sign in to comment.