Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Apply refactored shortcuts component on codebase
Browse files Browse the repository at this point in the history
Issue #1283
  • Loading branch information
pablosichert committed Nov 16, 2017
1 parent 7a9485d commit 1bf091a
Show file tree
Hide file tree
Showing 24 changed files with 405 additions and 453 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"react-redux": "~5.0.6",
"react-router": "^3.2.0",
"react-router-redux": "^4.0.8",
"react-shortcuts": "~2.0.0",
"react-tagsinput": "~3.18.0",
"react-translate-component": "~0.14.0",
"redux": "~3.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Shortcuts/Shortcut.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import keymap from './keymap';
import keymap from '../../shortcuts/keymap';

export default class Shortcut extends Component {
static contextTypes = {
Expand Down
14 changes: 1 addition & 13 deletions src/components/app/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import counterpart from 'counterpart';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import {connect} from 'react-redux';
import { ShortcutManager } from 'react-shortcuts';

import { processNewRecord } from '../../actions/GenericActions';
import {
Expand All @@ -14,7 +13,7 @@ import {
patch,
} from '../../actions/WindowActions';
import { getSelection } from '../../reducers/windowHandler';
import keymap from '../../keymap.js';
import keymap from '../../shortcuts/keymap';

import Process from '../Process';
import ModalContextShortcuts from '../shortcuts/ModalContextShortcuts';
Expand All @@ -24,8 +23,6 @@ import Window from '../Window';
import Indicator from './Indicator';
import OverlayField from './OverlayField';

const shortcutManager = new ShortcutManager(keymap);

const mapStateToProps = (state, props) => ({
parentSelection: getSelection({
state,
Expand All @@ -38,10 +35,6 @@ const mapStateToProps = (state, props) => ({
class Modal extends Component {
mounted = false;

static childContextTypes = {
shortcuts: PropTypes.object.isRequired,
}

static propTypes = {
dispatch: PropTypes.func.isRequired,
}
Expand Down Expand Up @@ -112,10 +105,6 @@ class Modal extends Component {
this.setState({ isTooltipShow: key });
}

getChildContext = () => {
return { shortcuts: shortcutManager };
}

initEventListeners = () => {
const modalContent = document.querySelector('.js-panel-modal-content');

Expand Down Expand Up @@ -469,7 +458,6 @@ class Modal extends Component {
>
{this.renderModalBody()}
</div>

<ModalContextShortcuts
apply={modalType === 'process' ?
this.handleStart :
Expand Down
12 changes: 1 addition & 11 deletions src/components/app/QuickActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import {

import QuickActionsDropdown from './QuickActionsDropdown';

import keymap from '../../keymap.js';
import keymap from '../../shortcuts/keymap';
import QuickActionsContextShortcuts
from '../shortcuts/QuickActionsContextShortcuts';
import Tooltips from '../tooltips/Tooltips.js'
import { ShortcutManager } from 'react-shortcuts';
const shortcutManager = new ShortcutManager(keymap);

class QuickActions extends Component {
constructor(props){
Expand Down Expand Up @@ -96,10 +94,6 @@ class QuickActions extends Component {
}
}

getChildContext = () => {
return { shortcuts: shortcutManager }
}

handleClickOutside = () => {
this.toggleDropdown();
}
Expand Down Expand Up @@ -257,10 +251,6 @@ class QuickActions extends Component {
}
}

QuickActions.childContextTypes = {
shortcuts: PropTypes.object.isRequired
}

QuickActions.propTypes = {
dispatch: PropTypes.func.isRequired
};
Expand Down
12 changes: 1 addition & 11 deletions src/components/app/RawModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import {
closeListIncludedView
} from '../../actions/ListActions';

import keymap from '../../keymap.js';
import keymap from '../../shortcuts/keymap';
import ModalContextShortcuts from '../shortcuts/ModalContextShortcuts';
import { ShortcutManager } from 'react-shortcuts';
import Tooltips from '../tooltips/Tooltips.js';
const shortcutManager = new ShortcutManager(keymap);

class RawModal extends Component {
state = {
Expand Down Expand Up @@ -56,10 +54,6 @@ class RawModal extends Component {
});
}

getChildContext = () => {
return { shortcuts: shortcutManager }
}

initEventListeners = () => {
const modalContent = document.querySelector('.js-panel-modal-content')

Expand Down Expand Up @@ -177,10 +171,6 @@ const mapStateToProps = state => ({
modalVisible: state.windowHandler.modal.visible || false
});

RawModal.childContextTypes = {
shortcuts: PropTypes.object.isRequired
}

RawModal.propTypes = {
dispatch: PropTypes.func.isRequired,
modalVisible: PropTypes.bool
Expand Down
13 changes: 1 addition & 12 deletions src/components/filters/FiltersItem.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import RawWidget from '../widget/RawWidget';
import OverlayField from '../app/OverlayField';
import counterpart from 'counterpart';
import keymap from '../../keymap.js';
import keymap from '../../shortcuts/keymap';
import ModalContextShortcuts from '../shortcuts/ModalContextShortcuts';
import { ShortcutManager } from 'react-shortcuts';
import Tooltips from '../tooltips/Tooltips.js';
const shortcutManager = new ShortcutManager(keymap);

class FiltersItem extends Component {
constructor(props) {
Expand Down Expand Up @@ -64,10 +61,6 @@ class FiltersItem extends Component {
}
}

getChildContext = () => {
return { shortcuts: shortcutManager }
}

setValue = (property, value, id, valueTo) => {
//TODO: LOOKUPS GENERATE DIFFERENT TYPE OF PROPERTY parameters
// IT HAS TO BE UNIFIED
Expand Down Expand Up @@ -238,8 +231,4 @@ class FiltersItem extends Component {
)}
}

FiltersItem.childContextTypes = {
shortcuts: PropTypes.object.isRequired
}

export default FiltersItem
2 changes: 1 addition & 1 deletion src/components/header/Breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import counterpart from 'counterpart';

import MenuOverlay from './MenuOverlay';
import Tooltips from '../tooltips/Tooltips';
import keymap from '../../keymap.js';
import keymap from '../../shortcuts/keymap';

class Breadcrumb extends Component {
constructor(props) {
Expand Down
13 changes: 1 addition & 12 deletions src/components/header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import { ShortcutManager } from 'react-shortcuts';

import {
deleteRequest,
Expand All @@ -12,7 +11,7 @@ import {
} from '../../actions/GenericActions';
import { openModal } from '../../actions/WindowActions';
import logo from '../../assets/images/metasfresh_logo_green_thumb.png';
import keymap from '../../keymap';
import keymap from '../../shortcuts/keymap';

import Indicator from '../app/Indicator';
import Prompt from '../app/Prompt';
Expand All @@ -28,8 +27,6 @@ import SideList from './SideList';
import Subheader from './SubHeader';
import UserDropdown from './UserDropdown';

const shortcutManager = new ShortcutManager(keymap);

const mapStateToProps = state => ({
inbox: state.appHandler.inbox,
me: state.appHandler.me,
Expand All @@ -51,10 +48,6 @@ class Header extends Component {
prompt: { open: false },
}

static childContextTypes = {
shortcuts: PropTypes.object.isRequired,
}

static propTypes = {
dispatch: PropTypes.func.isRequired,
inbox: PropTypes.object.isRequired,
Expand Down Expand Up @@ -97,10 +90,6 @@ class Header extends Component {
}
}

getChildContext = () => {
return { shortcuts: shortcutManager };
}

initEventListeners = () => {
document.addEventListener('scroll', this.handleScroll);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/SideList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Referenced from './Referenced';
import DocumentList from '../app/DocumentList';
import onClickOutside from 'react-onclickoutside';
import Tooltips from '../tooltips/Tooltips';
import keymap from '../../keymap.js';
import keymap from '../../shortcuts/keymap';
import counterpart from 'counterpart';

class SideList extends Component {
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/SubHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
updateBreadcrumb,
} from '../../actions/MenuActions';
import { getSelection } from '../../reducers/windowHandler';
import keymap from '../../keymap.js';
import keymap from '../../shortcuts/keymap';

import Actions from './Actions';
import BookmarkButton from './BookmarkButton';
Expand Down
114 changes: 69 additions & 45 deletions src/components/shortcuts/DocumentListContextShortcuts.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,84 @@
import React, { Component } from 'react';
import { Shortcuts } from 'react-shortcuts';
import { Shortcut } from '../Shortcuts';

class DocumentListContextShortcuts extends Component {
constructor(props){
super(props);
}
handleShortcuts = (action, event) => {
const {
handleAdvancedEdit, handleOpenNewTab, handleDelete, getAllLeafs,
handleIndent
} = this.props;

switch (action) {
case 'OPEN_SELECTED':
export default class DocumentListContextShortcuts extends Component {
handlers = {
OPEN_SELECTED: event => {
event.preventDefault();

if (this.props.handleOpenNewTab) {
this.props.handleOpenNewTab();
}
},
REMOVE_SELECTED: event => {
event.preventDefault();

if (this.props.handleDelete) {
this.props.handleDelete();
}
},
ADVANCED_EDIT: event => {
event.preventDefault();
if(handleOpenNewTab) {
handleOpenNewTab();

if (this.props.handleAdvancedEdit) {
this.props.handleAdvancedEdit();
}
break;
case 'REMOVE_SELECTED':
},
SELECT_ALL_LEAFS: event => {
event.preventDefault();
if(handleDelete){
handleDelete();

if (this.props.getAllLeafs) {
this.props.getAllLeafs();
}
break;
case 'ADVANCED_EDIT':
},
EXPAND_INDENT: event => {
event.preventDefault();
if(handleAdvancedEdit){
handleAdvancedEdit();

if (this.props.handleIndent) {
this.props.handleIndent(true);
}
break;
case 'SELECT_ALL_LEAFS':
},
COLLAPSE_INDENT: event => {
event.preventDefault();
getAllLeafs();
break;
case 'EXPAND_INDENT':
handleIndent(true);
break;
case 'COLLAPSE_INDENT':
handleIndent(false);
break;

if (this.props.handleIndent) {
this.props.handleIndent(false);
}
}
}
};

render() {
return (
<Shortcuts
handler={this.handleShortcuts}
isolate
name="DOCUMENT_LIST_CONTEXT"
preventDefault
stopPropagation
targetNodeSelector="body"
return [
<Shortcut
key="OPEN_SELECTED"
name="OPEN_SELECTED"
handler={this.handlers.OPEN_SELECTED}
/>,
<Shortcut
key="REMOVE_SELECTED"
name="REMOVE_SELECTED"
handler={this.handlers.REMOVE_SELECTED}
/>,
<Shortcut
key="ADVANCED_EDIT"
name="ADVANCED_EDIT"
handler={this.handlers.ADVANCED_EDIT}
/>,
<Shortcut
key="SELECT_ALL_LEAFS"
name="SELECT_ALL_LEAFS"
handler={this.handlers.SELECT_ALL_LEAFS}
/>,
<Shortcut
key="EXPAND_INDENT"
name="EXPAND_INDENT"
handler={this.handlers.EXPAND_INDENT}
/>,
<Shortcut
key="COLLAPSE_INDENT"
name="COLLAPSE_INDENT"
handler={this.handlers.COLLAPSE_INDENT}
/>
);
];
}
}

export default DocumentListContextShortcuts;
Loading

0 comments on commit 1bf091a

Please sign in to comment.