Skip to content

Commit a023de8

Browse files
authored
Fix: Various bugs (#969)
1 parent 0f682ed commit a023de8

File tree

18 files changed

+406
-283
lines changed

18 files changed

+406
-283
lines changed

sqlmesh/core/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
AUDITS = "audits"
3535
MACROS = "macros"
3636
MODELS = "models"
37+
SEEDS = "seeds"
3738
TESTS = "tests"
3839
CACHE = ".cache"
3940
SCHEMA_YAML = "schema.yaml"

web/client/src/context/context.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ interface ContextStore {
3030
created_from: EnvironmentName,
3131
) => void
3232
removeLocalEnvironment: (environments: ModelEnvironment) => void
33-
addSyncronizedEnvironments: (environments: Environment[]) => void
34-
hasSyncronizedEnvironments: () => boolean
33+
addSynchronizedEnvironments: (environments: Environment[]) => void
34+
hasSynchronizedEnvironments: () => boolean
3535
setInitialDates: (
3636
initialStartDate?: ContextEnvironmentStart,
3737
initialEndDate?: ContextEnvironmentEnd,
@@ -141,7 +141,7 @@ export const useStoreContext = create<ContextStore>((set, get) => ({
141141
}
142142
})
143143
},
144-
addSyncronizedEnvironments(envs = []) {
144+
addSynchronizedEnvironments(envs = []) {
145145
set(s => {
146146
const environments = Array.from(s.environments)
147147

@@ -153,13 +153,13 @@ export const useStoreContext = create<ContextStore>((set, get) => ({
153153
if (environment == null) {
154154
environment = new ModelEnvironment(
155155
env,
156-
EnumRelativeLocation.Syncronized,
156+
EnumRelativeLocation.Synchronized,
157157
)
158158

159159
environments.push(environment)
160160
} else {
161161
environment.update(env)
162-
environment.setType(EnumRelativeLocation.Syncronized)
162+
environment.setType(EnumRelativeLocation.Synchronized)
163163
}
164164

165165
if (environment.isInitial && environment.isDefault) {
@@ -178,11 +178,11 @@ export const useStoreContext = create<ContextStore>((set, get) => ({
178178
}
179179
})
180180
},
181-
hasSyncronizedEnvironments() {
181+
hasSynchronizedEnvironments() {
182182
const s = get()
183183

184184
return Array.from(s.environments).some(
185-
({ type }) => type === EnumRelativeLocation.Syncronized,
185+
({ type }) => type === EnumRelativeLocation.Synchronized,
186186
)
187187
},
188188
}))

web/client/src/library/components/editor/extensions/SqlMeshDialect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function useSqlMeshExtension(): [
3333
const SQLKeywords = (options?.keywords ?? '') + WHITE_SPACE
3434
const SQLMeshModelDictionary = SQLMeshModelKeywords(dialects)
3535
const SQLMeshKeywords =
36-
'audit model name kind owner cron start storage_format time_column partitioned_by pre post batch_size audits dialect'
36+
'columns grain tags audit model name kind owner cron start storage_format time_column partitioned_by pre post batch_size audits dialect'
3737
const SQLMeshTypes =
3838
'seed full incremental_by_time_range incremental_by_unique_key view embedded'
3939

web/client/src/library/components/graph/Graph.tsx

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
isNil,
4343
isTrue,
4444
} from '../../../utils'
45-
import { EnumSize, EnumVariant } from '~/types/enum'
45+
import { EnumSide, EnumSize, EnumVariant, type Side } from '~/types/enum'
4646
import {
4747
ArrowRightCircleIcon,
4848
InformationCircleIcon,
@@ -139,13 +139,13 @@ const ModelColumnDisplay = memo(function ModelColumnDisplay({
139139
<CodeEditor.SQLMeshDialect
140140
content={source}
141141
type={EnumFileExtensions.SQL}
142-
className="scrollbar--vertical-md scrollbar--horizontal-md !h-[25vh] !max-w-[30rem]"
142+
className="scrollbar--vertical-md scrollbar--horizontal-md overflow-auto !h-[25vh] !max-w-[30rem]"
143143
>
144144
{({ extensions, content }) => (
145145
<CodeEditor
146146
extensions={extensions.concat(modelExtensions)}
147147
content={content}
148-
className="text-xs"
148+
className="text-xs pr-2"
149149
/>
150150
)}
151151
</CodeEditor.SQLMeshDialect>
@@ -209,23 +209,23 @@ const ModelNodeHandles = memo(function ModelNodeHandles({
209209
className,
210210
)}
211211
>
212-
{hasRight && (
212+
{hasLeft && (
213213
<Handle
214214
type="target"
215-
id={toNodeOrEdgeId('right', id)}
216-
position={Position.Right}
215+
id={toNodeOrEdgeId(EnumSide.Left, id)}
216+
position={Position.Left}
217217
isConnectable={false}
218218
className={clsx(
219219
'w-2 h-2 rounded-full !bg-secondary-500 dark:!bg-primary-500',
220220
)}
221221
/>
222222
)}
223223
{children}
224-
{hasLeft && (
224+
{hasRight && (
225225
<Handle
226226
type="source"
227-
id={toNodeOrEdgeId('left', id)}
228-
position={Position.Left}
227+
id={toNodeOrEdgeId(EnumSide.Right, id)}
228+
position={Position.Right}
229229
isConnectable={false}
230230
className={clsx(
231231
'w-2 h-2 rounded-full !bg-secondary-500 dark:!bg-primary-500',
@@ -261,16 +261,16 @@ const ModelNodeHeaderHandles = memo(function ModelNodeHeaderHandles({
261261
className,
262262
)}
263263
>
264-
{hasRight && (
264+
{hasLeft && (
265265
<Handle
266266
type="target"
267-
id={toNodeOrEdgeId('right', id)}
268-
position={Position.Right}
267+
id={toNodeOrEdgeId(EnumSide.Left, id)}
268+
position={Position.Left}
269269
isConnectable={false}
270-
className={clsx(
271-
'w-2 h-2 rounded-full !bg-secondary-500 dark:!bg-primary-500',
272-
)}
273-
/>
270+
className={clsx('!bg-transparent -ml-2 dark:text-primary-500')}
271+
>
272+
<ArrowRightCircleIcon className="w-5 bg-theme rounded-full" />
273+
</Handle>
274274
)}
275275
<span className="inline-block w-full">
276276
{type != null && (
@@ -288,6 +288,7 @@ const ModelNodeHeaderHandles = memo(function ModelNodeHeaderHandles({
288288
{type === 'sql' && 'SQL'}
289289
{type === 'seed' && 'Seed'}
290290
{type === 'cte' && 'CTE'}
291+
{type === 'external' && 'External'}
291292
</span>
292293
)}
293294
<span
@@ -300,16 +301,16 @@ const ModelNodeHeaderHandles = memo(function ModelNodeHeaderHandles({
300301
{label}
301302
</span>
302303
</span>
303-
{hasLeft && (
304+
{hasRight && (
304305
<Handle
305306
type="source"
306-
id={toNodeOrEdgeId('left', id)}
307-
position={Position.Left}
307+
id={toNodeOrEdgeId(EnumSide.Right, id)}
308+
position={Position.Right}
308309
isConnectable={false}
309-
className={clsx('!bg-transparent -ml-2 dark:text-primary-500')}
310-
>
311-
<ArrowRightCircleIcon className="w-5 bg-theme rounded-full" />
312-
</Handle>
310+
className={clsx(
311+
'w-2 h-2 rounded-full !bg-secondary-500 dark:!bg-primary-500',
312+
)}
313+
/>
313314
)}
314315
</div>
315316
)
@@ -388,7 +389,7 @@ const ModelColumn = memo(function ModelColumn({
388389

389390
debouncedGetColumnLineage(column.name)
390391
.then(data => {
391-
setIsEmpty(hasNoModels())
392+
setIsEmpty(hasNoModels(data))
392393
updateColumnLineage(data)
393394
})
394395
.catch(error => {
@@ -577,13 +578,23 @@ const ModelColumns = memo(function ModelColumns({
577578

578579
const removeEdges = useCallback(
579580
function removeEdges(columnId: string): void {
581+
const visited = new Set<string>()
582+
580583
removeActiveEdges(
581-
[columnId, walk(columnId, 'left'), walk(columnId, 'right')].flat(),
584+
[
585+
columnId,
586+
walk(columnId, EnumSide.Left),
587+
walk(columnId, EnumSide.Right),
588+
].flat(),
582589
)
583590

584-
function walk(id: string, side: 'left' | 'right'): string[] {
591+
function walk(id: string, side: Side): string[] {
592+
if (visited.has(id)) return []
593+
585594
const edges = connections.get(id)?.[side] ?? []
586595

596+
visited.add(id)
597+
587598
return [id, edges.map(edge => walk(edge, side))].flat(
588599
Infinity,
589600
) as string[]
@@ -768,7 +779,6 @@ function ModelColumnLineage({
768779
void createGraphLayout(nodesAndEdges)
769780
.then(layout => {
770781
toggleEdgeAndNodes(layout.edges, layout.nodes)
771-
772782
setIsBuildingLayout(
773783
isArrayEmpty(layout.nodes) || isArrayEmpty(layout.edges),
774784
)
@@ -806,7 +816,7 @@ function ModelColumnLineage({
806816

807817
visibility.set(
808818
edge.source,
809-
isFalse(visibility.get(edge.source)) ? false : edge.hidden,
819+
isFalse(visibility.has(edge.source)) ? false : edge.hidden,
810820
)
811821
}
812822

@@ -944,8 +954,8 @@ function ModelNode({
944954
showColumns ? 'rounded-t-lg' : 'rounded-lg',
945955
isCTE ? 'bg-accent-500' : 'bg-secondary-100 dark:bg-primary-900',
946956
)}
947-
hasLeft={sourcePosition === Position.Left}
948-
hasRight={targetPosition === Position.Right}
957+
hasLeft={targetPosition === Position.Left}
958+
hasRight={sourcePosition === Position.Right}
949959
handleClick={isInteractive ? handleClick : undefined}
950960
/>
951961
</div>

web/client/src/library/components/graph/context.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { type ModelSQLMeshModel } from '@models/sqlmesh-model'
55
import { createContext, useState, useContext, useCallback } from 'react'
66
import { toNodeOrEdgeId } from './help'
77
import { type ErrorIDE } from '~/library/pages/ide/context'
8+
import { EnumSide } from '~/types/enum'
89

910
export interface Connections {
1011
left: string[]
@@ -104,8 +105,8 @@ export default function LineageFlowProvider({
104105
function removeActiveEdges(edges: string[]): void {
105106
setActiveEdges(activeEdges => {
106107
edges.forEach(edge => {
107-
activeEdges.set(toNodeOrEdgeId('left', edge), 0)
108-
activeEdges.set(toNodeOrEdgeId('right', edge), 0)
108+
activeEdges.set(toNodeOrEdgeId(EnumSide.Left, edge), 0)
109+
activeEdges.set(toNodeOrEdgeId(EnumSide.Right, edge), 0)
109110
})
110111

111112
return new Map(activeEdges)
@@ -125,8 +126,8 @@ export default function LineageFlowProvider({
125126
const isActiveColumn = useCallback(
126127
function isActive(modelName: string, columnName: string): boolean {
127128
return (
128-
hasActiveEdge(toNodeOrEdgeId('left', modelName, columnName)) ||
129-
hasActiveEdge(toNodeOrEdgeId('right', modelName, columnName))
129+
hasActiveEdge(toNodeOrEdgeId(EnumSide.Left, modelName, columnName)) ||
130+
hasActiveEdge(toNodeOrEdgeId(EnumSide.Right, modelName, columnName))
130131
)
131132
},
132133
[hasActiveEdge],

0 commit comments

Comments
 (0)