feat: save as template
This commit is contained in:
parent
5554b1c260
commit
7285dd04ee
@ -35,8 +35,6 @@ import { I18nextProvider } from 'react-i18next';
|
||||
import { Link, NavLink } from 'react-router-dom';
|
||||
import apiClient from './apiClient';
|
||||
|
||||
console.log = (...args) => null;
|
||||
|
||||
apiClient.axios.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
|
@ -26,7 +26,6 @@ const InternalField: React.FC = (props) => {
|
||||
if (!uiSchema) {
|
||||
return;
|
||||
}
|
||||
console.log('uiSchema', uiSchema);
|
||||
setFieldProps('title', uiSchema.title);
|
||||
setFieldProps('description', uiSchema.description);
|
||||
setFieldProps('initialValue', uiSchema.default);
|
||||
|
@ -62,7 +62,7 @@ export const useSchemaTemplateManager = () => {
|
||||
const { mode, template } = options;
|
||||
if (mode === 'copy') {
|
||||
const { data } = await api.request({
|
||||
url: `/uiSchemas:getJsonSchema/${template.uid}`,
|
||||
url: `/uiSchemas:getJsonSchema/${template.uid}?includeAsyncNode=true`,
|
||||
});
|
||||
const s = data?.data || {};
|
||||
regenerateUid(s);
|
||||
@ -79,7 +79,7 @@ export const useSchemaTemplateManager = () => {
|
||||
},
|
||||
async copyTemplateSchema(template) {
|
||||
const { data } = await api.request({
|
||||
url: `/uiSchemas:getJsonSchema/${template.uid}`,
|
||||
url: `/uiSchemas:getJsonSchema/${template.uid}?includeAsyncNode=true`,
|
||||
});
|
||||
const s = data?.data || {};
|
||||
regenerateUid(s);
|
||||
@ -88,26 +88,16 @@ export const useSchemaTemplateManager = () => {
|
||||
async saveAsTemplate(values) {
|
||||
const { uid: schemaId } = values;
|
||||
const key = uid();
|
||||
await api.resource('uiSchemaTemplates').create({
|
||||
await api.resource('uiSchemas').saveAsTemplate({
|
||||
filterByTk: schemaId,
|
||||
values: {
|
||||
key,
|
||||
...values,
|
||||
},
|
||||
});
|
||||
await api.request({
|
||||
url: `/uiSchemas:clearAncestor/${schemaId}`,
|
||||
});
|
||||
await refresh();
|
||||
return { key };
|
||||
},
|
||||
async duplicate(template) {
|
||||
const { data } = await api.request({
|
||||
url: `/uiSchemas:getJsonSchema/${template.uid}`,
|
||||
});
|
||||
const s = data?.data || {};
|
||||
regenerateUid(s);
|
||||
return s;
|
||||
},
|
||||
getTemplateBySchemaId(schemaId) {
|
||||
return templates?.find((template) => template.uid === schemaId);
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Context } from '@nocobase/actions';
|
||||
import { ActionParams } from '@nocobase/resourcer';
|
||||
import lodash from 'lodash';
|
||||
import UiSchemaRepository from '../repository';
|
||||
import { ActionParams } from '@nocobase/resourcer';
|
||||
|
||||
const getRepositoryFromCtx = (ctx: Context) => {
|
||||
return ctx.db.getCollection('uiSchemas').repository as UiSchemaRepository;
|
||||
@ -64,6 +64,30 @@ export const uiSchemaActions = {
|
||||
insertAfterBegin: insertPositionActionBuilder('afterBegin'),
|
||||
insertBeforeEnd: insertPositionActionBuilder('beforeEnd'),
|
||||
insertAfterEnd: insertPositionActionBuilder('afterEnd'),
|
||||
|
||||
async saveAsTemplate(ctx: Context, next) {
|
||||
const { filterByTk, values } = ctx.action.params;
|
||||
const db = ctx.db;
|
||||
const transaction = await db.sequelize.transaction();
|
||||
try {
|
||||
await db.getRepository('uiSchemaTemplates').create({
|
||||
values: {
|
||||
...values,
|
||||
uid: filterByTk,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
await db.getRepository<UiSchemaRepository>('uiSchemas').clearAncestor(filterByTk, { transaction });
|
||||
ctx.body = {
|
||||
result: 'ok',
|
||||
};
|
||||
await transaction.commit();
|
||||
} catch (error) {
|
||||
await transaction.rollback();
|
||||
throw error;
|
||||
}
|
||||
await next();
|
||||
},
|
||||
};
|
||||
|
||||
function insertPositionActionBuilder(position: 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd') {
|
||||
|
Loading…
Reference in New Issue
Block a user