Skip to content

Commit

Permalink
Merge pull request #1291 from guardian/jsh-tr/deeper-dnd
Browse files Browse the repository at this point in the history
[Housekeeping]: Rename root-level drag and drop element; improve comments in WithDimensions component
  • Loading branch information
jonathonherbert authored Dec 22, 2020
2 parents 9aa6db7 + fca27de commit ca48acd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions fronts-client/src/components/Clipboard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Dispatch } from 'types/Store';
import React, { RefObject } from 'react';
import { connect } from 'react-redux';
import { Root, Move, PosSpec } from 'lib/dnd';
import { DragAndDropRoot, Move, PosSpec } from 'lib/dnd';
import type { State } from 'types/State';
import { insertCardFromDropEvent } from 'util/collectionUtils';
import {
Expand Down Expand Up @@ -168,7 +168,7 @@ class Clipboard extends React.Component<ClipboardProps> {
<ButtonLabel>Clear clipboard</ButtonLabel>
</ClearClipboardButton>
</ClipboardHeader>
<Root
<DragAndDropRoot
id="clipboard"
data-testid="clipboard"
style={{ display: 'flex', flex: 1 }}
Expand Down Expand Up @@ -227,7 +227,7 @@ class Clipboard extends React.Component<ClipboardProps> {
</>
)}
</ClipboardLevel>
</Root>
</DragAndDropRoot>
</ClipboardBody>
</StyledDragIntentContainer>
</ClipboardWrapper>
Expand Down
6 changes: 3 additions & 3 deletions fronts-client/src/components/FrontsEdit/FrontContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import sortBy from 'lodash/sortBy';
import debounce from 'lodash/debounce';
import { events } from 'services/GA';
import { Root, PosSpec, Move } from 'lib/dnd';
import { DragAndDropRoot, PosSpec, Move } from 'lib/dnd';
import Collection from './Collection';
import type { State } from 'types/State';
import WithDimensions from 'components/util/WithDimensions';
Expand Down Expand Up @@ -202,7 +202,7 @@ class FrontContent extends React.Component<FrontProps, FrontState> {
>
<WithDimensions>
{({ width }) => (
<Root id={this.props.id} data-testid={this.props.id}>
<DragAndDropRoot id={this.props.id} data-testid={this.props.id}>
{front.collections.map((collectionId) => (
<CollectionContainer
key={collectionId}
Expand Down Expand Up @@ -237,7 +237,7 @@ class FrontContent extends React.Component<FrontProps, FrontState> {
/>
</CollectionContainer>
))}
</Root>
</DragAndDropRoot>
)}
</WithDimensions>
</FrontCollectionsContainer>
Expand Down
6 changes: 3 additions & 3 deletions fronts-client/src/components/util/WithDimensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ interface Props {
const initialState = { width: undefined, height: undefined } as Dimensions;

/**
* Supplies the dimensions of the given element to its children.
* Supplies the dimensions of the wrapper div provided by this component to its children.
*
* ```
* <WithDimensions element={this.someHTMLElement}>
* <WithDimensions>
* {({ width, height }) => (
* <p>`The dimensions of the given element are ${width} x ${height}`</p>
* <p>`The dimensions of the parent div element are ${width} x ${height}`</p>
* )
* </WithDimensions>
* ```
Expand Down
2 changes: 1 addition & 1 deletion fronts-client/src/lib/dnd/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const RootContainer = styled.div`
}
`;

export default class Root extends React.Component<Props, State> {
export default class DragAndDropRoot extends React.Component<Props, State> {
public state = { store: createStore() };
private rootRef = React.createRef<HTMLDivElement>();

Expand Down
42 changes: 21 additions & 21 deletions fronts-client/src/lib/dnd/__tests__/dnd.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import TestRenderer from 'react-test-renderer';
import Root from '../Root';
import DragAndDropRoot from '../Root';
import Level from '../Level';

const createDragEvent = (top: boolean) => {
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Curation', () => {
let edit: any;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
arr={[{ id: '1' }, { id: '2' }]}
type="a"
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('Curation', () => {
);
}}
</Level>
</Root>
</DragAndDropRoot>
);

runDrag(nodeProps)(dropProps);
Expand All @@ -121,7 +121,7 @@ describe('Curation', () => {
let edit: any;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
arr={[{ id: '1' }, { id: '2' }]}
type="a"
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('Curation', () => {
);
}}
</Level>
</Root>
</DragAndDropRoot>
);

runDrag(nodeProps)(dropProps);
Expand All @@ -177,7 +177,7 @@ describe('Curation', () => {
let edit: any;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
arr={[{ id: '1' }, { id: '2' }]}
type="a"
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('Curation', () => {
);
}}
</Level>
</Root>
</DragAndDropRoot>
);

runDrag(nodeProps)(dropProps);
Expand All @@ -228,7 +228,7 @@ describe('Curation', () => {
let to: any;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
arr={[{ id: '2' }]}
parentId="1"
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('Curation', () => {
</Level>
)}
</Level>
</Root>
</DragAndDropRoot>
);

const data = {
Expand All @@ -283,7 +283,7 @@ describe('Curation', () => {
let edit;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
arr={[{ id: '2' }]}
type="a"
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('Curation', () => {
);
}}
</Level>
</Root>
</DragAndDropRoot>
);

runDrag(dragProps)(dropProps);
Expand All @@ -331,7 +331,7 @@ describe('Curation', () => {
let edit: any;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
parentType="root"
parentId="root"
Expand All @@ -355,7 +355,7 @@ describe('Curation', () => {
return false;
}}
</Level>
</Root>
</DragAndDropRoot>
);

runDrag(dragProps)(dropProps);
Expand All @@ -369,7 +369,7 @@ describe('Curation', () => {
let edit: any;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
arr={[{ id: '1' }]}
parentType="root"
Expand All @@ -390,7 +390,7 @@ describe('Curation', () => {
return null;
}}
</Level>
</Root>
</DragAndDropRoot>
);

runDrag(dragProps)(dropProps);
Expand All @@ -404,7 +404,7 @@ describe('Curation', () => {
let edit: any;

setup(
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
arr={[{ id: '1' }]}
parentType="root"
Expand All @@ -425,7 +425,7 @@ describe('Curation', () => {
return null;
}}
</Level>
</Root>
</DragAndDropRoot>
);

runDrag(dragProps)(dropProps);
Expand All @@ -440,7 +440,7 @@ describe('Curation', () => {

setup(
<div>
<Root id="@@ROOT">
<DragAndDropRoot id="@@ROOT">
<Level
type="a"
getId={({ id }) => id}
Expand All @@ -456,8 +456,8 @@ describe('Curation', () => {
return null;
}}
</Level>
</Root>
<Root id="@@ROOT2">
</DragAndDropRoot>
<DragAndDropRoot id="@@ROOT2">
<Level
type="a"
getId={({ id }) => id}
Expand All @@ -475,7 +475,7 @@ describe('Curation', () => {
>
{() => null}
</Level>
</Root>
</DragAndDropRoot>
</div>
);

Expand Down
2 changes: 1 addition & 1 deletion fronts-client/src/lib/dnd/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as Root } from './Root';
export { default as DragAndDropRoot } from './Root';
export {
default as Level,
Move,
Expand Down

0 comments on commit ca48acd

Please sign in to comment.