I am using a Gantt and Scheduler Pro instance on the same page, partnered together to show the same data in sync with eachother. I have configured a single ProjectModel as such:
However, on initial load, both the Scheduler and Gantt instances call the load URL, which fetches the same data (tasks, resources, deps, etc.). There are quite a lot of tasks in our gantt and loading this takes some time, slowing down the initial render. Is it possible to only load that data once for both components, since the data is identical?
The weird timeout to add the components as partners is necessary because the Gantt and Scheduler wrappers need to be loaded dynamically (no SSR), and can finish loading at different times. So setting the parent needs to be handled in this way to ensure that both components have loaded before linking them.
This causes React to trigger a redraw when this happens, so this causes the ProjectModel in the wrapper to be created twice, causing the load to be called twice. My wrapper looks like so:
The issue arises because I want to dynamically set the silenceInitialCommit flag, based on whether entries were added into the database in the back-end. I need to let chronograph calculate the new values in the front-end and update them if so, and I'd like to avoid that if there's no need to.
Creating the ProjectModel outside of the component doesn't allow me to change the silenceInitialCommit flag after its been set, and I need to access the props within the component to determine what its value should be.
I've tried adding in a ref, or a useState or useEffect hook, but nothing seems to fix the issue. Any thoughts?
The issue arises because I want to dynamically set the silenceInitialCommit flag, based on whether entries were added into the database in the back-end. I need to let chronograph calculate the new values in the front-end and update them if so, and I'd like to avoid that if there's no need to.
If there is nothing to commit (all calculated and saved before), silenceInitialCommit: false should not trigger any extra data saving, I am not sure why do you need to update that dynamically at all. Maybe you're trying to make a workaround for our bug. Please comment this moment and if you still have a request - we need steps to reproduce that.
Anyway, I have two ideas to share:
https://reactjs.org/docs/context.html - this solution will be working here. You'll need to wrap your component into context, and define project model as a part of that context. You'll still be allowed to create project model at the moment you need.
I didn't test, because I don't have a test case, but in theory that should work here.
// declare var out of component
let project;
export default function ProductGantt({ ganttRef, schedulerRef, silenceInitialCommit, ...props }) {
// check if project already created
project = project || new ProjectModel({ silenceInitialCommit, ....... });
Right, a context provider is probably the Reactive solution to the issue. I will look into that for the time being.
However, you say silenceInitialCommit should automatically compare the post-propagation values with what's received from the database, and if nothing was changed the commit should abort? If so, that would remove my need to keep track of that myself. As it exists though, I could:
Insert some records into the database from the back-end (not accounting for things like non-
working time, calendars, etc.).
Open my web page containing the Gantt component, loading the data from the database.
The Chronograph engine updates tasks to honor dependencies and calendars and writes the entire dataset back to the server, containing the updated values.
Use the Gantt as normal.
If I do this, and then repeat steps 2-4, the initial commit still writes the whole dataset to the server on load, even if no data has changed since the last time the Gantt was opened. Is this the expected behaviour for this use case?
It is not expected behaviour. If all data has been saved in previous initial commit, project.changes will be empty after next reload and no request will be triggered. If you have it triggered, please check if you saved all data without changes in dates or other scheduling sensitive data. If all good and you have commit triggered anyway, that sounds like a bug. Might be good to get a test case to reproduce that for debugging.