⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
import { useTranslations } from 'next-intl';
import type { HotkeyOverrides } from '@/lib/api/endpoints/settings';
import {
HOTKEYS,
HOTKEY_GROUPS,
type HotkeyCombos,
type HotkeyDef,
type HotkeyId,
} from '@/utils/hotkeys';
import HotkeysEditorRow from './HotkeysEditorRow';
// The shortcut list, grouped as the hotkey map declares. `base` is what applies
// without the overrides being edited (the built-in bindings in god mode, the
// instance bindings on the account screen), so resetting a row falls back to it.
// Rebinding to a combination already in use is refused by the row's parent through
// the conflict it reports here.
export default function HotkeysEditor({
base,
overrides,
onChange,
}: {
base: HotkeyCombos;
overrides: HotkeyOverrides;
onChange: (overrides: HotkeyOverrides) => void;
}) {
const t = useTranslations('common.hotkeys');
const effective = (id: HotkeyId) => overrides[id] ?? base[id];
// The command already bound to a combination, so a duplicate is visible before it
// is saved rather than leaving one of the two unreachable.
const conflictFor = (def: HotkeyDef): string | null => {
const combo = effective(def.id);
const other = HOTKEYS.find((h) => h.id !== def.id && effective(h.id) === combo);
return other ? t(`commands.${other.id}`) : null;
};
function record(id: HotkeyId, combo: string) {
onChange({ ...overrides, [id]: combo });
}
function reset(id: HotkeyId) {
const next = { ...overrides };
delete next[id];
onChange(next);
}
return (
<div className="space-y-6">
{HOTKEY_GROUPS.map((group) => (
<div key={group}>
<p className="mb-1 text-xs font-medium text-muted-foreground">{t(`groups.${group}`)}</p>
<div className="divide-y divide-border/60">
{HOTKEYS.filter((h) => h.group === group).map((def) => (
<HotkeysEditorRow
key={def.id}
def={def}
combo={effective(def.id)}
overridden={overrides[def.id] != null}
conflictWith={conflictFor(def)}
onRecord={(combo) => record(def.id, combo)}
onReset={() => reset(def.id)}
/>
))}
</div>
</div>
))}
</div>
);
}