From 2d5ed78ac9b45e438e13103396e641d6f765f196 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 2 Feb 2023 16:12:28 +0800 Subject: [PATCH] feat: gant block code improve --- .../src/block-provider/GanttBlockProvider.tsx | 9 +++-- .../antd/gantt/components/gantt/gantt.tsx | 37 ++----------------- .../schema-component/antd/gantt/context.ts | 5 +-- .../client/src/schema-initializer/utils.ts | 2 +- 4 files changed, 11 insertions(+), 42 deletions(-) diff --git a/packages/core/client/src/block-provider/GanttBlockProvider.tsx b/packages/core/client/src/block-provider/GanttBlockProvider.tsx index cefbf73b2f..d6dffd0637 100644 --- a/packages/core/client/src/block-provider/GanttBlockProvider.tsx +++ b/packages/core/client/src/block-provider/GanttBlockProvider.tsx @@ -2,6 +2,7 @@ import { useField } from '@formily/react'; import { Spin } from 'antd'; import React, { createContext, useContext, useEffect, useState } from 'react'; import { BlockProvider, useBlockRequestContext } from './BlockProvider'; +import { TableBlockProvider } from './TableBlockProvider'; export const GanttBlockContext = createContext({}); @@ -91,10 +92,10 @@ const formatData = (data = [], fieldNames, tasks: any[] = [], projectId: any = u } else { tasks.push({ start: new Date(item[fieldNames.start]), - end: new Date(item[fieldNames.end]||item[fieldNames.start]), + end: new Date(item[fieldNames.end] || item[fieldNames.start]), name: item[fieldNames.title], id: item.id + '', - type: fieldNames.end?'task':'milestone', + type: fieldNames.end ? 'task' : 'milestone', progress: item[fieldNames.progress] * 100 || 0, project: projectId, }); @@ -127,7 +128,9 @@ const InternalGanttBlockProvider = (props) => { export const GanttBlockProvider = (props) => { return ( - + + + ); }; diff --git a/packages/core/client/src/schema-component/antd/gantt/components/gantt/gantt.tsx b/packages/core/client/src/schema-component/antd/gantt/components/gantt/gantt.tsx index c9ee984027..3727bfd7e5 100644 --- a/packages/core/client/src/schema-component/antd/gantt/components/gantt/gantt.tsx +++ b/packages/core/client/src/schema-component/antd/gantt/components/gantt/gantt.tsx @@ -16,28 +16,9 @@ import { DateSetup } from '../../types/date-setup'; import { HorizontalScroll } from '../other/horizontal-scroll'; import { removeHiddenTasks, sortTasks } from '../../helpers/other-helper'; import { wrapper } from './style'; -import { GanttToolbarContext } from '../../context'; import { useDesignable } from '../../../../../schema-component'; -import { TableBlockProvider, useGanttBlockContext, useBlockRequestContext } from '../../../../../block-provider'; +import { useGanttBlockContext, useBlockRequestContext } from '../../../../../block-provider'; -function ActionBars(props: any) { - const fieldSchema = useFieldSchema(); - const toolBarSchema: Schema = useMemo( - () => - fieldSchema.reduceProperties((buf: any, current: any) => { - if (current['x-component'].endsWith('.ActionBar')) { - return current; - } - return buf; - }, null), - [], - ); - return ( - - - - ); -} const getColumnWidth = (dataSetLength: any, clientWidth: any) => { const columnWidth = clientWidth / dataSetLength > 50 ? Math.floor(clientWidth / dataSetLength) + 20 : 50; @@ -434,21 +415,9 @@ export const Gantt: any = (props: any) => { return (
-
- - - - + +
(null); +// export const GanttToolbarContext = createContext(null); export const CalendarContext = createContext(null); export const DeleteEventContext = createContext(null); -export const useDeleteEvent = () => { - return useContext(DeleteEventContext); -} diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 7a4d5d23e2..ac1c2b2678 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -1048,7 +1048,7 @@ export const createGanttBlockSchema = (options) => { properties: { toolBar: { type: 'void', - 'x-component': 'Gantt.ActionBar', + 'x-component': 'ActionBar', 'x-component-props': { style: { marginBottom: 24,