UNPKG

lml-main

Version:

This is now a mono repository published into many standalone packages.

83 lines 3.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const React = require("react"); const react_redux_1 = require("react-redux"); const react_router_redux_1 = require("react-router-redux"); const selectors_1 = require("../../jobs/selectors"); const cosmoui_1 = require("cosmoui"); const Actions = require("../actions"); // todo - fix circular import here const modals_1 = require("../../allocation/actions/modals"); const actions_1 = require("../../allocation/actions"); const Mousetrap = require("mousetrap"); class KeyboardShortcutsComponent extends React.Component { componentDidMount() { const { notificationInfo, deallocateActiveJob, onKeyEnterPress, onKeyUpPress, onKeyDownPress, showAllocationModal, } = this.props; const trays = ['live', 'allocated', 'accepted', 'progress', 'completed']; // Mousetrap.bind(["alt+a"], (e: ExtendedKeyboardEvent, combo: string) => { // ReactRouter.browserHistory.push(trays[1]) // }) Mousetrap.bind(['alt+l'], (e, combo) => { this.props.redirect(trays[0]); }); Mousetrap.bind(['alt+p'], (e, combo) => { this.props.redirect(trays[3]); }); Mousetrap.bind(['alt+c'], (e, combo) => { this.props.redirect(trays[4]); }); Mousetrap.bind(['right'], (e, combo) => { this.props.selectTrayToRight(); }); Mousetrap.bind(['left'], (e, combo) => { this.props.selectTrayToLeft(); }); Mousetrap.bind(['ctrl+u', 'f4', 'shift+f4'], (e, combo) => { if (this.props.jobStatus === trays[1]) { deallocateActiveJob(); } }); Mousetrap.bind(['up'], (e, combo) => { e.preventDefault(); onKeyUpPress(); }); Mousetrap.bind(['down'], (e, combo) => { e.preventDefault(); onKeyDownPress(); }); Mousetrap.bind(['enter'], (e, combo) => { onKeyEnterPress(); }); Mousetrap.bind(['alt+a', 'alt+x'], (e, combo) => { console.log('ALT + A has been triggered', this.props.jobStatus, trays); // be careful with this!! if you destructure jobStatus out of the props at the start // then it will preserve the initial value of jobStatus so you are stuck with whatever // value happened to be there when it was first loaded if (this.props.jobStatus === trays[0] || this.props.jobStatus === trays[1]) { e.preventDefault(); console.log(showAllocationModal); showAllocationModal(); } }); } render() { // console.log('RENDER SHORT CUT KEY', this.props) return null; } } const mapStateToProps = (state) => ({ jobStatus: selectors_1.getJobPage(state), }); const mapActionsToProps = { notificationInfo: cosmoui_1.notificationInfo, deallocateActiveJob: actions_1.deallocateActiveJob, onKeyUpPress: Actions.onKeyUpPress, onKeyDownPress: Actions.onKeyDownPress, onKeyEnterPress: Actions.onKeyEnterPress, selectTrayToLeft: Actions.onKeyLeftPress, selectTrayToRight: Actions.onKeyRightPress, showAllocationModal: modals_1.showAllocationModal, redirect: (path) => react_router_redux_1.push({ pathname: path }), }; exports.KeyboardShortcuts = react_redux_1.connect(mapStateToProps, mapActionsToProps)(KeyboardShortcutsComponent); //# sourceMappingURL=keyboard-shortcuts.js.map