From f38f26b01928dc6bcde2ce66046b9588cd2e42d3 Mon Sep 17 00:00:00 2001 From: Pablo Sichert Date: Mon, 6 Nov 2017 23:37:29 +0100 Subject: [PATCH] Hotfix: process starting twice when using shortcut Only activate shortcuts for the last mounted QuickActionsContextShortcuts component Issue #1283 Issue #1324 --- .../shortcuts/QuickActionsContextShortcuts.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/shortcuts/QuickActionsContextShortcuts.js b/src/components/shortcuts/QuickActionsContextShortcuts.js index b32dcd086..8e9777625 100644 --- a/src/components/shortcuts/QuickActionsContextShortcuts.js +++ b/src/components/shortcuts/QuickActionsContextShortcuts.js @@ -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; @@ -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 (