Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler does not conform to the outside parent div #107

Open
1 task done
AsifDaum opened this issue Sep 23, 2023 · 3 comments
Open
1 task done

scheduler does not conform to the outside parent div #107

AsifDaum opened this issue Sep 23, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@AsifDaum
Copy link

AsifDaum commented Sep 23, 2023

Checklist

  • I've verified that I'm running react-big-schedule version 4.2.0 or higher

Describe the bug

The scheduler does not conform to the outside parent div no matter what I try, the second issue is that when I change the viewType, from day to week or month, the entire scheduler expands outside the div and will not look functional.

Currently the scheduler does not conform to the outside div:

266804314-cd7c7c2e-f373-4c9f-9bd0-44875642e45e

If I change to week:

image

If I rerender the component it reshapes itself back to a normal size, but its still not conforming to the outside div.

image

I have tried the

  1. responsiveByParent route Specific usage of responsiveByParent hbatalhaStch/react-big-scheduler#26
  2. Scheduler does not respect the size of the parent container. (version 4.2.1) #52
    Which is running react not in strict mode, my production version has the same identical issues.
  3. besidesWidth: window.innerWidth <= 1600 ? 100 : 350, // you need to add this

None have worked so far, from my understanding it seems that the resource table have a dynamic width that increases its size dependent on the width rather than the events table.

What could it be and what should I be trying? I would really like this to work in my application.

