Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOIMOD-3412 and FOIMOD-2982 : Comments Tab - Type of Comments (Peer Review, Internal, General) fixes #5377

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './comments.scss'
import { ActionContext } from './ActionContext'
import { setFOILoader } from '../../../../actions/FOI/foiRequestActions'
import Editor, { createEditorStateWithText } from '@draft-js-plugins/editor';
import { convertToRaw, EditorState } from "draft-js";
import { convertToRaw, EditorState, RichUtils } from "draft-js";
import createMentionPlugin, {
defaultSuggestionsFilter
} from '@draft-js-plugins/mention';
Expand All @@ -15,8 +15,8 @@ import {
UnderlineButton,
UnorderedListButton,
OrderedListButton,

} from '@draft-js-plugins/buttons';
//import createLinkPlugin from '@draft-js-plugins/anchor';
import {namesort,suggestionList } from './commentutils'

import { getFullnameList, getCommentTypeIdByName } from '../../../../helper/FOI/helper'
Expand All @@ -29,7 +29,6 @@ import Confirm from '../../../../containers/Confirm'
import CustomizedTooltip from '../Tooltip/MuiTooltip/Tooltip';



const staticToolbarPlugin = createToolbarPlugin();
const mentionPlugin = createMentionPlugin();
const { Toolbar } = staticToolbarPlugin;
Expand All @@ -41,12 +40,10 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
const [uftext, setuftext] = useState('')
const [textlength, setTextLength] = useState(1000)
const [open, setOpen] = useState(false);
//console.log("ADD-fullnameList:",fullnameList)

const isCommentTagListLoading = useSelector((state) => state.foiRequests.isCommentTagListLoading);
let fulluserlist = suggestionList([...fullnameList]).sort(namesort)
// console.log("ADD-fulluserlist:",fulluserlist)
// console.log("ADD-restrictedReqTaglist:",restrictedReqTaglist)


const [mentionList, setMentionList] = useState(isCommentTagListLoading ? [{name: 'Loading...'}] : isRestricted ? restrictedReqTaglist :fulluserlist);
const [suggestions, setSuggestions] = useState(mentionList);
Expand All @@ -60,7 +57,6 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
setSuggestions(isCommentTagListLoading ? [{name: 'Loading...'}] : isRestricted ? restrictedReqTaglist :suggestionList([...fulluserlist]).sort(namesort));
}, [fullnameList])

//console.log("ADD-mentionList:",mentionList)

const onOpenChange = (_open) => {
setOpen(_open);
Expand Down Expand Up @@ -141,18 +137,24 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
return length;
}

const _handleKeyCommand = (e) => {
const _handleKeyCommand = (e) => {

const currentContent = editorState.getCurrentContent();
const currentContentLength = currentContent.getPlainText('').length;
const selectedTextLength = _getLengthOfSelectedText();
if ((e === 'backspace' || e === 'delete') && currentContentLength - 1 >= 0) {
setTextLength((maxcharacterlimit) - (currentContentLength - 1))
}

if ((e === 'backspace' || e === 'delete') && selectedTextLength > 0) {
setTextLength(maxcharacterlimit - (currentContentLength - selectedTextLength))
}
setuftext(currentContent.getPlainText(''))
//For enabling keyboard shortcuts
const newState = RichUtils.handleKeyCommand(editorState, e);
if (newState) {
setEditorState(newState);
return 'handled';
}
}

const _handleBeforeInput = () => {
Expand Down Expand Up @@ -203,8 +205,7 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
if (add) {
setEditorState(EditorState.createEmpty())
setuftext('')
}

}
setRemoveComment(false);
}
})
Expand All @@ -222,10 +223,6 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
const cancelComment = () => {
setshowaddbox(false)
setEditorState(createEditorStateWithText(''))
// setConfirmModalOpen(false);

// setEditorChange(false)
//setTextLength(1000);
}

const openConfirmModal = () =>{
Expand All @@ -244,9 +241,8 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
</div>]
};

const isActive = editorState.getCurrentInlineStyle().has('BOLD');
console.log('BoldButton isActive:', isActive);

//const isActive = editorState.getCurrentInlineStyle().has('BOLD');


