Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add help page #120

Merged
merged 6 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/components/TracePage/KeyboardShortcutsHelp.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright (c) 2017 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.KeyboardShortcutsHelp kbd {
background: #f5f5f5;
border: 1px solid #e8e8e8;
border-bottom: 1px solid #ddd;
color: #000;
margin-right: 0.4em;
padding: 0.25em 0.3em;
}
98 changes: 98 additions & 0 deletions src/components/TracePage/KeyboardShortcutsHelp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// @flow

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import React from 'react';
import { Button, Modal } from 'semantic-ui-react';

import { kbdMappings } from './keyboard-shortcuts';

import './KeyboardShortcutsHelp.css';

const symbolConv = {
up: '↑',
right: '→',
down: '↓',
left: '←',
shift: '⇧',
};

const descriptions = {
scrollPageDown: 'Scroll down',
scrollPageUp: 'Scroll up',
scrollToNextVisibleSpan: 'Scroll to the next visible span',
scrollToPrevVisibleSpan: 'Scroll to the previous visible span',
panLeft: 'Pan left',
panLeftFast: 'Pan left — Large',
panRight: 'Pan right',
panRightFast: 'Pan right — Large',
zoomIn: 'Zoom in',
zoomInFast: 'Zoom in — Large',
zoomOut: 'Zoom out',
zoomOutFast: 'Zoom out — Large',
};

function convertKeys(keyConfig: string | string[]): string[][] {
const config = Array.isArray(keyConfig) ? keyConfig : [keyConfig];
return config.map(str => str.split('+').map(part => symbolConv[part] || part.toUpperCase()));
}

export default function KeyboardShortcutsHelp() {
const rows = [];
Object.keys(kbdMappings).forEach(title => {
const keyConfigs = convertKeys(kbdMappings[title]);
const configs = keyConfigs.map(config =>
<tr key={String(config)}>
<td>
{config.map(s =>
<kbd key={s}>
{s}
</kbd>
)}
</td>
<td>
{descriptions[title]}
</td>
</tr>
);
rows.push(...configs);
});
return (
<Modal
trigger={
<Button basic compact size="tiny">
<h3>⌘</h3>
</Button>
}
>
<Modal.Header>Keyboard Shortcuts</Modal.Header>
<Modal.Content>
<Modal.Description>
<table className="KeyboardShortcutsHelp ui celled table">
<thead>
<tr>
<th>Key(s)</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
</Modal.Description>
</Modal.Content>
</Modal>
);
}
4 changes: 4 additions & 0 deletions src/components/TracePage/TracePageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { Dropdown, Menu } from 'semantic-ui-react';

import KeyboardShortcutsHelp from './KeyboardShortcutsHelp';
import { formatDatetime, formatDuration } from '../../utils/date';

export const HEADER_ITEMS = [
Expand Down Expand Up @@ -68,6 +69,9 @@ export default function TracePageHeader(props) {
</h2>
</div>
<div className="inline-block mr1">
<KeyboardShortcutsHelp />
</div>
<div className="mr1">
<Menu>
<Dropdown text="View Options" className="item">
<Dropdown.Menu>
Expand Down
2 changes: 1 addition & 1 deletion src/components/TracePage/keyboard-shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type ShortcutCallbacks = {
zoomOutFast: CombokeysHandler,
};

const kbdMappings = {
export const kbdMappings = {
scrollPageDown: 's',
scrollPageUp: 'w',
scrollToNextVisibleSpan: 'f',
Expand Down