set-conflicts
The functionality is available in PRO Edition only
PRODescription
Fires on each scheduling calculation and updates the state of conflicts for links and constraintsThe action works only if auto scheduling is enabled.
On every action that triggers auto scheduling, conflicts are analyzed across the entire Gantt, not just for the tasks and links directly affected by that action. The set-conflicts action sets the resulting array into the conflicts state, replacing its previous value entirely: conflicts stay in the array until the tasks or links involved are changed, and an empty array means that no conflicts remain.
The same array feeds the ConflictReport list and the conflict highlighting on the chart.
Usage
"set-conflicts": ({
conflicts: IConflict[]
}) => boolean | void;
interface IConflict {
type: "link" | "constraint";
task: string | number;
link?: string | number;
required: Date;
}
Parameters
The callback of the set-conflicts action takes an object with the following parameter:
conflicts- (required) an array of conflicts. EachIConflictobject has the following parameters:type- (required) the kind of conflict:"constraint"- the task ends up outside its constraint"link"- the task's dates don't satisfy an incoming link
task- (required) the id of the violated task: the task that misses its constraint, or the successor task of the violated linklink- (optional) the id of the violated link; set for link conflicts onlyrequired- (required) the start date that clears the conflict: the date the task would have to start on to satisfy its constraint or link
If a link is drawn to or from a summary task, the conflict is reported for the leaf task that is actually blocked, while link holds the id of the link as it is drawn on the chart.
Constraint conflicts are reported rarely because when tasks are edited, constraints shift along with the tasks, so the constraint stays satisfied while the link is reported as violated.
The most frequent cause of a constraint conflict is a manually scheduled task: scheduling doesn't move it, so it can stay outside its constraint.
For handling the action you can use the Event Bus methods. Returning false from the action handler will block the action (see Preventing actions)
Example
The example below shows how to count the reported conflicts after each scheduling run.
import { getData } from "./common/data";
import { Gantt } from "@svar/react-gantt";
const data = getData();
function App() {
function init(api) {
api.on("set-conflicts", ({ conflicts }) => {
console.log(
"link conflicts:",
conflicts.filter(c => c.type === "link")
);
console.log(
"constraint conflicts:",
conflicts.filter(c => c.type === "constraint")
);
});
}
return (
<Gantt
tasks={data.tasks}
links={data.links}
schedule={{ auto: true }}
init={init}
/>
);
}
export default App;
Related articles:
- How to access Gantt API
- Constraints
- ConflictReport
- show-conflicts action
- api.getState()
- schedule property