mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:55:50 +00:00
fix: select field set as title field (#4703)
* fix: select field set as title field * fix: select field set as title field * fix: select field set as title field * fix: select field set as title field
This commit is contained in:
parent
82fc9ee7da
commit
0e778e7e47
@ -17,6 +17,7 @@ import {
|
|||||||
useCollectionParentRecordData,
|
useCollectionParentRecordData,
|
||||||
useProps,
|
useProps,
|
||||||
withDynamicSchemaProps,
|
withDynamicSchemaProps,
|
||||||
|
getLabelFormatValue,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { parseExpression } from 'cron-parser';
|
import { parseExpression } from 'cron-parser';
|
||||||
import type { Dayjs } from 'dayjs';
|
import type { Dayjs } from 'dayjs';
|
||||||
@ -62,6 +63,8 @@ function Toolbar(props: ToolbarProps) {
|
|||||||
|
|
||||||
const useEvents = (dataSource: any, fieldNames: any, date: Date, view: (typeof Weeks)[number]) => {
|
const useEvents = (dataSource: any, fieldNames: any, date: Date, view: (typeof Weeks)[number]) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { fields } = useCollection();
|
||||||
|
const labelUiSchema = fields.find((v) => v.name === fieldNames?.title)?.uiSchema;
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!Array.isArray(dataSource)) return [];
|
if (!Array.isArray(dataSource)) return [];
|
||||||
const events = [];
|
const events = [];
|
||||||
@ -105,10 +108,10 @@ const useEvents = (dataSource: any, fieldNames: any, date: Date, view: (typeof W
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res) return out;
|
if (res) return out;
|
||||||
|
const title = getLabelFormatValue(labelUiSchema, get(item, fieldNames.title), true);
|
||||||
const event = {
|
const event = {
|
||||||
id: get(item, fieldNames.id || 'id'),
|
id: get(item, fieldNames.id || 'id'),
|
||||||
title: get(item, fieldNames.title) || t('Untitle'),
|
title: title || t('Untitle'),
|
||||||
start: eventStart.toDate(),
|
start: eventStart.toDate(),
|
||||||
end: eventStart.add(intervalTime, 'millisecond').toDate(),
|
end: eventStart.add(intervalTime, 'millisecond').toDate(),
|
||||||
};
|
};
|
||||||
|
@ -15,6 +15,8 @@ import {
|
|||||||
useBlockRequestContext,
|
useBlockRequestContext,
|
||||||
TableBlockProvider,
|
TableBlockProvider,
|
||||||
useTableBlockContext,
|
useTableBlockContext,
|
||||||
|
getLabelFormatValue,
|
||||||
|
useCollection,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
export const GanttBlockContext = createContext<any>({});
|
export const GanttBlockContext = createContext<any>({});
|
||||||
@ -28,15 +30,18 @@ const formatData = (
|
|||||||
hideChildren = false,
|
hideChildren = false,
|
||||||
checkPermassion?: (any) => boolean,
|
checkPermassion?: (any) => boolean,
|
||||||
primaryKey?: string,
|
primaryKey?: string,
|
||||||
|
labelUiSchema?: any,
|
||||||
) => {
|
) => {
|
||||||
data.forEach((item: any) => {
|
data.forEach((item: any) => {
|
||||||
const disable = checkPermassion(item);
|
const disable = checkPermassion(item);
|
||||||
const percent = parseFloat((item[fieldNames.progress] * 100).toFixed(2));
|
const percent = parseFloat((item[fieldNames.progress] * 100).toFixed(2));
|
||||||
|
const title = getLabelFormatValue(labelUiSchema, item[fieldNames.title]);
|
||||||
|
|
||||||
if (item.children && item.children.length) {
|
if (item.children && item.children.length) {
|
||||||
tasks.push({
|
tasks.push({
|
||||||
start: new Date(item[fieldNames.start] ?? undefined),
|
start: new Date(item[fieldNames.start] ?? undefined),
|
||||||
end: new Date(item[fieldNames.end] ?? undefined),
|
end: new Date(item[fieldNames.end] ?? undefined),
|
||||||
name: item[fieldNames.title],
|
name: title,
|
||||||
id: item[primaryKey] + '',
|
id: item[primaryKey] + '',
|
||||||
type: 'project',
|
type: 'project',
|
||||||
progress: percent > 100 ? 100 : percent || 0,
|
progress: percent > 100 ? 100 : percent || 0,
|
||||||
@ -45,12 +50,21 @@ const formatData = (
|
|||||||
color: item.color,
|
color: item.color,
|
||||||
isDisabled: disable,
|
isDisabled: disable,
|
||||||
});
|
});
|
||||||
formatData(item.children, fieldNames, tasks, item.id + '', hideChildren, checkPermassion, primaryKey);
|
formatData(
|
||||||
|
item.children,
|
||||||
|
fieldNames,
|
||||||
|
tasks,
|
||||||
|
item.id + '',
|
||||||
|
hideChildren,
|
||||||
|
checkPermassion,
|
||||||
|
primaryKey,
|
||||||
|
labelUiSchema,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
tasks.push({
|
tasks.push({
|
||||||
start: item[fieldNames.start] ? new Date(item[fieldNames.start]) : undefined,
|
start: item[fieldNames.start] ? new Date(item[fieldNames.start]) : undefined,
|
||||||
end: new Date(item[fieldNames.end] || item[fieldNames.start]),
|
end: new Date(item[fieldNames.end] || item[fieldNames.start]),
|
||||||
name: item[fieldNames.title],
|
name: title,
|
||||||
id: item[primaryKey] + '',
|
id: item[primaryKey] + '',
|
||||||
type: fieldNames.end ? 'task' : 'milestone',
|
type: fieldNames.end ? 'task' : 'milestone',
|
||||||
progress: percent > 100 ? 100 : percent || 0,
|
progress: percent > 100 ? 100 : percent || 0,
|
||||||
@ -85,7 +99,7 @@ const InternalGanttBlockProvider = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const GanttBlockProvider = (props) => {
|
export const GanttBlockProvider = (props) => {
|
||||||
const params = { filter: props.params.filter, paginate: false, sort: ['id'] };
|
const params = { filter: props.params?.filter, paginate: false, sort: ['id'] };
|
||||||
const collection = useCollection_deprecated();
|
const collection = useCollection_deprecated();
|
||||||
|
|
||||||
if (collection?.tree) {
|
if (collection?.tree) {
|
||||||
@ -107,12 +121,15 @@ export const useGanttBlockContext = () => {
|
|||||||
|
|
||||||
export const useGanttBlockProps = () => {
|
export const useGanttBlockProps = () => {
|
||||||
const ctx = useGanttBlockContext();
|
const ctx = useGanttBlockContext();
|
||||||
|
const { fieldNames } = ctx;
|
||||||
const [tasks, setTasks] = useState<any>([]);
|
const [tasks, setTasks] = useState<any>([]);
|
||||||
const { getPrimaryKey, name, template, writableView } = useCollection_deprecated();
|
const { getPrimaryKey, name, template, writableView } = useCollection_deprecated();
|
||||||
const { parseAction } = useACLRoleContext();
|
const { parseAction } = useACLRoleContext();
|
||||||
const ctxBlock = useTableBlockContext();
|
const ctxBlock = useTableBlockContext();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const primaryKey = getPrimaryKey();
|
const primaryKey = getPrimaryKey();
|
||||||
|
const { fields } = useCollection();
|
||||||
|
const labelUiSchema = fields.find((v) => v.name === fieldNames?.title)?.uiSchema;
|
||||||
const checkPermission = (record) => {
|
const checkPermission = (record) => {
|
||||||
const actionPath = `${name}:update`;
|
const actionPath = `${name}:update`;
|
||||||
const schema = {};
|
const schema = {};
|
||||||
@ -128,7 +145,16 @@ export const useGanttBlockProps = () => {
|
|||||||
ctx.field.data = tasksData;
|
ctx.field.data = tasksData;
|
||||||
};
|
};
|
||||||
const expandAndCollapseAll = (flag) => {
|
const expandAndCollapseAll = (flag) => {
|
||||||
const data = formatData(ctx.service.data?.data, ctx.fieldNames, [], undefined, flag, checkPermission, primaryKey);
|
const data = formatData(
|
||||||
|
ctx.service.data?.data,
|
||||||
|
ctx.fieldNames,
|
||||||
|
[],
|
||||||
|
undefined,
|
||||||
|
flag,
|
||||||
|
checkPermission,
|
||||||
|
primaryKey,
|
||||||
|
labelUiSchema,
|
||||||
|
);
|
||||||
setTasks(data);
|
setTasks(data);
|
||||||
ctx.field.data = data;
|
ctx.field.data = data;
|
||||||
};
|
};
|
||||||
@ -143,6 +169,7 @@ export const useGanttBlockProps = () => {
|
|||||||
false,
|
false,
|
||||||
checkPermission,
|
checkPermission,
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
labelUiSchema,
|
||||||
);
|
);
|
||||||
setTasks(data);
|
setTasks(data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
useCompile,
|
useCompile,
|
||||||
useFilterAPI,
|
useFilterAPI,
|
||||||
useProps,
|
useProps,
|
||||||
|
getLabelFormatValue,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { Button, Space } from 'antd';
|
import { Button, Space } from 'antd';
|
||||||
@ -48,7 +49,8 @@ export const AMapBlock = (props) => {
|
|||||||
const [, setPrevSelected] = useState<any>(null);
|
const [, setPrevSelected] = useState<any>(null);
|
||||||
const selectingModeRef = useRef(selectingMode);
|
const selectingModeRef = useRef(selectingMode);
|
||||||
selectingModeRef.current = selectingMode;
|
selectingModeRef.current = selectingMode;
|
||||||
|
const { fields } = useCollection();
|
||||||
|
const labelUiSchema = fields.find((v) => v.name === fieldNames?.marker)?.uiSchema;
|
||||||
const setOverlayOptions = (overlay: AMap.Polygon | AMap.Marker, state?: boolean) => {
|
const setOverlayOptions = (overlay: AMap.Polygon | AMap.Marker, state?: boolean) => {
|
||||||
const extData = overlay.getExtData();
|
const extData = overlay.getExtData();
|
||||||
const selected = typeof state === 'undefined' ? extData.selected : !state;
|
const selected = typeof state === 'undefined' ? extData.selected : !state;
|
||||||
@ -133,6 +135,7 @@ export const AMapBlock = (props) => {
|
|||||||
const overlays = dataSource
|
const overlays = dataSource
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
const data = getSource(item, fieldNames?.field, cf?.interface)?.filter(Boolean);
|
const data = getSource(item, fieldNames?.field, cf?.interface)?.filter(Boolean);
|
||||||
|
const title = getLabelFormatValue(labelUiSchema, item[fieldNames.marker]);
|
||||||
if (!data?.length) return [];
|
if (!data?.length) return [];
|
||||||
return data.map((mapItem) => {
|
return data.map((mapItem) => {
|
||||||
const overlay = mapRef.current?.setOverlay(collectionField.type, mapItem, {
|
const overlay = mapRef.current?.setOverlay(collectionField.type, mapItem, {
|
||||||
@ -142,7 +145,7 @@ export const AMapBlock = (props) => {
|
|||||||
label: {
|
label: {
|
||||||
direction: 'bottom',
|
direction: 'bottom',
|
||||||
offset: [0, 5],
|
offset: [0, 5],
|
||||||
content: fieldNames?.marker ? compile(item[fieldNames.marker]) : undefined,
|
content: fieldNames?.marker ? compile(title) : undefined,
|
||||||
},
|
},
|
||||||
extData: {
|
extData: {
|
||||||
id: item[primaryKey],
|
id: item[primaryKey],
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
useCompile,
|
useCompile,
|
||||||
useFilterAPI,
|
useFilterAPI,
|
||||||
useProps,
|
useProps,
|
||||||
|
getLabelFormatValue,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { Button, Space } from 'antd';
|
import { Button, Space } from 'antd';
|
||||||
@ -67,7 +68,8 @@ export const GoogleMapsBlock = (props) => {
|
|||||||
const selectionOverlayRef = useRef<google.maps.Polygon | null>(null);
|
const selectionOverlayRef = useRef<google.maps.Polygon | null>(null);
|
||||||
const overlaysRef = useRef<google.maps.MVCObject[]>([]);
|
const overlaysRef = useRef<google.maps.MVCObject[]>([]);
|
||||||
selectingModeRef.current = selectingMode;
|
selectingModeRef.current = selectingMode;
|
||||||
|
const { fields } = useCollection();
|
||||||
|
const labelUiSchema = fields.find((v) => v.name === fieldNames?.marker)?.uiSchema;
|
||||||
const { getCollectionJoinField } = useCollectionManager_deprecated();
|
const { getCollectionJoinField } = useCollectionManager_deprecated();
|
||||||
|
|
||||||
const setOverlayOptions = (overlay: google.maps.MVCObject, state?: boolean) => {
|
const setOverlayOptions = (overlay: google.maps.MVCObject, state?: boolean) => {
|
||||||
@ -175,6 +177,7 @@ export const GoogleMapsBlock = (props) => {
|
|||||||
const overlays: google.maps.MVCObject[] = dataSource
|
const overlays: google.maps.MVCObject[] = dataSource
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
const data = getSource(item, fieldNames?.field, cf?.interface);
|
const data = getSource(item, fieldNames?.field, cf?.interface);
|
||||||
|
const title = getLabelFormatValue(labelUiSchema, item[fieldNames.marker]);
|
||||||
if (!data?.length) return [];
|
if (!data?.length) return [];
|
||||||
return data?.filter(Boolean).map((mapItem) => {
|
return data?.filter(Boolean).map((mapItem) => {
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
@ -187,7 +190,7 @@ export const GoogleMapsBlock = (props) => {
|
|||||||
fontFamily: 'inherit',
|
fontFamily: 'inherit',
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
color: '#333',
|
color: '#333',
|
||||||
text: fieldNames?.marker ? compile(item[markerName]) : undefined,
|
text: fieldNames?.marker ? compile(title) : undefined,
|
||||||
} as google.maps.MarkerLabel,
|
} as google.maps.MarkerLabel,
|
||||||
});
|
});
|
||||||
overlay?.set(OVERLAY_KEY, item[primaryKey]);
|
overlay?.set(OVERLAY_KEY, item[primaryKey]);
|
||||||
|
Loading…
Reference in New Issue
Block a user