From dde48fc775134e4aba71790e542a3121e78996cd Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 17 Jan 2022 23:02:35 +0800 Subject: [PATCH] feat: add RemoteSchemaComponent --- .../components/RemoteSchemaComponent.tsx | 32 +++++++++++++++++++ .../src/schema-component/components/index.tsx | 1 + 2 files changed, 33 insertions(+) create mode 100644 packages/client/src/schema-component/components/RemoteSchemaComponent.tsx 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';