Skip to content
Snippets Groups Projects
Commit f84b69de authored by Muthukrishnanmatriot's avatar Muthukrishnanmatriot
Browse files

TMSS-997 - updated the code for copy to clipboard function

parent 0cd27c9d
No related branches found
No related tags found
2 merge requests!634WIP: COBALT commissioning delta,!573Resolve TMSS-997
...@@ -199,6 +199,7 @@ ...@@ -199,6 +199,7 @@
} }
.p-growl { .p-growl {
z-index: 3000 !important; z-index: 3000 !important;
width: 40em;
} }
.viewtable .p-hidden-accessible { .viewtable .p-hidden-accessible {
position: relative; position: relative;
...@@ -282,9 +283,8 @@ In Excel View the for Accordion background color override ...@@ -282,9 +283,8 @@ In Excel View the for Accordion background color override
padding-left: 10px; padding-left: 10px;
background-color: black; background-color: black;
margin-left: -3px; margin-left: -3px;
} }
.show_error { .show_error {
width: 40em;
margin-left: 67em; margin-left: 67em;
height: auto !important; height: auto !important;
} }
......
import React, {Component} from 'react'; import React, {Component} from 'react';
import UIConstants from './utils/ui.constants'; import UIConstants from './utils/ui.constants';
import { Growl } from 'primereact/components/growl/Growl';
export class ShowErrorDetails extends Component { export class ShowErrorDetails extends Component {
constructor(props) { constructor(props) {
...@@ -9,6 +10,7 @@ export class ShowErrorDetails extends Component { ...@@ -9,6 +10,7 @@ export class ShowErrorDetails extends Component {
showDetails: false showDetails: false
} }
this.showHideErrorDetails = this.showHideErrorDetails.bind(this); this.showHideErrorDetails = this.showHideErrorDetails.bind(this);
this.copyErrorDetailsToClipboard = this.copyErrorDetailsToClipboard.bind(this);
} }
/** /**
...@@ -30,23 +32,48 @@ export class ShowErrorDetails extends Component { ...@@ -30,23 +32,48 @@ export class ShowErrorDetails extends Component {
} }
} }
/**
* Copy the error details to clipboard
*/
async copyErrorDetailsToClipboard() {
try {
const queryOpts = { name: 'clipboard-write', allowWithoutGesture: true };
await navigator.permissions.query(queryOpts);
await navigator.clipboard.writeText(this.props.response.request.response);
} catch(error) {
try{
const elem = document.createElement('textarea');
elem.value = this.props.response.request.response;
document.body.appendChild(elem);
elem.select();
document.execCommand('copy');
document.body.removeChild(elem);
} catch (error) {
this.growl.show({severity: 'error', summary: 'Warning', detail: 'Unable to copy the data to clipboard'});
}
}
this.growl.show({severity: 'success', summary: '', detail: 'Error details is copied to clipboard'});
}
render() { render() {
const httpStatusMsg = UIConstants.httpStatusMessages[this.props.response.status]; const httpStatusMsg = UIConstants.httpStatusMessages[this.props.response.status];
const data = httpStatusMsg? httpStatusMsg.detail: ''; const data = httpStatusMsg? httpStatusMsg.detail: '';
var message = '['+this.props.response.status+'] '+JSON.stringify(this.props.response.statusText)+ ' ['+data+']'; var message = '['+this.props.response.status+'] '+JSON.stringify(this.props.response.statusText)+ ' ['+data+']';
return ( return (
<div> <div>
<Growl ref={(el) => this.growl = el} />
<div> <div>
{message} {message}
</div> </div>
<div> <div>
<div className="show_error_hide" > <div className="show_error_hide" >
<a href='#' onClick={this.showHideErrorDetails} > {this.state.buttonLabel} </a> <a href='#' onClick={this.showHideErrorDetails} > {this.state.buttonLabel} </a>
<a href='#' onClick={this.copyErrorDetailsToClipboard} style={{marginLeft: '1em'}} title="Copy the error details to clipboard" > <i class="fas fa-copy"></i> </a>
</div> </div>
{this.state.showDetails && {this.state.showDetails &&
<div> <div>
<p style={{fontWeight: 'bold'}}> Error Details: </p> <p style={{fontWeight: 'bold'}}> Error Details:</p>
<div className="show_error_details" > <div id="showError" className="show_error_details" >
{this.props.response.request.response} {this.props.response.request.response}
</div> </div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment