Skip to content

Commit

Permalink
Merge branch 'fix/shortcuts-tab-bug' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Aug 9, 2024
2 parents c4dc72b + 666242a commit 978be04
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/actionbar/FormActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,46 +66,59 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
previousView,
setPreviousView,
goToResourceId,
isActive,
} = useContext(ActionViewContext) as ActionViewContextType;

useHotkeys(
"pagedown",
() => {
if (!isActive) {
return;
}
tryNavigate(onNextClick);
},
{ enableOnFormTags: true, preventDefault: true },
[tryNavigate, onNextClick],
[tryNavigate, onNextClick, isActive],
);

useHotkeys(
"pageup",
() => {
if (!isActive) {
return;
}
tryNavigate(onPreviousClick);
},
{ enableOnFormTags: true, preventDefault: true },
[tryNavigate, onNextClick],
[tryNavigate, onNextClick, isActive],
);

useHotkeys(
"ctrl+s,command+s",
() => {
if (!isActive) {
return;
}
onFormSave?.();
},
{ enableOnFormTags: true, preventDefault: true },
[onFormSave],
[onFormSave, isActive],
);

// Shortcut ctl+l to change to previous view
useHotkeys(
"ctrl+l,command+l",
(event) => {
() => {
if (!isActive) {
return;
}
if (previousView) {
setPreviousView?.(currentView);
setCurrentView?.(previousView);
}
},
{ enableOnFormTags: true, preventDefault: true },
[previousView, currentView],
[previousView, currentView, isActive],
);

const { t } = useLocale();
Expand Down
9 changes: 8 additions & 1 deletion src/actionbar/TreeActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function TreeActionBar(props: Props) {
results,
limit,
totalItems,
isActive,
} = useContext(ActionViewContext) as ActionViewContextType;

const { parentContext = {}, treeExpandable, toolbar } = props;
Expand All @@ -80,18 +81,24 @@ function TreeActionBar(props: Props) {
useHotkeys(
"ctrl+l,command+l",
() => {
if (!isActive) {
return;
}
if (previousView) {
setPreviousView?.(currentView);
setCurrentView?.(previousView);
}
},
{ enableOnFormTags: true, preventDefault: true },
[previousView, currentView],
[previousView, currentView, isActive],
);

useHotkeys(
"ctrl+f,command+f",
() => {
if (!isActive) {
return;
}
setSearchVisible?.(!searchVisible);
},
{ enableOnFormTags: true, preventDefault: true },
Expand Down
3 changes: 3 additions & 0 deletions src/context/ActionViewContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type ActionViewContextType = {
limit?: number;
setLimit?: (value: number) => void;
setTitle?: (value: string) => void;
isActive: boolean;
};

export const ActionViewContext = createContext<ActionViewContextType | null>(
Expand Down Expand Up @@ -91,6 +92,7 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
setSearchTreeNameSearch,
goToResourceId,
limit: limitProps,
isActive,
} = props;

const [formIsSaving, setFormIsSaving] = useState<boolean>(false);
Expand Down Expand Up @@ -204,6 +206,7 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
limit,
setLimit,
setTitle,
isActive,
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/views/ActionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ function ActionView(props: Props, ref: any) {
searchTreeNameSearch={searchTreeNameSearch}
goToResourceId={goToResourceId}
limit={limit}
isActive={tabKey === activeKey}
>
{content()}
<GoToResourceModal
Expand Down

0 comments on commit 978be04

Please sign in to comment.