2020-11-11 15:23:39 +08:00
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { Form, DrawerForm } from './Form/index';
|
|
|
|
import { Table } from './Table';
|
|
|
|
import { Details } from './Details';
|
|
|
|
import { useRequest, request, Spin } from '@nocobase/client';
|
|
|
|
import { SimpleTable } from './SimpleTable';
|
2020-11-13 22:01:14 +08:00
|
|
|
import api from '@/api-client';
|
2020-11-11 15:23:39 +08:00
|
|
|
|
|
|
|
const TEMPLATES = new Map<string, any>();
|
|
|
|
|
|
|
|
export function registerView(template: string, Template: any) {
|
|
|
|
TEMPLATES.set(template, Template);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getViewTemplate(template: string) {
|
|
|
|
return TEMPLATES.get(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
registerView('DrawerForm', DrawerForm);
|
|
|
|
registerView('PermissionForm', DrawerForm);
|
|
|
|
registerView('Form', Form);
|
|
|
|
registerView('Table', Table);
|
|
|
|
registerView('SimpleTable', SimpleTable);
|
|
|
|
registerView('Details', Details);
|
|
|
|
|
|
|
|
export default function ViewFactory(props) {
|
2020-11-13 22:01:14 +08:00
|
|
|
const { activeTab, viewCollectionName, viewName, reference } = props;
|
|
|
|
console.log({viewCollectionName, viewName});
|
|
|
|
const { data = {}, error, loading, run } = useRequest(() => api.resource(viewCollectionName).getView({
|
|
|
|
resourceKey: viewName,
|
|
|
|
}), {
|
2020-11-11 15:23:39 +08:00
|
|
|
refreshDeps: [viewCollectionName, viewName],
|
|
|
|
});
|
2020-11-13 22:01:14 +08:00
|
|
|
console.log(activeTab);
|
2020-11-11 15:23:39 +08:00
|
|
|
if (loading) {
|
|
|
|
return <Spin/>;
|
|
|
|
}
|
|
|
|
const { template } = data.data;
|
|
|
|
const Template = getViewTemplate(template);
|
|
|
|
return Template && <Template {...props} ref={reference} schema={data.data}/>;
|
|
|
|
}
|