fix(bi): issue of parsing label of region & file field (#2366)
* fix: issue of parsing label of region & file field * fix: test
This commit is contained in:
parent
0fe5b5367a
commit
7151345c40
@ -64,6 +64,18 @@ describe('hooks', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}[name]),
|
}[name]),
|
||||||
|
getInterface: (i: string) => {
|
||||||
|
switch (i) {
|
||||||
|
case 'm2o':
|
||||||
|
return {
|
||||||
|
filterable: {
|
||||||
|
nested: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
},
|
||||||
} as any);
|
} as any);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ArrayField } from '@formily/core';
|
import { ArrayField } from '@formily/core';
|
||||||
import { ISchema, Schema, useForm } from '@formily/react';
|
import { ISchema, Schema, useForm } from '@formily/react';
|
||||||
import { useACLRoleContext, useCollectionManager } from '@nocobase/client';
|
import { CollectionFieldOptions, useACLRoleContext, useCollectionManager } from '@nocobase/client';
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ChartConfigContext } from './block/ChartConfigure';
|
import { ChartConfigContext } from './block/ChartConfigure';
|
||||||
@ -23,7 +23,13 @@ export type FieldOption = {
|
|||||||
targetFields?: FieldOption[];
|
targetFields?: FieldOption[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFields = (collection?: string) => {
|
export const useFields = (
|
||||||
|
collection?: string,
|
||||||
|
): (CollectionFieldOptions & {
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
})[] => {
|
||||||
const { current } = useContext(ChartConfigContext);
|
const { current } = useContext(ChartConfigContext);
|
||||||
if (!collection) {
|
if (!collection) {
|
||||||
collection = current?.collection || '';
|
collection = current?.collection || '';
|
||||||
@ -43,15 +49,18 @@ export const useFields = (collection?: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useFieldsWithAssociation = (collection?: string) => {
|
export const useFieldsWithAssociation = (collection?: string) => {
|
||||||
const { getCollectionFields } = useCollectionManager();
|
const { getCollectionFields, getInterface } = useCollectionManager();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const fields = useFields(collection);
|
const fields = useFields(collection);
|
||||||
return fields.map((field) => {
|
return fields.map((field) => {
|
||||||
|
const filterable = getInterface(field.interface)?.filterable;
|
||||||
const label = Schema.compile(field.uiSchema?.title || field.name, { t });
|
const label = Schema.compile(field.uiSchema?.title || field.name, { t });
|
||||||
if (!field.target) {
|
if (!(filterable && (filterable?.nested || filterable?.children?.length))) {
|
||||||
return { ...field, label };
|
return { ...field, label };
|
||||||
}
|
}
|
||||||
const targetFields = (getCollectionFields(field.target) || [])
|
let targetFields = [];
|
||||||
|
if (filterable?.nested) {
|
||||||
|
const nestedFields = (getCollectionFields(field.target) || [])
|
||||||
.filter((targetField) => {
|
.filter((targetField) => {
|
||||||
return targetField.interface;
|
return targetField.interface;
|
||||||
})
|
})
|
||||||
@ -61,6 +70,19 @@ export const useFieldsWithAssociation = (collection?: string) => {
|
|||||||
label: `${label} / ${Schema.compile(targetField.uiSchema?.title || targetField.name, { t })}`,
|
label: `${label} / ${Schema.compile(targetField.uiSchema?.title || targetField.name, { t })}`,
|
||||||
value: `${field.name}.${targetField.name}`,
|
value: `${field.name}.${targetField.name}`,
|
||||||
}));
|
}));
|
||||||
|
targetFields = [...targetFields, ...nestedFields];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterable?.children?.length) {
|
||||||
|
const children = filterable.children.map((child: any) => ({
|
||||||
|
...child,
|
||||||
|
key: `${field.name}.${child.name}`,
|
||||||
|
label: `${label} / ${Schema.compile(child.schema?.title || child.title || child.name, { t })}`,
|
||||||
|
value: `${field.name}.${child.name}`,
|
||||||
|
}));
|
||||||
|
targetFields = [...targetFields, ...children];
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...field,
|
...field,
|
||||||
label,
|
label,
|
||||||
|
Loading…
Reference in New Issue
Block a user