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: Shortcuts were not activated 2022 4 #1848

Merged
merged 3 commits into from Aug 31, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 6 additions & 22 deletions frontend-html/src/gui/connections/CDataViewHeader.tsx
Expand Up @@ -71,6 +71,12 @@ import { getTrueSelectedRowIndex } from "model/selectors/DataView/getTrueSelecte
import { getAreCrudButtonsEnabled } from "model/selectors/DataView/getAreCrudButtonsEnabled";
import { IDataView } from "model/entities/types/IDataView";
import { saveColumnConfigurationsAsync } from "model/actions/DataView/TableView/saveColumnConfigurations";
import {
isAddRecordShortcut,
isDeleteRecordShortcut,
isDuplicateRecordShortcut,
isFilterRecordShortcut
} from "utils/keyShortcuts";

@observer
export class CDataViewHeaderInner extends React.Component<{
Expand Down Expand Up @@ -485,25 +491,3 @@ export function CDataViewHeader(props: { isVisible: boolean }) {
const extension = useContext(CtxDataViewHeaderExtension);
return <CDataViewHeaderInner isVisible={props.isVisible} extension={extension}/>;
}

export function isAddRecordShortcut(event: any) {
return (
((event.ctrlKey || event.metaKey) && !event.shiftKey && event.key === "i") ||
((event.ctrlKey || event.metaKey) && event.shiftKey && event.key === "j") ||
event.key === "Insert"
);
}

export function isDeleteRecordShortcut(event: any) {
return (event.ctrlKey || event.metaKey) && !event.shiftKey && event.key === "Delete";
}

export function isDuplicateRecordShortcut(event: any) {
return (
(event.ctrlKey || event.metaKey) && !event.shiftKey && (event.key === "d" || event.key === "k")
);
}

export function isFilterRecordShortcut(event: any) {
return (event.ctrlKey || event.metaKey) && event.key === "f";
}
9 changes: 1 addition & 8 deletions frontend-html/src/gui/connections/CScreenToolbar.tsx
Expand Up @@ -52,14 +52,7 @@ import { About } from "model/entities/AboutInfo";
import { showDialog } from "model/selectors/getDialogStack";
import { AboutDialog } from "gui/Components/Dialogs/AboutDialog";
import { geScreenActionButtonsState } from "model/actions-ui/ScreenToolbar/saveBottonVisible";

function isSaveShortcut(event: any) {
return event.key === "s" && (event.ctrlKey || event.metaKey);
}

function isRefreshShortcut(event: any) {
return event.key === "r" && (event.ctrlKey || event.metaKey);
}
import { isRefreshShortcut, isSaveShortcut } from "utils/keyShortcuts";

@observer
export class CScreenToolbar extends React.Component<{}> {
Expand Down
Expand Up @@ -54,13 +54,7 @@ import { action, computed } from "mobx";
import { getPanelMenuActions } from "model/selectors/DataView/getPanelMenuActions";
import { DropdownDivider } from "gui/Components/Dropdown/DropdownDivider";
import { getAreCrudButtonsEnabled } from "model/selectors/DataView/getAreCrudButtonsEnabled";
import {
isAddRecordShortcut,
isDeleteRecordShortcut,
isDuplicateRecordShortcut,
isFilterRecordShortcut,
renderRowCount
} from "gui/connections/CDataViewHeader";
import { renderRowCount} from "gui/connections/CDataViewHeader";
import { DataViewHeader } from "gui/Components/DataViewHeader/DataViewHeader";
import "gui/connections/MobileComponents/Grid/DataViewHeader.module.scss"
import { getMobileState } from "model/selectors/getMobileState";
Expand All @@ -71,6 +65,12 @@ import { getColumnConfigurationModel } from "model/selectors/getColumnConfigurat
import { saveColumnConfigurationsAsync } from "model/actions/DataView/TableView/saveColumnConfigurations";
import { getRecordInfo } from "model/selectors/RecordInfo/getRecordInfo";
import { RecordInfo } from "gui/connections/MobileComponents/Grid/RecordInfo";
import {
isAddRecordShortcut,
isDeleteRecordShortcut,
isDuplicateRecordShortcut,
isFilterRecordShortcut
} from "utils/keyShortcuts";

@observer
export class DataViewHeaderInner extends React.Component<{
Expand Down
22 changes: 22 additions & 0 deletions frontend-html/src/index.tsx
Expand Up @@ -44,6 +44,12 @@ import { preventDoubleclickSelect } from "utils/mouse";
import { RootError } from "RootError";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { ArrayPrototypes } from "@origam/utils"
import {
isAddRecordShortcut,
isDeleteRecordShortcut,
isDuplicateRecordShortcut,
isFilterRecordShortcut
} from "utils/keyShortcuts";

if (import.meta.env.DEV) {
axios.defaults.timeout = 3600000;
Expand All @@ -63,9 +69,25 @@ function disableAutoZoomingOnIPhone(){
}
}

function disableCollidingBrowserShortcuts() {
const ignoreShortcuts = (event: KeyboardEvent) => {
if (
isAddRecordShortcut(event) ||
isDuplicateRecordShortcut(event) ||
isDeleteRecordShortcut(event) ||
isFilterRecordShortcut(event)
) {
event.preventDefault();
}
};

window.addEventListener("keydown", ignoreShortcuts);
}

async function main() {
disableAutoZoomingOnIPhone();
preventDoubleclickSelect();
disableCollidingBrowserShortcuts();
const locationHash = window.location.hash;
const TOKEN_OVR_HASH = "#origamAuthTokenOverride=";
if (locationHash.startsWith(TOKEN_OVR_HASH)) {
Expand Down
Expand Up @@ -28,6 +28,17 @@ import { handleError } from "model/actions/handleError";
import { getDataView } from "model/selectors/DataView/getDataView";
import { shouldProceedToChangeRow } from "model/actions-ui/DataView/TableView/shouldProceedToChangeRow";
import { getGridFocusManager } from "model/entities/GridFocusManager";
import {
isSaveShortcut,
isAddRecordShortcut,
isDeleteRecordShortcut,
isDuplicateRecordShortcut,
isFilterRecordShortcut
} from "utils/keyShortcuts";
import { onDeleteRowClick } from "model/actions-ui/DataView/onDeleteRowClick";
import { onCreateRowClick } from "model/actions-ui/DataView/onCreateRowClick";
import { onCopyRowClick } from "model/actions-ui/DataView/onCopyRowClick";
import { onFilterButtonClick } from "model/actions-ui/DataView/onFilterButtonClick";

export function onFieldKeyDown(ctx: any) {

Expand Down Expand Up @@ -112,6 +123,20 @@ export function onFieldKeyDown(ctx: any) {
tablePanelView.triggerOnFocusTable();
break;
}
default: {
if (isSaveShortcut(event)) {
tablePanelView.setEditing(false);
yield*flushCurrentRowData(ctx)();
} else if (isAddRecordShortcut(event)) {
yield onCreateRowClick(dataView)(event);
} else if (isDeleteRecordShortcut(event)) {
yield onDeleteRowClick(dataView)(event);
} else if (isDuplicateRecordShortcut(event)) {
yield onCopyRowClick(dataView)(event);
} else if (isFilterRecordShortcut(event)) {
yield onFilterButtonClick(dataView)(event);
}
}
}
} catch (e) {
yield*handleError(ctx)(e);
Expand Down
49 changes: 49 additions & 0 deletions frontend-html/src/utils/keyShortcuts.ts
@@ -0,0 +1,49 @@
/*
Copyright 2005 - 2023 Advantage Solutions, s. r. o.

This file is part of ORIGAM (http://www.origam.org).

ORIGAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ORIGAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>.
*/


export function isSaveShortcut(event: any) {
return event.key === "s" && (event.ctrlKey || event.metaKey);
}

export function isRefreshShortcut(event: any) {
return event.key === "r" && (event.ctrlKey || event.metaKey);
}

export function isAddRecordShortcut(event: any) {
return (
((event.ctrlKey || event.metaKey) && !event.shiftKey && event.key === "i") ||
((event.ctrlKey || event.metaKey) && event.shiftKey && event.key === "j") ||
event.key === "Insert"
);
}

export function isDeleteRecordShortcut(event: any) {
return (event.ctrlKey || event.metaKey) && !event.shiftKey && event.key === "Delete";
}

export function isDuplicateRecordShortcut(event: any) {
return (
(event.ctrlKey || event.metaKey) && !event.shiftKey && (event.key === "d" || event.key === "k")
);
}

export function isFilterRecordShortcut(event: any) {
return (event.ctrlKey || event.metaKey) && event.key === "f";
}