@@ -118,12 +118,21 @@ type Ipynb = {
118
118
metadata : { kernelspec : KernelSpec } ;
119
119
} ;
120
120
121
+ function ensureExtension ( filename , ext ) {
122
+ if ( ! filename ) return filename ;
123
+ if ( ! filename . endsWith ( "." + ext ) ) {
124
+ return filename + "." + ext ;
125
+ }
126
+ return filename ;
127
+ }
128
+
121
129
interface Props {
122
130
project_id : string ;
123
131
onSuccess : ( ) => void ;
124
132
ext : Ext ;
125
133
docName : string ;
126
134
show : boolean ;
135
+ filename ?: string ;
127
136
}
128
137
129
138
function AIGenerateDocument ( {
@@ -132,6 +141,7 @@ function AIGenerateDocument({
132
141
project_id,
133
142
ext,
134
143
docName,
144
+ filename : filename0 ,
135
145
} : Props ) {
136
146
const projectActions = useActions ( { project_id } ) ;
137
147
const current_path = useTypedRedux ( { project_id } , "current_path" ) ;
@@ -145,7 +155,12 @@ function AIGenerateDocument({
145
155
const [ saving , setSaving ] = useState < boolean > ( false ) ;
146
156
const [ error , setError ] = useState < string > ( "" ) ;
147
157
const [ preview , setPreview ] = useState < string | null > ( null ) ;
148
- const [ filename , setFilename ] = useState < string > ( "" ) ;
158
+ const [ filename , setFilename ] = useState < string > (
159
+ ensureExtension ( filename0 ?? "" , ext ) ,
160
+ ) ;
161
+ useEffect ( ( ) => {
162
+ setFilename ( ensureExtension ( filename0 ?? "" , ext ) ) ;
163
+ } , [ filename0 ] ) ;
149
164
const promptRef = useRef < HTMLElement > ( null ) ;
150
165
151
166
const [ kernelSpecs , setKernelSpecs ] = useState < KernelSpec [ ] | null | string > (
@@ -452,6 +467,9 @@ function AIGenerateDocument({
452
467
}
453
468
454
469
function updateFilename ( fnNext : string ) {
470
+ if ( filename ) {
471
+ return ;
472
+ }
455
473
const fn = sanitizeFilename ( fnNext , ext ) ;
456
474
const timestamp = getTimestamp ( ) ;
457
475
setFilename ( `${ fn } -${ timestamp } .${ ext } ` ) ;
@@ -741,7 +759,6 @@ function AIGenerateDocument({
741
759
}
742
760
743
761
function renderDialog ( ) {
744
- const empty = prompt . trim ( ) == "" ;
745
762
return (
746
763
< >
747
764
< Paragraph strong >
@@ -754,7 +771,7 @@ function AIGenerateDocument({
754
771
/>
755
772
</ Paragraph >
756
773
{ renderJupyterKernelSelector ( ) }
757
- < Paragraph type = { empty ? "danger" : undefined } >
774
+ < Paragraph >
758
775
Provide a detailed description of the { docName } document you want to
759
776
create:
760
777
</ Paragraph >
@@ -767,7 +784,6 @@ function AIGenerateDocument({
767
784
placeholder = { PLACEHOLDER }
768
785
value = { prompt }
769
786
disabled = { querying }
770
- status = { empty ? "error" : undefined }
771
787
onChange = { ( { target : { value } } ) => setPrompt ( value ) }
772
788
onPressEnter = { ( e ) => {
773
789
if ( e . shiftKey ) {
@@ -899,7 +915,7 @@ function AIGenerateDocument({
899
915
setPreview ( null ) ;
900
916
} }
901
917
>
902
- < Icon name = "arrow-left" /> Discard
918
+ Cancel
903
919
</ Button >
904
920
< Button
905
921
type = "primary"
@@ -959,12 +975,14 @@ export function AIGenerateDocumentModal({
959
975
setShow,
960
976
project_id,
961
977
ext,
978
+ filename,
962
979
} : {
963
980
show : boolean ;
964
981
setShow : ( val : boolean ) => void ;
965
982
project_id : string ;
966
983
style ?: CSS ;
967
984
ext : Props [ "ext" ] ;
985
+ filename ?: string ;
968
986
} ) {
969
987
const docName = file_options ( `x.${ ext } ` ) . name ?? `${ capitalize ( ext ) } ` ;
970
988
@@ -986,6 +1004,7 @@ export function AIGenerateDocumentModal({
986
1004
onSuccess = { ( ) => setShow ( false ) }
987
1005
ext = { ext }
988
1006
docName = { docName }
1007
+ filename = { filename }
989
1008
/>
990
1009
</ Modal >
991
1010
) ;
@@ -996,11 +1015,13 @@ export function AIGenerateDocumentButton({
996
1015
style,
997
1016
mode = "full" ,
998
1017
ext,
1018
+ filename,
999
1019
} : {
1000
1020
project_id : string ;
1001
1021
style ?: CSS ;
1002
1022
mode ?: "full" | "flyout" ;
1003
1023
ext : Props [ "ext" ] ;
1024
+ filename ?: string ;
1004
1025
} ) {
1005
1026
const [ show , setShow ] = useState < boolean > ( false ) ;
1006
1027
@@ -1046,6 +1067,7 @@ export function AIGenerateDocumentButton({
1046
1067
show = { show }
1047
1068
setShow = { setShow }
1048
1069
project_id = { project_id }
1070
+ filename = { filename }
1049
1071
/>
1050
1072
</ >
1051
1073
) ;
0 commit comments