-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
DnD support for custom event components #716
Conversation
hey sorry i'm not sure why the current api doesn't already work? Addons shouldn't be specifying Event components at all, the DnD addon (at least used to) just use the EventWrapper component, if it's not it should go back to doing that, vs something more complicate like this. The Wrapper components were specifically added for these use cases. |
(and thanks for another PR btw) |
Yeah, alas the current version of dnd in addons indeed does smash the It looks like the original draggable implementation used a custom I'll take a look at using the wrapper for both - it would make things a LOT cleaner (thanks). ps: might be some other stuff in this PR (like the storybooks, docs and a bit of minor cleanup) which might be helpful. Feel free to close this if you prefer, or I'll push updates as soon as I have a moment to work on this. Thanks for your help and suggestions. |
I do think it's fine for addons to provide default components, but the Wrapper should inject things like resize handles either as markup or as a callback or something, react dnd already has these patterns. That way if someone wants to customize the Event component they have the extra props needed to add the resize handles, otherwise we can use the default in the addon (so we don't polute the core app with assumptions of addons) |
Moving back to the wrappers should also fix this bug: #629 |
I'm working on this... I've removed the need for a custom Turns out that the dnd addon ended up getting quite a bit of reworking - maybe I've been overzealous... it is going to be a pretty big diff after all. I'm not sure of the oss etiquette here and certainly don't want to submit a PR which oversteps acceptable bounds (!). Even so, there are a lot of DnD corner cases which neither the current, nor updated code handles gracefully, so at best, this is an incremental "improvement". I'll submit the PR when I think it's presentable - would love feedback from anyone so inclined! No offense will be taken if the PR is too divergent! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like these changes. Consolidating the resize functionality into one component works for me. I think that is what we initially wanted to do but did not get around to it. Thanks for the PR. I think it's a much needed improvement.
I think there's still a lot of work I need to do on this... I guess I'd like a bit more time (and another update) in the coming week if we can hold off? Since I issued the PR, I've been working on a few biggish things to further streamline:
I'm new at BTW: Along the way, I've been perplexed by the choice to have |
@ehahn9 When the idea was first implemented the thought was to have a drop and resize be handled differently but in retrospect it doesn't matter because we have the callback functions to handle that anyway. Take the code with a grain of salt since it was worked on and off for a few months before it was implemented. If the API is updated as you propose, ie removing the There is no rush to get this working right way. The initial implementation was just to get something out there for others to use and then tweak it more going forward. At least that was my approach to the whole thing. When you are ready to have this reviewed just give a holler and I will take another look. The process is to have at least 2 contributors approve before merging. The fact that you are working on improving this is great and I appreciate the effort! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good! For discussion, a downside with the current approach is that a user can't customize the resize handles in EventComponent if they wanted too. The upside is that the component "just works" nicely out of the box, even with a custom EventComponent.
I'm not sure if that tradeoff is the right one but maybe that's something we can change if folks complain about it? This is definitely more flexible than what we have now so either way it's an improvement
src/addons/dragAndDrop/index.js
Outdated
@@ -75,44 +125,26 @@ export default function withDragAndDrop( | |||
this.state.isDragging && 'rbc-addons-dnd-is-dragging' | |||
) | |||
|
|||
let EventComponent = components.event || TitleComponent | |||
if (resizable) { | |||
EventComponent = withEventResizability( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this neat, one issue here tho is that this creates a new class per render, which is not cheap, for a lot of reasons. THe big one being React can never reuse the the markup because the render -> render the "type" is actually different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't use a HOC here, instead I'd move the withEventResizability
logic directly into the event wrapper component, or if there is value in splitting it out (does anything else use the HOC?) Use it on the wrapper component wrapping props.children
instead, leaving EventComponent alone until it's being rendered. The other thing that avoids, btw, is the fact that a user can specify an EventComponent per view like:
components = {
event: DefaultEventComponent,
month: { event: MonthEventComponent },
week: { event: WeekEventComponent },
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed you said:
implemented all of the drag & resize in the EventWrapper - no more withEventResizability
above, Sorry ignore those bits of the comments :)
As promised, here's the updated PR:
Delighted for any inputs/comments - so sorry it ended up being such a big PR - let me know if I've bitten off too much! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question on resizing the event in month view when it is not an all day event.
* 2. If the event is a non-allDay event and is being displayed | ||
* normally, we can drag it north-south to resize the times. | ||
* | ||
* 3. If the event is a non-allDay event and is being displayed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't resizing an event, that is not all day, in month view extend the event to be more than one day long? Meaning it would extend the event to the next day at the same end time as it was previous. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arecvlohe you're absolutely right - your suggested behavior is perfectly reasonable, too. In fact it matches how drop (as opposed to resize) works when dropping a non-allDay event on the date header: it retains the times but changes the date.
Great catch. I'll change the behavior and re-push when I have a moment to work on this!
step: PropTypes.number, | ||
} | ||
|
||
// constructor(...args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commented out stuff has been here for a while and I am wondering if it's still needed. Thoughts @jquense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry about that, its my own personal reminder for how to structure the react-dnd stuff so that the drop areas align with the shap of the even vs just where the mouse is over (which i think is more intuitive feeling) I left it there to save my place, but haven't had the time to explore it any further. We can remove it (git has is saved obviously) unless someone wants to pick it up ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sure would love to see the drop target be based on the mouse-relative location, not the top of the event. I agree that the current behavior isn't the best user experience. I ran out of energy (and competence :-)) on this so didn't tackle it.
@arecvlohe: changed drop behavior to preserve times when dropping on days (some tricky corner cases, but all happiness in the end!). Also clean up docs to match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Hi @ehahn9 . Can you provide an example? Both resizable and custom event components are supported. very thankful ! |
I'll try to work on an example in the coming week. The existing DnD example is easily extended. In the meantime, there's a fair bit o' documentation in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm,but I haven't had a chance to try it .I defer to the rest of y'all on thus :)
Hey what's the status on this PR? Would like to know if this is stable to be merged to master or if it requires more work. Awesome work btw! 👍 |
@ehahn9 When you think the PR is ready go ahead and merge. |
Hi @arecvlohe - embassingly, this is my first open source PR so I'm a bit fuzzy on process - I apologize. Can you help me understand your request? I guess I don't feel confident enough to "own" the merge to the master, but open to learning. (I'm guessing it isn't as simple just |
@ehahn9 A PR needs 2 approvals from collaborators for it to be accepted into the code base, which you have on this. Since the commit is pretty large I don't think anyone else wants to merge in something not knowing if it is complete or not. For that reason, you have ownership over the commit. I think the only other thing you need to do is merge master into your branch and it should be good to go. If you think it passes all your checks feel free to merge by clicking the green button, squash and merge. If you are still hesitant, just reach out and I can do it. But I want to make sure it's ready before I do. |
I think it would help to write up a contributing doc for the repo to clarify some of these things. |
Thanks, @arecvlohe -- looks like the merge is ready. I'm happy to do the merge -- best to merge or merge-squash? Sorry for all the newbie q's... |
squash and merge is preferred here yeah 👍 |
[second attempt, hopefully better PR]
I've been trying to use the drag and drop addon with a custom Event component. Alas, the addon needs to use its own ResizeEvent component and thus overwrites mine.
I have no idea if this PR is useful to anyone else, but I thought I'd submit it just in case in inspires someone more experienced than me to work on this further :-)
This PR changes the behavior to use a HOC (withEventResizability()) to compose a new component which effectively wraps any caller-supplied Event component. (To mimic the base Calendar behavior it wraps a new TitleComponent as the default).
I also tried to DRY up the original ResizeEvent and ResizeMonthlyEvent into a single wrapper which takes a direction (horizontal or vertical) to determine where the anchors go, etc.
And I changed a bunch of other gratuitous stuff like adding more docs, using static class props, etc. I also added two new storybooks: one showing drag+resize, the other drag+resize with a custom event component.
Feel free to discard/close this if it isn't useful, but also feel free to put me to work on edits/updates - I'll give it my best shot, time-permitting.
(ps: I know addons aren't really part of react-big-calendar - apologies if I've put this issue in the wrong place).[