Skip to content

Commit f646168

Browse files
authored
chore(webapp): adds shortcut key for admin area (#2570)
* Allow shortcuts hook to work if undefined * Conditionally show shortcut button if only 1 result * LinkButton can accept conditionally shown shortcuts
1 parent a6896b4 commit f646168

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

apps/webapp/app/components/primitives/Buttons.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -298,19 +298,17 @@ export const Button = forwardRef<HTMLButtonElement, ButtonPropsType>(
298298
const innerRef = useRef<HTMLButtonElement>(null);
299299
useImperativeHandle(ref, () => innerRef.current as HTMLButtonElement);
300300

301-
if (props.shortcut) {
302-
useShortcutKeys({
303-
shortcut: props.shortcut,
304-
action: (e) => {
305-
if (innerRef.current) {
306-
innerRef.current.click();
307-
e.preventDefault();
308-
e.stopPropagation();
309-
}
310-
},
311-
disabled,
312-
});
313-
}
301+
useShortcutKeys({
302+
shortcut: props.shortcut,
303+
action: (e) => {
304+
if (innerRef.current) {
305+
innerRef.current.click();
306+
e.preventDefault();
307+
e.stopPropagation();
308+
}
309+
},
310+
disabled: disabled || !props.shortcut,
311+
});
314312

315313
return (
316314
<button
@@ -345,16 +343,16 @@ export const LinkButton = ({
345343
...props
346344
}: LinkPropsType) => {
347345
const innerRef = useRef<HTMLAnchorElement>(null);
348-
if (props.shortcut) {
349-
useShortcutKeys({
350-
shortcut: props.shortcut,
351-
action: () => {
352-
if (innerRef.current) {
353-
innerRef.current.click();
354-
}
355-
},
356-
});
357-
}
346+
347+
useShortcutKeys({
348+
shortcut: props.shortcut,
349+
action: () => {
350+
if (innerRef.current) {
351+
innerRef.current.click();
352+
}
353+
},
354+
disabled: disabled || !props.shortcut,
355+
});
358356

359357
if (disabled) {
360358
return (

apps/webapp/app/routes/admin._index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,17 @@ export default function AdminDashboardRoute() {
138138
<TableCell isSticky={true}>
139139
<Form method="post" reloadDocument>
140140
<input type="hidden" name="id" value={user.id} />
141-
142141
<Button
143142
type="submit"
144143
name="action"
145144
value="impersonate"
146145
className="mr-2"
147146
variant="tertiary/small"
147+
shortcut={
148+
users.length === 1
149+
? { modifiers: ["mod"], key: "enter", enabledOnInputElements: true }
150+
: undefined
151+
}
148152
>
149153
Impersonate
150154
</Button>

apps/webapp/app/routes/admin.orgs.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export default function AdminDashboardRoute() {
117117
to={`/@/orgs/${org.slug}`}
118118
className="mr-2"
119119
variant="tertiary/small"
120+
shortcut={
121+
organizations.length === 1
122+
? { modifiers: ["mod"], key: "enter", enabledOnInputElements: true }
123+
: undefined
124+
}
120125
>
121126
Impersonate
122127
</LinkButton>

0 commit comments

Comments
 (0)