Skip to content

Commit 998ce69

Browse files
feat: reuse EditWithAIForm to show formatted code before apply it
1 parent 097fb5e commit 998ce69

File tree

2 files changed

+8
-7
lines changed
  • apps/web/src/components/v2Editor/customBlocks/sql
  • packages/editor/src/blocks

2 files changed

+8
-7
lines changed

apps/web/src/components/v2Editor/customBlocks/sql/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,15 @@ function SQLBlock(props: Props) {
403403
}, [router, props.document.workspaceId])
404404

405405
const onToggleFormatSQLCode = useCallback(() => {
406-
const formattedCode = getSQLCodeFormatted(source)
406+
const sqlCodeFormatted = getSQLCodeFormatted(source)
407407

408-
if (!formattedCode) {
408+
if (!sqlCodeFormatted) {
409409
return
410410
}
411411

412-
updateYText(source, formattedCode)
413-
}, [source])
412+
// Reuse the `EditWithAIForm` component to show the formatted SQL code
413+
props.block.setAttribute('aiSuggestions', sqlCodeFormatted)
414+
}, [source, props.block])
414415

415416
const onToggleIsBlockHiddenInPublished = useCallback(() => {
416417
props.onToggleIsBlockHiddenInPublished(blockId)

packages/editor/src/blocks/sql.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ export function duplicateSQLBlock(
149149
source: duplicateYText(prevAttributes.source),
150150
dataframeName: clone(prevAttributes.dataframeName),
151151
dataSourceId: prevAttributes.dataSourceId
152-
? options?.datasourceMap?.get(prevAttributes.dataSourceId) ??
153-
prevAttributes.dataSourceId
152+
? (options?.datasourceMap?.get(prevAttributes.dataSourceId) ??
153+
prevAttributes.dataSourceId)
154154
: null,
155155
isFileDataSource: prevAttributes.isFileDataSource,
156156
result: options?.noState ? null : clone(prevAttributes.result),
@@ -364,5 +364,5 @@ export function getSQLCodeFormatted(source: Y.Text) {
364364
tabWidth: 4,
365365
})
366366

367-
return formatted;
367+
return new Y.Text(formatted)
368368
}

0 commit comments

Comments
 (0)