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

fix: remove click in favor of onClick #226

Merged
merged 7 commits into from
Apr 24, 2023
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
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = {
props: true,
ignorePropertyModificationsFor: ['accumulator', 'state', 'event']
}
]
],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error'
}
};
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@reduxjs/toolkit": "^1.9.2",
"@sentry/browser": "^7.43.0",
"@tinymce/tinymce-react": "^4.3.0",
"@zextras/carbonio-design-system": "^1.2.0",
"@zextras/carbonio-design-system": "^2.0.0",
"@zextras/carbonio-ui-preview": "^1.1.0",
"darkreader": "^4.9.58",
"history": "^5.3.0",
Expand All @@ -115,7 +115,7 @@
},
"peerDependencies": {
"@reduxjs/toolkit": "^1 >=1.9",
"@zextras/carbonio-design-system": "^1",
"@zextras/carbonio-design-system": "^2",
"@zextras/carbonio-ui-preview": "^1",
"core-js": "^3.27.2",
"lodash": "^4.17.21",
Expand Down
6 changes: 6 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ export const DARK_READER_PROP_KEY = 'zappDarkreaderMode';
export const SENTRY_SHELL_DSN = 'https://[email protected]/6';
export const SENTRY_FEEDBACK_DNS =
'https://[email protected]/8';

export enum ResultLabelType {
NORMAL = 'normal',
WARNING = 'warning',
ERROR = 'error'
}
50 changes: 27 additions & 23 deletions src/keyboard-shortcuts/keyboard-shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import React from 'react';
import { type Action } from '../../types';

type handleKeyboardShortcutsProps = {
primaryAction: any;
secondaryActions: any;
event: any;
inputRef: any;
primaryAction: Action;
secondaryActions: Action[];
event: KeyboardEvent;
inputRef: React.RefObject<HTMLInputElement | HTMLTextAreaElement>;
currentApp: string;
};

Expand All @@ -18,17 +21,16 @@ const modifierKeysSecondTier = ['p'];
let keySequence = '';

export const handleKeyboardShortcuts = (props: handleKeyboardShortcutsProps): void => {
const createEmail = props.secondaryActions?.filter((item: any) => item.id === 'create-mail')[0]
?.click;
const createEmail = props.secondaryActions?.filter((item) => item.id === 'create-mail')[0]
?.onClick;
const createAppointment = props.secondaryActions?.filter(
(item: any) => item.id === 'new-appointment'
)[0]?.click;
const createContact = props.secondaryActions?.filter(
(item: any) => item.id === 'create-contact'
)[0]?.click;
(item) => item.id === 'new-appointment'
)[0]?.onClick;
const createContact = props.secondaryActions?.filter((item) => item.id === 'create-contact')[0]
?.onClick;

// will be used in future implementations
const ctrlModifierIsActive = props.event.ctrlKey || props.event.metaKey;
// const ctrlModifierIsActive = props.event.ctrlKey || props.event.metaKey;

const consoleLogKeyCombination = (): void => {
// console.log(
Expand All @@ -41,58 +43,60 @@ export const handleKeyboardShortcuts = (props: handleKeyboardShortcutsProps): vo
props.event.stopImmediatePropagation();
};

const eventTargetElement = props.event.target instanceof HTMLElement ? props.event.target : null;
const isGlobalContext =
props.event?.target?.isContentEditable === false &&
props.event?.target?.nodeName !== 'INPUT' &&
props.event.target.nodeName !== 'TEXTAREA';
eventTargetElement &&
!eventTargetElement.isContentEditable &&
eventTargetElement.nodeName !== 'INPUT' &&
eventTargetElement.nodeName !== 'TEXTAREA';

const callKeyboardShortcutAction = (): void => {
switch (keySequence) {
case 'n':
if (props.primaryAction && isGlobalContext) {
consoleLogKeyCombination();
props.primaryAction.click();
props.primaryAction.onClick?.(props.event);
}
break;

case 'nm':
if (isGlobalContext) {
consoleLogKeyCombination();
createEmail();
createEmail?.(props.event);
}
break;

case 'na':
if (isGlobalContext) {
consoleLogKeyCombination();
createAppointment();
createAppointment?.(props.event);
}
break;

case 'nc':
if (isGlobalContext) {
consoleLogKeyCombination();
createContact();
createContact?.(props.event);
}
break;

case 'c':
if (isGlobalContext) {
consoleLogKeyCombination();
createContact();
createContact?.(props.event);
}
break;

case '/':
if (isGlobalContext) {
props.event.preventDefault();
consoleLogKeyCombination();
props.inputRef ? props.inputRef.current?.focus() : null;
props.inputRef.current?.focus();
}
break;

default:
null;
break;
}
keySequence = '';
};
Expand All @@ -115,6 +119,6 @@ export const handleKeyboardShortcuts = (props: handleKeyboardShortcutsProps): vo
break;

default:
null;
break;
}
};
1 change: 0 additions & 1 deletion src/network/fetch-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { AvailableLocalesResponse } from '../../types';
import { SHELL_APP_ID } from '../constants';
import { useAccountStore } from '../store/account';
import { getSoapFetch } from './fetch';

export const fetchLocales = (): Promise<any> =>
Expand Down
Loading