feat: add RemoteSchemaComponent
This commit is contained in:
parent
150deb28c1
commit
dde48fc775
@ -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 || {})} />;
|
||||
};
|
@ -2,3 +2,4 @@ export * from './RecursionComponent';
|
||||
export * from './SchemaComponent';
|
||||
export * from './SchemaComponentProvider';
|
||||
export * from './SchemaOptionsExpressionScopeProvider';
|
||||
export * from './RemoteSchemaComponent';
|
||||
|
Loading…
Reference in New Issue
Block a user