Skip to content

Commit

Permalink
fix: switch DnD to modern context API (was legacy)
Browse files Browse the repository at this point in the history
Fixes jquense#1795. Related to jquense#1776.
  • Loading branch information
ehahn9 committed Jan 26, 2021
1 parent 8ffe39d commit 6def209
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 54 deletions.
3 changes: 3 additions & 0 deletions src/addons/dragAndDrop/DnDContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react'

export const DnDContext = React.createContext()
12 changes: 2 additions & 10 deletions src/addons/dragAndDrop/EventContainerWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types'
import React from 'react'
import * as dates from '../../utils/dates'
import { findDOMNode } from 'react-dom'
import { DnDContext } from './DnDContext'

import Selection, {
getBoundsForNode,
Expand All @@ -27,16 +28,7 @@ class EventContainerWrapper extends React.Component {
resource: PropTypes.any,
}

static contextTypes = {
draggable: PropTypes.shape({
onStart: PropTypes.func,
onEnd: PropTypes.func,
onDropFromOutside: PropTypes.func,
onBeginAction: PropTypes.func,
dragAndDropAction: PropTypes.object,
dragFromOutsideItem: PropTypes.func,
}),
}
static contextType = DnDContext

constructor(...args) {
super(...args)
Expand Down
13 changes: 2 additions & 11 deletions src/addons/dragAndDrop/EventWrapper.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import PropTypes from 'prop-types'
import React from 'react'
import clsx from 'clsx'
import { accessor } from '../../utils/propTypes'
import { accessor as get } from '../../utils/accessors'
import { DnDContext } from './DnDContext'

class EventWrapper extends React.Component {
static contextTypes = {
draggable: PropTypes.shape({
onStart: PropTypes.func,
onEnd: PropTypes.func,
onBeginAction: PropTypes.func,
draggableAccessor: accessor,
resizableAccessor: accessor,
dragAndDropAction: PropTypes.object,
}),
}
static contextType = DnDContext

static propTypes = {
type: PropTypes.oneOf(['date', 'time']),
Expand Down
12 changes: 2 additions & 10 deletions src/addons/dragAndDrop/WeekWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { eventSegments } from '../../utils/eventLevels'
import Selection, { getBoundsForNode } from '../../Selection'
import EventRow from '../../EventRow'
import { dragAccessors } from './common'
import { DnDContext } from './DnDContext'

const propTypes = {}

Expand All @@ -32,16 +33,7 @@ class WeekWrapper extends React.Component {
resourceId: PropTypes.any,
}

static contextTypes = {
draggable: PropTypes.shape({
onStart: PropTypes.func,
onEnd: PropTypes.func,
dragAndDropAction: PropTypes.object,
onDropFromOutside: PropTypes.func,
onBeginAction: PropTypes.func,
dragFromOutsideItem: PropTypes.func,
}),
}
static contextType = DnDContext

constructor(...args) {
super(...args)
Expand Down
32 changes: 9 additions & 23 deletions src/addons/dragAndDrop/withDragAndDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EventWrapper from './EventWrapper'
import EventContainerWrapper from './EventContainerWrapper'
import WeekWrapper from './WeekWrapper'
import { mergeComponents } from './common'
import { DnDContext } from './DnDContext'

/**
* Creates a higher-order component (HOC) supporting drag & drop and optionally resizing
Expand Down Expand Up @@ -94,23 +95,6 @@ export default function withDragAndDrop(Calendar) {
step: 30,
}

static contextTypes = {
dragDropManager: PropTypes.object,
}

static childContextTypes = {
draggable: PropTypes.shape({
onStart: PropTypes.func,
onEnd: PropTypes.func,
onBeginAction: PropTypes.func,
onDropFromOutside: PropTypes.func,
dragFromOutsideItem: PropTypes.func,
draggableAccessor: accessor,
resizableAccessor: accessor,
dragAndDropAction: PropTypes.object,
}),
}

constructor(...args) {
super(...args)

Expand All @@ -125,7 +109,7 @@ export default function withDragAndDrop(Calendar) {
this.state = { interacting: false }
}

getChildContext() {
getDnDContextValue() {
return {
draggable: {
onStart: this.handleInteractionStart,
Expand Down Expand Up @@ -197,11 +181,13 @@ export default function withDragAndDrop(Calendar) {
)

return (
<Calendar
{...props}
elementProps={elementPropsWithDropFromOutside}
components={this.components}
/>
<DnDContext.Provider value={this.getDnDContextValue()}>
<Calendar
{...props}
elementProps={elementPropsWithDropFromOutside}
components={this.components}
/>
</DnDContext.Provider>
)
}
}
Expand Down

0 comments on commit 6def209

Please sign in to comment.