Sha256: 0708336846a7145c1a5c942811cb5620fcc816cbd53f64f67a9f06484cc0ad59

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { DndProvider } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';

import Priority from './Priority';
import { prioritizeGroups } from './GroupsHelpers';

const Groups = ({groups}) => {
  const [priorities, setPriorities] = useState(prioritizeGroups(groups));

  const moveGroup = (group, source, target, insert) => {
    const result = priorities;

    // insert the group into the correct priority
    if (insert) {
      // insert a new priority with the group
      result.splice(target, 0, [ group ]);
    } else {
      // add group to existing priority
      result[target].push(group);
    }

    // remove group from source priority
    result[source] = result[source].filter(e => (e !== group));

    // remove priority if it is empty
    if (result[source].length === 0) {
      result.splice(group.priority, 1);
    }

    setPriorities(result);
  };

  return (
    <DndProvider backend={HTML5Backend}>
      <div className="group-list">
        {priorities.map(groups, index => (
          <Priority priority={index} groups={groups} /> 
        ))}
      </div>
    </DndProvider>
  );
};

export default Groups;

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman_patch-1.2.0.alpha1 webpack/components/Groups/Groups.js
foreman_patch-1.1.6.alpha5 webpack/components/Groups/Groups.js
foreman_patch-1.1.6.alpha4 webpack/components/Groups/Groups.js
foreman_patch-1.1.5 webpack/components/Groups/Groups.js
foreman_patch-1.1.4 webpack/components/Groups/Groups.js
foreman_patch-1.1.3 webpack/components/Groups/Groups.js
foreman_patch-1.1.1 webpack/components/Groups/Groups.js