Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#71925 @types/frappe-gantt: Update to lates…
Browse files Browse the repository at this point in the history
…t frappe-gantt library by @IILimitlessII
  • Loading branch information
IILimitlessII authored Mar 3, 2025
1 parent d2b9248 commit c6078b0
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 50 deletions.
163 changes: 145 additions & 18 deletions types/frappe-gantt/frappe-gantt-tests.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,167 @@
import Gantt from "frappe-gantt";

const tasks = [
// Test basic task structure
const tasks: Gantt.Task[] = [
{
id: "Task 1",
name: "Redesign website",
start: "2016-12-28",
end: "2016-12-31",
progress: 20,
color: "#fff",
dependencies: "Task 2, Task 3",
},
{
id: "Task 2",
name: "Task with duration",
start: "2016-12-28",
duration: "2 days",
color: "#000",
progress: 50,
},
{
id: "Task 3",
name: "Custom class task",
start: "2016-12-28",
end: "2016-12-31",
progress: 75,
color_progress: "#fff",
custom_class: "custom-task",
},
];
const gantt1 = new Gantt("#gantt", tasks);

// Test different constructor signatures
const gantt1 = new Gantt("#gantt", tasks);
const gantt2 = new Gantt(new HTMLElement(), tasks);
const gantt3 = new Gantt(new SVGElement(), tasks);

gantt1.change_view_mode(Gantt.VIEW_MODE.WEEK);
gantt1.refresh(tasks);
// Test view modes
gantt1.change_view_mode("Week");
gantt1.change_view_mode("Day", true);

new Gantt("#gantt", tasks, {
on_click: task => {},
on_date_change: (task, start, end) => {},
on_progress_change: (task, progress) => {},
on_view_change: mode => {},
// Test view mode object
gantt1.change_view_mode({
name: "Month",
padding: "1 day",
date_format: "YYYY-MM-DD",
upper_text: (date: Date) => date.toLocaleDateString(),
lower_text: "DD",
column_width: 50,
step: "1 day",
snap_at: "1 day",
thick_line: (date: Date) => date.getDate() === 1,
});

// Test task operations
gantt1.refresh(tasks);
gantt1.update_task("Task 1", { progress: 50 });
const task = gantt1.get_task("Task 1");

// Test view checks
gantt1.view_is("Week");
gantt1.view_is(["Week", "Day"]);
gantt1.view_is({ name: "Week" });

// Test utility methods
gantt1.unselect_all();
const oldestDate = gantt1.get_oldest_starting_date();
gantt1.clear();

// Test comprehensive options
new Gantt("#gantt", tasks, {
custom_popup_html: task => {
const end_date = task._end.toDateString();
return `
<div class="details-container">
<h5>${task.name}</h5>
<p>Expected to finish by ${end_date}</p>
<p>${task.progress}% completed!</p>
</div>
`;
// Basic display options
arrow_curve: 5,
auto_move_label: true,
bar_corner_radius: 3,
bar_height: 20,
column_width: 30,
container_height: "auto",
date_format: "YYYY-MM-DD",

// Holiday and ignore settings
holidays: {
red: "weekend",
blue: ["2023-12-25", "2023-12-26"],
green: (date: Date) => date.getDay() === 5,
purple: [
{ date: "2023-12-31", name: "New Year's Eve" },
{ date: "2024-01-01", name: "New Year's Day" },
],
},
ignore: ["2023-12-24", "2023-12-25"],

// Layout options
infinite_padding: true,
language: "es",
lines: "both",
lower_header_height: 20,
move_dependencies: true,
padding: 10,

// Popup options
popup: true,
popup_on: "click",

// Readonly options
readonly: false,
readonly_dates: false,
readonly_progress: false,

// Scroll and progress options
scroll_to: "today",
show_expected_progress: true,
snap_at: "1 day",
today_button: true,
upper_header_height: 50,

// View mode options
view_mode: "Week",
view_mode_select: true,
view_modes: [
{
name: "Quarter Day",
padding: "1 hour",
date_format: "HH:mm",
upper_text: "DD MMM",
lower_text: "HH:mm",
column_width: 25,
step: "15 mins",
snap_at: "15 mins",
},
{
name: "Day",
padding: "1 day",
date_format: "DD MMM",
upper_text: "MMMM YYYY",
lower_text: "DD",
column_width: 50,
step: "1 day",
snap_at: "1 day",
thick_line: (date: Date) => date.getDay() === 1,
},
],

// Event handlers
on_click: (task: Gantt.Task) => {
console.log(`Task ${task.name} clicked`);
},
on_date_change: (task: Gantt.Task, start: Date, end: Date) => {
console.log(`Task ${task.name} dates changed to ${start} - ${end}`);
},
on_progress_change: (task: Gantt.Task, progress: number) => {
console.log(`Task ${task.name} progress changed to ${progress}%`);
},
on_view_change: (mode: Gantt.ViewModeObject) => {
console.log(`View changed to ${mode.name}`);
},
});

// Test static VIEW_MODE property
const viewModes = {
quarterDay: Gantt.VIEW_MODE.QUARTER_DAY,
halfDay: Gantt.VIEW_MODE.HALF_DAY,
day: Gantt.VIEW_MODE.DAY,
week: Gantt.VIEW_MODE.WEEK,
month: Gantt.VIEW_MODE.MONTH,
year: Gantt.VIEW_MODE.YEAR,
};
103 changes: 72 additions & 31 deletions types/frappe-gantt/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,93 @@
export = Gantt;
export default Gantt;

declare class Gantt {
constructor(wrapper: string | HTMLElement | SVGElement, tasks: Gantt.Task[], options?: Gantt.Options);

change_view_mode(mode: Gantt.viewMode): void;
tasks: Gantt.Task[];
options: Gantt.Options;

setup_wrapper(element: string | HTMLElement | SVGElement): void;
setup_options(options: Gantt.Options): void;
setup_tasks(tasks: Gantt.Task[]): void;
refresh(tasks: Gantt.Task[]): void;
change_view_mode(mode?: Gantt.viewMode | Gantt.ViewModeObject, maintain_scroll?: boolean): void;
update_task(id: string, new_details: Partial<Gantt.Task>): void;
get_task(id: string): Gantt.Task | undefined;
unselect_all(): void;
view_is(modes: string | string[] | Gantt.ViewModeObject): boolean;
get_oldest_starting_date(): Date;
clear(): void;

static VIEW_MODE: Record<Gantt.viewModeKey, Gantt.viewMode>;
}

declare namespace Gantt {
interface Task {
id: string;
id?: string;
name: string;
start: string;
end: string;
end?: string;
duration?: string;
progress: number;
dependencies: string;
custom_class?: string | undefined;
dependencies?: string | string[];
custom_class?: string;
color?: string | undefined;
color_progress?: string | undefined;
_start?: Date;
_end?: Date;
_index?: number;
}

interface EnrichedTask extends Task {
_start: Date;
_end: Date;
_index: number;
invalid?: boolean | undefined;
interface ViewModeObject {
name: viewMode;
padding?: string | [string, string];
date_format?: string;
upper_text?: string | ((date: Date, last_date: Date | null, language: string) => string);
lower_text?: string | ((date: Date, last_date: Date | null, language: string) => string);
column_width?: number;
step?: string;
snap_at?: string;
thick_line?: (date: Date) => boolean;
}

interface Options {
header_height?: number | undefined;
column_width?: number | undefined;
step?: number | undefined;
view_modes?: viewMode[] | undefined;
bar_height?: number | undefined;
bar_corner_radius?: number | undefined;
arrow_curve?: number | undefined;
padding?: number | undefined;
view_mode?: viewMode | undefined;
date_format?: string | undefined;
custom_popup_html?: string | ((task: EnrichedTask) => string) | undefined;
language?: string | undefined;
on_click?: ((task: EnrichedTask) => void) | undefined;
on_date_change?: ((task: EnrichedTask, start: Date, end: Date) => void) | undefined;
on_progress_change?: ((task: EnrichedTask, progress: number) => void) | undefined;
on_view_change?: ((mode: viewMode) => void) | undefined;
arrow_curve?: number;
auto_move_label?: boolean;
bar_corner_radius?: number;
bar_height?: number;
column_width?: number;
container_height?: "auto" | number;
date_format?: string;
holidays?: Record<
string,
string | string[] | ((date: Date) => boolean) | Array<{ date: string; name: string }>
>;
ignore?: string | string[] | ((date: Date) => boolean);
infinite_padding?: boolean;
language?: string;
lines?: "vertical" | "horizontal" | "both" | "none";
lower_header_height?: number;
move_dependencies?: boolean;
padding?: number;
popup?: boolean | string | ((task: Task) => string);
popup_on?: string;
readonly?: boolean;
readonly_dates?: boolean;
readonly_progress?: boolean;
scroll_to?: string | "today" | "start" | "end" | Date;
show_expected_progress?: boolean;
snap_at?: string;
today_button?: boolean;
upper_header_height?: number;
view_mode?: viewMode;
view_mode_select?: boolean;
view_modes?: ViewModeObject[];
on_click?: (task: Task) => void;
on_date_change?: (task: Task, start: Date, end: Date) => void;
on_progress_change?: (task: Task, progress: number) => void;
on_view_change?: (mode: ViewModeObject) => void;
}

type viewMode = "Quarter Day" | "Half Day" | "Day" | "Week" | "Month" | "Year";

type viewMode = "Hour" | "Quarter Day" | "Half Day" | "Day" | "Week" | "Month" | "Year";
type viewModeKey = "QUARTER_DAY" | "HALF_DAY" | "DAY" | "WEEK" | "MONTH" | "YEAR";

const VIEW_MODE: Record<viewModeKey, viewMode>;
}
7 changes: 6 additions & 1 deletion types/frappe-gantt/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"private": true,
"name": "@types/frappe-gantt",
"version": "0.6.9999",
"version": "0.9.9999",
"type": "module",
"projects": [
"https://github.com/frappe/gantt"
],
Expand All @@ -16,6 +17,10 @@
{
"name": "Elijah Lucian",
"githubUsername": "eli7vh"
},
{
"name": "Rahul Singh",
"githubUsername": "IILimitlessII"
}
]
}

0 comments on commit c6078b0

Please sign in to comment.