Skip to content

Commit f2da77b

Browse files
authored
Merge pull request #4 from ucfx/demo
fix: fix some bugs & improve demo testing
2 parents c54889e + f887eaa commit f2da77b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4242
-1407
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
<h1 align="center">react-pert</h1>
1+
# react-pert
2+
3+
<img src="public/cover.jpg" />
4+
5+
[![-](https://img.shields.io/github/stars/ucfx/react-pert?style=for-the-badge&colorA=000000&colorB=6868ff)](https://github.com/ucfx/react-pert/stargazers)
6+
[![-](https://img.shields.io/npm/v/react-pert?style=for-the-badge&colorA=000000&colorB=6868ff)](https://www.npmjs.com/package/react-pert)
7+
[![Build Size](https://img.shields.io/bundlephobia/minzip/react-pert?label=bundle%20size&style=for-the-badge&colorA=000000&colorB=6868ff)](https://bundlephobia.com/result?p=react-pert)
8+
[![Downloads](https://img.shields.io/npm/dt/react-pert.svg?style=for-the-badge&colorA=000000&colorB=6868ff)](https://www.npmjs.com/package/react-pert)
29

310
## :star2: Overview
411

components.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": false,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.ts",
8+
"css": "src/index.css",
9+
"baseColor": "zinc",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils",
16+
"ui": "@/components/ui",
17+
"lib": "@/lib",
18+
"hooks": "@/hooks"
19+
},
20+
"iconLibrary": "lucide"
21+
}

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!doctype html>
2-
<html lang="en">
2+
<html lang="en" class="dark">
33

44
<head>
55
<meta charset="UTF-8" />
6-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<link rel="icon" type="image/svg+xml" href="/pert.svg" />
77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
88
<title>react-pert Demo</title>
99
</head>

lib/components/Pert/Pert.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use client";
12
import { InternalPertProvider } from "../../context/pertContext";
23
import { PertProps, PertStyles } from "../../types/pert.types";
34
import PertChart from "./PertChart";

lib/components/Pert/PertChart.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@ let externalSetSelectedTask: {
2222
} | null = null;
2323

2424
export const setSelectedTask = (taskKey: string | null) => {
25-
if (externalSetSelectedTask) {
26-
if (!taskKey) {
27-
externalSetSelectedTask.setter(null);
28-
} else if (externalSetSelectedTask.getTask) {
29-
const task = externalSetSelectedTask.getTask(taskKey);
30-
if (task && externalSetSelectedTask.onSelect) {
31-
externalSetSelectedTask.onSelect(task);
32-
}
33-
externalSetSelectedTask.setter(taskKey);
34-
}
25+
if (!externalSetSelectedTask) return;
26+
27+
const { setter, onSelect, getTask } = externalSetSelectedTask;
28+
29+
if (!taskKey) {
30+
setter(null);
31+
onSelect?.(null);
32+
return;
3533
}
34+
35+
const task = getTask?.(taskKey) ?? null;
36+
onSelect?.(task);
37+
setter(task ? taskKey : null);
3638
};
3739

3840
export const PertChart: React.FC<PertChartProps> = ({ tasks, onSelect, styles }) => {
@@ -52,6 +54,7 @@ export const PertChart: React.FC<PertChartProps> = ({ tasks, onSelect, styles })
5254
const tasksHash = JSON.stringify(tasks);
5355
if (tasksHashRef.current !== tasksHash) {
5456
calculatePertResults(tasks);
57+
setSelectedTask(null);
5558
tasksHashRef.current = tasksHash;
5659
}
5760
}, [tasks, calculatePertResults]);

lib/constants/pert.constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const DEFAULT_COLORS = {
1313
CRITICAL: "#ff9147",
1414
TASK_BG: "#aaaeff",
1515
CHART_BG: "#fff",
16-
GRID: "#00000030",
16+
GRID: "#83838350",
1717
TEXT: "#000",
1818
SELECTED: "#6868ff",
1919
STROKE: "#615f77",

lib/types/pert.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export interface PertStyles {
119119

120120
/**
121121
* Color of the grid lines in the chart.
122-
* @default "#00000030"
122+
* @default "#83838350"
123123
*/
124124
gridColor?: string;
125125

lib/utlis/Pert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class Pert {
123123
private calculateLateTimes(k: string, projectDuration: number) {
124124
const task = this.tasksMap.get(k)!;
125125
const successors = this.getSuccessors(task);
126-
if (successors.length === 0) this.tasksMap.get(this.lastTaskKey)!.dependsOn?.push(k);
126+
if (task.key !== this.lastTaskKey && successors.length === 0)
127+
this.tasksMap.get(this.lastTaskKey)!.dependsOn?.push(k);
127128

128129
let lateFinish =
129130
successors.length === 0

package.json

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,47 @@
3838
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
3939
"semantic-release": "semantic-release"
4040
},
41-
"dependencies": {
41+
"peerDependencies": {
4242
"react": "^18.3.1",
4343
"react-dom": "^18.3.1"
4444
},
4545
"devDependencies": {
46-
"@eslint/js": "^9.11.1",
47-
"@types/node": "^22.7.5",
48-
"@types/react": "^18.3.10",
49-
"@types/react-dom": "^18.3.0",
50-
"@vitejs/plugin-react": "^4.3.2",
51-
"eslint": "^9.11.1",
52-
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
53-
"eslint-plugin-react-refresh": "^0.4.12",
54-
"globals": "^15.9.0",
46+
"@eslint/js": "^9.19.0",
47+
"@radix-ui/react-label": "^2.1.2",
48+
"@radix-ui/react-popover": "^1.1.6",
49+
"@radix-ui/react-scroll-area": "^1.2.3",
50+
"@radix-ui/react-select": "^2.1.6",
51+
"@radix-ui/react-separator": "^1.1.2",
52+
"@radix-ui/react-slider": "^1.2.3",
53+
"@radix-ui/react-slot": "^1.1.2",
54+
"@radix-ui/react-switch": "^1.1.3",
55+
"@radix-ui/react-tabs": "^1.1.3",
56+
"@types/node": "^22.13.1",
57+
"@types/react": "^18.3.18",
58+
"@types/react-dom": "^18.3.5",
59+
"@vitejs/plugin-react": "^4.3.4",
60+
"autoprefixer": "^10.4.20",
61+
"class-variance-authority": "^0.7.1",
62+
"clsx": "^2.1.1",
63+
"eslint": "^9.19.0",
64+
"eslint-plugin-react-hooks": "^5.1.0",
65+
"eslint-plugin-react-refresh": "^0.4.18",
66+
"globals": "^15.14.0",
67+
"lucide-react": "^0.475.0",
68+
"postcss": "^8.5.1",
69+
"react-colorful": "^5.6.1",
5570
"rimraf": "^6.0.1",
56-
"semantic-release": "^24.1.2",
57-
"typescript": "^5.5.3",
58-
"typescript-eslint": "^8.7.0",
59-
"vite": "^5.4.8",
60-
"vite-plugin-dts": "^4.2.4",
71+
"semantic-release": "^24.2.1",
72+
"tailwind-merge": "^3.0.1",
73+
"tailwindcss": "3",
74+
"tailwindcss-animate": "^1.0.7",
75+
"typescript": "^5.7.3",
76+
"typescript-eslint": "^8.23.0",
77+
"vaul": "^1.1.2",
78+
"vite": "^6.1.0",
79+
"vite-plugin-dts": "^4.5.0",
6180
"vite-plugin-lib-inject-css": "^2.2.1",
62-
"vite-tsconfig-paths": "^5.0.1"
81+
"vite-tsconfig-paths": "^5.1.4"
6382
},
6483
"keywords": [
6584
"react",

0 commit comments

Comments
 (0)