@@ -34,7 +34,7 @@ import { DataTable } from "@/components/ui/data-table";
3434interface ModelContextEditorProps {
3535 datasetId : string ;
3636 modelId : string ;
37- schema : DataModelColumn [ ] ;
37+ schema ? : DataModelColumn [ ] ;
3838 existingContext ?: Pick < ModelContext , "context" | "columnContext" > | null ;
3939 className ?: string ;
4040}
@@ -65,7 +65,7 @@ function ModelContextEditor(props: ModelContextEditorProps) {
6565
6666 // Filter existing column contexts to only include columns that exist in the current schema
6767 const filteredColumnContexts = useMemo ( ( ) => {
68- if ( ! existingContext ?. columnContext ) return [ ] ;
68+ if ( ! existingContext ?. columnContext || ! schema ) return [ ] ;
6969
7070 const schemaColumnNames = new Set ( schema . map ( ( col ) => col . name ) ) ;
7171 return existingContext . columnContext . filter ( ( colCtx ) =>
@@ -78,7 +78,7 @@ function ModelContextEditor(props: ModelContextEditorProps) {
7878 resolver : zodResolver ( modelContextSchema ) ,
7979 defaultValues : {
8080 tableContext : existingContext ?. context || "" ,
81- columnContexts : schema . map ( ( column ) => {
81+ columnContexts : schema ? .map ( ( column ) => {
8282 const existingColContext = filteredColumnContexts . find (
8383 ( ctx ) => ctx . name === column . name ,
8484 ) ;
@@ -93,12 +93,12 @@ function ModelContextEditor(props: ModelContextEditorProps) {
9393 // Prepare data for DataTable
9494 const tableData : ColumnRow [ ] = useMemo (
9595 ( ) =>
96- schema . map ( ( column , index ) => ( {
96+ schema ? .map ( ( column , index ) => ( {
9797 columnName : column . name ,
9898 columnType : column . type ,
9999 columnDescription : column . description ,
100100 index,
101- } ) ) ,
101+ } ) ) ?? [ ] ,
102102 [ schema ] ,
103103 ) ;
104104
@@ -165,7 +165,7 @@ function ModelContextEditor(props: ModelContextEditorProps) {
165165
166166 try {
167167 // Filter out empty contexts and only include columns that exist in schema
168- const schemaColumnNames = new Set ( schema . map ( ( col ) => col . name ) ) ;
168+ const schemaColumnNames = new Set ( schema ? .map ( ( col ) => col . name ) ) ;
169169 const columnContext = data . columnContexts
170170 . filter ( ( ctx ) => ctx . context && ctx . context . trim ( ) !== "" )
171171 . filter ( ( ctx ) => schemaColumnNames . has ( ctx . name ) )
@@ -209,43 +209,51 @@ function ModelContextEditor(props: ModelContextEditorProps) {
209209 Table schema and context to help the AI understand your model
210210 </ CardDescription >
211211 </ CardHeader >
212- < Form { ... form } >
213- < form onSubmit = { safeSubmit ( form . handleSubmit ( onSubmit ) ) } >
214- < CardContent className = "space-y-4 " >
215- < FormField
216- control = { form . control }
217- name = "tableContext"
218- render = { ( { field } ) => (
219- < FormItem >
220- < FormLabel className = "text-sm" > Table Context </ FormLabel >
221- < FormControl >
222- < Textarea
223- { ... field }
224- placeholder = "Describe the purpose and usage of this table... "
225- rows = { 2 }
226- className = "text-sm"
227- / >
228- </ FormControl >
229- < FormMessage />
230- </ FormItem >
231- ) }
232- />
233-
234- < div className = "space-y-2" >
235- < DataTable
236- columns = { columns }
237- data = { tableData }
238- pagination = { false }
212+ { ! schema || schema . length === 0 ? (
213+ < CardContent >
214+ < p className = "text-sm text-muted-foreground " >
215+ No schema found. Please trigger a new run
216+ </ p >
217+ </ CardContent >
218+ ) : (
219+ < Form { ... form } >
220+ < form onSubmit = { safeSubmit ( form . handleSubmit ( onSubmit ) ) } >
221+ < CardContent className = "space-y-4" >
222+ < FormField
223+ control = { form . control }
224+ name = "tableContext "
225+ render = { ( { field } ) => (
226+ < FormItem >
227+ < FormLabel className = "text-sm" > Table Context </ FormLabel >
228+ < FormControl >
229+ < Textarea
230+ { ... field }
231+ placeholder = "Describe the purpose and usage of this table..."
232+ rows = { 2 }
233+ className = "text-sm"
234+ / >
235+ </ FormControl >
236+ < FormMessage />
237+ </ FormItem >
238+ ) }
239239 />
240- </ div >
241- </ CardContent >
242- < CardFooter className = "pt-3" >
243- < Button type = "submit" disabled = { isSubmitting } size = "sm" >
244- { isSubmitting ? "Saving..." : "Save" }
245- </ Button >
246- </ CardFooter >
247- </ form >
248- </ Form >
240+
241+ < div className = "space-y-2" >
242+ < DataTable
243+ columns = { columns }
244+ data = { tableData }
245+ pagination = { false }
246+ />
247+ </ div >
248+ </ CardContent >
249+ < CardFooter className = "pt-3" >
250+ < Button type = "submit" disabled = { isSubmitting } size = "sm" >
251+ { isSubmitting ? "Saving..." : "Save" }
252+ </ Button >
253+ </ CardFooter >
254+ </ form >
255+ </ Form >
256+ ) }
249257 </ Card >
250258 ) ;
251259}
0 commit comments