@@ -102,7 +102,6 @@ export default function Editor({
102102 const tabTableContent = useStoreEditor ( s => s . tabTableContent )
103103 const tabTerminalContent = useStoreEditor ( s => s . tabTerminalContent )
104104
105- const [ isSaved , setIsSaved ] = useState ( true )
106105 const [ formEvaluate , setFormEvaluate ] = useState < FormEvaluate > ( {
107106 start : toDateFormat ( toDate ( Date . now ( ) - DAY ) ) ,
108107 end : toDateFormat ( new Date ( ) ) ,
@@ -114,6 +113,9 @@ export default function Editor({
114113 > ( [ ] )
115114 const [ dialect , setDialect ] = useState < string > ( )
116115 const [ isValid , setIsValid ] = useState ( true )
116+ const [ dialectCache , setDialectCache ] = useState < Map < ModelFile , string > > (
117+ new Map ( ) ,
118+ )
117119
118120 const { refetch : planRun } = useApiPlanRun ( environment . name , {
119121 planOptions : {
@@ -129,8 +131,6 @@ export default function Editor({
129131
130132 const mutationSaveFile = useMutationApiSaveFile ( client , {
131133 onSuccess ( file : File ) {
132- setIsSaved ( true )
133-
134134 if ( file == null ) return
135135
136136 activeFile . updateContent ( file . content )
@@ -139,9 +139,6 @@ export default function Editor({
139139
140140 void debouncedPlanRun ( )
141141 } ,
142- onMutate ( ) {
143- setIsSaved ( false )
144- } ,
145142 } )
146143
147144 const debouncedSaveChange = useMemo (
@@ -159,7 +156,6 @@ export default function Editor({
159156
160157 if ( e . data . topic === 'dialects' ) {
161158 setDialects ( e . data . payload . dialects ?? [ ] )
162- setDialect ( e . data . payload . dialect )
163159 }
164160 } ,
165161 [ activeFile ] ,
@@ -213,13 +209,17 @@ export default function Editor({
213209 setTabTableContent ( bucket . get ( EnumEditorTabs . Table ) )
214210 setTabTerminalContent ( bucket . get ( EnumEditorTabs . Terminal ) )
215211
216- const model = models ?. get ( activeFile . path ) ?. name
212+ const model = models ?. get ( activeFile . path )
217213
218214 if ( model != null ) {
219215 setFormEvaluate ( s => ( {
220216 ...s ,
221- model,
217+ model : model . name ,
222218 } ) )
219+
220+ setDialect ( model . dialect )
221+ } else {
222+ setDialect ( dialectCache . get ( activeFile ) )
223223 }
224224 } , [ activeFile ] )
225225
@@ -624,10 +624,12 @@ export default function Editor({
624624 < div className = "px-2 flex justify-between items-center min-h-[2rem]" >
625625 < EditorFooter
626626 activeFile = { activeFile }
627- isSaved = { isSaved }
628627 dialects = { dialects }
629628 dialect = { dialect }
630- setDialect = { setDialect }
629+ setDialect = { dialect => {
630+ setDialectCache ( new Map ( [ ...dialectCache , [ activeFile , dialect ] ] ) )
631+ setDialect ( dialect )
632+ } }
631633 isValid = { isValid }
632634 />
633635 </ div >
@@ -671,16 +673,18 @@ function EditorFooter({
671673 dialect,
672674 setDialect,
673675 activeFile,
674- isSaved,
675676 isValid,
676677} : {
677678 activeFile : ModelFile
678- isSaved : boolean
679679 isValid : boolean
680680 dialects : Array < { dialect_title : string ; dialect_name : string } >
681681 dialect ?: string
682- setDialect : ( dialect ? : string ) => void
682+ setDialect : ( dialect : string ) => void
683683} ) : JSX . Element {
684+ const dialect_title = useMemo (
685+ ( ) => dialects . find ( d => d . dialect_name === dialect ) ?. dialect_title ,
686+ [ dialects , dialect ] ,
687+ )
684688 return (
685689 < div className = "mr-4" >
686690 < Indicator
@@ -700,27 +704,36 @@ function EditorFooter({
700704 text = "Language"
701705 value = { getLanguageByExtension ( activeFile . extension ) }
702706 />
703- { activeFile . extension === '.sql' && isArrayNotEmpty ( dialects ) && (
704- < span className = "inline-block mr-2" >
705- < small className = "font-bold text-xs mr-2" > Dialect</ small >
706- < select
707- className = "text-xs m-0 px-1 py-[0.125rem] bg-neutral-10 rounded"
708- value = { dialect }
709- onChange = { ( e : React . ChangeEvent < HTMLSelectElement > ) => {
710- setDialect ( e . target . value )
711- } }
712- >
713- { dialects . map ( dialect => (
714- < option
715- key = { dialect . dialect_title }
716- value = { dialect . dialect_name }
717- >
718- { dialect . dialect_title }
719- </ option >
720- ) ) }
721- </ select >
722- </ span >
707+ { activeFile . isSQLMeshModel && (
708+ < Indicator
709+ className = "mr-2"
710+ text = "Dialect"
711+ value = { dialect_title }
712+ />
723713 ) }
714+ { activeFile . extension === '.sql' &&
715+ isArrayNotEmpty ( dialects ) &&
716+ isFalse ( activeFile . isSQLMeshModel ) && (
717+ < span className = "inline-block mr-2" >
718+ < small className = "font-bold text-xs mr-2" > Dialect</ small >
719+ < select
720+ className = "text-xs m-0 px-1 py-[0.125rem] bg-neutral-10 rounded"
721+ value = { dialect }
722+ onChange = { ( e : React . ChangeEvent < HTMLSelectElement > ) => {
723+ setDialect ( e . target . value )
724+ } }
725+ >
726+ { dialects . map ( dialect => (
727+ < option
728+ key = { dialect . dialect_title }
729+ value = { dialect . dialect_name }
730+ >
731+ { dialect . dialect_title }
732+ </ option >
733+ ) ) }
734+ </ select >
735+ </ span >
736+ ) }
724737 { activeFile . isSQLMeshModel && (
725738 < Indicator
726739 className = "mr-2"
0 commit comments