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

Adding draggableId to DraggableLocation #2482

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export default function calculateReorderImpact({
destination: {
droppableId: destination.descriptor.id,
index,
draggableId: match.descriptor.id,
},
},
};
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export type DroppableDimension = {|
export type DraggableLocation = {|
droppableId: DroppableId,
index: number,
draggableId?: DraggableId,
|};

export type DraggableIdMap = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
destination: {
index: preset.inForeign3.descriptor.index,
droppableId: preset.inForeign3.descriptor.droppableId,
draggableId: preset.inForeign3.descriptor.id,
},
},
};
Expand Down Expand Up @@ -187,6 +188,7 @@ import {
destination: {
index: preset.inForeign4.descriptor.index,
droppableId: preset.inForeign4.descriptor.droppableId,
draggableId: preset.inForeign4.descriptor.id,
},
},
};
Expand Down Expand Up @@ -308,6 +310,7 @@ import {
destination: {
index: preset.inForeign2.descriptor.index,
droppableId: preset.inForeign2.descriptor.droppableId,
draggableId: preset.inForeign2.descriptor.id,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
// is now in position of inForeign3
droppableId: preset.foreign.descriptor.id,
index: preset.inForeign3.descriptor.index,
draggableId: preset.inForeign3.descriptor.id,
},
},
};
Expand All @@ -103,6 +104,7 @@ import {
// is now in position of inForeign2
droppableId: preset.inForeign2.descriptor.droppableId,
index: preset.inForeign2.descriptor.index,
draggableId: preset.inForeign2.descriptor.id,
},
},
};
Expand Down Expand Up @@ -160,6 +162,7 @@ import {
// is now in position of inForeign3
droppableId: preset.inForeign3.descriptor.droppableId,
index: preset.inForeign3.descriptor.index,
draggableId: preset.inForeign3.descriptor.id,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { getOffsetForStartEdge } from '../../util/get-offset-for-edge';
destination: {
index: preset.inForeign4.descriptor.index,
droppableId: preset.inForeign4.descriptor.droppableId,
draggableId: preset.inForeign4.descriptor.id,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const viewport: Viewport = getViewport();
destination: {
droppableId: droppable.descriptor.id,
index: 0,
draggableId: visible.descriptor.id,
},
},
};
Expand Down Expand Up @@ -296,6 +297,7 @@ const viewport: Viewport = getViewport();
destination: {
droppableId: droppable.descriptor.id,
index: 0,
draggableId: visible.descriptor.id,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
// is now in position of inHome3
droppableId: preset.home.descriptor.id,
index: preset.inHome3.descriptor.index,
draggableId: preset.inHome3.descriptor.id,
},
},
};
Expand Down Expand Up @@ -176,6 +177,7 @@ import {
destination: {
droppableId: preset.home.descriptor.id,
index: preset.inHome2.descriptor.index,
draggableId: preset.inHome2.descriptor.id,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
// is now in position of inHome2
droppableId: preset.home.descriptor.id,
index: preset.inHome2.descriptor.index,
draggableId: preset.inHome2.descriptor.id,
},
},
};
Expand All @@ -107,6 +108,7 @@ import {
// is now in position of inHome1
droppableId: preset.home.descriptor.id,
index: preset.inHome1.descriptor.index,
draggableId: preset.inHome1.descriptor.id,
},
},
};
Expand Down Expand Up @@ -168,6 +170,7 @@ import {
droppableId: preset.home.descriptor.id,
// is now in position of inHome2
index: preset.inHome2.descriptor.index,
draggableId: preset.inHome2.descriptor.id,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const viewport: Viewport = getViewport();
// now in position of inHome2 as it has moved backwards (it started displaced)
droppableId: preset.home.descriptor.id,
index: preset.inHome2.descriptor.index,
draggableId: preset.inHome2.descriptor.id,
},
},
};
Expand Down Expand Up @@ -151,6 +152,7 @@ const viewport: Viewport = getViewport();
// is now in place of inHome2
droppableId: preset.home.descriptor.id,
index: preset.inHome2.descriptor.index,
draggableId: preset.inHome2.descriptor.id,
},
},
};
Expand Down
6 changes: 5 additions & 1 deletion test/unit/state/middleware/responders/repeated-use.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ it('should behave correctly across multiple drags', () => {
expect(responders.onDragStart).toHaveBeenCalledTimes(1);

// update
const newIndex = initialPublishArgs.critical.draggable.index + 1;
const state: State = store.getState();
const newDraggableId = Object.keys(state.dimensions.draggables)[newIndex];
const update: DragUpdate = {
...getDragStart(),
destination: {
droppableId: initialPublishArgs.critical.droppable.id,
index: initialPublishArgs.critical.draggable.index + 1,
index: newIndex,
draggableId: newDraggableId,
},
combine: null,
};
Expand Down
6 changes: 5 additions & 1 deletion test/unit/state/middleware/responders/update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ it('should call onDragUpdate if the position has changed on move', () => {
expect(responders.onDragUpdate).not.toHaveBeenCalled();

jest.runOnlyPendingTimers();
const newIndex = initialPublishArgs.critical.draggable.index + 1;
const state: State = store.getState();
const newDraggableId = Object.keys(state.dimensions.draggables)[newIndex];
const update: DragUpdate = {
...getDragStart(),
combine: null,
destination: {
droppableId: initialPublishArgs.critical.droppable.id,
index: initialPublishArgs.critical.draggable.index + 1,
index: newIndex,
draggableId: newDraggableId,
},
};
expect(responders.onDragUpdate).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ import {
destination: {
droppableId: preset.foreign.descriptor.id,
index: preset.inForeign2.descriptor.index,
draggableId: preset.inForeign2.descriptor.id,
},
},
};
Expand Down Expand Up @@ -372,6 +373,7 @@ import {
destination: {
droppableId: preset.foreign.descriptor.id,
index: preset.inForeign2.descriptor.index,
draggableId: preset.inForeign2.descriptor.id,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const dontCare: Position = { x: 0, y: 0 };
destination: {
droppableId: preset.home.descriptor.id,
index: preset.inHome2.descriptor.index,
draggableId: preset.inHome2.descriptor.id,
},
},
};
Expand Down Expand Up @@ -131,6 +132,7 @@ const dontCare: Position = { x: 0, y: 0 };
destination: {
droppableId: preset.home.descriptor.id,
index: preset.inHome2.descriptor.index,
draggableId: preset.inHome2.descriptor.id,
},
},
};
Expand Down Expand Up @@ -171,6 +173,7 @@ const dontCare: Position = { x: 0, y: 0 };
destination: {
droppableId: preset.home.descriptor.id,
index: preset.inHome4.descriptor.index,
draggableId: preset.inHome4.descriptor.id,
},
},
};
Expand Down
31 changes: 26 additions & 5 deletions test/unit/state/move-in-direction/move-in-direction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { tryGetDestination } from '../../../../src/state/get-impact-location';
describe('on the vertical axis', () => {
const preset = getPreset(vertical);
const state = getStatePreset(vertical);
const draggables = Object.keys(state.preset.dimensions.draggables);

it('should move forward on a MOVE_DOWN', () => {
const result: ?PublicResult = moveInDirection({
Expand All @@ -24,9 +25,12 @@ describe('on the vertical axis', () => {
});

invariant(result, 'expected a result');
const idx = 1;
const newDraggableId = draggables[idx];
const expected: DraggableLocation = {
droppableId: preset.home.descriptor.id,
index: 1,
index: idx,
draggableId: newDraggableId,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand All @@ -38,9 +42,12 @@ describe('on the vertical axis', () => {
});

invariant(result, 'expected a result');
const idx = 0;
const newDraggableId = draggables[idx];
const expected: DraggableLocation = {
droppableId: preset.home.descriptor.id,
index: 0,
index: idx,
draggableId: newDraggableId,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand All @@ -55,6 +62,7 @@ describe('on the vertical axis', () => {
const expected: DraggableLocation = {
droppableId: preset.foreign.descriptor.id,
index: 1,
draggableId: preset.inForeign2.descriptor.id,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand All @@ -69,6 +77,7 @@ describe('on the vertical axis', () => {
const expected: DraggableLocation = {
droppableId: preset.home.descriptor.id,
index: 0,
draggableId: preset.inHome1.descriptor.id,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand All @@ -77,6 +86,7 @@ describe('on the vertical axis', () => {
describe('on the horizontal axis', () => {
const preset = getPreset(horizontal);
const state = getStatePreset(horizontal);
const draggables = Object.keys(state.preset.dimensions.draggables);

it('should move forward on a MOVE_RIGHT', () => {
const result: ?PublicResult = moveInDirection({
Expand All @@ -85,9 +95,12 @@ describe('on the horizontal axis', () => {
});

invariant(result, 'expected a result');
const idx = 1;
const newDraggableId = draggables[idx];
const expected: DraggableLocation = {
droppableId: preset.home.descriptor.id,
index: 1,
index: idx,
draggableId: newDraggableId,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand All @@ -99,9 +112,12 @@ describe('on the horizontal axis', () => {
});

invariant(result, 'expected a result');
const idx = 0;
const newDraggableId = draggables[idx];
const expected: DraggableLocation = {
droppableId: preset.home.descriptor.id,
index: 0,
index: idx,
draggableId: newDraggableId,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand All @@ -116,6 +132,7 @@ describe('on the horizontal axis', () => {
const expected: DraggableLocation = {
droppableId: preset.foreign.descriptor.id,
index: 1,
draggableId: preset.inForeign2.descriptor.id,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand All @@ -127,9 +144,12 @@ describe('on the horizontal axis', () => {
});

invariant(result, 'expected a result');
const idx = 0;
const newDraggableId = draggables[idx];
const expected: DraggableLocation = {
droppableId: preset.home.descriptor.id,
index: 0,
index: idx,
draggableId: newDraggableId,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand Down Expand Up @@ -181,6 +201,7 @@ describe('on the horizontal axis', () => {
const expected: DraggableLocation = {
droppableId: preset.foreign.descriptor.id,
index: 1,
draggableId: preset.inForeign2.descriptor.id,
};
expect(tryGetDestination(result.impact)).toEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const enableCombine = (droppable: DroppableDimension): DroppableDimension => ({
destination: {
index: preset.inForeign2.descriptor.index,
droppableId: preset.foreign.descriptor.id,
draggableId: preset.inForeign2.descriptor.id,
},
},
};
Expand Down Expand Up @@ -127,6 +128,7 @@ const enableCombine = (droppable: DroppableDimension): DroppableDimension => ({
destination: {
index: preset.inForeign1.descriptor.index,
droppableId: preset.foreign.descriptor.id,
draggableId: preset.inForeign1.descriptor.id,
},
},
};
Expand Down Expand Up @@ -194,6 +196,7 @@ const enableCombine = (droppable: DroppableDimension): DroppableDimension => ({
destination: {
index: preset.inForeign2.descriptor.index,
droppableId: preset.foreign.descriptor.id,
draggableId: preset.inForeign2.descriptor.id,
},
},
};
Expand Down Expand Up @@ -263,6 +266,7 @@ const enableCombine = (droppable: DroppableDimension): DroppableDimension => ({
destination: {
index: preset.inForeign1.descriptor.index,
droppableId: preset.foreign.descriptor.id,
draggableId: preset.inForeign1.descriptor.id,
},
},
};
Expand Down
Loading