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

Resize Month Events and Resize Week/Day Events on Both Ends #578

Merged
merged 50 commits into from
Jan 12, 2018
Merged

Resize Month Events and Resize Week/Day Events on Both Ends #578

merged 50 commits into from
Jan 12, 2018

Conversation

arecvlohe
Copy link
Collaborator

@arecvlohe arecvlohe commented Oct 5, 2017

Description

This PR adds the ability to resize month events as well as resize week/day events on both ends, top and bottom. I wasn't able to get this to perform correctly on hover which I suppose is ideal. We might find inspiration from #577.

This is a long standing issue so it would be good to see some movement on this.

Also, I think this could be a good first implementation that is refined on going forward.

Screenshots

Month

resize-month-event

Week

resize-event-week

Issues

#382

PRs

#577, #541, #406

jnmandal and others added 21 commits May 20, 2017 12:20
Summary: There were errors in my branch because importing the .default was not pulling in the correct default whereas when I removed it, it seemed to work fine. This might be some kind of change in React 15.6 for how default modules are imported/required.
Summary: For <EventCell /> to know that it can be resized I am passing down the resize prop to that component. This is because, unlike in the previous implementation, I am not passing down what would be the eventWrapper from the dragAndDrop addon. I didn't know how to pass down multiple components based on whether the calendar was resizable. So I went this route. Sorry, not sorry.
Summary: I created <ResizableEventLR /> to handle resizing events in the month view. If <EventCell resizable /> then it will render the resizable component.

I added styles so that I could see what is going on. There is a red bg. Sorry, not sorry.

There is no functionality at the moment but I started building it out. There is certainly more to be worked on here.
Summary: Updated the resize function to be aware of the end as well as the start time. This is when there are two dnd handlers on an event at once.

I renamed the component to be more semantic with its usage. Styles were correspondingly updated.
Summary: I didn't realize the conent should be aligned left.
Summary: Refactored components to look a bit more readable.
Summary: Refactored <ResizableEvent /> and added the ability to resize the top component.
Summary: Refactored the if/else statement into a switch statement.
Summary: I deleted these chanages thinking they were old. My mistake!
Summary: Remove unused code.
@arecvlohe arecvlohe closed this Oct 5, 2017
@arecvlohe
Copy link
Collaborator Author

Actually, I think I will keep this open

@svanetten1976
Copy link

@arecvlohe @jnmandal any idea if this excellent feature you guys added is going to get merged into the project?

@arecvlohe
Copy link
Collaborator Author

@svanetten1976 I don't have a good idea. @jquense might know better than me. I don't really know what/how things get vetted and merged.

Copy link

@jnmandal jnmandal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯💯💯 thanks for picking this up @arecvlohe

