feat: add RemoteSchemaComponent

This commit is contained in:
chenos 2022-01-17 23:02:35 +08:00
parent 150deb28c1
commit dde48fc775
2 changed files with 33 additions and 0 deletions

View File

@ -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<RemoteSchemaComponentProps> = (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 <Spin />;
}
return <SchemaComponent scope={scope} schema={transform(data?.data || {})} />;
};

View File

@ -2,3 +2,4 @@ export * from './RecursionComponent';
export * from './SchemaComponent';
export * from './SchemaComponentProvider';
export * from './SchemaOptionsExpressionScopeProvider';
export * from './RemoteSchemaComponent';