refactor(constants): add ENTITIES constant and replace magic strings in editor reducer and inspector

This commit is contained in:
Kirill Shumilov
2016-07-15 14:18:11 +03:00
parent b9a6425346
commit 9d6086e879
3 changed files with 12 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
import R from 'ramda';
import React from 'react';
import Widgets from './InspectorWidgets';
import * as ENTITIES from '../constants/entities';
const styles = {
container: {
@@ -48,21 +48,23 @@ class Inspector extends React.Component {
} else if (selection.length === 1) {
const entity = (selection[0].entity);
switch (entity) {
default:
case 'Node':
case ENTITIES.NODE:
this.widgets = [
new Widgets.HintWidget({
text: 'There are no properties for the selected node.',
}),
];
break;
case 'Link':
case ENTITIES.LINK:
this.widgets = [
new Widgets.HintWidget({
text: 'Links have not any properties.',
}),
];
break;
default:
this.widgets = [];
break;
}
} else {
this.widgets = [

View File

@@ -0,0 +1,3 @@
export const NODE = 'Node';
export const LINK = 'Link';
export const PIN = 'Pin';

View File

@@ -7,6 +7,7 @@ import {
EDITOR_SET_MODE,
EDITOR_SET_SELECTED_NODETYPE,
} from '../actionTypes';
import * as ENTITIES from '../constants/entities';
const addSelection = (entityName, action, state) => {
const select = {
@@ -25,9 +26,9 @@ export const editor = (state = {}, action) => {
linkingPin: null,
});
case EDITOR_SELECT_NODE:
return addSelection('Node', action, state);
return addSelection(ENTITIES.NODE, action, state);
case EDITOR_SELECT_LINK:
return addSelection('Link', action, state);
return addSelection(ENTITIES.LINK, action, state);
case EDITOR_SELECT_PIN:
return R.set(R.lensProp('linkingPin'), action.payload.id, state);
case EDITOR_SET_MODE: