/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import { TableOutlined } from '@ant-design/icons'; import { FormLayout } from '@formily/antd-v5'; import { SchemaOptionsContext } from '@formily/react'; import { FormDialog, SchemaInitializerItem, SchemaComponent, SchemaComponentOptions, useAPIClient, useGlobalTheme, useSchemaInitializer, } from '@nocobase/client'; import { error } from '@nocobase/utils/client'; import React, { useCallback, useContext, useMemo } from 'react'; import { useChartQueryMetadataContext } from './ChartQueryMetadataProvider'; import { lang } from './locale'; import { getQueryTypeSchema } from './settings/queryTypes'; export interface ChartQueryMetadata { id: number; title: string; type: string; fields: { name: string }[]; } export const ChartQueryBlockInitializer = (props) => { const { templateWrap, onCreateBlockSchema, componentType, createBlockSchema, ...others } = props; const { setVisible } = useSchemaInitializer(); const apiClient = useAPIClient(); const ctx = useChartQueryMetadataContext(); const options = useContext(SchemaOptionsContext); const { theme } = useGlobalTheme(); const onAddQuery = useCallback( (info) => { FormDialog( { sql: lang('Add SQL query'), json: lang('Add JSON query'), }[info.key], () => { return (