diff --git a/js/packages/quary-extension-bus/src/callBacks.ts b/js/packages/quary-extension-bus/src/callBacks.ts index 53cee325..1b8de047 100644 --- a/js/packages/quary-extension-bus/src/callBacks.ts +++ b/js/packages/quary-extension-bus/src/callBacks.ts @@ -54,6 +54,7 @@ export type Callbacks = { chartViewRunQuery: ChartFile chartViewChangeHandler: ChartFile chartViewOpenTextEditor: null + chartViewCreateModel: string } export const useCallBackFrontEnd = ( diff --git a/js/packages/quary-extension-ui/src/components/ChartEditor.stories.tsx b/js/packages/quary-extension-ui/src/components/ChartEditor.stories.tsx index cc4cedd2..767c7322 100644 --- a/js/packages/quary-extension-ui/src/components/ChartEditor.stories.tsx +++ b/js/packages/quary-extension-ui/src/components/ChartEditor.stories.tsx @@ -9,6 +9,7 @@ const meta: Meta = { registerChangeChartFile: { action: 'change chart file' }, onClickRunQuery: { action: 'run query' }, onClickEdit: { action: 'edit' }, + onClickCreateModel: { action: 'create model' }, }, } diff --git a/js/packages/quary-extension-ui/src/components/ChartEditor.tsx b/js/packages/quary-extension-ui/src/components/ChartEditor.tsx index e46dfdc2..7e4174b5 100644 --- a/js/packages/quary-extension-ui/src/components/ChartEditor.tsx +++ b/js/packages/quary-extension-ui/src/components/ChartEditor.tsx @@ -13,6 +13,7 @@ interface Props { allAssets: string[] onClickEdit: () => void onClickRunQuery: (chartFile: ChartFile) => void + onCLickCreateModel: (sql: string) => void registerChangeChartFile: (config: ChartFile) => void } @@ -24,6 +25,7 @@ export const ChartEditor: React.FC = ({ onClickEdit, registerChangeChartFile, title, + onCLickCreateModel, }) => (
= ({ allAssets={allAssets} disabled={chartResults.type === 'loading'} onClickEdit={onClickEdit} + onClickCreateModel={onCLickCreateModel} onClickRunQuery={(source) => { onClickRunQuery({ ...chartFile, diff --git a/js/packages/quary-extension-ui/src/components/ChartEditorHeader.stories.tsx b/js/packages/quary-extension-ui/src/components/ChartEditorHeader.stories.tsx index 8ab40fe2..f814a994 100644 --- a/js/packages/quary-extension-ui/src/components/ChartEditorHeader.stories.tsx +++ b/js/packages/quary-extension-ui/src/components/ChartEditorHeader.stories.tsx @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/react' +import * as React from 'react' import { Card } from './Card' import { ChartEditorHeader } from './ChartEditorHeader' diff --git a/js/packages/quary-extension-ui/src/components/ChartEditorHeader.tsx b/js/packages/quary-extension-ui/src/components/ChartEditorHeader.tsx index d750b10b..a0389f4e 100644 --- a/js/packages/quary-extension-ui/src/components/ChartEditorHeader.tsx +++ b/js/packages/quary-extension-ui/src/components/ChartEditorHeader.tsx @@ -1,6 +1,6 @@ import { ChartFile } from '@quary/proto/quary/service/v1/chart_file' import * as z from 'zod' -import { PencilSquareIcon, PlayIcon } from '@heroicons/react/20/solid' +import { PencilSquareIcon, PlayIcon, PlusIcon } from '@heroicons/react/20/solid' import React, { useState } from 'react' import { Select, @@ -12,6 +12,12 @@ import { SelectValue, } from './ui/select' import { Button } from './ui/button' +import { + TooltipProvider, + Tooltip, + TooltipContent, + TooltipTrigger, +} from './ui/tooltip' import { Input } from '@/components/ui/input.tsx' interface Props { @@ -24,6 +30,8 @@ interface Props { onClickRunQuery: (source: ChartFile['source']) => void // open text editor onClickEdit: () => void + // create a model from the sql should open file + onClickCreateModel: (sql: string) => void } export const ChartEditorHeader: React.FC = ({ @@ -32,6 +40,7 @@ export const ChartEditorHeader: React.FC = ({ disabled, onChangeSource: onChangeSourceProp, onClickRunQuery, + onClickCreateModel, onClickEdit, }) => { const [state, changeState] = useState(data) @@ -86,18 +95,25 @@ export const ChartEditorHeader: React.FC = ({ allAssets={allAssets} disabled={disabled} values={values} - onChangeSource={changeState} + onChangeSource={onChangeSource} + onClickCreateModel={onClickCreateModel} /> - - + /> + + + + + + +

Edit Yaml

+
+
+
) } @@ -107,6 +123,7 @@ interface SubFormProps { disabled: boolean onChangeSource: (source: ChartFile['source']) => void allAssets: string[] + onClickCreateModel: (sql: string) => void } const SubForm: React.FC = ({ @@ -114,9 +131,9 @@ const SubForm: React.FC = ({ disabled, onChangeSource, allAssets, + onClickCreateModel, }) => { switch (values.type) { - // TODO Implement other cases case 'rawSql': return (
@@ -134,7 +151,7 @@ const SubForm: React.FC = ({ ) case 'preTemplatedSql': return ( -
+
= ({ }) }} /> + onClickCreateModel(values.preTemplatedSql)} + disabled={disabled} + />
) case 'reference': @@ -245,3 +266,45 @@ const FormSchema = z.union([ ]) type FormValues = z.infer + +const CreateModelButton = ({ + onClick, + disabled, +}: { + onClick: () => void + disabled: boolean +}) => ( + + + + + + +

Create Model

+
+
+
+) + +const RunQueryButton = ({ + onClick, + disabled, +}: { + onClick: () => void + disabled: boolean +}) => ( + + + + + + +

Run Query

+
+
+
+) diff --git a/js/packages/quary-extension-ui/src/views/ChartEditorView.tsx b/js/packages/quary-extension-ui/src/views/ChartEditorView.tsx index 9220025d..19dcb762 100644 --- a/js/packages/quary-extension-ui/src/views/ChartEditorView.tsx +++ b/js/packages/quary-extension-ui/src/views/ChartEditorView.tsx @@ -9,19 +9,25 @@ interface Props { } export const ChartEditorView: React.FC = ({ chart }) => { - const { chartViewChangeHandler, chartViewRunQuery, chartViewOpenTextEditor } = - useCallBackFrontEnd( - [ - 'chartViewChangeHandler', - 'chartViewRunQuery', - 'chartViewOpenTextEditor', - ], - vscode.postMessage, - ) + const { + chartViewChangeHandler, + chartViewRunQuery, + chartViewOpenTextEditor, + chartViewCreateModel, + } = useCallBackFrontEnd( + [ + 'chartViewChangeHandler', + 'chartViewRunQuery', + 'chartViewOpenTextEditor', + 'chartViewCreateModel', + ], + vscode.postMessage, + ) const [chartFile, setChartFile] = React.useState(chart.chartFile) return (