-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
548cc38
commit 9f7017b
Showing
7 changed files
with
185 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useState } from 'react' | ||
import { CompilerFeedbackProps, CompilerReport } from '../types' | ||
import { RenderIf } from '@remix-ui/helper' | ||
import { CopyToClipboard } from '@remix-ui/clipboard' | ||
import { FeedbackAlert } from './feedbackAlert' | ||
|
||
export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openErrorLocation, askGPT }: CompilerFeedbackProps) { | ||
const [showException, setShowException] = useState<boolean>(true) | ||
|
||
const handleCloseException = () => { | ||
setShowException(false) | ||
} | ||
|
||
const handleOpenError = (report: CompilerReport) => { | ||
if (report.labels.length > 0) { | ||
openErrorLocation(filePathToId[report.labels[0].file_id], report.labels[0].range.start) | ||
} | ||
} | ||
|
||
const handleAskGPT = (report: CompilerReport) => { | ||
askGPT(report) | ||
} | ||
|
||
return ( | ||
<div> | ||
{ | ||
(feedback && typeof feedback === 'string') || (Array.isArray(feedback) && feedback.length > 0) ? ( | ||
<div className="circuit_errors_box"> | ||
<RenderIf condition={ (typeof feedback === "string") && showException }> | ||
<div className="circuit_feedback error alert alert-danger" data-id="circuit_feedback"> | ||
<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} onClick={() => handleOpenError(response)}> | ||
<RenderIf condition={response.type === 'Error'}> | ||
<div className={`circuit_feedback ${response.type.toLowerCase()} alert alert-danger`} data-id="circuit_feedback"> | ||
<FeedbackAlert | ||
message={response.message + (response.labels[0] ? ": " + response.labels[0].message + ` ${filePathToId[response.labels[0].file_id]}:${response.labels[0].range.start}:${response.labels[0].range.end}` : '')} | ||
askGPT={ () => handleAskGPT(response) } /> | ||
</div> | ||
</RenderIf> | ||
<RenderIf condition={(response.type === 'Warning') && !hideWarnings}> | ||
<div className={`circuit_feedback ${response.type.toLowerCase()} alert alert-warning`} data-id="circuit_feedback"> | ||
<FeedbackAlert | ||
message={response.message} | ||
askGPT={() => { handleAskGPT(response) }} /> | ||
</div> | ||
</RenderIf> | ||
</div> | ||
) | ||
) | ||
} | ||
</> | ||
</RenderIf> | ||
</div> | ||
) : <></> | ||
} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useState } from 'react' | ||
import { FeedbackAlertProps } from '../types' | ||
import { RenderIf } from '@remix-ui/helper' | ||
import {CopyToClipboard} from '@remix-ui/clipboard' | ||
|
||
export function FeedbackAlert ({ message, askGPT }: FeedbackAlertProps) { | ||
const [ showAlert, setShowAlert] = useState<boolean>(true) | ||
|
||
const handleCloseAlert = () => { | ||
setShowAlert(false) | ||
} | ||
|
||
return ( | ||
<RenderIf condition={showAlert}> | ||
<> | ||
<span> { message } </span> | ||
<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> | ||
<span className="border border-success text-success btn-sm" onClick={(e) => { | ||
e.stopPropagation() | ||
askGPT() | ||
}}>Ask RemixAI</span> | ||
</div> | ||
</> | ||
</RenderIf> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters