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

Commit

Permalink
Hotfix: process starting twice when using shortcut
Browse files Browse the repository at this point in the history
Only activate shortcuts for the last mounted QuickActionsContextShortcuts component

Issue #1283
Issue #1324
  • Loading branch information
pablosichert committed Nov 6, 2017
1 parent e3b8d19 commit f38f26b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/shortcuts/QuickActionsContextShortcuts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import React, { Component } from 'react';
import { Shortcuts } from 'react-shortcuts';

/* TODO: Refactor this hack
* https://github.com/metasfresh/metasfresh-webui-frontend/issues/1283
*/
let componentHierarchy = [];

class QuickActionsContextShortcuts extends Component {
componentWillMount() {
// Rerender components lower in the hierarchy when a new one is added
const _componentHierarchy = componentHierarchy;
componentHierarchy = [...componentHierarchy, this];

for (const component of _componentHierarchy) {
component.forceUpdate();
}
}

componentWillUnmount() {
componentHierarchy = componentHierarchy.filter(
component => component !== this
);
}

handleShortcuts = (action, event) => {
const {handleClick, onClick} = this.props;

Expand All @@ -18,6 +39,11 @@ class QuickActionsContextShortcuts extends Component {
}

render() {
// Only render the top most component in the hierarchy
if (componentHierarchy[componentHierarchy.length - 1] !== this) {
return null;
}

return (
<Shortcuts
name="QUICK_ACTIONS"
Expand Down

0 comments on commit f38f26b

Please sign in to comment.