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 { Link, NavLink } from 'react-router-dom';
|
||||||
import apiClient from './apiClient';
|
import apiClient from './apiClient';
|
||||||
|
|
||||||
console.log = (...args) => null;
|
|
||||||
|
|
||||||
apiClient.axios.interceptors.response.use(
|
apiClient.axios.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
|
@ -26,7 +26,6 @@ const InternalField: React.FC = (props) => {
|
|||||||
if (!uiSchema) {
|
if (!uiSchema) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('uiSchema', uiSchema);
|
|
||||||
setFieldProps('title', uiSchema.title);
|
setFieldProps('title', uiSchema.title);
|
||||||
setFieldProps('description', uiSchema.description);
|
setFieldProps('description', uiSchema.description);
|
||||||
setFieldProps('initialValue', uiSchema.default);
|
setFieldProps('initialValue', uiSchema.default);
|
||||||
|
@ -62,7 +62,7 @@ export const useSchemaTemplateManager = () => {
|
|||||||
const { mode, template } = options;
|
const { mode, template } = options;
|
||||||
if (mode === 'copy') {
|
if (mode === 'copy') {
|
||||||
const { data } = await api.request({
|
const { data } = await api.request({
|
||||||
url: `/uiSchemas:getJsonSchema/${template.uid}`,
|
url: `/uiSchemas:getJsonSchema/${template.uid}?includeAsyncNode=true`,
|
||||||
});
|
});
|
||||||
const s = data?.data || {};
|
const s = data?.data || {};
|
||||||
regenerateUid(s);
|
regenerateUid(s);
|
||||||
@ -79,7 +79,7 @@ export const useSchemaTemplateManager = () => {
|
|||||||
},
|
},
|
||||||
async copyTemplateSchema(template) {
|
async copyTemplateSchema(template) {
|
||||||
const { data } = await api.request({
|
const { data } = await api.request({
|
||||||
url: `/uiSchemas:getJsonSchema/${template.uid}`,
|
url: `/uiSchemas:getJsonSchema/${template.uid}?includeAsyncNode=true`,
|
||||||
});
|
});
|
||||||
const s = data?.data || {};
|
const s = data?.data || {};
|
||||||
regenerateUid(s);
|
regenerateUid(s);
|
||||||
@ -88,26 +88,16 @@ export const useSchemaTemplateManager = () => {
|
|||||||
async saveAsTemplate(values) {
|
async saveAsTemplate(values) {
|
||||||
const { uid: schemaId } = values;
|
const { uid: schemaId } = values;
|
||||||
const key = uid();
|
const key = uid();
|
||||||
await api.resource('uiSchemaTemplates').create({
|
await api.resource('uiSchemas').saveAsTemplate({
|
||||||
|
filterByTk: schemaId,
|
||||||
values: {
|
values: {
|
||||||
key,
|
key,
|
||||||
...values,
|
...values,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await api.request({
|
|
||||||
url: `/uiSchemas:clearAncestor/${schemaId}`,
|
|
||||||
});
|
|
||||||
await refresh();
|
await refresh();
|
||||||
return { key };
|
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) {
|
getTemplateBySchemaId(schemaId) {
|
||||||
return templates?.find((template) => template.uid === schemaId);
|
return templates?.find((template) => template.uid === schemaId);
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Context } from '@nocobase/actions';
|
import { Context } from '@nocobase/actions';
|
||||||
|
import { ActionParams } from '@nocobase/resourcer';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
import UiSchemaRepository from '../repository';
|
import UiSchemaRepository from '../repository';
|
||||||
import { ActionParams } from '@nocobase/resourcer';
|
|
||||||
|
|
||||||
const getRepositoryFromCtx = (ctx: Context) => {
|
const getRepositoryFromCtx = (ctx: Context) => {
|
||||||
return ctx.db.getCollection('uiSchemas').repository as UiSchemaRepository;
|
return ctx.db.getCollection('uiSchemas').repository as UiSchemaRepository;
|
||||||
@ -64,6 +64,30 @@ export const uiSchemaActions = {
|
|||||||
insertAfterBegin: insertPositionActionBuilder('afterBegin'),
|
insertAfterBegin: insertPositionActionBuilder('afterBegin'),
|
||||||
insertBeforeEnd: insertPositionActionBuilder('beforeEnd'),
|
insertBeforeEnd: insertPositionActionBuilder('beforeEnd'),
|
||||||
insertAfterEnd: insertPositionActionBuilder('afterEnd'),
|
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') {
|
function insertPositionActionBuilder(position: 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd') {
|
||||||
|
Loading…
Reference in New Issue
Block a user