parent
f0d76b9159
commit
dd7966aba9
@ -0,0 +1,54 @@ |
||||
import { useState } from 'react' |
||||
import { CompilerFeedbackProps } from '../types' |
||||
import { RenderIf } from '@remix-ui/helper' |
||||
import {CopyToClipboard} from '@remix-ui/clipboard' |
||||
import { FeedbackAlert } from './feedbackAlert' |
||||
|
||||
export function CompilerFeedback ({ feedback, filePathToId }: CompilerFeedbackProps) { |
||||
const [ showException, setShowException ] = useState<boolean>(true) |
||||
|
||||
const handleCloseException = () => { |
||||
setShowException(false) |
||||
} |
||||
|
||||
return ( |
||||
<div> |
||||
<div className="circuit_errors_box py-4"> |
||||
<RenderIf condition={ (typeof feedback === "string") && showException }> |
||||
<div className="circuit_feedback error alert alert-danger"> |
||||
<span> { feedback } </span> |
||||
<div className="close" data-id="renderer" onClick={handleCloseException}> |
||||
<i className="fas fa-times"></i> |
||||
</div> |
||||
<div className="d-flex pt-1 flex-row-reverse"> |
||||
<span className="ml-3 pt-1 py-1" > |
||||
<CopyToClipboard content={feedback} className="p-0 m-0 far fa-copy error" direction={'top'} /> |
||||
</span> |
||||
</div> |
||||
</div> |
||||
</RenderIf> |
||||
<RenderIf condition={ Array.isArray(feedback) }> |
||||
<> |
||||
{ |
||||
Array.isArray(feedback) && feedback.map((response, index) => ( |
||||
<div key={index}> |
||||
<RenderIf condition={response.type === 'Error'}> |
||||
<div className={`circuit_feedback ${response.type.toLowerCase()} alert alert-danger`}> |
||||
<FeedbackAlert message={response.message} location={ response.labels[0] ? response.labels[0].message + ` ${filePathToId[response.labels[0].file_id]}:${response.labels[0].range.start}:${response.labels[0].range.end}` : null} /> |
||||
</div> |
||||
</RenderIf> |
||||
<RenderIf condition={response.type === 'Warning'}> |
||||
<div className={`circuit_feedback ${response.type.toLowerCase()} alert alert-warning`}> |
||||
<FeedbackAlert message={response.message} location={null} /> |
||||
</div> |
||||
</RenderIf> |
||||
</div> |
||||
) |
||||
) |
||||
} |
||||
</> |
||||
</RenderIf> |
||||
</div> |
||||
</div> |
||||
) |
||||
} |
@ -0,0 +1,31 @@ |
||||
import { useState } from 'react' |
||||
import { FeedbackAlertProps } from '../types' |
||||
import { RenderIf } from '@remix-ui/helper' |
||||
import {CopyToClipboard} from '@remix-ui/clipboard' |
||||
|
||||
export function FeedbackAlert ({ message, location }: FeedbackAlertProps) { |
||||
const [ showAlert, setShowAlert] = useState<boolean>(true) |
||||
|
||||
const handleCloseAlert = () => { |
||||
setShowAlert(false) |
||||
} |
||||
|
||||
return ( |
||||
<RenderIf condition={showAlert}> |
||||
<> |
||||
<span> { message } </span> |
||||
<RenderIf condition={location !== null}> |
||||
<span> { location }</span> |
||||
</RenderIf> |
||||
<div className="close" data-id="renderer" onClick={handleCloseAlert}> |
||||
<i className="fas fa-times"></i> |
||||
</div> |
||||
<div className="d-flex pt-1 flex-row-reverse"> |
||||
<span className="ml-3 pt-1 py-1" > |
||||
<CopyToClipboard content={message} className="p-0 m-0 far fa-copy error" direction={'top'} /> |
||||
</span> |
||||
</div> |
||||
</> |
||||
</RenderIf> |
||||
) |
||||
} |
Loading…
Reference in new issue