mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 23:19:26 +08:00
feat: gant block code improve
This commit is contained in:
parent
6b3d75ff48
commit
2d5ed78ac9
@ -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<any>({});
|
||||
|
||||
@ -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 (
|
||||
<BlockProvider {...props} params={{ ...props.params, paginate: false }}>
|
||||
<InternalGanttBlockProvider {...props} />
|
||||
<TableBlockProvider {...props} params={{ ...props.params, paginate: false }}>
|
||||
<InternalGanttBlockProvider {...props} />
|
||||
</TableBlockProvider>
|
||||
</BlockProvider>
|
||||
);
|
||||
};
|
||||
|
@ -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 (
|
||||
<GanttToolbarContext.Provider value={{ ...props }}>
|
||||
<RecursionField name={toolBarSchema.name} schema={toolBarSchema} />
|
||||
</GanttToolbarContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<ActionBars />
|
||||
<div>
|
||||
<TableBlockProvider
|
||||
{...ctx}
|
||||
params={{
|
||||
paginate: false,
|
||||
}}
|
||||
service={{
|
||||
...ctx.service,
|
||||
}}
|
||||
onExpandClick={handleTableExpanderClick}
|
||||
>
|
||||
<RecursionField name={'table'} schema={fieldSchema.properties.table} />
|
||||
</TableBlockProvider>
|
||||
|
||||
<RecursionField name={'anctionBar'} schema={fieldSchema.properties.toolBar} />
|
||||
<RecursionField name={'table'} schema={fieldSchema.properties.table} />
|
||||
<div className={cx(wrapper)} onKeyDown={handleKeyDown} tabIndex={0} ref={wrapperRef}>
|
||||
<TaskGantt
|
||||
gridProps={gridProps}
|
||||
|
@ -1,9 +1,6 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
|
||||
export const GanttToolbarContext = createContext<any>(null);
|
||||
// export const GanttToolbarContext = createContext<any>(null);
|
||||
export const CalendarContext = createContext(null);
|
||||
export const DeleteEventContext = createContext(null);
|
||||
|
||||
export const useDeleteEvent = () => {
|
||||
return useContext(DeleteEventContext);
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user