@@ -5,11 +5,12 @@ import CodeEditor, {
55import { Disclosure , Tab } from '@headlessui/react'
66import { MinusCircleIcon , PlusCircleIcon } from '@heroicons/react/24/solid'
77import { EnumFileExtensions } from '@models/file'
8- import { isFalse , isString , isTrue , toDateFormat } from '@utils/index'
8+ import { isString , isTrue , toDateFormat } from '@utils/index'
99import clsx from 'clsx'
1010import { type ModelSQLMeshModel } from '@models/sqlmesh-model'
1111import { ModelColumns } from '@components/graph/Graph'
1212import { useLineageFlow } from '@components/graph/context'
13+ import TabList from '@components/tab/Tab'
1314
1415const Documentation = function Documentation ( {
1516 model,
@@ -92,85 +93,59 @@ const Documentation = function Documentation({
9293 < Section headline = "SQL" >
9394 < CodeEditor . RemoteFile path = { model . path } >
9495 { ( { file } ) => (
95- < >
96- < Tab . Group defaultIndex = { withQuery ? 1 : 0 } >
97- < Tab . List className = "w-full whitespace-nowrap px-2 pt-3 flex justify-center items-center" >
98- < Tab
99- disabled = { isFalse ( withCode ) }
100- className = { ( { selected } ) =>
101- clsx (
102- 'inline-block font-medium px-3 py-1 mr-2 last-child:mr-0 rounded-md relative' ,
103- selected
104- ? 'bg-secondary-500 text-secondary-100 cursor-default'
105- : 'bg-secondary-10 ' ,
106- isFalse ( withCode )
107- ? 'opacity-50 cursor-not-allowed'
108- : 'cursor-pointer' ,
109- )
110- }
111- >
112- Source Code
113- </ Tab >
114- < Tab
115- disabled = { isFalse ( withQuery ) }
116- className = { ( { selected } ) =>
117- clsx (
118- 'inline-block font-medium px-3 py-1 mr-2 last-child:mr-0 rounded-md relative' ,
119- selected
120- ? 'bg-secondary-500 text-secondary-100 cursor-default'
121- : 'bg-secondary-10 ' ,
122- isFalse ( withQuery )
123- ? 'opacity-50 cursor-not-allowed'
124- : 'cursor-pointer' ,
125- )
126- }
96+ < Tab . Group defaultIndex = { withQuery ? 1 : 0 } >
97+ < TabList
98+ list = {
99+ [
100+ withCode && 'Source Code' ,
101+ withQuery && 'Compiled Query' ,
102+ ] . filter ( Boolean ) as string [ ]
103+ }
104+ className = "!justify-center"
105+ />
106+
107+ < Tab . Panels className = "h-full w-full overflow-hidden bg-neutral-10 mt-4 rounded-lg" >
108+ < Tab . Panel
109+ unmount = { false }
110+ className = { clsx (
111+ 'flex flex-col w-full h-full relative px-2 overflow-hidden p-2' ,
112+ 'ring-white ring-opacity-60 ring-offset-2 ring-offset-blue-400 focus:outline-none focus:ring-2' ,
113+ ) }
114+ >
115+ < CodeEditor . SQLMeshDialect
116+ content = { file . content }
117+ type = { file . extension }
127118 >
128- Compiled Query
129- </ Tab >
130- </ Tab . List >
131- < Tab . Panels className = "h-full w-full overflow-hidden bg-neutral-10 mt-4 rounded-lg" >
132- < Tab . Panel
133- unmount = { false }
134- className = { clsx (
135- 'flex flex-col w-full h-full relative px-2 overflow-hidden p-2' ,
136- 'ring-white ring-opacity-60 ring-offset-2 ring-offset-blue-400 focus:outline-none focus:ring-2' ,
119+ { ( { extensions, content } ) => (
120+ < CodeEditor
121+ extensions = { extensions . concat ( modelExtensions ) }
122+ content = { content }
123+ className = "text-xs"
124+ />
137125 ) }
126+ </ CodeEditor . SQLMeshDialect >
127+ </ Tab . Panel >
128+ < Tab . Panel
129+ unmount = { false }
130+ className = { clsx (
131+ 'w-full h-full ring-white ring-opacity-60 ring-offset-2 ring-offset-blue-400 focus:outline-none focus:ring-2 p-2' ,
132+ ) }
133+ >
134+ < CodeEditor . Default
135+ type = { EnumFileExtensions . SQL }
136+ content = { model . sql ?? '' }
138137 >
139- < CodeEditor . SQLMeshDialect
140- content = { file . content }
141- type = { file . extension }
142- >
143- { ( { extensions, content } ) => (
144- < CodeEditor
145- extensions = { extensions . concat ( modelExtensions ) }
146- content = { content }
147- className = "text-xs"
148- />
149- ) }
150- </ CodeEditor . SQLMeshDialect >
151- </ Tab . Panel >
152- < Tab . Panel
153- unmount = { false }
154- className = { clsx (
155- 'w-full h-full ring-white ring-opacity-60 ring-offset-2 ring-offset-blue-400 focus:outline-none focus:ring-2 p-2' ,
138+ { ( { extensions, content } ) => (
139+ < CodeEditor
140+ extensions = { extensions . concat ( modelExtensions ) }
141+ content = { content }
142+ className = "text-xs"
143+ />
156144 ) }
157- >
158- < CodeEditor . Default
159- type = { EnumFileExtensions . SQL }
160- content = { model . sql ?? '' }
161- >
162- { ( { extensions, content } ) => (
163- < CodeEditor
164- extensions = { extensions . concat ( modelExtensions ) }
165- content = { content }
166- className = "text-xs"
167- />
168- ) }
169- </ CodeEditor . Default >
170- </ Tab . Panel >
171- </ Tab . Panels >
172- </ Tab . Group >
173- </ >
145+ </ CodeEditor . Default >
146+ </ Tab . Panel >
147+ </ Tab . Panels >
148+ </ Tab . Group >
174149 ) }
175150 </ CodeEditor . RemoteFile >
176151 </ Section >
0 commit comments