mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
feat: gantt block empty state placeholder
This commit is contained in:
parent
5328136da2
commit
8b44a3b762
@ -51,7 +51,7 @@ export const TaskGantt: React.FC<TaskGanttProps> = forwardRef(
|
|||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
width={gridProps.svgWidth}
|
width={gridProps.svgWidth}
|
||||||
height={barProps.rowHeight * barProps.tasks.length}
|
height={barProps.rowHeight * (barProps.tasks.length||3)}
|
||||||
fontFamily={barProps.fontFamily}
|
fontFamily={barProps.fontFamily}
|
||||||
ref={ganttSVGRef}
|
ref={ganttSVGRef}
|
||||||
>
|
>
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import React, { ReactChild } from "react";
|
import React, { ReactChild } from 'react';
|
||||||
import { cx } from '@emotion/css';
|
import { cx } from '@emotion/css';
|
||||||
import { Task } from "../../types/public-types";
|
import { Task } from '../../types/public-types';
|
||||||
import { addToDate } from "../../helpers/date-helper";
|
import { addToDate } from '../../helpers/date-helper';
|
||||||
import { gridRowLine, gridRow,gridTick } from './style';
|
import { gridRowLine, gridRow, gridTick } from './style';
|
||||||
|
import { uid } from '@nocobase/utils/client';
|
||||||
|
|
||||||
export type GridBodyProps = {
|
export type GridBodyProps = {
|
||||||
tasks: Task[];
|
tasks: Task[];
|
||||||
@ -13,6 +14,7 @@ export type GridBodyProps = {
|
|||||||
todayColor: string;
|
todayColor: string;
|
||||||
rtl: boolean;
|
rtl: boolean;
|
||||||
};
|
};
|
||||||
|
const empty = [{ id: uid() }, { id: uid() }, { id: uid() }];
|
||||||
export const GridBody: React.FC<GridBodyProps> = ({
|
export const GridBody: React.FC<GridBodyProps> = ({
|
||||||
tasks,
|
tasks,
|
||||||
dates,
|
dates,
|
||||||
@ -22,38 +24,25 @@ export const GridBody: React.FC<GridBodyProps> = ({
|
|||||||
todayColor,
|
todayColor,
|
||||||
rtl,
|
rtl,
|
||||||
}) => {
|
}) => {
|
||||||
|
const data = tasks.length ? tasks : empty;
|
||||||
let y = 0;
|
let y = 0;
|
||||||
const gridRows: ReactChild[] = [];
|
const gridRows: ReactChild[] = [];
|
||||||
const rowLines: ReactChild[] = [
|
const rowLines: ReactChild[] = [
|
||||||
<line
|
<line key="RowLineFirst" x="0" y1={0} x2={svgWidth} y2={0} className={cx(gridRowLine)} />,
|
||||||
key="RowLineFirst"
|
|
||||||
x="0"
|
|
||||||
y1={0}
|
|
||||||
x2={svgWidth}
|
|
||||||
y2={0}
|
|
||||||
className={cx(gridRowLine)}
|
|
||||||
/>,
|
|
||||||
];
|
];
|
||||||
for (const task of tasks) {
|
for (const task of data) {
|
||||||
gridRows.push(
|
gridRows.push(
|
||||||
<rect
|
<rect key={'Row' + task.id} x="0" y={y} width={svgWidth} height={rowHeight} className={cx(gridRow)} />,
|
||||||
key={"Row" + task.id}
|
|
||||||
x="0"
|
|
||||||
y={y}
|
|
||||||
width={svgWidth}
|
|
||||||
height={rowHeight}
|
|
||||||
className={cx(gridRow)}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
rowLines.push(
|
rowLines.push(
|
||||||
<line
|
<line
|
||||||
key={"RowLine" + task.id}
|
key={'RowLine' + task.id}
|
||||||
x="0"
|
x="0"
|
||||||
y1={y + rowHeight}
|
y1={y + rowHeight}
|
||||||
x2={svgWidth}
|
x2={svgWidth}
|
||||||
y2={y + rowHeight}
|
y2={y + rowHeight}
|
||||||
className={cx(gridRowLine)}
|
className={cx(gridRowLine)}
|
||||||
/>
|
/>,
|
||||||
);
|
);
|
||||||
y += rowHeight;
|
y += rowHeight;
|
||||||
}
|
}
|
||||||
@ -64,59 +53,24 @@ export const GridBody: React.FC<GridBodyProps> = ({
|
|||||||
let today: ReactChild = <rect />;
|
let today: ReactChild = <rect />;
|
||||||
for (let i = 0; i < dates.length; i++) {
|
for (let i = 0; i < dates.length; i++) {
|
||||||
const date = dates[i];
|
const date = dates[i];
|
||||||
ticks.push(
|
ticks.push(<line key={date.getTime()} x1={tickX} y1={0} x2={tickX} y2={y} className={cx(gridTick)} />);
|
||||||
<line
|
|
||||||
key={date.getTime()}
|
|
||||||
x1={tickX}
|
|
||||||
y1={0}
|
|
||||||
x2={tickX}
|
|
||||||
y2={y}
|
|
||||||
className={cx(gridTick)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
if (
|
if (
|
||||||
(i + 1 !== dates.length &&
|
(i + 1 !== dates.length && date.getTime() < now.getTime() && dates[i + 1].getTime() >= now.getTime()) ||
|
||||||
date.getTime() < now.getTime() &&
|
|
||||||
dates[i + 1].getTime() >= now.getTime()) ||
|
|
||||||
// if current date is last
|
// if current date is last
|
||||||
(i !== 0 &&
|
(i !== 0 &&
|
||||||
i + 1 === dates.length &&
|
i + 1 === dates.length &&
|
||||||
date.getTime() < now.getTime() &&
|
date.getTime() < now.getTime() &&
|
||||||
addToDate(
|
addToDate(date, date.getTime() - dates[i - 1].getTime(), 'millisecond').getTime() >= now.getTime())
|
||||||
date,
|
|
||||||
date.getTime() - dates[i - 1].getTime(),
|
|
||||||
"millisecond"
|
|
||||||
).getTime() >= now.getTime())
|
|
||||||
) {
|
) {
|
||||||
today = (
|
today = <rect x={tickX} y={0} width={columnWidth} height={y} fill={todayColor} />;
|
||||||
<rect
|
|
||||||
x={tickX}
|
|
||||||
y={0}
|
|
||||||
width={columnWidth}
|
|
||||||
height={y}
|
|
||||||
fill={todayColor}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// rtl for today
|
// rtl for today
|
||||||
if (
|
if (rtl && i + 1 !== dates.length && date.getTime() >= now.getTime() && dates[i + 1].getTime() < now.getTime()) {
|
||||||
rtl &&
|
today = <rect x={tickX + columnWidth} y={0} width={columnWidth} height={y} fill={todayColor} />;
|
||||||
i + 1 !== dates.length &&
|
|
||||||
date.getTime() >= now.getTime() &&
|
|
||||||
dates[i + 1].getTime() < now.getTime()
|
|
||||||
) {
|
|
||||||
today = (
|
|
||||||
<rect
|
|
||||||
x={tickX + columnWidth}
|
|
||||||
y={0}
|
|
||||||
width={columnWidth}
|
|
||||||
height={y}
|
|
||||||
fill={todayColor}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
tickX += columnWidth;
|
tickX += columnWidth;
|
||||||
}
|
}
|
||||||
|
console.log(gridRows, rowLines, ticks, today);
|
||||||
return (
|
return (
|
||||||
<g className="gridBody">
|
<g className="gridBody">
|
||||||
<g className="rows">{gridRows}</g>
|
<g className="rows">{gridRows}</g>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user