import React from 'react'; import { connect } from 'react-redux'; import { searchableFieldsSelector } from '../selectors/search'; import { canvasMarginsSelector } from '../selectors/canvas'; import { hideHelp } from '../actions/app-actions'; const GENERAL_SHORTCUTS = [ {key: 'esc', label: 'Close active panel'}, {key: '/', label: 'Activate search field'}, {key: '?', label: 'Toggle shortcut menu'}, {key: 'g', label: 'Switch to Graph view'}, {key: 't', label: 'Switch to Table view'}, {key: 'r', label: 'Switch to Resources view'}, ]; const CANVAS_METRIC_SHORTCUTS = [ {key: '<', label: 'Select and pin previous metric'}, {key: '>', label: 'Select and pin next metric'}, {key: 'q', label: 'Unpin current metric'}, ]; function renderShortcuts(cuts) { return (
{cuts.map(({key, label}) => (
{key}
{label}
))}
); } function renderShortcutPanel() { return (

Shortcuts

General

{renderShortcuts(GENERAL_SHORTCUTS)}

Canvas Metrics

{renderShortcuts(CANVAS_METRIC_SHORTCUTS)}
); } const BASIC_SEARCHES = [ {term: 'foo', label: 'All fields for foo'}, { term: 'pid: 12345', label: Any field matching pid for the value 12345 }, ]; const REGEX_SEARCHES = [ { term: 'foo|bar', label: 'All fields for foo or bar' }, { term: 'command: foo(bar|baz)', label: command field for foobar or foobaz }, ]; const METRIC_SEARCHES = [ {term: 'cpu > 4%', label: CPU greater than 4%}, { term: 'memory < 10mb', label: Memory less than 10 megabytes }, ]; function renderSearches(searches) { return (
{searches.map(({term, label}) => (
{term}
{label}
))}
); } function renderSearchPanel() { return (

Search

Basics

{renderSearches(BASIC_SEARCHES)}

Regular expressions

{renderSearches(REGEX_SEARCHES)}

Metrics

{renderSearches(METRIC_SEARCHES)}
); } function renderFieldsPanel(currentTopologyName, searchableFields) { const none = ( None ); const currentTopology = ( {currentTopologyName} ); return (

Fields and Metrics

Searchable fields and metrics in the
currently selected {currentTopology} topology:

Fields

{searchableFields.get('fields').map(f => (
{f}
))} {searchableFields.get('fields').size === 0 && none}

Metrics

{searchableFields.get('metrics').map(m => (
{m}
))} {searchableFields.get('metrics').size === 0 && none}
); } function HelpPanel({ currentTopologyName, searchableFields, onClickClose, canvasMargins }) { return (

Help

{renderShortcutPanel()} {renderSearchPanel()} {renderFieldsPanel(currentTopologyName, searchableFields)}
); } function mapStateToProps(state) { return { canvasMargins: canvasMarginsSelector(state), searchableFields: searchableFieldsSelector(state), currentTopologyName: state.getIn(['currentTopology', 'fullName']) }; } export default connect(mapStateToProps, { onClickClose: hideHelp })(HelpPanel);