Giter VIP home page Giter VIP logo

react-sortly's People

Contributors

ericfries avatar lytc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-sortly's Issues

Dependency resolving

Apparently some of the dependencies are not being resolved correctly when using yarn.
I had to install immutability-helper and use-debounce manually to get sortly to work

Sample not working

As DND package is updated (and since this one imports * dnd version), the sample usage is no longer working. DND package does not export DragDropContext.

@lytc is this package still supported?

I really miss ability to scroll while dragging

Current behaviour:
Selecting any element disables scrolling ability. Only possibility now is to find that sweet spot on bottom and top of the screen but thats sometimes very hard/unusable for example with few nested set items dragging

Expected behaviour:
Ability to use scroll or up/down arrow while dragging.

My solution:
i was looking around for this feature and only thread i found was react-dnd/react-dnd#553

Im lookin on to that.

License?

Hi there!

We're interested in using react-sortly for a project, it looks like a nice wrapper around react-dnd. However, I'm worried there's no LICENSE on the project (other than in package.json). Can you clarify what the license is for this code? Thanks!

Restrict nesting

I am trying to restrict the nesting so that items at the top level and one level below can only be sorted. Furthermore for deeper nested items (path.length > 1) it should not be possible to drop them as first or second level item. To accomplish that I use the onMove handler to check the dragged items path against it's original items path. The handler looks something like this:

const onMove = (newItems, dragIndex, newIndex) => {
  const draggedItem = newItems[newIndex];
  const originalItem = items.find(({ id }) => id === draggedItem.id);
  if (!originalItem) {
    return false; // Just to assure originalItem was found...
  }
  const originalNestingLevel = originalItem.path.length;
  const newNestingLevel = draggedItem.path.length;
  
  // Prevent changing the nesting for items with path.length <= 1
  if (originalNestingLevel <= 1 && originalNestingLevel !== newNestingLevel) {
    return false;
  }

  // Prevent changing the nesting for items with path.length > 1
  // to path.length <= 1
  if (originalNestingLevel > 1 && newNestingLevel <= 1) {
    return false;
  }
  return true;
};

The sort only part works perfectly fine.
The nesting part also works fine when items at the second level (path.length = 1) have children. However if they don't have any children it is not possible to drag a deeper nested item from another second level item below this childless item for some reason.

Do you have any ideas how to solve this problem?
Thanks in advance and thanks for this awesome component.
I was looking ages for nested dnd.

Wrong documentation for convert util function

Seems like there is a wrong documentation for the convert util function, I tried to use it and it didn't work, e.g:

const items = [
  {id: 1, parentId: null, index: 0, name: "Categories"},
  {id: 2, parentId: null, index: 1, name: "Brand"},
  {id: 3, parentId: 1, index: 0, name: "Bags"},
  {id: 4, parentId: 1, index: 1, name: "Mugs"},
  {id: 5, parentId: 1, index: 2, name: "Clothing"},
  {id: 8, parentId: 2, index: 0, name: "Ruby"},
  {id: 9, parentId: 2, index: 1, name: "Apache"},
  {id: 10, parentId: 2, index: 2, name: "Spree"},
  {id: 11, parentId: 2, index: 3, name: "Rails"}
];

const convertedItems = convert(items);

The result for convertedItems is an empty array.

Solution

The thing is that the database data must not have null as a parentId for the first level items.

The data must look something like this:

const items = [
  {id: 1, parentId: 0, index: 0, name: "Categories"},
  {id: 2, parentId: 0, index: 1, name: "Brand"},
  {id: 3, parentId: 1, index: 0, name: "Bags"},
  {id: 4, parentId: 1, index: 1, name: "Mugs"},
  {id: 5, parentId: 1, index: 2, name: "Clothing"},
  {id: 8, parentId: 2, index: 0, name: "Ruby"},
  {id: 9, parentId: 2, index: 1, name: "Apache"},
  {id: 10, parentId: 2, index: 2, name: "Spree"},
  {id: 11, parentId: 2, index: 3, name: "Rails"}
];

Multiple unnecessary re-renders

Hi there,

Frist off - I'm loving Sortly. I'm making use of it in a Meteor app I'm hacking together as a prof of concept.

One thing I'm having a problem with though. My itemRenderer renders multiple times, even with no prop changes and I was wondering if you could help cast a little light on things....

I've tried to use React.memo with a custom equal function, but even with that, and equal props, I still get the problem (I noted that in one of your examples, you used Reac.memo, and I'm assuming the same problem exists in that too).

I think it all comes down to the hooks. I'm using useDrag and useDrop hooks. I think they always return different functions, and therefore cause a re-render. Not sure if they need to work like this or if there is some tweak I can make to prevent it. I'm not massively familiar with React or even Javascript (part of the reason I'm making my app is to learn).

Any thoughts?

Dragging Ghost

demo

I am using your library nested inside of react-dnd-HOC and it works great! The only issue I've noticed is that the ghosting is picking up the whole parent container instead of just itself and its descendants. Any thoughts on how to remove/correct the ghosting?

Collapse tree node

I think it will be a great feature if a tree node with children can be collapsed the same way it can be expanded.

There is have few throubles

demo example is wrong HTML5Backend doesn't export as default need to be use between the curly brackets. Second issue appeared saying drop is not a function shortly library not working properly and demo examples are thrown errors

UMD support needed .

Hello, really this is very light weight and it's amazing . Is there any UMD build !?

maxDepth Example

Great library!

I'm trying to create a list that only allows one level of nesting. I've tried setting maxDepth to 0, 1 and 2 each each value seems to allow for an infinite level of nesting. Is there a working example using maxDepth?

Feature Request: Virtualisation

Hi there,

I've run into a bit of an issue with my app when it comes to longer lists - horrible lag! Nothing to do with react-sortly, it's just that the list I'm rendering has some quite heavy items in it.

I was wondering if you could add some virtualisation to Sortly?

I've had a play with virtualising my list (Virtuoso) and it makes my longer lists that were taking 2seconds to mount/dismount as good as instant!

Unfortunately, I can't get Sortly and Virtuoso to play nice together, so in my tests, I removed Sortly. But if virtualisation could be built-in, this would be a massive improvement.

Any thoughts?

Jest encountered an unexpected token

Im encountering this error when trying to test my project if I have sortly enabled

  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    C:\Workspaces\myProject\frontend\node_modules\react-sortly\lib\index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Sortly from './Sortly';
                                                                                             ^^^^^^

react 17 support

Is it possible to support React from version 17?

currently react-sortly needs a peer Dependency of react@"^16.10.1".
This keeps us from using your package.

Kind regards

maxDepth issue

I have set the maxDepth on 1. So I can make a structure of that's only two layers deep. But when I'm able to drag two layers deep on a second layer so the structure is three layers deep. and that's not what I want...

Did anyone tried to unit test it using jest + enzyme?

As you figured I run unit tests using jest and enzyme.
Problem is that item renderer isn't triggered even, when component is mounted. So I can't make tests against rendered item.

FYI, I'm not writing tests for this lib. I'm writing tests in my own project, where react-sortly is used inside some components.

Functionality issue, even in example.

It seems that this has a functionality issue that renders it unusable for my use scenario:

If you have several depth elements and you try to move them back and forth, it will only allow you to move the last element with a certain depth. So If I have a scenario like the attached printscreen, it will only allow me to move element number 3, and not 1 and 2.

Is this the way it should work?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.