chore: using plugin locale

This commit is contained in:
sealday 2024-03-15 15:02:23 +08:00
parent ac1e9abf77
commit bca3a324e4
12 changed files with 96 additions and 267 deletions

View File

@ -7,11 +7,11 @@ import {
useSchemaInitializerItem, useSchemaInitializerItem,
} from '@nocobase/client'; } from '@nocobase/client';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useAuditLogsTranslation } from './locale';
export const AuditLogsBlockInitializer = () => { export const AuditLogsBlockInitializer = () => {
const { insert } = useSchemaInitializer(); const { insert } = useSchemaInitializer();
const { t } = useTranslation(); const { t } = useAuditLogsTranslation();
const itemConfig = useSchemaInitializerItem(); const itemConfig = useSchemaInitializerItem();
const schema = createTableBlockSchema({ const schema = createTableBlockSchema({

View File

@ -1,11 +1,12 @@
import { ExtendCollectionsProvider, TableBlockProvider } from '@nocobase/client';
import React from 'react'; import React from 'react';
import { ExtendCollectionsProvider, TableBlockProvider } from '@nocobase/client';
import { useAuditChangesCollection, useAuditLogsCollection, useCollectionsCollection } from './collections'; import { useAuditChangesCollection, useAuditLogsCollection, useCollectionsCollection } from './collections';
export const AuditLogsBlockProvider: React.FC = ({ children, ...restProps }) => { export const AuditLogsBlockProvider: React.FC = ({ children, ...restProps }) => {
const auditChangesCollection = useAuditChangesCollection(); const auditChangesCollection = useAuditChangesCollection();
const auditLogsCollection = useAuditLogsCollection(); const auditLogsCollection = useAuditLogsCollection();
const collectionsCollection = useCollectionsCollection(); const collectionsCollection = useCollectionsCollection();
console.log('audit logs blocks');
return ( return (
<ExtendCollectionsProvider collections={[auditLogsCollection, auditChangesCollection, collectionsCollection]}> <ExtendCollectionsProvider collections={[auditLogsCollection, auditChangesCollection, collectionsCollection]}>

View File

@ -3,7 +3,7 @@ import { useAuditLogsTranslation } from './locale';
export const useAuditLogsCollection = () => { export const useAuditLogsCollection = () => {
return { return {
name: 'auditLogs', name: 'auditLogs',
title: '{{t("Audit logs")}}', title: tval('Audit logs'),
fields: [ fields: [
{ {
name: 'createdAt', name: 'createdAt',
@ -11,7 +11,7 @@ export const useAuditLogsCollection = () => {
interface: 'createdAt', interface: 'createdAt',
uiSchema: { uiSchema: {
type: 'datetime', type: 'datetime',
title: '{{t("Created at")}}', title: tval('Created at'),
'x-component': 'DatePicker', 'x-component': 'DatePicker',
'x-component-props': { 'x-component-props': {
showTime: true, showTime: true,
@ -26,14 +26,14 @@ export const useAuditLogsCollection = () => {
interface: 'select', interface: 'select',
uiSchema: { uiSchema: {
type: 'string', type: 'string',
title: '{{t("Action type")}}', title: tval('Action type'),
'x-component': 'Select', 'x-component': 'Select',
'x-component-props': { ellipsis: true }, 'x-component-props': { ellipsis: true },
'x-read-pretty': true, 'x-read-pretty': true,
enum: [ enum: [
{ label: '{{t("Create record")}}', value: 'create', color: 'lime' }, { label: tval('Create record'), value: 'create', color: 'lime' },
{ label: '{{t("Update record")}}', value: 'update', color: 'gold' }, { label: tval('Update record'), value: 'update', color: 'gold' },
{ label: '{{t("Delete record")}}', value: 'destroy', color: 'magenta' }, { label: tval('Delete record'), value: 'destroy', color: 'magenta' },
], ],
}, },
}, },
@ -42,7 +42,7 @@ export const useAuditLogsCollection = () => {
type: 'string', type: 'string',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("Record ID")}}', title: tval('Record ID'),
type: 'string', type: 'string',
'x-component': 'Input', 'x-component': 'Input',
'x-component-props': { ellipsis: true }, 'x-component-props': { ellipsis: true },
@ -59,7 +59,7 @@ export const useAuditLogsCollection = () => {
foreignKey: 'collectionName', foreignKey: 'collectionName',
uiSchema: { uiSchema: {
type: 'object', type: 'object',
title: '{{t("Collection")}}', title: tval('Collection'),
'x-component': 'AssociationField', 'x-component': 'AssociationField',
'x-component-props': { fieldNames: { value: 'name', label: 'title' }, ellipsis: true }, 'x-component-props': { fieldNames: { value: 'name', label: 'title' }, ellipsis: true },
'x-read-pretty': true, 'x-read-pretty': true,
@ -75,7 +75,7 @@ export const useAuditLogsCollection = () => {
target: 'users', target: 'users',
uiSchema: { uiSchema: {
type: 'object', type: 'object',
title: '{{t("User")}}', title: tval('User'),
'x-component': 'AssociationField', 'x-component': 'AssociationField',
'x-component-props': { fieldNames: { value: 'id', label: 'nickname' }, ellipsis: true }, 'x-component-props': { fieldNames: { value: 'id', label: 'nickname' }, ellipsis: true },
'x-read-pretty': true, 'x-read-pretty': true,
@ -101,14 +101,14 @@ export const useAuditLogsCollection = () => {
export const useAuditChangesCollection = () => { export const useAuditChangesCollection = () => {
return { return {
name: 'auditChanges', name: 'auditChanges',
title: '{{t("Audit Changes")}}', title: tval('Audit Changes'),
fields: [ fields: [
{ {
name: 'field', name: 'field',
type: 'json', type: 'json',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("Field")}}', title: tval('Field'),
'x-component': 'AuditLogsField', 'x-component': 'AuditLogsField',
}, },
}, },
@ -117,7 +117,7 @@ export const useAuditChangesCollection = () => {
name: 'before', name: 'before',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("Before change")}}', title: tval('Before change'),
'x-component': 'AuditLogsValue', 'x-component': 'AuditLogsValue',
}, },
}, },
@ -126,7 +126,7 @@ export const useAuditChangesCollection = () => {
name: 'after', name: 'after',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("After change")}}', title: tval('After change'),
'x-component': 'AuditLogsValue', 'x-component': 'AuditLogsValue',
}, },
}, },
@ -137,14 +137,14 @@ export const useAuditChangesCollection = () => {
export const useCollectionsCollection = () => { export const useCollectionsCollection = () => {
return { return {
name: 'collections', name: 'collections',
title: '{{t("Collections")}}', title: tval('Collections'),
fields: [ fields: [
{ {
name: 'name', name: 'name',
type: 'string', type: 'string',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("Collection name")}}', title: tval('Collection name'),
type: 'string', type: 'string',
'x-component': 'Input', 'x-component': 'Input',
'x-component-props': { ellipsis: true }, 'x-component-props': { ellipsis: true },
@ -155,7 +155,7 @@ export const useCollectionsCollection = () => {
type: 'string', type: 'string',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("Collection display name")}}', title: tval('Collection display name'),
type: 'string', type: 'string',
'x-component': 'Input', 'x-component': 'Input',
'x-component-props': { ellipsis: true }, 'x-component-props': { ellipsis: true },

View File

@ -1,12 +1,12 @@
import { ActionInitializer } from '@nocobase/client'; import { ActionInitializer } from '@nocobase/client';
import React from 'react'; import React from 'react';
import { tval } from '../locale';
export const AuditLogsViewActionInitializer = () => { export const AuditLogsViewActionInitializer = () => {
const schema = { const schema = {
type: 'void', type: 'void',
title: '{{ t("View") }}', title: tval('View'),
'x-action': 'view', 'x-action': 'view',
// 'x-designer': 'Action.Designer',
'x-toolbar': 'ActionSchemaToolbar', 'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:view', 'x-settings': 'actionSettings:view',
'x-component': 'Action', 'x-component': 'Action',
@ -16,7 +16,7 @@ export const AuditLogsViewActionInitializer = () => {
properties: { properties: {
drawer: { drawer: {
type: 'void', type: 'void',
title: '{{ t("View record") }}', title: tval('View record'),
'x-component': 'Action.Container', 'x-component': 'Action.Container',
'x-component-props': { 'x-component-props': {
className: 'nb-action-popup', className: 'nb-action-popup',
@ -29,7 +29,7 @@ export const AuditLogsViewActionInitializer = () => {
properties: { properties: {
tab1: { tab1: {
type: 'void', type: 'void',
title: '{{t("Details")}}', title: tval('Details'),
'x-component': 'Tabs.TabPane', 'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer', 'x-designer': 'Tabs.Designer',
'x-component-props': {}, 'x-component-props': {},
@ -184,7 +184,7 @@ export const AuditLogsViewActionInitializer = () => {
properties: { properties: {
viewer: { viewer: {
type: 'void', type: 'void',
title: '{{ t("View record") }}', title: tval('View record'),
'x-component': 'RecordPicker.Viewer', 'x-component': 'RecordPicker.Viewer',
'x-component-props': { 'x-component-props': {
className: 'nb-action-popup', className: 'nb-action-popup',
@ -198,7 +198,7 @@ export const AuditLogsViewActionInitializer = () => {
properties: { properties: {
tab1: { tab1: {
type: 'void', type: 'void',
title: '{{t("Details")}}', title: tval('Details'),
'x-component': 'Tabs.TabPane', 'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer', 'x-designer': 'Tabs.Designer',
'x-component-props': {}, 'x-component-props': {},

View File

@ -11,10 +11,11 @@ import {
} from '@nocobase/client'; } from '@nocobase/client';
import React, { createContext, useContext } from 'react'; import React, { createContext, useContext } from 'react';
import { AuditLogsDesigner } from './AuditLogsDesigner'; import { AuditLogsDesigner } from './AuditLogsDesigner';
import { tval } from '../locale';
const collection = { const collection = {
name: 'auditLogs', name: 'auditLogs',
title: '{{t("Audit logs")}}', title: tval('Audit logs'),
fields: [ fields: [
{ {
name: 'createdAt', name: 'createdAt',
@ -22,7 +23,7 @@ const collection = {
interface: 'createdAt', interface: 'createdAt',
uiSchema: { uiSchema: {
type: 'datetime', type: 'datetime',
title: '{{t("Created at")}}', title: tval('Created at'),
'x-component': 'DatePicker', 'x-component': 'DatePicker',
'x-component-props': { 'x-component-props': {
showTime: true, showTime: true,
@ -36,13 +37,13 @@ const collection = {
interface: 'select', interface: 'select',
uiSchema: { uiSchema: {
type: 'string', type: 'string',
title: '{{t("Action type")}}', title: tval('Action type'),
'x-component': 'Select', 'x-component': 'Select',
'x-read-pretty': true, 'x-read-pretty': true,
enum: [ enum: [
{ label: '{{t("Create record")}}', value: 'create', color: 'lime' }, { label: tval('Create record'), value: 'create', color: 'lime' },
{ label: '{{t("Update record")}}', value: 'update', color: 'gold' }, { label: tval('Update record'), value: 'update', color: 'gold' },
{ label: '{{t("Delete record")}}', value: 'destroy', color: 'magenta' }, { label: tval('Delete record'), value: 'destroy', color: 'magenta' },
], ],
}, },
}, },
@ -112,7 +113,7 @@ export const AuditLogs: any = () => {
ext['column31'] = { ext['column31'] = {
type: 'void', type: 'void',
'x-component': 'TableV2.Column', 'x-component': 'TableV2.Column',
title: '{{t("Record ID")}}', title: tval('Record ID'),
properties: { properties: {
recordId: { recordId: {
'x-component': 'Input', 'x-component': 'Input',
@ -141,7 +142,7 @@ export const AuditLogs: any = () => {
properties: { properties: {
filter: { filter: {
type: 'void', type: 'void',
title: '{{ t("Filter") }}', title: tval('Filter'),
'x-action': 'filter', 'x-action': 'filter',
// 'x-designer': 'Filter.Action.Designer', // 'x-designer': 'Filter.Action.Designer',
'x-component': 'Filter.Action', 'x-component': 'Filter.Action',
@ -166,7 +167,7 @@ export const AuditLogs: any = () => {
properties: { properties: {
actions: { actions: {
type: 'void', type: 'void',
title: '{{ t("Actions") }}', title: tval('Actions'),
'x-action-column': 'actions', 'x-action-column': 'actions',
'x-decorator': 'TableV2.Column.ActionBar', 'x-decorator': 'TableV2.Column.ActionBar',
'x-component': 'TableV2.Column', 'x-component': 'TableV2.Column',
@ -251,7 +252,7 @@ export const AuditLogs: any = () => {
properties: { properties: {
collection: { collection: {
type: 'string', type: 'string',
title: '{{t("Collection display name")}}', title: tval('Collection display name'),
'x-component': 'Collection', 'x-component': 'Collection',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-read-pretty': true, 'x-read-pretty': true,
@ -306,7 +307,7 @@ export const AuditLogs: any = () => {
properties: { properties: {
user: { user: {
type: 'string', type: 'string',
title: '{{t("User")}}', title: tval('User'),
'x-component': 'Username', 'x-component': 'Username',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-read-pretty': true, 'x-read-pretty': true,
@ -325,7 +326,7 @@ export const AuditLogs: any = () => {
properties: { properties: {
changes: { changes: {
type: 'array', type: 'array',
title: '{{t("Field value changes")}}', title: tval('Field value changes'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'ArrayTable', 'x-component': 'ArrayTable',
'x-component-props': { 'x-component-props': {
@ -340,7 +341,7 @@ export const AuditLogs: any = () => {
'x-component': 'ArrayTable.Column', 'x-component': 'ArrayTable.Column',
'x-component-props': { 'x-component-props': {
width: 200, width: 200,
title: '{{t("Field")}}', title: tval('Field'),
}, },
properties: { properties: {
field: { field: {
@ -355,7 +356,7 @@ export const AuditLogs: any = () => {
'x-component': 'ArrayTable.Column', 'x-component': 'ArrayTable.Column',
'x-component-props': { 'x-component-props': {
width: 200, width: 200,
title: '{{t("Before change")}}', title: tval('Before change'),
}, },
properties: { properties: {
before: { before: {
@ -370,7 +371,7 @@ export const AuditLogs: any = () => {
'x-component': 'ArrayTable.Column', 'x-component': 'ArrayTable.Column',
'x-component-props': { 'x-component-props': {
width: 200, width: 200,
title: '{{t("After change")}}', title: tval('After change'),
}, },
properties: { properties: {
after: { after: {
@ -432,7 +433,7 @@ export const AuditLogs: any = () => {
column3: { column3: {
type: 'void', type: 'void',
'x-component': 'TableV2.Column', 'x-component': 'TableV2.Column',
title: '{{t("Collection display name")}}', title: tval('Collection display name'),
properties: { properties: {
collection: { collection: {
'x-component': 'Collection', 'x-component': 'Collection',
@ -444,7 +445,7 @@ export const AuditLogs: any = () => {
column4: { column4: {
type: 'void', type: 'void',
'x-component': 'TableV2.Column', 'x-component': 'TableV2.Column',
title: '{{t("User")}}', title: tval('User'),
properties: { properties: {
user: { user: {
'x-component': 'Username', 'x-component': 'Username',

View File

@ -11,7 +11,7 @@ import {
useTableBlockContext, useTableBlockContext,
} from '@nocobase/client'; } from '@nocobase/client';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useAuditLogsTranslation } from '../locale';
export const AuditLogsDesigner = () => { export const AuditLogsDesigner = () => {
const { name, title } = useCollection_deprecated(); const { name, title } = useCollection_deprecated();
@ -19,7 +19,7 @@ export const AuditLogsDesigner = () => {
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const { form } = useFormBlockContext(); const { form } = useFormBlockContext();
const { service } = useTableBlockContext(); const { service } = useTableBlockContext();
const { t } = useTranslation(); const { t } = useAuditLogsTranslation();
const { dn } = useDesignable(); const { dn } = useDesignable();
return ( return (
<GeneralSchemaDesigner title={title || name}> <GeneralSchemaDesigner title={title || name}>

View File

@ -1,34 +1,23 @@
import { Plugin, SchemaInitializerItemType } from '@nocobase/client'; import { Plugin, SchemaInitializerItemType } from '@nocobase/client';
import { AuditLogsProvider } from './AuditLogsProvider'; import { AuditLogsProvider } from './AuditLogsProvider';
import { import { auditLogsTableActionColumnInitializers } from './initializers/AuditLogsTableActionColumnInitializers';
auditLogsTableActionColumnInitializers, import { auditLogsTableActionInitializers } from './initializers/AuditLogsTableActionInitializers';
auditLogsTableActionColumnInitializers_deprecated, import { auditLogsTableColumnInitializers } from './initializers/AuditLogsTableColumnInitializers';
} from './initializers/AuditLogsTableActionColumnInitializers'; import { tval } from './locale';
import {
auditLogsTableActionInitializers,
auditLogsTableActionInitializers_deprecated,
} from './initializers/AuditLogsTableActionInitializers';
import {
auditLogsTableColumnInitializers,
auditLogsTableColumnInitializers_deprecated,
} from './initializers/AuditLogsTableColumnInitializers';
export * from './AuditLogsBlockInitializer'; export * from './AuditLogsBlockInitializer';
export * from './AuditLogsProvider'; export * from './AuditLogsProvider';
export class AuditLogsPlugin extends Plugin { export class AuditLogsPlugin extends Plugin {
async load() { async load() {
this.app.use(AuditLogsProvider); this.app.use(AuditLogsProvider);
this.app.schemaInitializerManager.add(auditLogsTableActionInitializers_deprecated);
this.app.schemaInitializerManager.add(auditLogsTableActionInitializers); this.app.schemaInitializerManager.add(auditLogsTableActionInitializers);
this.app.schemaInitializerManager.add(auditLogsTableActionColumnInitializers_deprecated);
this.app.schemaInitializerManager.add(auditLogsTableActionColumnInitializers); this.app.schemaInitializerManager.add(auditLogsTableActionColumnInitializers);
this.app.schemaInitializerManager.add(auditLogsTableColumnInitializers_deprecated);
this.app.schemaInitializerManager.add(auditLogsTableColumnInitializers); this.app.schemaInitializerManager.add(auditLogsTableColumnInitializers);
const blockInitializers = this.app.schemaInitializerManager.get('page:addBlock'); const blockInitializers = this.app.schemaInitializerManager.get('page:addBlock');
const recordBlockInitializers = this.app.schemaInitializerManager.get('popup:common:addBlock'); const recordBlockInitializers = this.app.schemaInitializerManager.get('popup:common:addBlock');
const auditLogs: Omit<SchemaInitializerItemType, 'name'> = { const auditLogs: Omit<SchemaInitializerItemType, 'name'> = {
title: '{{t("Audit logs")}}', title: tval('Audit logs'),
Component: 'AuditLogsBlockInitializer', Component: 'AuditLogsBlockInitializer',
}; };
blockInitializers.add('otherBlocks.auditLogs', auditLogs); blockInitializers.add('otherBlocks.auditLogs', auditLogs);

View File

@ -1,10 +1,11 @@
import { InitializerWithSwitch, useSchemaInitializerItem } from '@nocobase/client'; import { InitializerWithSwitch, useSchemaInitializerItem } from '@nocobase/client';
import React from 'react'; import React from 'react';
import { tval } from '../locale';
export const AuditLogsTableActionColumnInitializer = () => { export const AuditLogsTableActionColumnInitializer = () => {
const schema = { const schema = {
type: 'void', type: 'void',
title: '{{ t("Actions") }}', title: tval('Actions'),
'x-decorator': 'TableV2.Column.ActionBar', 'x-decorator': 'TableV2.Column.ActionBar',
'x-component': 'TableV2.Column', 'x-component': 'TableV2.Column',
'x-designer': 'TableV2.ActionColumnDesigner', 'x-designer': 'TableV2.ActionColumnDesigner',

View File

@ -1,82 +1,10 @@
import { MenuOutlined } from '@ant-design/icons'; import { MenuOutlined } from '@ant-design/icons';
import { useFieldSchema } from '@formily/react'; import { useFieldSchema } from '@formily/react';
import { import { createDesignable, Resizable, SchemaInitializer, useAPIClient, useDesignable } from '@nocobase/client';
CompatibleSchemaInitializer,
createDesignable,
Resizable,
useAPIClient,
useDesignable,
} from '@nocobase/client';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { tval, useAuditLogsTranslation } from '../locale';
/** export const auditLogsTableActionColumnInitializers = new SchemaInitializer({
* @deprecated
*/
export const auditLogsTableActionColumnInitializers_deprecated = new CompatibleSchemaInitializer({
name: 'AuditLogsTableActionColumnInitializers',
insertPosition: 'beforeEnd',
Component: (props: any) => <MenuOutlined {...props} style={{ cursor: 'pointer' }} />,
useInsert() {
const fieldSchema = useFieldSchema();
const api = useAPIClient();
const { refresh } = useDesignable();
const { t } = useTranslation();
return (schema) => {
const spaceSchema = fieldSchema.reduceProperties((buf, schema) => {
if (schema['x-component'] === 'Space') {
return schema;
}
return buf;
}, null);
if (!spaceSchema) {
return;
}
const dn = createDesignable({
t,
api,
refresh,
current: spaceSchema,
});
dn.loadAPIClientEvents();
dn.insertBeforeEnd(schema);
};
},
items: [
{
name: 'enableActions',
type: 'itemGroup',
title: '{{t("Enable actions")}}',
children: [
{
name: 'view',
type: 'item',
title: '{{t("View")}}',
Component: 'AuditLogsViewActionInitializer',
schema: {
'x-component': 'Action.Link',
'x-action': 'view',
'x-decorator': 'ACLActionProvider',
},
},
],
},
{
name: 'divider',
type: 'divider',
},
{
name: 'columnWidth',
type: 'item',
title: '{{t("Column width")}}',
Component: Resizable,
},
],
});
export const auditLogsTableActionColumnInitializers = new CompatibleSchemaInitializer(
{
name: 'auditLogsTable:configureItemActions', name: 'auditLogsTable:configureItemActions',
insertPosition: 'beforeEnd', insertPosition: 'beforeEnd',
Component: (props: any) => <MenuOutlined {...props} style={{ cursor: 'pointer' }} />, Component: (props: any) => <MenuOutlined {...props} style={{ cursor: 'pointer' }} />,
@ -84,7 +12,7 @@ export const auditLogsTableActionColumnInitializers = new CompatibleSchemaInitia
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const api = useAPIClient(); const api = useAPIClient();
const { refresh } = useDesignable(); const { refresh } = useDesignable();
const { t } = useTranslation(); const { t } = useAuditLogsTranslation();
return (schema) => { return (schema) => {
const spaceSchema = fieldSchema.reduceProperties((buf, schema) => { const spaceSchema = fieldSchema.reduceProperties((buf, schema) => {
@ -110,12 +38,12 @@ export const auditLogsTableActionColumnInitializers = new CompatibleSchemaInitia
{ {
name: 'enableActions', name: 'enableActions',
type: 'itemGroup', type: 'itemGroup',
title: '{{t("Enable actions")}}', title: tval('Enable actions'),
children: [ children: [
{ {
name: 'view', name: 'view',
type: 'item', type: 'item',
title: '{{t("View")}}', title: tval('View'),
Component: 'AuditLogsViewActionInitializer', Component: 'AuditLogsViewActionInitializer',
schema: { schema: {
'x-component': 'Action.Link', 'x-component': 'Action.Link',
@ -132,10 +60,8 @@ export const auditLogsTableActionColumnInitializers = new CompatibleSchemaInitia
{ {
name: 'columnWidth', name: 'columnWidth',
type: 'item', type: 'item',
title: '{{t("Column width")}}', title: tval('Column width'),
Component: Resizable, Component: Resizable,
}, },
], ],
}, });
auditLogsTableActionColumnInitializers_deprecated,
);

View File

@ -1,12 +1,9 @@
import { CompatibleSchemaInitializer } from '@nocobase/client'; import { SchemaInitializer } from '@nocobase/client';
import { tval } from '../locale';
/** export const auditLogsTableActionInitializers = new SchemaInitializer({
* @deprecated name: 'auditLogsTable:configureActions',
* title: tval('Configure actions'),
*/
export const auditLogsTableActionInitializers_deprecated = new CompatibleSchemaInitializer({
name: 'AuditLogsTableActionInitializers',
title: "{{t('Configure actions')}}",
icon: 'SettingOutlined', icon: 'SettingOutlined',
style: { style: {
marginLeft: 8, marginLeft: 8,
@ -14,12 +11,12 @@ export const auditLogsTableActionInitializers_deprecated = new CompatibleSchemaI
items: [ items: [
{ {
type: 'itemGroup', type: 'itemGroup',
title: "{{t('Enable actions')}}", title: tval('Enable actions'),
name: 'enableActions', name: 'enableActions',
children: [ children: [
{ {
name: 'filter', name: 'filter',
title: "{{t('Filter')}}", title: tval('Filter'),
Component: 'FilterActionInitializer', Component: 'FilterActionInitializer',
schema: { schema: {
'x-align': 'left', 'x-align': 'left',
@ -27,7 +24,7 @@ export const auditLogsTableActionInitializers_deprecated = new CompatibleSchemaI
}, },
{ {
name: 'refresh', name: 'refresh',
title: "{{t('Refresh')}}", title: tval('Refresh'),
Component: 'RefreshActionInitializer', Component: 'RefreshActionInitializer',
schema: { schema: {
'x-align': 'right', 'x-align': 'right',
@ -37,40 +34,3 @@ export const auditLogsTableActionInitializers_deprecated = new CompatibleSchemaI
}, },
], ],
}); });
export const auditLogsTableActionInitializers = new CompatibleSchemaInitializer(
{
name: 'auditLogsTable:configureActions',
title: "{{t('Configure actions')}}",
icon: 'SettingOutlined',
style: {
marginLeft: 8,
},
items: [
{
type: 'itemGroup',
title: "{{t('Enable actions')}}",
name: 'enableActions',
children: [
{
name: 'filter',
title: "{{t('Filter')}}",
Component: 'FilterActionInitializer',
schema: {
'x-align': 'left',
},
},
{
name: 'refresh',
title: "{{t('Refresh')}}",
Component: 'RefreshActionInitializer',
schema: {
'x-align': 'right',
},
},
],
},
],
},
auditLogsTableActionInitializers_deprecated,
);

View File

@ -1,5 +1,5 @@
import { import {
CompatibleSchemaInitializer, SchemaInitializer,
SchemaInitializerChildren, SchemaInitializerChildren,
useAssociatedTableColumnInitializerFields, useAssociatedTableColumnInitializerFields,
useCompile, useCompile,
@ -7,12 +7,12 @@ import {
useTableColumnInitializerFields, useTableColumnInitializerFields,
} from '@nocobase/client'; } from '@nocobase/client';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { tval, useAuditLogsTranslation } from '../locale';
// 表格列配置 // 表格列配置
const ParentCollectionFields = () => { const ParentCollectionFields = () => {
const inheritFields = useInheritsTableColumnInitializerFields(); const inheritFields = useInheritsTableColumnInitializerFields();
const { t } = useTranslation(); const { t } = useAuditLogsTranslation();
const compile = useCompile(); const compile = useCompile();
if (!inheritFields?.length) return null; if (!inheritFields?.length) return null;
const res = []; const res = [];
@ -30,7 +30,7 @@ const ParentCollectionFields = () => {
const AssociatedFields = () => { const AssociatedFields = () => {
const associatedFields = useAssociatedTableColumnInitializerFields(); const associatedFields = useAssociatedTableColumnInitializerFields();
const { t } = useTranslation(); const { t } = useAuditLogsTranslation();
if (!associatedFields?.length) return null; if (!associatedFields?.length) return null;
const schema: any = [ const schema: any = [
@ -44,14 +44,11 @@ const AssociatedFields = () => {
return <SchemaInitializerChildren>{schema}</SchemaInitializerChildren>; return <SchemaInitializerChildren>{schema}</SchemaInitializerChildren>;
}; };
/** export const auditLogsTableColumnInitializers = new SchemaInitializer({
* @deprecated name: 'auditLogsTable:configureColumns',
*/
export const auditLogsTableColumnInitializers_deprecated = new CompatibleSchemaInitializer({
name: 'AuditLogsTableColumnInitializers',
insertPosition: 'beforeEnd', insertPosition: 'beforeEnd',
icon: 'SettingOutlined', icon: 'SettingOutlined',
title: '{{t("Configure columns")}}', title: tval('Configure columns'),
wrap(s) { wrap(s) {
if (s['x-action-column']) { if (s['x-action-column']) {
return s; return s;
@ -72,7 +69,7 @@ export const auditLogsTableColumnInitializers_deprecated = new CompatibleSchemaI
{ {
name: 'displayFields', name: 'displayFields',
type: 'itemGroup', type: 'itemGroup',
title: '{{t("Display fields")}}', title: tval('Display fields'),
useChildren: useTableColumnInitializerFields, useChildren: useTableColumnInitializerFields,
}, },
{ {
@ -85,55 +82,8 @@ export const auditLogsTableColumnInitializers_deprecated = new CompatibleSchemaI
}, },
{ {
name: 'actionColumn', name: 'actionColumn',
title: '{{t("Action column")}}', title: tval('Action column'),
Component: 'AuditLogsTableActionColumnInitializer', Component: 'AuditLogsTableActionColumnInitializer',
}, },
], ],
}); });
export const auditLogsTableColumnInitializers = new CompatibleSchemaInitializer(
{
name: 'auditLogsTable:configureColumns',
insertPosition: 'beforeEnd',
icon: 'SettingOutlined',
title: '{{t("Configure columns")}}',
wrap(s) {
if (s['x-action-column']) {
return s;
}
return {
type: 'void',
'x-decorator': 'TableV2.Column.Decorator',
'x-designer': 'TableV2.Column.Designer',
'x-component': 'TableV2.Column',
properties: {
[s.name]: {
...s,
},
},
};
},
items: [
{
name: 'displayFields',
type: 'itemGroup',
title: '{{t("Display fields")}}',
useChildren: useTableColumnInitializerFields,
},
{
name: 'parentCollectionFields',
Component: ParentCollectionFields,
},
{
name: 'associationFields',
Component: AssociatedFields,
},
{
name: 'actionColumn',
title: '{{t("Action column")}}',
Component: 'AuditLogsTableActionColumnInitializer',
},
],
},
auditLogsTableColumnInitializers_deprecated,
);

View File

@ -1,4 +1,5 @@
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { tval } from './locale';
export const createSchema = () => { export const createSchema = () => {
const filterSchema = { const filterSchema = {
@ -7,7 +8,7 @@ export const createSchema = () => {
popover: true, popover: true,
}, },
type: 'void', type: 'void',
title: '{{t("Filter")}}', title: tval('Filter'),
properties: { properties: {
popover: { popover: {
type: 'void', type: 'void',
@ -44,7 +45,7 @@ export const createSchema = () => {
}, },
cancel: { cancel: {
type: 'void', type: 'void',
title: '{{t("Cancel")}}', title: tval('Cancel'),
'x-component': 'Action', 'x-component': 'Action',
'x-component-props': { 'x-component-props': {
useAction: '{{cm.useCancelFilterAction}}', useAction: '{{cm.useCancelFilterAction}}',
@ -52,7 +53,7 @@ export const createSchema = () => {
}, },
submit: { submit: {
type: 'void', type: 'void',
title: '{{t("Submit")}}', title: tval('Submit'),
'x-component': 'Action', 'x-component': 'Action',
'x-component-props': { 'x-component-props': {
type: 'primary', type: 'primary',
@ -110,7 +111,7 @@ export const createSchema = () => {
properties: { properties: {
column1: { column1: {
type: 'void', type: 'void',
title: "{{t('Created at')}}", title: tval('Created at'),
'x-component': 'Table.Column', 'x-component': 'Table.Column',
properties: { properties: {
created_at: { created_at: {
@ -125,7 +126,7 @@ export const createSchema = () => {
}, },
column2: { column2: {
type: 'void', type: 'void',
title: "{{t('Created by')}}", title: tval('Created by'),
'x-component': 'Table.Column', 'x-component': 'Table.Column',
properties: { properties: {
'user.nickname': { 'user.nickname': {
@ -137,7 +138,7 @@ export const createSchema = () => {
}, },
column3: { column3: {
type: 'void', type: 'void',
title: "{{t('Collection display name')}}", title: tval('Collection display name'),
'x-component': 'Table.Column', 'x-component': 'Table.Column',
properties: { properties: {
'collection.title': { 'collection.title': {
@ -149,7 +150,7 @@ export const createSchema = () => {
}, },
column4: { column4: {
type: 'void', type: 'void',
title: "{{t('Action type')}}", title: tval('Action type'),
'x-component': 'Table.Column', 'x-component': 'Table.Column',
properties: { properties: {
type: { type: {
@ -166,7 +167,7 @@ export const createSchema = () => {
}, },
[uid()]: { [uid()]: {
type: 'void', type: 'void',
title: "{{t('Actions')}}", title: tval('Actions'),
'x-component': 'Table.Column', 'x-component': 'Table.Column',
'x-component-props': { 'x-component-props': {
width: 60, width: 60,
@ -192,7 +193,7 @@ export const createSchema = () => {
properties: { properties: {
created_at: { created_at: {
type: 'string', type: 'string',
title: "{{t('Created at')}}", title: tval('Created at'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'DatePicker', 'x-component': 'DatePicker',
'x-read-pretty': true, 'x-read-pretty': true,
@ -202,37 +203,37 @@ export const createSchema = () => {
}, },
'user.nickname': { 'user.nickname': {
type: 'string', type: 'string',
title: "{{t('Created by')}}", title: tval('Created by'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input', 'x-component': 'Input',
'x-read-pretty': true, 'x-read-pretty': true,
}, },
'collection.title': { 'collection.title': {
type: 'string', type: 'string',
title: "{{t('Collection display name')}}", title: tval('Collection display name'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input', 'x-component': 'Input',
'x-read-pretty': true, 'x-read-pretty': true,
}, },
type: { type: {
type: 'string', type: 'string',
title: "{{t('Action type')}}", title: tval('Action type'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Select', 'x-component': 'Select',
'x-read-pretty': true, 'x-read-pretty': true,
enum: [ enum: [
{ {
label: "{{t('Insert')}}", label: tval('Insert'),
value: 'create', value: 'create',
color: 'green', color: 'green',
}, },
{ {
label: "{{t('Update')}}", label: tval('Update'),
value: 'update', value: 'update',
color: 'blue', color: 'blue',
}, },
{ {
label: "{{t('Delete')}}", label: tval('Delete'),
value: 'destroy', value: 'destroy',
color: 'red', color: 'red',
}, },
@ -240,7 +241,7 @@ export const createSchema = () => {
}, },
changes: { changes: {
type: 'array', type: 'array',
title: "{{t('Data changes')}}", title: tval('Data changes'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Table.Array', 'x-component': 'Table.Array',
'x-component-props': { 'x-component-props': {
@ -253,7 +254,7 @@ export const createSchema = () => {
column1: { column1: {
type: 'void', type: 'void',
'x-component': 'Table.Column', 'x-component': 'Table.Column',
'x-component-props': { title: "{{t('Field display name')}}" }, 'x-component-props': { title: tval('Field display name') },
properties: { properties: {
field: { field: {
type: 'string', type: 'string',