diff --git a/packages/client/src/schema-component/components/RemoteSchemaComponent.tsx b/packages/client/src/schema-component/components/RemoteSchemaComponent.tsx new file mode 100644 index 000000000..54ac22912 --- /dev/null +++ b/packages/client/src/schema-component/components/RemoteSchemaComponent.tsx @@ -0,0 +1,32 @@ +import React from 'react'; +import { Spin } from 'antd'; +import { useRequest } from '../../api-client'; +import { SchemaComponent } from './SchemaComponent'; +import { Schema } from '@formily/react'; + +export interface RemoteSchemaComponentProps { + scope?: any; + uid?: string; + transform?: (schema: Schema) => Schema; +} + +const defaultTransform = (s: Schema) => s; + +export const RemoteSchemaComponent: React.FC = (props) => { + const { scope, uid, transform = defaultTransform } = props; + if (!uid) { + return null; + } + const { data, loading } = useRequest( + { + url: `/ui_schemas:getJsonSchema/${uid}`, + }, + { + refreshDeps: [uid], + }, + ); + if (loading) { + return ; + } + return ; +}; diff --git a/packages/client/src/schema-component/components/index.tsx b/packages/client/src/schema-component/components/index.tsx index f5871b464..6afcac991 100644 --- a/packages/client/src/schema-component/components/index.tsx +++ b/packages/client/src/schema-component/components/index.tsx @@ -2,3 +2,4 @@ export * from './RecursionComponent'; export * from './SchemaComponent'; export * from './SchemaComponentProvider'; export * from './SchemaOptionsExpressionScopeProvider'; +export * from './RemoteSchemaComponent';