@@ -5,6 +5,7 @@ import '@vaadin/combo-box';
5
5
import '@vaadin/item' ;
6
6
import '@vaadin/icon' ;
7
7
import '@vaadin/list-box' ;
8
+ import '@vaadin/text-field' ;
8
9
import '@qomponent/qui-card' ;
9
10
import '@vaadin/grid' ;
10
11
import '@vaadin/tabs' ;
@@ -19,6 +20,7 @@ import '@vaadin/dialog';
19
20
import '@qomponent/qui-dot' ;
20
21
import 'qui-assistant-button' ;
21
22
import 'qui-assistant-warning' ;
23
+ import '@qomponent/qui-badge' ;
22
24
import { dialogFooterRenderer , dialogHeaderRenderer , dialogRenderer } from '@vaadin/dialog/lit.js' ;
23
25
import { observeState } from 'lit-element-state' ;
24
26
import { assistantState } from 'assistant-state' ;
@@ -91,8 +93,6 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
91
93
display: flex;
92
94
align-items: center;
93
95
padding-bottom: 10px;
94
- border-bottom-style: dotted;
95
- border-bottom-color: var(--lumo-contrast-10pct);
96
96
}
97
97
98
98
.sqlInput .cm-content {
@@ -111,9 +111,13 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
111
111
margin: 0;
112
112
}
113
113
114
- #sql {
114
+ #sqlInput {
115
+ width: 100%;
116
+ }
117
+ #assistantInput {
115
118
width: 100%;
116
119
}
120
+
117
121
.data {
118
122
display: flex;
119
123
flex-direction: column;
@@ -161,6 +165,12 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
161
165
align-self: center;
162
166
padding-top: 50px;
163
167
}
168
+
169
+ qui-badge {
170
+ cursor: pointer;
171
+ padding-left: 2px;
172
+ padding-right: 5px;
173
+ }
164
174
` ;
165
175
166
176
static properties = {
@@ -172,6 +182,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
172
182
_selectedTableIndex :{ state : true } ,
173
183
_selectedTableCols :{ state : true } ,
174
184
_currentSQL : { state : true } ,
185
+ _currentEnglish : { state : true } ,
175
186
_currentDataSet : { state : true } ,
176
187
_isWatching : { state : true } ,
177
188
_watchId : { state : false } ,
@@ -186,7 +197,9 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
186
197
_showBusyLoadingDialog : { state : true } ,
187
198
_showAssistantWarning : { state : true } ,
188
199
_showImportSQLDialog : { state : true } ,
189
- _showErDiagramDialog : { state : true }
200
+ _showErDiagramDialog : { state : true } ,
201
+ _englishToSQLEnabled : { state : true } ,
202
+ _englishToSQLLoadingMessage : { state : true }
190
203
} ;
191
204
192
205
constructor ( ) {
@@ -199,6 +212,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
199
212
this . _selectedTableCols = null ;
200
213
this . _selectedTableIndex = 0 ;
201
214
this . _currentSQL = null ;
215
+ this . _currentEnglish = null ;
202
216
this . _currentDataSet = null ;
203
217
this . _isWatching = false ;
204
218
this . _watchId = null ;
@@ -214,6 +228,8 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
214
228
this . _showAssistantWarning = false ;
215
229
this . _showImportSQLDialog = false ;
216
230
this . _showErDiagramDialog = false ;
231
+ this . _englishToSQLEnabled = false ;
232
+ this . _englishToSQLLoadingMessage = null ;
217
233
}
218
234
219
235
connectedCallback ( ) {
@@ -236,6 +252,8 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
236
252
return map ;
237
253
} , { } ) ;
238
254
} ) ;
255
+
256
+ this . _englishToSQLEnabled = false ; // TODO: Load from storage
239
257
}
240
258
241
259
disconnectedCallback ( ) {
@@ -551,17 +569,25 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
551
569
_renderTableData ( ) {
552
570
if ( this . _selectedTable && this . _currentDataSet && this . _currentDataSet . cols ) {
553
571
return html `< div class ="data ">
554
- ${ this . _renderSqlInput ( ) }
555
572
${ this . _renderTableDataGrid ( ) }
573
+ ${ this . _renderSqlInput ( ) }
556
574
</ div >
557
575
` ;
558
576
} else if ( this . _displaymessage ) {
559
577
return html `< span > ${ this . _displaymessage } </ span > ` ;
560
578
} else {
561
- return html `< div style ="color: var(--lumo-secondary-text-color);width: 95%; " >
562
- < div > Fetching data...</ div >
563
- < vaadin-progress-bar indeterminate > </ vaadin-progress-bar >
564
- </ div > ` ;
579
+ if ( assistantState . current . isConfigured && this . _englishToSQLEnabled ) {
580
+ return html `< div style ="color: var(--lumo-secondary-text-color);width: 95%; " >
581
+ < div > ${ this . _englishToSQLLoadingMessage } </ div >
582
+ < vaadin-progress-bar indeterminate > </ vaadin-progress-bar >
583
+ </ div > ` ;
584
+ } else {
585
+ return html `< div style ="color: var(--lumo-secondary-text-color);width: 95%; " >
586
+ < div > Fetching data ...</ div >
587
+ < vaadin-progress-bar indeterminate > </ vaadin-progress-bar >
588
+ </ div > ` ;
589
+ }
590
+
565
591
}
566
592
}
567
593
@@ -633,15 +659,14 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
633
659
if ( this . _allowSql ) {
634
660
return html `
635
661
< div class ="sqlInput ">
636
- < qui-themed-code-block @shiftEnter =${ this . _shiftEnterPressed } content ="${ this . _currentSQL } "
637
- class="font-large cursor-text" id="sql" mode="sql"
638
- value='${ this . _currentSQL } ' editable> </ qui-themed-code-block >
639
- < vaadin-button class ="no-margin " slot ="suffix " theme ="icon tertiary small " aria-label ="Clear ">
662
+ ${ this . _renderEnglishToSQLButton ( ) }
663
+ ${ this . _renderInputTextField ( ) }
664
+ < vaadin-button class ="no-margin " theme ="icon tertiary small " aria-label ="Clear ">
640
665
< vaadin-tooltip .hoverDelay =${ 500 } slot ="tooltip" text="Clear"> </ vaadin-tooltip >
641
- < vaadin-icon class ="small-icon " @click =${ this . _clearSqlInput }
666
+ < vaadin-icon class ="small-icon " @click =${ this . _clearInput }
642
667
icon ="font-awesome-solid:broom"> </ vaadin-icon >
643
668
</ vaadin-button >
644
- < vaadin-button class ="no-margin " slot =" suffix " theme ="icon tertiary small " aria-label ="Run ">
669
+ < vaadin-button class ="no-margin " theme ="icon tertiary small " aria-label ="Run ">
645
670
< vaadin-tooltip .hoverDelay =${ 500 } slot ="tooltip" text="Run"> </ vaadin-tooltip >
646
671
< vaadin-icon class ="small-icon " @click =${ this . _executeClicked }
647
672
icon ="font-awesome-solid:play"> </ vaadin-icon >
@@ -652,6 +677,42 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
652
677
}
653
678
}
654
679
680
+ _renderInputTextField ( ) {
681
+ if ( assistantState . current . isConfigured && this . _englishToSQLEnabled ) {
682
+ return html `< vaadin-text-field value ='${ this . _currentEnglish } ' placeholder ="Describe the data you are looking for in English " @keydown ="${ this . _englishKeyDown } " id ="assistantInput ">
683
+ < vaadin-icon slot ="prefix " icon ="font-awesome-solid:robot " title ="${ this . _currentSQL } "> </ vaadin-icon >
684
+ </ vaadin-text-field > ` ;
685
+ } else {
686
+ return html `< qui-themed-code-block @shiftEnter =${ this . _shiftEnterPressed } content ="${ this . _currentSQL } "
687
+ class="font-large cursor-text" id="sqlInput" mode="sql"
688
+ value='${ this . _currentSQL } ' editable> </ qui-themed-code-block > ` ;
689
+ }
690
+ }
691
+
692
+ _renderEnglishToSQLButton ( ) {
693
+ if ( assistantState . current . isConfigured ) {
694
+ if ( this . _englishToSQLEnabled ) {
695
+ return html `Using < qui-badge @click =${ this . _switchEnglishToSQL } color ="var(--quarkus-assistant)"> < span > Assistant</ span > </ qui-badge > ` ;
696
+ } else {
697
+ return html `Using < qui-badge @click =${ this . _switchEnglishToSQL } > < span > SQL</ span > </ qui-badge > ` ;
698
+ }
699
+ }
700
+ }
701
+
702
+ _switchEnglishToSQL ( ) {
703
+ if ( this . _englishToSQLEnabled ) {
704
+ this . _englishToSQLEnabled = false ;
705
+ } else {
706
+ this . _englishToSQLEnabled = true ;
707
+ }
708
+ }
709
+
710
+ _englishKeyDown ( e ) {
711
+ if ( e . key === 'Enter' ) {
712
+ this . _executeClickedAI ( ) ;
713
+ }
714
+ }
715
+
655
716
_generateErDiagram ( ) {
656
717
if ( this . _selectedDataSource ) {
657
718
this . _showBusyLoadingDialog = "Generating ER Diagram ... please wait" ;
@@ -670,7 +731,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
670
731
'value' : 'true'
671
732
} ) . then ( e => {
672
733
this . _allowSql = true ;
673
- } ) ; ;
734
+ } ) ;
674
735
}
675
736
676
737
_columnNameRenderer ( col ) {
@@ -762,7 +823,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
762
823
this . _fetchTableDefinitions ( ) ;
763
824
this . _selectedTableIndex = event . detail . value ;
764
825
this . _selectedTable = this . _tables [ this . _selectedTableIndex ] ;
765
- this . _clearSqlInput ( ) ;
826
+ this . _clearInput ( ) ;
766
827
}
767
828
768
829
_previousPage ( ) {
@@ -801,7 +862,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
801
862
notifier . showErrorMessage ( jsonRpcResponse . result . error ) ;
802
863
} else if ( jsonRpcResponse . result . message ) {
803
864
notifier . showInfoMessage ( jsonRpcResponse . result . message ) ;
804
- this . _clearSqlInput ( ) ;
865
+ this . _clearInput ( ) ;
805
866
} else {
806
867
this . _currentDataSet = jsonRpcResponse . result ;
807
868
this . _currentNumberOfPages = this . _getNumberOfPages ( ) ;
@@ -840,16 +901,55 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
840
901
}
841
902
842
903
_executeClicked ( ) {
843
- let newValue = this . shadowRoot . getElementById ( 'sql' ) . getAttribute ( 'value' ) ;
904
+ if ( assistantState . current . isConfigured && this . _englishToSQLEnabled ) {
905
+ this . _executeClickedAI ( ) ;
906
+ } else {
907
+ this . _executeClickedSQL ( ) ;
908
+ }
909
+ }
910
+
911
+ _executeClickedSQL ( ) {
912
+ let newValue = this . shadowRoot . getElementById ( 'sqlInput' ) . getAttribute ( 'value' ) ;
844
913
this . _executeSQL ( newValue ) ;
845
914
}
846
915
847
- _clearSqlInput ( ) {
848
- if ( this . _selectedTable ) {
849
- if ( this . _appendSql ) {
850
- this . _executeSQL ( "select * from " + this . _selectedTable . tableSchema + "." + this . _selectedTable . tableName + " " + this . _appendSql ) ;
851
- } else {
852
- this . _executeSQL ( "select * from " + this . _selectedTable . tableSchema + "." + this . _selectedTable . tableName ) ;
916
+ _executeClickedAI ( ) {
917
+ this . _currentEnglish = this . shadowRoot . getElementById ( 'assistantInput' ) . value ;
918
+ this . _englishToSQLLoadingMessage = "Creating SQL from \"" + this . _currentEnglish + "\"" ;
919
+ this . _currentDataSet = null ;
920
+ this . _currentSQL = null ;
921
+
922
+ this . jsonRpc . englishToSQL ( {
923
+ datasource :this . _selectedDataSource . name ,
924
+ schema : this . _selectedTable . tableSchema ,
925
+ name : this . _selectedTable . tableName ,
926
+ english : this . _currentEnglish
927
+ } ) . then ( jsonRpcResponse => {
928
+ if ( jsonRpcResponse . result . error ) {
929
+ notifier . showErrorMessage ( jsonRpcResponse . result . error ) ;
930
+ } else {
931
+ let sql = jsonRpcResponse . result . sql ;
932
+ this . _englishToSQLLoadingMessage = "Using SQL \"" + sql + "\"" ;
933
+ notifier . showInfoMessage ( sql ) ;
934
+ this . _executeSQL ( sql ) ;
935
+ }
936
+ } ) ;
937
+
938
+
939
+
940
+ }
941
+
942
+ _clearInput ( ) {
943
+ if ( assistantState . current . isConfigured && this . _englishToSQLEnabled ) {
944
+ this . _currentEnglish = null ;
945
+ this . shadowRoot . getElementById ( 'assistantInput' ) . value = '' ;
946
+ } else {
947
+ if ( this . _selectedTable ) {
948
+ if ( this . _appendSql ) {
949
+ this . _executeSQL ( "select * from " + this . _selectedTable . tableSchema + "." + this . _selectedTable . tableName + " " + this . _appendSql ) ;
950
+ } else {
951
+ this . _executeSQL ( "select * from " + this . _selectedTable . tableSchema + "." + this . _selectedTable . tableName ) ;
952
+ }
853
953
}
854
954
}
855
955
}
@@ -861,6 +961,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
861
961
_executeSQL ( sql ) {
862
962
this . _currentSQL = sql . trim ( ) ;
863
963
this . _executeCurrentSQL ( ) ;
964
+ this . _englishToSQLLoadingMessage = null ;
864
965
}
865
966
866
967
_startsWithIgnoreCaseAndSpaces ( str , searchString ) {
0 commit comments