mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 07:29:24 +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 { Spin } from 'antd';
|
||||||
import React, { createContext, useContext, useEffect, useState } from 'react';
|
import React, { createContext, useContext, useEffect, useState } from 'react';
|
||||||
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
|
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
|
||||||
|
import { TableBlockProvider } from './TableBlockProvider';
|
||||||
|
|
||||||
export const GanttBlockContext = createContext<any>({});
|
export const GanttBlockContext = createContext<any>({});
|
||||||
|
|
||||||
@ -91,10 +92,10 @@ const formatData = (data = [], fieldNames, tasks: any[] = [], projectId: any = u
|
|||||||
} else {
|
} else {
|
||||||
tasks.push({
|
tasks.push({
|
||||||
start: new Date(item[fieldNames.start]),
|
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],
|
name: item[fieldNames.title],
|
||||||
id: item.id + '',
|
id: item.id + '',
|
||||||
type: fieldNames.end?'task':'milestone',
|
type: fieldNames.end ? 'task' : 'milestone',
|
||||||
progress: item[fieldNames.progress] * 100 || 0,
|
progress: item[fieldNames.progress] * 100 || 0,
|
||||||
project: projectId,
|
project: projectId,
|
||||||
});
|
});
|
||||||
@ -127,7 +128,9 @@ const InternalGanttBlockProvider = (props) => {
|
|||||||
export const GanttBlockProvider = (props) => {
|
export const GanttBlockProvider = (props) => {
|
||||||
return (
|
return (
|
||||||
<BlockProvider {...props} params={{ ...props.params, paginate: false }}>
|
<BlockProvider {...props} params={{ ...props.params, paginate: false }}>
|
||||||
<InternalGanttBlockProvider {...props} />
|
<TableBlockProvider {...props} params={{ ...props.params, paginate: false }}>
|
||||||
|
<InternalGanttBlockProvider {...props} />
|
||||||
|
</TableBlockProvider>
|
||||||
</BlockProvider>
|
</BlockProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -16,28 +16,9 @@ import { DateSetup } from '../../types/date-setup';
|
|||||||
import { HorizontalScroll } from '../other/horizontal-scroll';
|
import { HorizontalScroll } from '../other/horizontal-scroll';
|
||||||
import { removeHiddenTasks, sortTasks } from '../../helpers/other-helper';
|
import { removeHiddenTasks, sortTasks } from '../../helpers/other-helper';
|
||||||
import { wrapper } from './style';
|
import { wrapper } from './style';
|
||||||
import { GanttToolbarContext } from '../../context';
|
|
||||||
import { useDesignable } from '../../../../../schema-component';
|
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 getColumnWidth = (dataSetLength: any, clientWidth: any) => {
|
||||||
const columnWidth = clientWidth / dataSetLength > 50 ? Math.floor(clientWidth / dataSetLength) + 20 : 50;
|
const columnWidth = clientWidth / dataSetLength > 50 ? Math.floor(clientWidth / dataSetLength) + 20 : 50;
|
||||||
@ -434,21 +415,9 @@ export const Gantt: any = (props: any) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ActionBars />
|
|
||||||
<div>
|
<div>
|
||||||
<TableBlockProvider
|
<RecursionField name={'anctionBar'} schema={fieldSchema.properties.toolBar} />
|
||||||
{...ctx}
|
<RecursionField name={'table'} schema={fieldSchema.properties.table} />
|
||||||
params={{
|
|
||||||
paginate: false,
|
|
||||||
}}
|
|
||||||
service={{
|
|
||||||
...ctx.service,
|
|
||||||
}}
|
|
||||||
onExpandClick={handleTableExpanderClick}
|
|
||||||
>
|
|
||||||
<RecursionField name={'table'} schema={fieldSchema.properties.table} />
|
|
||||||
</TableBlockProvider>
|
|
||||||
|
|
||||||
<div className={cx(wrapper)} onKeyDown={handleKeyDown} tabIndex={0} ref={wrapperRef}>
|
<div className={cx(wrapper)} onKeyDown={handleKeyDown} tabIndex={0} ref={wrapperRef}>
|
||||||
<TaskGantt
|
<TaskGantt
|
||||||
gridProps={gridProps}
|
gridProps={gridProps}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
import { createContext, useContext } from 'react';
|
import { createContext, useContext } from 'react';
|
||||||
|
|
||||||
export const GanttToolbarContext = createContext<any>(null);
|
// export const GanttToolbarContext = createContext<any>(null);
|
||||||
export const CalendarContext = createContext(null);
|
export const CalendarContext = createContext(null);
|
||||||
export const DeleteEventContext = createContext(null);
|
export const DeleteEventContext = createContext(null);
|
||||||
|
|
||||||
export const useDeleteEvent = () => {
|
|
||||||
return useContext(DeleteEventContext);
|
|
||||||
}
|
|
||||||
|
@ -1048,7 +1048,7 @@ export const createGanttBlockSchema = (options) => {
|
|||||||
properties: {
|
properties: {
|
||||||
toolBar: {
|
toolBar: {
|
||||||
type: 'void',
|
type: 'void',
|
||||||
'x-component': 'Gantt.ActionBar',
|
'x-component': 'ActionBar',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
style: {
|
style: {
|
||||||
marginBottom: 24,
|
marginBottom: 24,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user