fix: gantt collapse & expand (#3982)

This commit is contained in:
katherinehhh 2024-04-09 16:37:02 +08:00 committed by GitHub
parent de7b75fea7
commit 8eee6756d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -56,9 +56,12 @@ const InternalTableBlockProvider = (props: Props) => {
} }
}, [service?.loading, fieldSchema]); }, [service?.loading, fieldSchema]);
const setExpandFlagValue = useCallback(() => { const setExpandFlagValue = useCallback(
setExpandFlag(!expandFlag); (falg) => {
}, [expandFlag]); setExpandFlag(falg || !expandFlag);
},
[expandFlag],
);
return ( return (
<FixedBlockWrapper> <FixedBlockWrapper>

View File

@ -6,8 +6,9 @@ import {
BlockProvider, BlockProvider,
useBlockRequestContext, useBlockRequestContext,
TableBlockProvider, TableBlockProvider,
useTableBlockContext,
} from '@nocobase/client'; } from '@nocobase/client';
import _ from 'lodash';
export const GanttBlockContext = createContext<any>({}); export const GanttBlockContext = createContext<any>({});
GanttBlockContext.displayName = 'GanttBlockContext'; GanttBlockContext.displayName = 'GanttBlockContext';
@ -36,7 +37,7 @@ const formatData = (
color: item.color, color: item.color,
isDisabled: disable, isDisabled: disable,
}); });
formatData(item.children, fieldNames, tasks, item.id + '', hideChildren, checkPermassion); formatData(item.children, fieldNames, tasks, item.id + '', hideChildren, checkPermassion, primaryKey);
} 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,
@ -102,6 +103,8 @@ export const useGanttBlockProps = () => {
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 primaryKey = getPrimaryKey(); const primaryKey = getPrimaryKey();
const checkPermission = (record) => { const checkPermission = (record) => {
const actionPath = `${name}:update`; const actionPath = `${name}:update`;
@ -135,8 +138,12 @@ export const useGanttBlockProps = () => {
); );
setTasks(data); setTasks(data);
ctx.field.data = data; ctx.field.data = data;
if (tasks.length > 0) {
ctxBlock.setExpandFlag(true);
}
} }
}, [ctx?.service?.loading]); }, [ctx?.service?.loading]);
console.log(tasks);
return { return {
fieldNames: ctx.fieldNames, fieldNames: ctx.fieldNames,
timeRange: ctx.timeRange, timeRange: ctx.timeRange,