Skip to content

Commit

Permalink
Merge pull request #615 from codaco/feature/ensure-uids
Browse files Browse the repository at this point in the history
Ensure uids exist for all nodes in app
  • Loading branch information
bryfox authored Aug 1, 2018
2 parents 522e307 + fc316d8 commit 7388bc3
Show file tree
Hide file tree
Showing 46 changed files with 320 additions and 445 deletions.
47 changes: 23 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"cordova-plugin-wkwebview-engine": "^1.1.4",
"cordova-plugin-x-socialsharing": "^5.2.1",
"cordova-plugin-zeroconf": "^1.3.3",
"object-hash": "^1.3.0",
"react-id-swiper": "^1.6.4"
},
"homepage": ".",
Expand Down
10 changes: 5 additions & 5 deletions public/protocols/development.netcanvas/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,35 +482,35 @@
"previousInterview": {
"nodes": [
{
"uid": "previous_1",
"uid": "person_1",
"type": "person",
"name": "Anita",
"nickname": "Annie",
"age": "23"
},
{
"uid": "previous_2",
"uid": "person_2",
"type": "person",
"name": "Barry",
"nickname": "Baz",
"age": "23"
},
{
"uid": "previous_3",
"uid": "person_3",
"type": "person",
"name": "Carlito",
"nickname": "Carl",
"age": "23"
},
{
"uid": "previous_4",
"uid": "person_4",
"type": "person",
"name": "Dee",
"nickname": "Dee",
"age": "23"
},
{
"uid": "previous_5",
"uid": "person_5",
"type": "person",
"name": "Eugine",
"nickname": "Eu",
Expand Down
9 changes: 5 additions & 4 deletions src/components/CardList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cx from 'classnames';
import { scrollable, selectable } from '../behaviours';
import { Card } from '.';
import { Icon } from '../ui/components';
import { NodePK } from '../ducks/modules/network';

const EnhancedCard = selectable(Card);

Expand All @@ -23,7 +24,7 @@ const CardList = (props) => {
onDeleteCard,
onToggleCard,
selected,
uid,
getKey,
} = props;

const classNames = cx('card-list', className);
Expand All @@ -32,7 +33,7 @@ const CardList = (props) => {
<div className={classNames}>
{
nodes.map(node => (
<span className="card-list__content" key={uid(node)}>
<span className="card-list__content" key={getKey(node)}>
<EnhancedCard
label={label(node)}
multiselect={multiselect}
Expand Down Expand Up @@ -62,7 +63,7 @@ CardList.propTypes = {
onDeleteCard: PropTypes.func,
onToggleCard: PropTypes.func,
selected: PropTypes.func,
uid: PropTypes.func,
getKey: PropTypes.func,
};

CardList.defaultProps = {
Expand All @@ -75,7 +76,7 @@ CardList.defaultProps = {
onDeleteCard: null,
onToggleCard: () => {},
selected: () => false,
uid: node => node.uid,
getKey: node => node[NodePK],
};

export default compose(
Expand Down
10 changes: 6 additions & 4 deletions src/components/ListSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';

import { Button } from '../ui/components';
import { CardList } from '.';
import { NodePK } from '../ducks/modules/network';

class ListSelect extends Component {
constructor(props) {
Expand Down Expand Up @@ -82,7 +83,7 @@ class ListSelect extends Component {
/**
* @param {object} node
*/
selected = node => !!this.props.selectedNodes.find(current => current.uid === node.uid);
selected = node => !!this.props.selectedNodes.find(current => current[NodePK] === node[NodePK]);

/**
* @param property to sort by
Expand Down Expand Up @@ -129,11 +130,12 @@ class ListSelect extends Component {
* @param {object} node
*/
toggleCard = (node) => {
const index = this.props.selectedNodes.findIndex(current => current.uid === node.uid);
const matchingPK = n => n[NodePK] === node[NodePK];
const index = this.props.selectedNodes.findIndex(matchingPK);
if (index !== -1) {
this.props.onRemoveNode(this.props.nodes.find(current => current.uid === node.uid));
this.props.onRemoveNode(this.props.nodes.find(matchingPK));
} else {
this.props.onSubmitNode(this.props.nodes.find(current => current.uid === node.uid));
this.props.onSubmitNode(this.props.nodes.find(matchingPK));
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/components/NodeBin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { compose, withProps } from 'recompose';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { actionCreators as sessionsActions } from '../ducks/modules/sessions';
import { NodePK } from '../ducks/modules/network';
import { DropTarget, MonitorDropTarget } from '../behaviours/DragAndDrop';

/**
Expand Down Expand Up @@ -43,7 +44,7 @@ export default compose(
connect(null, mapDispatchToProps),
withProps(props => ({
accepts: ({ meta }) => meta.itemType === 'EXISTING_NODE',
onDrop: ({ meta }) => props.removeNode(meta.uid),
onDrop: ({ meta }) => props.removeNode(meta[NodePK]),
})),
DropTarget,
MonitorDropTarget(['isOver', 'willAccept']),
Expand Down
5 changes: 3 additions & 2 deletions src/components/NodeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MonitorDragSource,
} from '../behaviours/DragAndDrop';
import sortOrder from '../utils/sortOrder';
import { NodePK } from '../ducks/modules/network';

const EnhancedNode = DragSource(selectable(Node));

Expand Down Expand Up @@ -98,7 +99,7 @@ class NodeList extends Component {
exit,
} = this.state;

const isSource = !!find(nodes, ['uid', get(meta, 'uid', null)]);
const isSource = !!find(nodes, [NodePK, get(meta, NodePK, null)]);
const isValidTarget = !isSource && willAccept;
const isHovering = isValidTarget && isOver;

Expand All @@ -118,7 +119,7 @@ class NodeList extends Component {
{
nodes.map((node, index) => (
<NodeTransition
key={`${node.uid}`}
key={`${node[NodePK]}`}
index={index}
stagger={stagger}
>
Expand Down
5 changes: 3 additions & 2 deletions src/components/OrdinalBinBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MonitorDragSource,
} from '../behaviours/DragAndDrop';
import sortOrder from '../utils/sortOrder';
import { NodePK } from '../ducks/modules/network';

const EnhancedNode = DragSource(selectable(Node));

Expand Down Expand Up @@ -92,7 +93,7 @@ class OrdinalBinBucket extends Component {
exit,
} = this.state;

const isSource = !!find(nodes, ['uid', get(meta, 'uid', null)]);
const isSource = !!find(nodes, [NodePK, get(meta, NodePK, null)]);
const isValidTarget = !isSource && willAccept;
const isHovering = isValidTarget && isOver;

Expand All @@ -115,7 +116,7 @@ class OrdinalBinBucket extends Component {
nodes.map((node, index) => (
index < 3 && (
<NodeTransition
key={`${node.uid}`}
key={`${node[NodePK]}`}
index={index}
stagger={stagger}
>
Expand Down
Loading

0 comments on commit 7388bc3

Please sign in to comment.