mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 16:15:44 +00:00
refactor: association schemaInitialize
This commit is contained in:
parent
00ce83e236
commit
044ea14d47
@ -47,50 +47,13 @@ export const linkTo: IField = {
|
||||
},
|
||||
availableTypes: ['belongsToMany'],
|
||||
schemaInitialize(schema: ISchema, { readPretty, block, targetCollection }) {
|
||||
return;
|
||||
if (targetCollection?.titleField && schema['x-component-props']) {
|
||||
schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' };
|
||||
schema['x-component-props'].fieldNames.label = targetCollection.titleField;
|
||||
}
|
||||
|
||||
if (targetCollection?.template === 'file') {
|
||||
const fieldNames = schema['x-component-props']['fieldNames'] || { label: 'preview', value: 'id' };
|
||||
fieldNames.label = 'preview';
|
||||
schema['x-component-props']['fieldNames'] = fieldNames;
|
||||
schema['x-component-props'].quickUpload = true;
|
||||
schema['x-component-props'].selectFile = true;
|
||||
}
|
||||
|
||||
if (block === 'Form') {
|
||||
if (schema['x-component'] === 'AssociationSelect') {
|
||||
Object.assign(schema, {
|
||||
type: 'string',
|
||||
'x-designer': 'AssociationSelect.Designer',
|
||||
});
|
||||
} else {
|
||||
schema.type = 'string';
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
return schema;
|
||||
} else {
|
||||
if (readPretty) {
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
};
|
||||
} else {
|
||||
schema['properties'] = {
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
schema['x-component-props'] = schema['x-component-props'] || {};
|
||||
schema['x-component-props']['ellipsis'] = true;
|
||||
|
||||
// 预览文件时需要的参数
|
||||
schema['x-component-props']['size'] = 'small';
|
||||
}
|
||||
|
@ -54,48 +54,13 @@ export const m2m: IField = {
|
||||
availableTypes: ['belongsToMany'],
|
||||
schemaInitialize(schema: ISchema, { readPretty, block, targetCollection }) {
|
||||
schema['type'] = 'array';
|
||||
return;
|
||||
if (targetCollection?.titleField && schema['x-component-props']) {
|
||||
schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' };
|
||||
schema['x-component-props'].fieldNames.label = targetCollection.titleField;
|
||||
}
|
||||
|
||||
if (targetCollection?.template === 'file') {
|
||||
const fieldNames = schema['x-component-props']['fieldNames'] || { label: 'preview', value: 'id' };
|
||||
fieldNames.label = 'preview';
|
||||
schema['x-component-props']['fieldNames'] = fieldNames;
|
||||
schema['x-component-props'].quickUpload = true;
|
||||
schema['x-component-props'].selectFile = true;
|
||||
}
|
||||
|
||||
if (block === 'Form') {
|
||||
if (schema['x-component'] === 'AssociationSelect') {
|
||||
Object.assign(schema, {
|
||||
type: 'string',
|
||||
'x-designer': 'AssociationSelect.Designer',
|
||||
});
|
||||
} else {
|
||||
schema.type = 'string';
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
if (readPretty) {
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
};
|
||||
} else {
|
||||
schema['properties'] = {
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
schema['x-component-props'] = schema['x-component-props'] || {};
|
||||
schema['x-component-props']['ellipsis'] = true;
|
||||
|
||||
// 预览文件时需要的参数
|
||||
schema['x-component-props']['size'] = 'small';
|
||||
}
|
||||
|
@ -53,48 +53,13 @@ export const m2o: IField = {
|
||||
availableTypes: ['belongsTo'],
|
||||
schemaInitialize(schema: ISchema, { block, readPretty, targetCollection }) {
|
||||
schema['type'] = 'object';
|
||||
return;
|
||||
if (targetCollection?.titleField && schema['x-component-props']) {
|
||||
schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' };
|
||||
schema['x-component-props'].fieldNames.label = targetCollection.titleField;
|
||||
}
|
||||
|
||||
if (targetCollection?.template === 'file') {
|
||||
const fieldNames = schema['x-component-props']['fieldNames'] || { label: 'preview', value: 'id' };
|
||||
fieldNames.label = 'preview';
|
||||
schema['x-component-props']['fieldNames'] = fieldNames;
|
||||
schema['x-component-props'].quickUpload = true;
|
||||
schema['x-component-props'].selectFile = true;
|
||||
}
|
||||
|
||||
if (block === 'Form') {
|
||||
if (schema['x-component'] === 'AssociationSelect') {
|
||||
Object.assign(schema, {
|
||||
type: 'string',
|
||||
'x-designer': 'AssociationSelect.Designer',
|
||||
});
|
||||
} else {
|
||||
schema.type = 'string';
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
if (readPretty) {
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
};
|
||||
} else {
|
||||
schema['properties'] = {
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
schema['x-component-props'] = schema['x-component-props'] || {};
|
||||
schema['x-component-props']['ellipsis'] = true;
|
||||
|
||||
// 预览文件时需要的参数
|
||||
schema['x-component-props']['size'] = 'small';
|
||||
}
|
||||
|
@ -53,83 +53,13 @@ export const o2m: IField = {
|
||||
availableTypes: ['hasMany'],
|
||||
schemaInitialize(schema: ISchema, { field, block, readPretty, targetCollection }) {
|
||||
schema['type'] = 'array';
|
||||
return;
|
||||
if (targetCollection?.titleField && schema['x-component-props']) {
|
||||
schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' };
|
||||
schema['x-component-props'].fieldNames.label = targetCollection.titleField;
|
||||
}
|
||||
|
||||
if (block === 'Form') {
|
||||
if (schema['x-component'] === 'TableField') {
|
||||
const association = `${field.collectionName}.${field.name}`;
|
||||
schema['type'] = 'void';
|
||||
schema['properties'] = {
|
||||
block: {
|
||||
type: 'void',
|
||||
'x-decorator': 'TableFieldProvider',
|
||||
'x-acl-action': `${association}:list`,
|
||||
'x-decorator-props': {
|
||||
collection: field.target,
|
||||
association: association,
|
||||
resource: association,
|
||||
action: 'list',
|
||||
params: {
|
||||
paginate: false,
|
||||
},
|
||||
showIndex: true,
|
||||
dragSort: false,
|
||||
fieldName: field.name,
|
||||
},
|
||||
properties: {
|
||||
actions: {
|
||||
type: 'void',
|
||||
'x-initializer': 'SubTableActionInitializers',
|
||||
'x-component': 'TableField.ActionBar',
|
||||
'x-component-props': {},
|
||||
},
|
||||
[field.name]: {
|
||||
type: 'array',
|
||||
'x-initializer': 'TableColumnInitializers',
|
||||
'x-component': 'TableV2',
|
||||
'x-component-props': {
|
||||
rowSelection: {
|
||||
type: 'checkbox',
|
||||
},
|
||||
useProps: '{{ useTableFieldProps }}',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (schema['x-component'] === 'AssociationSelect') {
|
||||
Object.assign(schema, {
|
||||
type: 'string',
|
||||
'x-designer': 'AssociationSelect.Designer',
|
||||
});
|
||||
} else {
|
||||
schema.type = 'string';
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
|
||||
if (readPretty) {
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
};
|
||||
} else {
|
||||
schema['properties'] = {
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
schema['x-component-props'] = schema['x-component-props'] || {};
|
||||
schema['x-component-props']['ellipsis'] = true;
|
||||
|
||||
// 预览文件时需要的参数
|
||||
schema['x-component-props']['size'] = 'small';
|
||||
}
|
||||
|
@ -9,72 +9,6 @@ import {
|
||||
} from './properties';
|
||||
import { IField } from './types';
|
||||
|
||||
const internalSchameInitialize = (schema: ISchema, { field, block, readPretty, action }) => {
|
||||
if (block === 'Form') {
|
||||
if (schema['x-component'] === 'FormField') {
|
||||
const association = `${field.collectionName}.${field.name}`;
|
||||
schema.type = 'void';
|
||||
schema.properties = {
|
||||
block: {
|
||||
type: 'void',
|
||||
'x-decorator': 'FormFieldProvider',
|
||||
'x-decorator-props': {
|
||||
collection: field.target,
|
||||
association: association,
|
||||
resource: association,
|
||||
action: action,
|
||||
fieldName: field.name,
|
||||
readPretty,
|
||||
},
|
||||
'x-component': 'CardItem',
|
||||
'x-component-props': {
|
||||
bordered: true,
|
||||
},
|
||||
properties: {
|
||||
[field.name]: {
|
||||
type: 'object',
|
||||
'x-component': 'FormV2',
|
||||
'x-component-props': {
|
||||
useProps: '{{ useFormFieldProps }}',
|
||||
},
|
||||
properties: {
|
||||
__form_grid: {
|
||||
type: 'void',
|
||||
'x-component': 'Grid',
|
||||
'x-initializer': 'FormItemInitializers',
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (schema['x-component'] === 'AssociationSelect') {
|
||||
Object.assign(schema, {
|
||||
type: 'string',
|
||||
'x-designer': 'AssociationSelect.Designer',
|
||||
});
|
||||
} else {
|
||||
schema.type = 'string';
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
schema.type = 'string';
|
||||
if (readPretty) {
|
||||
schema['properties'] = {
|
||||
viewer: cloneDeep(recordPickerViewer),
|
||||
};
|
||||
} else {
|
||||
schema['properties'] = {
|
||||
selector: cloneDeep(recordPickerSelector),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const o2o: IField = {
|
||||
name: 'o2o',
|
||||
type: 'object',
|
||||
@ -119,8 +53,6 @@ export const o2o: IField = {
|
||||
},
|
||||
availableTypes: ['hasOne'],
|
||||
schemaInitialize(schema: ISchema, { field, block, readPretty, action }) {
|
||||
return;
|
||||
internalSchameInitialize(schema, { field, block, readPretty, action });
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
schema['x-component-props'] = schema['x-component-props'] || {};
|
||||
schema['x-component-props']['ellipsis'] = true;
|
||||
@ -300,8 +232,6 @@ export const oho: IField = {
|
||||
},
|
||||
schemaInitialize(schema: ISchema, { field, block, readPretty, action }) {
|
||||
schema['type'] = 'object';
|
||||
return;
|
||||
internalSchameInitialize(schema, { field, block, readPretty, action });
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
schema['x-component-props'] = schema['x-component-props'] || {};
|
||||
schema['x-component-props']['ellipsis'] = true;
|
||||
@ -472,12 +402,9 @@ export const obo: IField = {
|
||||
},
|
||||
schemaInitialize(schema: ISchema, { field, block, readPretty, action, targetCollection }) {
|
||||
schema['type'] = 'object';
|
||||
return;
|
||||
internalSchameInitialize(schema, { field, block, readPretty, action });
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
schema['x-component-props'] = schema['x-component-props'] || {};
|
||||
schema['x-component-props']['ellipsis'] = true;
|
||||
|
||||
// 预览文件时需要的参数
|
||||
schema['x-component-props']['size'] = 'small';
|
||||
}
|
||||
@ -486,14 +413,6 @@ export const obo: IField = {
|
||||
schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' };
|
||||
schema['x-component-props'].fieldNames.label = targetCollection.titleField;
|
||||
}
|
||||
|
||||
if (targetCollection?.template === 'file') {
|
||||
const fieldNames = schema['x-component-props']['fieldNames'] || { label: 'preview', value: 'id' };
|
||||
fieldNames.label = 'preview';
|
||||
schema['x-component-props']['fieldNames'] = fieldNames;
|
||||
schema['x-component-props'].quickUpload = true;
|
||||
schema['x-component-props'].selectFile = true;
|
||||
}
|
||||
},
|
||||
properties: {
|
||||
'uiSchema.title': {
|
||||
|
@ -65,6 +65,7 @@ const InternalFileManager = (props) => {
|
||||
const [selectedRows, setSelectedRows] = useState([]);
|
||||
const insertSelector = useInsertSchema('Selector');
|
||||
const fieldNames = useFieldNames(props);
|
||||
console.log(fieldNames)
|
||||
const field: any = useField();
|
||||
const [options, setOptions] = useState([]);
|
||||
const { getField } = useCollection();
|
||||
@ -179,6 +180,7 @@ const FileManageReadPretty = connect((props) => {
|
||||
const field: any = useField();
|
||||
const { getField } = useCollection();
|
||||
const collectionField = getField(field.props.name);
|
||||
console.log(props)
|
||||
return collectionField ? <Preview {...props} /> : null;
|
||||
});
|
||||
|
||||
|
@ -16,6 +16,7 @@ export const ReadPretty = (props) => {
|
||||
const collectionField = getField(field.props.name);
|
||||
const isFileCollection = getCollection(collectionField?.target).template === 'file';
|
||||
const [currentMode, setCurrentMode] = useState(props.mode || isFileCollection ? 'FileManager' : 'Select');
|
||||
console.log(props)
|
||||
useEffect(() => {
|
||||
props.mode && setCurrentMode(props.mode);
|
||||
}, [props.mode]);
|
||||
|
Loading…
Reference in New Issue
Block a user