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

Refactor keycode exporting in ui_framework #13663

Merged
merged 5 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/core_plugins/kibana/public/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { documentationLinks } from 'ui/documentation_links/documentation_links';
import { showCloneModal } from './top_nav/show_clone_modal';
import { migrateLegacyQuery } from 'ui/utils/migrateLegacyQuery';
import { QueryManagerProvider } from 'ui/query_manager';
import { ESC_KEY_CODE } from 'ui_framework/services';
import { keycodes } from 'ui_framework/services';
import { DashboardContainerAPI } from './dashboard_container_api';

const app = uiModules.get('app/dashboard', [
Expand Down Expand Up @@ -328,7 +328,7 @@ app.directive('dashboardApp', function ($injector) {
$scope.exitFullScreenMode = () => setFullScreenMode(false);

document.addEventListener('keydown', (e) => {
if (e.keyCode === ESC_KEY_CODE) {
if (e.keyCode === keycodes.ESCAPE) {
setFullScreenMode(false);
}
}, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ uiModules.get('apps/management')
};

$scope.maybeCancel = function ($event, conf) {
if ($event.keyCode === keyCodes.ESC) {
if ($event.keyCode === keyCodes.ESCAPE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to replace the custom keyCodes instance here with import { keyCodes } from 'ui_framework/services';

$scope.cancelEdit(conf);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ngMock from 'ng_mock';
import '../kbn_ui_ace_keyboard_mode';
import {
ENTER_KEY,
ESC_KEY_CODE,
keycodes,
} from 'ui_framework/services';

describe('kbnUiAceKeyboardMode directive', () => {
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('kbnUiAceKeyboardMode directive', () => {
const hint = element.find('.uiAceKeyboardHint');
sinon.spy(hint[0], 'focus');
const ev = angular.element.Event('keydown'); // eslint-disable-line new-cap
ev.keyCode = ESC_KEY_CODE;
ev.keyCode = keycodes.ESCAPE;
textarea.trigger(ev);
expect(hint[0].focus.called).to.be(true);
expect(hint.hasClass('uiAceKeyboardHint-isInactive')).to.be(false);
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('kbnUiAceKeyboardModeService', () => {
const hint = element.find('.uiAceKeyboardHint');
sinon.spy(hint[0], 'focus');
const ev = angular.element.Event('keydown'); // eslint-disable-line new-cap
ev.keyCode = ESC_KEY_CODE;
ev.keyCode = keycodes.ESCAPE;
textarea.trigger(ev);
expect(hint[0].focus.called).to.be(true);
expect(hint.hasClass('uiAceKeyboardHint-isInactive')).to.be(false);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/accessibility/kbn_ui_ace_keyboard_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import angular from 'angular';
import { uiModules } from 'ui/modules';
import './kbn_ui_ace_keyboard_mode.less';
import { ESC_KEY_CODE, ENTER_KEY } from 'ui_framework/services';
import { keycodes, ENTER_KEY } from 'ui_framework/services';

let aceKeyboardModeId = 0;

Expand Down Expand Up @@ -64,7 +64,7 @@ uiModules.get('kibana')
});

uiAceTextbox.keydown((ev) => {
if (ev.keyCode === ESC_KEY_CODE) {
if (ev.keyCode === keycodes.ESCAPE) {
ev.preventDefault();
ev.stopPropagation();
enableOverlay();
Expand Down
4 changes: 2 additions & 2 deletions ui_framework/src/components/modal/confirm_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { KuiModalHeaderTitle } from './modal_header_title';
import { KuiModalBody } from './modal_body';
import { KuiModalBodyText } from './modal_body_text';
import { KuiButton } from '../index';
import { ESC_KEY_CODE } from '../../services';
import { keycodes } from '../../services';

export const CONFIRM_BUTTON = 'confirm';
export const CANCEL_BUTTON = 'cancel';
Expand All @@ -32,7 +32,7 @@ export function KuiConfirmModal({

const onKeyDown = (event) => {
// Treat the 'esc' key as a cancel indicator.
if (event.keyCode === ESC_KEY_CODE) {
if (event.keyCode === keycodes.ESCAPE) {
onCancel();
}
};
Expand Down
20 changes: 10 additions & 10 deletions ui_framework/src/services/accessibility/combo_box_key_codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
*/

import {
DOWN_KEY_CODE,
ENTER_KEY_CODE,
ESC_KEY_CODE,
TAB_KEY_CODE,
UP_KEY_CODE,
DOWN,
ENTER,
ESCAPE as ESC,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to change this to just be ESCAPE and update the consumers of this service, for consistency?

TAB,
UP,
} from '../key_codes';

export const comboBoxKeyCodes = {
DOWN: DOWN_KEY_CODE,
ENTER: ENTER_KEY_CODE,
ESC: ESC_KEY_CODE,
TAB: TAB_KEY_CODE,
UP: UP_KEY_CODE,
DOWN,
ENTER,
ESC,
TAB,
UP,
};
5 changes: 4 additions & 1 deletion ui_framework/src/services/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Export all keycodes under a `keycodes` named variable
import * as keycodes from './key_codes';
export { keycodes };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to keyCodes for consistent capitalization?


export {
accessibleClickKeys,
comboBoxKeyCodes,
Expand All @@ -6,6 +10,5 @@ export {
} from './accessibility';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the difference between ENTER_KEY from accessibility and keycodes.ENTER? Above you are importing import { keycodes, ENTER_KEY } from 'ui_framework/services'; which threw me off a bit. Seems like instead of ENTER_KEY it should just be keywords.ENTER

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Honestly I just refactored the key_codes file and left the accessible_click_keys as it was. I fixed that with now with another commit. Thanks.


export { SortableProperties } from './sort';
export { ESC_KEY_CODE } from './key_codes';

export { LEFT_ALIGNMENT, RIGHT_ALIGNMENT } from './alignment';
12 changes: 7 additions & 5 deletions ui_framework/src/services/key_codes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const DOWN_KEY_CODE = 40;
export const ENTER_KEY_CODE = 13;
export const ESC_KEY_CODE = 27;
export const TAB_KEY_CODE = 9;
export const UP_KEY_CODE = 38;
export const ENTER = 13;
export const ESCAPE = 27;
export const TAB = 9;

// Arrow keys
export const DOWN = 40;
export const UP = 38;