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 #1847

Merged
merged 2 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";
}
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,7 +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 } from "utils/keyShortcuts";
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 All @@ -42,11 +52,6 @@ export function onFieldKeyDown(ctx: any) {
const dataView = getDataView(ctx);
const tablePanelView = getTablePanelView(ctx);
tablePanelView.handleEditorKeyDown(event);
if( isSaveShortcut(event)){
tablePanelView.setEditing(false);
yield*flushCurrentRowData(ctx)();
return;
}
switch (event.key) {
case "Tab": {
if (isGoingToChangeRow(event)) {
Expand Down Expand Up @@ -118,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
22 changes: 22 additions & 0 deletions frontend-html/src/utils/keyShortcuts.ts
Expand Up @@ -24,3 +24,25 @@ export function isSaveShortcut(event: any) {
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";
}