@@ -26,8 +26,17 @@ import Markdown from "react-markdown";
2626import { SchemaDesigner } from "../../../../sharedInterfaces/schemaDesigner" ;
2727import { useMarkdownStyles } from "../../../common/styles" ;
2828import { useSchemaDesignerChangeContext } from "../definition/changes/schemaDesignerChangeContext" ;
29+ import { useSchemaDesignerSelector } from "../schemaDesignerSelector" ;
30+ import { CopilotChat } from "../../../../sharedInterfaces/copilotChat" ;
31+ import { ExecuteCommandRequest } from "../../../../sharedInterfaces/webview" ;
32+ import { GithubCopilot16Regular } from "../../../common/icons/fluentIcons" ;
33+ import {
34+ schemaDesignerPublishErrorDetailsLabel ,
35+ schemaDesignerPublishErrorFallbackDetails ,
36+ schemaDesignerPublishErrorPrompt ,
37+ } from "./publishChangesDialogPrompts" ;
2938
30- enum PublishDialogStages {
39+ export enum PublishDialogStages {
3140 NotStarted = "notStarted" ,
3241 ReportLoading = "reportLoading" ,
3342 ReportError = "reportError" ,
@@ -47,6 +56,45 @@ type PublishChangesDialogState = {
4756 currentStage : PublishDialogStages ;
4857} ;
4958
59+ export function buildSchemaDesignerPublishErrorPrompt ( errorString : string ) : string {
60+ const errorDetails = errorString . trim ( ) || schemaDesignerPublishErrorFallbackDetails ;
61+ return `${ schemaDesignerPublishErrorPrompt }
62+
63+ ${ schemaDesignerPublishErrorDetailsLabel }
64+ \`\`\`
65+ ${ errorDetails }
66+ \`\`\`` ;
67+ }
68+
69+ export function isReportOrPublishErrorStage ( currentStage : PublishDialogStages ) : boolean {
70+ return (
71+ currentStage === PublishDialogStages . ReportError ||
72+ currentStage === PublishDialogStages . PublishError
73+ ) ;
74+ }
75+
76+ export function getReportOrPublishErrorForStage (
77+ currentStage : PublishDialogStages ,
78+ reportError : string | undefined ,
79+ publishError : string | undefined ,
80+ ) : string {
81+ if ( currentStage === PublishDialogStages . ReportError ) {
82+ return reportError ?? "" ;
83+ }
84+ if ( currentStage === PublishDialogStages . PublishError ) {
85+ return publishError ?? "" ;
86+ }
87+ return "" ;
88+ }
89+
90+ export function shouldShowGithubCopilotFixButton (
91+ currentStage : PublishDialogStages ,
92+ isCopilotChatInstalled : boolean ,
93+ isDabEnabled : boolean ,
94+ ) : boolean {
95+ return isReportOrPublishErrorStage ( currentStage ) && isCopilotChatInstalled && isDabEnabled ;
96+ }
97+
5098const useStyles = makeStyles ( {
5199 errorSection : {
52100 marginBottom : "15px" ,
@@ -67,6 +115,8 @@ export function PublishChangesDialogButton() {
67115 const markdownClasses = useMarkdownStyles ( ) ;
68116 const context = useContext ( SchemaDesignerContext ) ;
69117 const changeContext = useSchemaDesignerChangeContext ( ) ;
118+ const isCopilotChatInstalled =
119+ useSchemaDesignerSelector ( ( s ) => s ?. isCopilotChatInstalled ) ?? false ;
70120 const [ open , setOpen ] = useState ( false ) ;
71121 const [ publishButtonDisabled , setPublishButtonDisabled ] = useState ( false ) ;
72122 const hasSchemaChanges = changeContext . schemaChangesCount > 0 ;
@@ -372,6 +422,42 @@ export function PublishChangesDialogButton() {
372422 ) ;
373423 } ;
374424
425+ const isGithubCopilotFixButtonVisible = ( ) => {
426+ return shouldShowGithubCopilotFixButton (
427+ state . currentStage ,
428+ isCopilotChatInstalled ,
429+ context . isDabEnabled ( ) ,
430+ ) ;
431+ } ;
432+
433+ const getCurrentError = ( ) => {
434+ return getReportOrPublishErrorForStage (
435+ state . currentStage ,
436+ state . reportError ,
437+ state . publishError ,
438+ ) ;
439+ } ;
440+
441+ const openGithubCopilotToFixError = async ( ) => {
442+ const prompt = buildSchemaDesignerPublishErrorPrompt ( getCurrentError ( ) ) ;
443+ setOpen ( false ) ;
444+ setState ( {
445+ ...state ,
446+ isConfirmationChecked : false ,
447+ } ) ;
448+
449+ await context . extensionRpc . sendRequest ( ExecuteCommandRequest . type , {
450+ command : CopilotChat . openFromUiCommand ,
451+ args : [
452+ {
453+ scenario : "schemaDesigner" ,
454+ entryPoint : "schemaDesignerPublishDialogError" ,
455+ prompt,
456+ } ,
457+ ] ,
458+ } ) ;
459+ } ;
460+
375461 const footerButtons = ( ) => {
376462 return (
377463 < >
@@ -428,6 +514,21 @@ export function PublishChangesDialogButton() {
428514 </ Button >
429515 </ DialogTrigger >
430516 ) }
517+ { isGithubCopilotFixButtonVisible ( ) && (
518+ < Tooltip
519+ content = { locConstants . schemaDesigner . askGithubCopilotToFixTooltip }
520+ relationship = "description" >
521+ < Button
522+ appearance = "secondary"
523+ icon = { < GithubCopilot16Regular /> }
524+ title = { locConstants . schemaDesigner . askGithubCopilotToFixTooltip }
525+ onClick = { async ( ) => {
526+ await openGithubCopilotToFixError ( ) ;
527+ } } >
528+ { locConstants . schemaDesigner . askGithubCopilotToFix }
529+ </ Button >
530+ </ Tooltip >
531+ ) }
431532 { state . currentStage !== PublishDialogStages . PublishLoading && (
432533 < DialogTrigger disableButtonEnhancement >
433534 < Button
0 commit comments