Skip to content

Commit 1ded87f

Browse files
authored
[UI] Set dialect from model and remove dates from apply step (#625)
1 parent 6f1a902 commit 1ded87f

5 files changed

Lines changed: 51 additions & 46 deletions

File tree

web/client/src/library/components/editor/Editor.tsx

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

web/client/src/library/components/plan/PlanWizard.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
type PlanTaskStatus,
1313
} from '../../../context/plan'
1414
import {
15-
includes,
1615
isArrayEmpty,
1716
isArrayNotEmpty,
1817
isFalse,
@@ -123,10 +122,6 @@ export default function PlanWizard({
123122
[backfills, change_categorization, activeBackfill],
124123
)
125124

126-
const isProgress = includes(
127-
[EnumPlanState.Cancelling, EnumPlanState.Applying],
128-
planState,
129-
)
130125
const isFinished = planState === EnumPlanState.Finished
131126
const hasNoChanges = [
132127
hasChanges,
@@ -308,11 +303,6 @@ export default function PlanWizard({
308303
setRefTaskProgress={setRefTaskProgress}
309304
/>
310305
</Suspense>
311-
<form>
312-
<fieldset className="flex w-full">
313-
<Plan.BackfillDates disabled={isProgress} />
314-
</fieldset>
315-
</form>
316306
</>
317307
)}
318308
{hasVirtualUpdate && (

web/client/src/library/components/tabs/Tabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default function Tabs({ className }: PropsTabs): JSX.Element {
128128
)}
129129
>
130130
{table != null && (
131-
<div className="w-full h-full overflow-hidden overflow-y-auto scrollbar scrollbar--horizontal scrollbar--vertical">
131+
<div className="w-full h-full overflow-auto scrollbar scrollbar--horizontal scrollbar--vertical">
132132
<table className="w-full h-full">
133133
<thead className="sticky top-0 bg-theme">
134134
{table.getHeaderGroups().map(headerGroup => (
@@ -155,7 +155,7 @@ export default function Tabs({ className }: PropsTabs): JSX.Element {
155155
{row.getVisibleCells().map(cell => (
156156
<td
157157
key={cell.id}
158-
className="px-2 py-1 text-sm text-left border-b border-neutral-50"
158+
className="px-2 py-1 text-sm text-left border-b border-neutral-50 whitespace-nowrap"
159159
>
160160
{flexRender(
161161
cell.column.columnDef.cell,

web/server/api/endpoints/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def get_models(
1818
path=str(model._path.relative_to(context.path)),
1919
description=model.description,
2020
owner=model.owner,
21+
dialect=model.dialect,
2122
)
2223
for model in context.models.values()
2324
}

web/server/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class EvaluateInput(BaseModel):
169169
class Model(BaseModel):
170170
name: str
171171
path: str
172+
dialect: str
172173
description: t.Optional[str]
173174
owner: t.Optional[str]
174175

0 commit comments

Comments
 (0)