Reproduction Link/Code


  const schedulerParentRef = useRef();
  var today = new Date();
  var date = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
  let schedulerData = new SchedulerData(
    date,
    ViewType.Day, // Change the status of daily, weekly or monthly
    false,
    false,
    {
      eventItemPopoverPlacement: "bottomRightMousePosition",
      responsiveByParent: true,
      besidesWidth: window.innerWidth <= 1600 ? 100 : 350,
      startResizable: false,
      endResizable: false,
      schedulerContentHeight: "100%",
      weekCellWidth: 80,
      dayCellWidth: 40,
    }
  );
  schedulerData.setResources([]);
  schedulerData.setEvents([]);

  useEffect(() => {
    dispatch(initialiseViewModel(schedulerData));

    return () => dispatch(reInitialiseViewModel());
  }, [date, dispatch, initialiseViewModel, reInitialiseViewModel]);

  const changeDate = (e) => {
    setDateState(e);
  };

  const getResources = useCallback(() => {
    getAuthorization()
      .get(`company/get_companyschedule_recources?assigned_to=${DropDownValue}`)
      .then((res) => {
        setResources(res.data.message ? [] : res.data);
        dispatch(setAPIDetailsUser(res.data.message ? [] : res.data));
        getEvents(); // Get events after resources have been set
      })
      .catch((err) => {
        console.log("Error in getting schedule", err);
      });
  }, [dispatch, DropDownValue]);

  const getEvents = useCallback(() => {
    getAuthorization()
      .get(`company/get_companyschedule_events?assigned_to=${DropDownValue}`)
      .then((res) => {
        setEvents(res.data.message ? [] : res.data);
        dispatch(setAPIDetailsUserEvents(res.data.message ? [] : res.data));
        setDataLoaded(true); // Set dataLoaded to true after both resources and events are set
      })
      .catch((err) => {
        console.log("Error in getting schedule", err);
      });
  }, [dispatch, DropDownValue]);

  //Set Scheduler Data
  useEffect(() => {
    if (dataLoaded) {
      viewModel.setResources(Resources);
      viewModel.setEvents(Events);
      dispatch(setViewModel(viewModel));
      setDataLoaded(false); // Reset after processing the loaded data
    }
  }, [dataLoaded, Resources, Events, DropDownValue]);

  useEffect(() => {
    setDataLoaded(false); // Reset the dataLoaded state before fetching
    getResources();
  }, [DropDownValue, getResources]);

  const prevClick = (schedulerData) => {
    schedulerData.prev();
    schedulerData.setEvents(Events);
    dispatch(setViewModel(schedulerData));
  };

  const nextClick = (schedulerData) => {
    schedulerData.next();
    schedulerData.setEvents(Events);
    dispatch(setViewModel(schedulerData));
  };

  const onViewChange = (schedulerData, view) => {
    schedulerData.setViewType(view.viewType, view.showAgenda, view.isEventPerspective);
    schedulerData.setEvents(Events);
    dispatch(setViewModel(schedulerData));
  };

  const onSelectDate = (schedulerData, date) => {
    schedulerData.setDate(date);
    schedulerData.setEvents(Events);
    dispatch(setViewModel(schedulerData));
  };

  const eventClicked = (schedulerData, event) => {
    setOpen(true);
    getAuthorization()
      .get(`company/schedule_view/${event.id}/`)
      .then((res) => {
        setScheduleDetails(res.data);
        setDateState([new Date(`${res.data.start_date}`), new Date(`${res.data.end_date}`)]);
      })
      .catch((err) => {
        console.log("Error in getting schedule details", err);
      });
  };

  const ops1 = (schedulerData, event) => {
    setOpen(true);
    getAuthorization()
      .get(`company/schedule_detail/${event.id}/`)
      .then((res) => {
        setScheduleDetails(res.data);
      })
      .catch((err) => {
        console.log("Error in getting schedule details", err);
      });
    // alert(
    //   `You just executed ops1 to event: {id: ${event.id}, title: ${
    //     event.title
    //   }}`
    // );
  };
  
    return (
    <div className="w-full" ref={schedulerParentRef}>
      {displayTimeline && (
        <div className="-mt-4" style={{ marginLeft: "auto" }}>
          <Scheduler
            parentRef={schedulerParentRef}
            schedulerData={viewModel}
            prevClick={prevClick}
            nextClick={nextClick}
            onSelectDate={onSelectDate}
            onViewChange={onViewChange}
            eventItemClick={eventClicked}
            viewEventClick={ops1}
            viewEventText="Details"
          />
        </div>
      )}

Steps to reproduce

  1. view scheduler and notice that its not the right size
  2. click on week and it jumps outside of the div

Operating System

windows

Browser

firefox

React version

^18.0.2

react-big-schedule version

^4.2.5

Additional Information

No response

@AsifDaum AsifDaum added the bug Something isn't working label Sep 23, 2023
@ansulagrawal
Copy link
Member

Hi @AsifDaum which package are you using. Its of our or hballtalblhaStch library.

Can you try to create a bug in code sandbox if possible

@AsifDaum
Copy link
Author

AsifDaum commented Sep 26, 2023

I was using your library, but the problem was consistent across both. I actually found out what the issue was anyway:

One developer had set global css to the scheduler which caused it not to render properly, by simply removing this I was able to get it to a more manageable state.

/* @media screen and (max-width: 900px) { .scheduler-view{ width: 820px !important; } } */ /* .scheduler-view{ width: 55vw !important; } */ /* table#RBS-Scheduler-root{ width: 100% !important; margin: 0px !important; } */

I commented it out and that caused it to render properly, but the bug that was mentioned by:

#52

appeared, where the window had to be resized for it to conform to the layout on first render.

I have bypassed this temporarily by doing the following:

`  useEffect(() => {
    const triggerResize = () => {
      window.dispatchEvent(new Event("resize"));
    };

    // Initial dispatch to ensure correct rendering
    triggerResize();

    // Optionally, you may want to set up a small delay before triggering the resize,
    // to ensure all rendering processes have completed:
    setTimeout(triggerResize, 100);

    // Clean up if needed when component is unmounted or relevant dependencies change
    // return () => {
    //   // Any cleanup code here
    // };
  }, []); // Empty dependency array means this useEffect runs once, similar to componentDidMount

  var today = new Date();
  var date = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
  let schedulerData = new SchedulerData(
    date,
    ViewType.Day, // Change the status of daily, weekly or monthly
    false,
    false,
    {
      eventItemPopoverPlacement: "bottomRightMousePosition",
      besidesWidth: window.innerWidth <= appSideBarStatus ? 70 : 360,
      startResizable: false,
      endResizable: false,
      schedulerContentHeight: "100%",
    }
  );
  schedulerData.setResources([]);
  schedulerData.setEvents([]);

  useEffect(() => {
    dispatch(initialiseViewModel(schedulerData));

    return () => dispatch(reInitialiseViewModel());
  }, [date, dispatch, initialiseViewModel, reInitialiseViewModel]);`

I added a resize event to make it adjust to the layout after its first render.

I had to also use the besidesWidth to ensure it fit the space correctly, its not perfect since I have a toggle-able sidebar but its working fine for now. Once you guys have corrected its layout issues then I think i'll be able to remove that stuff.

@ansulagrawal
Copy link
Member

We will try to solve the issue but not sure how much time it will take as I am also busy with some work so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants