mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
chore: kankan groupfield supports relations fields
This commit is contained in:
parent
4e5ac6f41b
commit
60240146a2
@ -14,8 +14,8 @@ export const KanbanBlockContext = createContext<any>({});
|
||||
const useGroupField = (props) => {
|
||||
const { getCollectionField } = useCollectionManager();
|
||||
const { groupField, collection } = props;
|
||||
if (typeof groupField === 'string') {
|
||||
return getCollectionField(`${collection}.${groupField}`);
|
||||
if (typeof groupField === 'object') {
|
||||
return getCollectionField(`${collection}.${groupField[0]}`);
|
||||
}
|
||||
if (groupField?.name) {
|
||||
return getCollectionField(groupField?.name);
|
||||
@ -120,7 +120,13 @@ export const KanbanBlockProvider = (props) => {
|
||||
}
|
||||
return (
|
||||
<BlockProvider {...props} params={params}>
|
||||
<InternalKanbanBlockProvider {...props} params={params} groupField={groupField} columns={columns} />
|
||||
<InternalKanbanBlockProvider
|
||||
{...props}
|
||||
params={params}
|
||||
groupField={groupField}
|
||||
associateCollectionField={props.groupField}
|
||||
columns={columns}
|
||||
/>
|
||||
</BlockProvider>
|
||||
);
|
||||
};
|
||||
|
@ -39,7 +39,7 @@ function Column({
|
||||
allowAddCard,
|
||||
cardAdderPosition = 'top',
|
||||
}) {
|
||||
const { fixedBlock, groupField, field } = useKanbanBlockContext();
|
||||
const { fixedBlock, groupField, associateCollectionField } = useKanbanBlockContext();
|
||||
const { name } = useCollection();
|
||||
const [headerHeight, setHeaderHeight] = useState(0);
|
||||
const [cardData, setCardData] = useState(children.cards);
|
||||
@ -55,7 +55,7 @@ function Column({
|
||||
if (children.value !== '__unknown__') {
|
||||
const filter = isAssociationField
|
||||
? {
|
||||
$and: [{ [groupField.name]: { id: { $eq: children.value } } }],
|
||||
$and: [{ [groupField.name]: { [associateCollectionField[1]]: { $eq: children.value } } }],
|
||||
}
|
||||
: {
|
||||
$and: [{ [groupField.name]: { $eq: children.value } }],
|
||||
|
@ -3,17 +3,20 @@ import { observer } from '@formily/react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { SchemaComponent } from '../../';
|
||||
import { useAPIClient } from '../../api-client';
|
||||
|
||||
export const KanbanOptions = observer((props) => {
|
||||
const { groupField, collectionFields } = props;
|
||||
const { groupField, collectionFields, getAssociateResource } = props;
|
||||
const [dataSource, setDataSource] = useState([]);
|
||||
const { t } = useTranslation();
|
||||
console.log(getAssociateResource);
|
||||
|
||||
useEffect(() => {
|
||||
if (groupField) {
|
||||
const field = collectionFields.find((v) => {
|
||||
return v.name === groupField[0];
|
||||
});
|
||||
console.log(field);
|
||||
if (['select', 'radioGroup'].includes(field.interface)) {
|
||||
const data = field.uiSchema.enum.map((v) => {
|
||||
return {
|
||||
@ -21,6 +24,20 @@ export const KanbanOptions = observer((props) => {
|
||||
};
|
||||
});
|
||||
setDataSource(data);
|
||||
} else {
|
||||
const resource = getAssociateResource(field.target);
|
||||
resource.list({ paginate: false }).then(({ data }) => {
|
||||
const optionsData = data?.data.map((v) => {
|
||||
return {
|
||||
...v,
|
||||
value: v[groupField[1]],
|
||||
label: v[groupField[1]],
|
||||
};
|
||||
});
|
||||
setDataSource(optionsData);
|
||||
});
|
||||
console.log(collectionFields);
|
||||
console.log(groupField);
|
||||
}
|
||||
}
|
||||
}, [groupField]);
|
||||
|
@ -16,6 +16,9 @@ export const KanbanBlockInitializer = (props) => {
|
||||
const { getCollectionFields, getCollectionFieldsOptions } = useCollectionManager();
|
||||
const options: any = useContext(SchemaOptionsContext);
|
||||
const api = useAPIClient();
|
||||
const getAssociateResource = (collectionName) => {
|
||||
return api.resource(collectionName);
|
||||
};
|
||||
return (
|
||||
<DataBlockInitializer
|
||||
{...props}
|
||||
@ -29,7 +32,7 @@ export const KanbanBlockInitializer = (props) => {
|
||||
const values = await FormDialog(t('Create kanban block'), () => {
|
||||
return (
|
||||
<SchemaComponentOptions
|
||||
scope={{ ...options.scope, collectionFields }}
|
||||
scope={{ ...options.scope, collectionFields, getAssociateResource }}
|
||||
components={{ ...options.components, KanbanOptions }}
|
||||
>
|
||||
<FormLayout layout={'vertical'}>
|
||||
@ -59,7 +62,7 @@ export const KanbanBlockInitializer = (props) => {
|
||||
dependencies: ['groupField'],
|
||||
fulfill: {
|
||||
schema: {
|
||||
'x-component-props': '{{{collectionFields,...$form.values}}}', //任意层次属性都支持表达式
|
||||
'x-component-props': '{{{getAssociateResource,collectionFields,...$form.values}}}',
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -88,7 +91,7 @@ export const KanbanBlockInitializer = (props) => {
|
||||
}
|
||||
insert(
|
||||
createKanbanBlockSchema({
|
||||
groupField: groupField,
|
||||
groupField: values.groupField,
|
||||
collection: item.name,
|
||||
columns: values.options,
|
||||
params: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user