return (
<>
Expand Down Expand Up @@ -284,7 +280,6 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
<p className="hideContent" id="commenttype-info">CommentTypeInfo</p>
</div>
</Grid>

<Editor
editorState={editorState}
onChange={_handleChange}
Expand All @@ -294,22 +289,31 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
plugins={plugins}
spellCheck={true}
/>
<Toolbar>
{
(externalProps) => {
console.log('externalProps:', externalProps)
return(
<div>
<BoldButton {...externalProps} />
<ItalicButton {...externalProps} />
<UnderlineButton {...externalProps} />
<UnorderedListButton {...externalProps} />
<OrderedListButton {...externalProps} />
</div>
)
<div style={{ display: 'flex', alignItems: 'center' }}>
<Toolbar>
{
(externalProps) => {
console.log('externalProps:', externalProps)
return(
<>
<div>
<BoldButton {...externalProps} />
<ItalicButton {...externalProps} />
<UnderlineButton {...externalProps} />
<UnorderedListButton {...externalProps} />
<OrderedListButton {...externalProps} />
</div>
</>
)
}
}
}
</Toolbar>
</Toolbar>
<div className={'col-lg-9'} style={{ marginLeft: '10px' }}>
<span className={textlength > 25 ? "characterlen" : "characterlen textred"}>
{textlength} characters remaining
</span>
</div>
</div>
<MentionSuggestions
open={open}
onOpenChange={onOpenChange}
Expand All @@ -322,21 +326,21 @@ const AddCommentField = ({ cancellor, parentId, add, fullnameList , restrictedRe
/>

</form>
<div className="inputActions">
<div className={'col-lg-9'}>
<div className="newCommentInputActions">
{/* <div className={'col-lg-9'}>
<span className={textlength > 25 ? "characterlen" : "characterlen textred"}>{textlength} characters remaining</span>
</div>
</div> */}
<button
className="btn-cancel"
className="btnCancel"
onClick={() => openConfirmModal() }
>
Cancel
</button>
<div className="col-lg-3">
<div>
{/* paperplanecontainer */}
<button
className= "btn-bottom btn btn-save" //"postBtn"
style={{width:'80%', padding: '0px'}}
style={{width:'200px', marginLeft:'10px', marginRight:'0px'}}
onClick={post}
type='button'
disabled={uftext.trim().length === 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faTimes } from '@fortawesome/free-solid-svg-icons'
import { setFOILoader } from '../../../../actions/FOI/foiRequestActions'
import Editor, { createEditorStateWithText } from '@draft-js-plugins/editor';
import { convertToRaw, convertFromRaw, EditorState } from "draft-js";
import { convertToRaw, convertFromRaw, EditorState, RichUtils } from "draft-js";
import createMentionPlugin, {
defaultSuggestionsFilter
} from '@draft-js-plugins/mention';
Expand Down Expand Up @@ -177,6 +177,12 @@ const InputField = ({ cancellor, parentId, child, inputvalue, edit, main, add, f
setTextLength(maxcharacterlimit - (currentContentLength - selectedTextLength))
}
setuftext(currentContent.getPlainText(''))
//For enabling keyboard shortcuts
const newState = RichUtils.handleKeyCommand(editorState, e);
if (newState) {
setEditorState(newState);
return 'handled';
}
}

const _handleBeforeInput = () => {
Expand Down Expand Up @@ -333,6 +339,7 @@ const InputField = ({ cancellor, parentId, child, inputvalue, edit, main, add, f
plugins={plugins}
spellCheck={true}
/>
<div style={{ display: 'flex', alignItems: 'center' }}>
<Toolbar>
{
(externalProps) => (
Expand All @@ -346,6 +353,10 @@ const InputField = ({ cancellor, parentId, child, inputvalue, edit, main, add, f
)
}
</Toolbar>
<div className={'col-lg-9'}>
<span className={textlength > 25 ? "characterlen" : "characterlen textred"}>{textlength} characters remaining</span>
</div>
</div>
<MentionSuggestions
open={open}
onOpenChange={onOpenChange}
Expand All @@ -359,9 +370,7 @@ const InputField = ({ cancellor, parentId, child, inputvalue, edit, main, add, f

</form>
<div className="inputActions">
<div className={'col-lg-11'}>
<span className={textlength > 25 ? "characterlen" : "characterlen textred"}>{textlength} characters remaining</span>
</div>

<div className="col-lg-1 paperplanecontainer">
<button
className="postBtn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
margin-top: 15px;
}

.newCommentInputActions{
display: flex;
justify-content: right;
align-items: center;
}

.inputActions {
display: flex;
background-color: white;
Expand Down Expand Up @@ -239,7 +245,7 @@
color: #fff !important;
}

.btn-cancel {
.btnCancel {
border: 1px solid #38598a;
background-color: #ffffff;
color: #38598a;
Expand All @@ -249,6 +255,7 @@
flex-basis: 50%;
font-family: BCSans-Bold, sans-serif !important;
margin-top: 10px;
max-width: 200px;
}

.actionDiv {
Expand Down Expand Up @@ -583,7 +590,7 @@ div.nofiltermessage {

button.bc4rxid {
background-color: transparent; //!important;
color: red; //#003366 !important;
color:#003366; //!important;
font-size: 14px;
border: 0;
padding-top: 5px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def deactivatecomment(cls, commentid, userid, commentsversion):

@classmethod
def updatecomment(cls, commentid, foirequestcomment, userid):
print("---updatecomment",foirequestcomment)
dbquery = db.session.query(FOIRawRequestComment)
comment = dbquery.filter_by(commentid=commentid).order_by(FOIRawRequestComment.commentsversion.desc()).first()
_commentsversion = 0
Expand Down Expand Up @@ -100,7 +101,7 @@ def updatecomment(cls, commentid, foirequestcomment, userid):
set_={"requestid": comment.requestid, "version":comment.version, "comment": foirequestcomment["comment"],
"taggedusers":_taggedusers, "parentcommentid":comment.parentcommentid, "isactive":True,
"created_at":datetime.now(), "createdby": userid, "updated_at": datetime.now(), "updatedby": userid,
"commenttypeid": comment.commenttypeid
"commenttypeid": foirequestcomment["commenttypeid"]
}
)
db.session.execute(updatestmt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def savecomment(cls, commenttypeid, foirequestcomment, version, userid,commentcr
parentcommentid = foirequestcomment["parentcommentid"] if 'parentcommentid' in foirequestcomment else None
taggedusers = foirequestcomment["taggedusers"] if 'taggedusers' in foirequestcomment else None
_createddate = datetime2.now().isoformat() if commentcreatedate is None else commentcreatedate
newcomment = FOIRequestComment(commenttypeid=foirequestcomment["commenttypeid"], ministryrequestid=foirequestcomment["ministryrequestid"],
newcomment = FOIRequestComment(commenttypeid=commenttypeid, ministryrequestid=foirequestcomment["ministryrequestid"],
version=version, comment=foirequestcomment["comment"], parentcommentid=parentcommentid, isactive=True, created_at=_createddate, createdby=userid,taggedusers=taggedusers, commentsversion=commentsversion)
db.session.add(newcomment)
db.session.commit()
Expand Down Expand Up @@ -75,6 +75,7 @@ def deactivatecomment(cls, commentid, userid, commentsversion):

@classmethod
def updatecomment(cls, commentid, foirequestcomment, userid):
print("updatecomment:",foirequestcomment)
dbquery = db.session.query(FOIRequestComment)
comment = dbquery.filter_by(commentid=commentid).order_by(FOIRequestComment.commentsversion.desc()).first()
_existingtaggedusers = []
Expand Down Expand Up @@ -105,7 +106,7 @@ def updatecomment(cls, commentid, foirequestcomment, userid):
set_={"ministryrequestid": comment.ministryrequestid,"version":comment.version, "comment": foirequestcomment["comment"],
"taggedusers":_taggedusers, "parentcommentid":comment.parentcommentid, "isactive":True,
"created_at":datetime2.now(), "createdby": userid, "updated_at": datetime2.now(), "updatedby": userid,
"commenttypeid": comment.commenttypeid
"commenttypeid": foirequestcomment["commenttypeid"]
}
)
db.session.execute(updatestmt)
Expand Down
6 changes: 3 additions & 3 deletions request-management-api/request_api/resources/foicomment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class CreateFOIRequestComment(Resource):
def post():
try:
requestjson = request.get_json()
minrquescommentschema = FOIMinistryRequestCommentSchema().load(requestjson)
result = commentservice().createministryrequestcomment(minrquescommentschema, AuthHelper.getuserid())
minrquescommentschema = FOIMinistryRequestCommentSchema().load(requestjson)
result = commentservice().createministryrequestcomment(minrquescommentschema, AuthHelper.getuserid(), minrquescommentschema["commenttypeid"])
if result.success == True:
asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "ministryrequest", AuthHelper.getuserid()))
return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
Expand All @@ -74,7 +74,7 @@ def post():
try:
requestjson = request.get_json()
rawrqcommentschema = FOIRawRequestCommentSchema().load(requestjson)
result = commentservice().createrawrequestcomment(rawrqcommentschema, AuthHelper.getuserid())
result = commentservice().createrawrequestcomment(rawrqcommentschema, AuthHelper.getuserid(), rawrqcommentschema["commenttypeid"])
if result.success == True:
asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "rawrequest", AuthHelper.getuserid()))
return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
Expand Down
2 changes: 1 addition & 1 deletion request-management-api/request_api/schemas/foicomment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Meta: # pylint: disable=too-few-public-methods
parentcommentid = fields.Int(data_key="parentcommentid",allow_none=True)
isactive = fields.Bool(data_key="isactive",allow_none=True)
taggedusers = fields.Str(data_key="taggedusers")
#commenttypeid= fields.Int(data_key="commenttypeid",allow_none=True)
commenttypeid= fields.Int(data_key="commenttypeid",allow_none=True)

class FOIMinistryRequestCommentSchema(Schema):
class Meta: # pylint: disable=too-few-public-methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __preparecomments(self, data):
if entry['parentcommentid'] is not None:
for _comment in comments:
if entry['parentcommentid'] == _comment['commentId']:
_comment['replies'].append(self.__comment(entry))
_comment['replies'].append(self.__comment(entry))
return comments

def __parentcomments(self, data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def createattachmentevent(self, requestid, userid, documents, requesttype):

def __createnotification(self, message, requestid, notificationtype, userid, requesttype):
if message is not None:
print("notificationtype:",notificationtype)
return notificationservice().createnotification({"message" : message}, requestid, requesttype , notificationtype, userid)

def __createcomment(self, requestid, message, ministryversion, userid, requesttype):
Expand Down
Loading
Loading