Skip to content

Commit 51ae985

Browse files
authored
Feat: Docs lineage for change categories (#817)
1 parent f270926 commit 51ae985

File tree

29 files changed

+1197
-803
lines changed

29 files changed

+1197
-803
lines changed

web/client/openapi.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,18 +960,20 @@
960960
},
961961
"Model": {
962962
"title": "Model",
963-
"required": ["name", "path", "dialect", "columns"],
963+
"required": ["name", "path", "dialect", "type", "columns"],
964964
"type": "object",
965965
"properties": {
966966
"name": { "title": "Name", "type": "string" },
967967
"path": { "title": "Path", "type": "string" },
968968
"dialect": { "title": "Dialect", "type": "string" },
969+
"type": { "title": "Type", "type": "string" },
969970
"columns": {
970971
"title": "Columns",
971972
"type": "array",
972973
"items": { "$ref": "#/components/schemas/Column" }
973974
},
974975
"description": { "title": "Description", "type": "string" },
976+
"owner": { "title": "Owner", "type": "string" },
975977
"details": { "$ref": "#/components/schemas/ModelDetails" },
976978
"sql": { "title": "Sql", "type": "string" }
977979
}
@@ -1017,8 +1019,7 @@
10171019
"contains_star_query": {
10181020
"title": "Contains Star Query",
10191021
"type": "boolean"
1020-
},
1021-
"type": { "title": "Type", "type": "string" }
1022+
}
10221023
}
10231024
},
10241025
"ModelsDiff": {
@@ -1163,7 +1164,7 @@
11631164
"title": "SnapshotChangeCategory",
11641165
"enum": [1, 2, 3, 4, 5],
11651166
"type": "integer",
1166-
"description": "Values are ordered by decreasing severity and that ordering is required.\n\nBREAKING: The change requires that snapshot modified and downstream dependencies be rebuilt\nNON_BREAKING: The change requires that only the snapshot modified be rebuilt\nFORWARD_ONLY: The change requires no rebuilding\nINDIRECT_BREAKING: The change was caused indirectly and is breaking.\nINDIRECT_FORWARD_ONLY: The change was caused indirectly and is forward-only."
1167+
"description": "Values are ordered by decreasing severity and that ordering is required.\n\nBREAKING: The change requires that snapshot modified and downstream dependencies be rebuilt\nNON_BREAKING: The change requires that only the snapshot modified be rebuilt\nFORWARD_ONLY: The change requires no rebuilding\nINDIRECT_BREAKING: The change was caused indirectly and is breaking.\nINDIRECT_NON_BREAKING: The change was caused indirectly by a non-breaking change."
11671168
},
11681169
"SnapshotDataVersion": {
11691170
"title": "SnapshotDataVersion",

web/client/src/context/context.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ModelSQLMeshModel } from '@models/sqlmesh-model'
12
import { create } from 'zustand'
23
import {
34
type Model,
@@ -17,8 +18,9 @@ interface ContextStore {
1718
environments: Set<ModelEnvironment>
1819
initialStartDate?: ContextEnvironmentStart
1920
initialEndDate?: ContextEnvironmentEnd
20-
models: Map<string, Model>
21+
models: Map<string, ModelSQLMeshModel>
2122
setModels: (models?: Model[]) => void
23+
refreshModels: () => void
2224
isExistingEnvironment: (
2325
environment: ModelEnvironment | EnvironmentName,
2426
) => boolean
@@ -46,15 +48,30 @@ export const useStoreContext = create<ContextStore>((set, get) => ({
4648
initialEndDate: undefined,
4749
models: new Map(),
4850
setModels(models = []) {
51+
const s = get()
52+
4953
set(() => ({
50-
models: models.reduce((acc, model) => {
51-
acc.set(model.name, model)
52-
acc.set(model.path, model)
54+
models: models.reduce((acc: Map<string, ModelSQLMeshModel>, model) => {
55+
let tempModel = s.models.get(model.path) ?? s.models.get(model.name)
56+
57+
if (tempModel == null) {
58+
tempModel = new ModelSQLMeshModel(model)
59+
} else {
60+
tempModel.update(model)
61+
}
62+
63+
acc.set(model.name, tempModel)
64+
acc.set(model.path, tempModel)
5365

5466
return acc
5567
}, new Map()),
5668
}))
5769
},
70+
refreshModels() {
71+
set(() => ({
72+
models: new Map(get().models),
73+
}))
74+
},
5875
getNextEnvironment() {
5976
return get().environments.values().next().value
6077
},

web/client/src/context/editor.ts

Lines changed: 5 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
type Model,
3-
type ColumnLineageApiLineageModelNameColumnNameGet200,
4-
} from '@api/client'
5-
import { uid, isObjectEmpty } from '@utils/index'
1+
import { uid } from '@utils/index'
62
import { create } from 'zustand'
73
import useLocalStorage from '~/hooks/useLocalStorage'
84
import { ModelFile } from '~/models'
@@ -33,7 +29,6 @@ interface EditorStore {
3329
previewQuery?: string
3430
previewTable?: any[]
3531
previewConsole?: string
36-
previewLineage?: Record<string, Lineage>
3732
selectTab: (tab?: EditorTab) => void
3833
updateStoredTabsIds: () => void
3934
addTab: (tab: EditorTab) => void
@@ -44,11 +39,6 @@ interface EditorStore {
4439
setPreviewQuery: (previewQuery?: string) => void
4540
setPreviewTable: (previewTable?: any[]) => void
4641
setPreviewConsole: (previewConsole?: string) => void
47-
setPreviewLineage: (
48-
models: Map<string, Model>,
49-
previewLineage?: Record<string, Lineage>,
50-
columns?: ColumnLineageApiLineageModelNameColumnNameGet200,
51-
) => void
5242
}
5343

5444
interface EditorPreview<TTable = any> {
@@ -86,7 +76,6 @@ export const useStoreEditor = create<EditorStore>((set, get) => ({
8676
previewQuery: undefined,
8777
previewTable: undefined,
8878
previewConsole: undefined,
89-
previewLineage: undefined,
9079
updateStoredTabsIds() {
9180
setStoredTabs({
9281
ids: Array.from(get().tabs.values())
@@ -135,6 +124,10 @@ export const useStoreEditor = create<EditorStore>((set, get) => ({
135124

136125
if (s.tabs.size === 0) {
137126
s.selectTab(undefined)
127+
} else if (s.tabs.size === 1) {
128+
const tabs = Array.from(s.tabs.values())
129+
130+
s.selectTab(tabs.at(0) as EditorTab)
138131
} else if (file.id === s.tab?.file.id) {
139132
const tabs = Array.from(s.tabs.values())
140133
const indexAt = tabs.findIndex(tab => tab.file === file)
@@ -158,15 +151,6 @@ export const useStoreEditor = create<EditorStore>((set, get) => ({
158151
setPreviewConsole(previewConsole) {
159152
set(() => ({ previewConsole }))
160153
},
161-
setPreviewLineage(models, lineage, columns) {
162-
const previewLineage = structuredClone(lineage)
163-
164-
if (columns != null && previewLineage != null) {
165-
mergeLineageWithColumns(models, previewLineage, columns)
166-
}
167-
168-
set(() => ({ previewLineage }))
169-
},
170154
}))
171155

172156
function createTab(file: ModelFile = createLocalFile()): EditorTab {
@@ -190,83 +174,3 @@ function createLocalFile(): ModelFile {
190174
function getStoredTabsIds(): ID[] {
191175
return getStoredTabs()?.ids ?? []
192176
}
193-
194-
// TODO: use better merge
195-
function mergeLineageWithColumns(
196-
models: Map<string, Model>,
197-
lineage: Record<string, Lineage>,
198-
columns: ColumnLineageApiLineageModelNameColumnNameGet200,
199-
): Record<string, Lineage> {
200-
for (const model in columns) {
201-
const lineageModel = lineage[model]
202-
const columnsModel = columns[model]
203-
204-
if (lineageModel == null || columnsModel == null) continue
205-
206-
if (lineageModel.columns == null) {
207-
lineageModel.columns = {}
208-
}
209-
210-
for (const columnName in columnsModel) {
211-
const columnsModelColumn = columnsModel[columnName]
212-
213-
if (columnsModelColumn == null) continue
214-
215-
const lineageModelColumn = lineageModel.columns[columnName] ?? {}
216-
217-
lineageModelColumn.source = columnsModelColumn.source
218-
lineageModelColumn.models = {}
219-
220-
lineageModel.columns[columnName] = lineageModelColumn
221-
222-
if (isObjectEmpty(columnsModelColumn.models)) continue
223-
224-
for (const columnModel in columnsModelColumn.models) {
225-
const columnsModelColumnModel = columnsModelColumn.models[columnModel]
226-
227-
if (columnsModelColumnModel == null) continue
228-
229-
const lineageModelColumnModel = lineageModelColumn.models[columnModel]
230-
231-
if (lineageModelColumnModel == null) {
232-
lineageModelColumn.models[columnModel] = columnsModelColumnModel
233-
} else {
234-
lineageModelColumn.models[columnModel] = Array.from(
235-
new Set(lineageModelColumnModel.concat(columnsModelColumnModel)),
236-
)
237-
}
238-
}
239-
}
240-
}
241-
242-
for (const modelName in lineage) {
243-
const model = models.get(modelName)
244-
const modelLineage = lineage[modelName]
245-
246-
if (model == null || modelLineage == null) {
247-
delete lineage[modelName]
248-
249-
continue
250-
}
251-
252-
if (modelLineage.columns == null) continue
253-
254-
if (model.columns == null) {
255-
delete modelLineage.columns
256-
257-
continue
258-
}
259-
260-
for (const columnName in modelLineage.columns) {
261-
const found = model.columns.find(c => c.name === columnName)
262-
263-
if (found == null) {
264-
delete modelLineage.columns[columnName]
265-
266-
continue
267-
}
268-
}
269-
}
270-
271-
return lineage
272-
}

web/client/src/context/lineage.tsx

Lines changed: 0 additions & 96 deletions
This file was deleted.

web/client/src/index.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ html[mode='dark'] {
204204
--color-editor-text: var(--color-neutral-300);
205205
--color-editor-active-line-text: var(--color-neutral-100);
206206

207-
--color-graph-edge-main: var(--color-primary-80);
208-
--color-graph-edge-secondary: var(--color-primary-40);
207+
--color-graph-edge-secondary: var(--color-primary-80);
208+
--color-graph-edge-main: var(--color-primary-40);
209209
}
210210

211211
html[mode='light'] {
@@ -228,8 +228,8 @@ html[mode='light'] {
228228
--color-editor-text: var(--color-neutral-600);
229229
--color-editor-active-line-text: var(--color-neutral-800);
230230

231-
--color-graph-edge-main: var(--color-secondary-80);
232-
--color-graph-edge-secondary: var(--color-secondary-40);
231+
--color-graph-edge-secondary: var(--color-secondary-80);
232+
--color-graph-edge-main: var(--color-secondary-40);
233233
}
234234

235235
html {

0 commit comments

Comments
 (0)