@jnmandal jnmandal mentioned this pull request Oct 17, 2017
src/EventCell.js Outdated
@@ -49,6 +50,10 @@ class EventCell extends React.Component {
if (eventPropGetter)
var { style, className: xClassName } = eventPropGetter(event, start, end, selected);

if (this.props.resizable) {
Copy link
Owner

@jquense jquense Oct 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These bits should be encapsulated in the addon code, the core library should not require things from /addons (so that they are optional)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean here. In our implementation at work I ended up removing this.

src/DayColumn.js Outdated
, messages
, eventComponent
, eventTimeRangeFormat
Copy link
Owner

@jquense jquense Oct 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a rebase error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is because of a fix I made in #406. eventComponent was being destructured incorrectly in the DayColumn component's renderEvents function (so it was always undefined). We need to be able to specify custom eventComponent for the addOn to work properly.. But its possible this has since been fixed some other way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using event component. I updated the addon to pass the ResizeEvent to components: { day: { event }, week: { event } } as opposed to creating a new prop inside of components. I think this is how the library is intended to be used.

examples/App.js Outdated
@@ -101,7 +102,7 @@ const Example = React.createClass({
<strong><i className='fa fa-code'/>{' View example source code'}</strong>
</a>
</div>
<Current className='demo' />
<Current className='demo' />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a space was removed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we fix it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean put the space back in?

// if we want to update the event while dragging we need to find the event
// by an identifier. here we use the title and the start time, but depending
// on use case you may want have a truly unique id attribute in the event
const nextEvents = events.map(existingEvent => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't indexOf work here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jquense this was due to a quirk in react-dnd, copying my explanation from #406

Since only the original event object is accessible through react-dnd... In the onEventResize callback you will not be able to use Array.prototype.indexOf for finding the event again -- unless you continue to mutate the original event and splice it into the cloned events array... but I'm not sure if we would want to recommend that practice

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally in the next iteration of the callback the new event will be there? Why can't we get react dnd to update the thing it's referencing. I don't love this logic is fairly flakey even for an example and likely to lead folks to copying it in their own code with potential issues. Last ditch we should at least add an id to events in the example and use that vs title and date instances

@tobiasandersen
Copy link
Collaborator

👍 Awesome! But there's quite a lot of noise here. Are all those commits and line changes necessary/relevant to this PR? cc @jquense

@arecvlohe
Copy link
Collaborator Author

@tobiasandersen Are you saying to rebase or remove things?

@tobiasandersen
Copy link
Collaborator

Rebase (or squash merge) :) I saw now that the heavy line changes was due the example bundle, which I guess makes sense!

@arecvlohe
Copy link
Collaborator Author

I will rebase some changes to remove some fluff from the commit history @tobiasandersen

@arecvlohe
Copy link
Collaborator Author

@tobiasandersen Doing a rebase is too insane, at least for me, with all the commits that have been merged over the past couple days. But I also think I missed what you were saying. Did you mean I can merge, just choose either the squash merge or rebase merge option?

@tobiasandersen
Copy link
Collaborator

Squash and merge would combine all your 47 commits into one. I usually prefer having 1 (or a few maximum) commits per PR. It keeps the history clean, and makes it easier when going back to find when and why things were introduced. However, it also removes the actual history. And I see that you've been a few people working on this – squashing would make it look like you wrote all of it.

I'd prefer a squash over the 47 commits if I were to choose from the two. But it's @jquense's project, so I think it's better if he decides what's best :)

@arecvlohe
Copy link
Collaborator Author

@tobiasandersen I hear you. Let's see what @jquense says...

@jquense
Copy link
Owner

jquense commented Jan 11, 2018

@arecvlohe You do whatever makes your life a bit easier to handle the rebase. Generally I think it's worth leaving the branch unsquashed and then squashing via the github butten whe nwe merge so that master ends up with one commit, and the original history is maintained. In this case tho i can imagine that the rebase is super painful without squashing so do what makes it's easier for you. We'll be sure to shout to out everyone who contributed to this PR

@arecvlohe
Copy link
Collaborator Author

I ran into another hiccup. After merging in master, in the DnD example I am not able to drag and drop events in the week and day view. However, month view works fine.

I will have to dig into this at some point but there is a lot to dig so any help is appreciated.

@arecvlohe
Copy link
Collaborator Author

@tobiasandersen @AlexMarvelo @jquense ^^^

@tobiasandersen
Copy link
Collaborator

I wouldn't be surprised if it's due to my latest PR (although I did test the DnD example before merging). I'll have look and get back.

@arecvlohe
Copy link
Collaborator Author

I will take a look this evening and see what I can find out

@tobiasandersen
Copy link
Collaborator

Cool! If it's anything from my last PR, it's probably this extra div that I added: https://github.com/intljusticemission/react-big-calendar/blob/0b2c2347efa8fe4fb77f7931634de9a8ee1362ac/src/DayColumn.js#L132.

If you don't find the problem I'll have a check when I wake up tomorrow!

@arecvlohe
Copy link
Collaborator Author

@tobiasandersen From what I can tell it looks like the event container is the culprit. Unfortunately in react-dnd there is not a way to drop on a div and have the drop be handled by a div underneath. So basically it just covers where it can be dropped and that is why nothing is happening. One way to maybe get around this is to set the z-index of the date cells to > 1 when there is a drag event.

@tobiasandersen
Copy link
Collaborator

Sorry about that, should have tested it more than I did. I'm thinking pointer-events: none on that div should be enough?

@arecvlohe
Copy link
Collaborator Author

I will check that out and see

@arecvlohe
Copy link
Collaborator Author

It works! I will wait for a successful build to complete first and then move forward with merging into master

@arecvlohe arecvlohe merged commit 546c4da into jquense:master Jan 12, 2018
@arecvlohe
Copy link
Collaborator Author

It is done 😄

@tobiasandersen
Copy link
Collaborator

Awesome! Great work! 🎉

@jadczyk
Copy link
Contributor

jadczyk commented Jan 14, 2018

Hi, after your merge it seems you cannot select events in weekly view anymore when not using drag'n'drop. You added pointer-events: none; to .rbc-events-container but didn't add pointer-events: all; to .rbc-event

@arecvlohe
Copy link
Collaborator Author

Good catch @jadczyk!

@arecvlohe
Copy link
Collaborator Author

@jadczyk Mind creating a PR to fix this?

@jadczyk
Copy link
Contributor

jadczyk commented Jan 14, 2018

Just did #690

@ehahn9
Copy link
Collaborator

ehahn9 commented Feb 3, 2018

Just started using the resize/DnD stuff - thanks @arecvlohe & others - hugely useful!

tl;dr: I'm looking for advice on how to best marry DnD with custom components.

When creating the underling calendar, it looks like the addon's withDragAndDrop HOC overwrites a bunch of component: props to add DnD. Alas, I have a custom Event component in day/week/month views (and in a custom view), so this is a bit of a challenge.

Would something like this make sense:

   const DnDCalendar = withDragAndDrop(BigCalendar)
   <DnDCalendar
     components={{
       week: {
         event: myCustomEventComponent
       }
     }}
   />

becomes instead:

   <DnDCalendar
     components={{
       week: {
         event: withDragAndDrop.customComponent(myCustomEventComponent)
       }
     }}
   />

The new HOC would wrap the user's components with one based on the current ResizableEvent (yes, there would have to be a month view variant, too).

I'm keen to get folks' other ideas/approaches (or validation of this one). I'm probably misunderstanding the DnD philosophy, but it was a surprise to see examples/dnd basically overwrite custom component props.

thx for any guidance/advice.

@alxmiron
Copy link
Contributor

alxmiron commented Feb 4, 2018

I think that no more additional work should be required to enable DnD except wrapping the calendar with withDragAndDrop. It's the best practice. I will take a look, what can be done. I see, that DnD addon does not really take care of custom event renderer now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants