Skip to content

Commit

Permalink
Be able to create new items on a modeltable view by pressing c
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-smith committed Dec 15, 2024
1 parent 198f744 commit 22a409b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions frontend/src/lib/components/CommandPalette/paletteData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const navigationLinks: NavigationLink[] = [
label: 'riskAssessments',
href: '/risk-assessments'
},
{
label: 'riskScenarios',
href: '/risk-scenarios'
},
{
label: 'actionPlan',
href: '/applied-controls'
Expand Down
39 changes: 39 additions & 0 deletions frontend/src/routes/(app)/(internal)/[model=urlmodel]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import { getSecureRedirect } from '$lib/utils/helpers';
import { goto } from '$app/navigation';
import { onMount } from 'svelte';
export let data: PageData;
export let form: ActionData;
$: URLModel = data.URLModel;
Expand Down Expand Up @@ -46,6 +48,43 @@
modalStore.trigger(modal);
}
function handleKeyDown(event: KeyboardEvent) {
if (event.metaKey || event.ctrlKey) return;
// Check if 'c' is pressed and no input fields are currently focused
if (
event.key.toLowerCase() === 'c' &&
document.activeElement?.tagName !== 'INPUT' &&
document.activeElement?.tagName !== 'TEXTAREA'
) {
// Prevent default 'c' key behavior
event.preventDefault();
// Check if the add button exists and is not in a disabled list
if (
![
'risk-matrices',
'frameworks',
'requirement-mapping-sets',
'user-groups',
'role-assignments'
].includes(URLModel)
) {
modalCreateForm();
}
}
}
onMount(() => {
// Add event listener when component mounts
window.addEventListener('keydown', handleKeyDown);
// Cleanup event listener when component is destroyed
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
});
$: if (form && form.redirect) {
goto(getSecureRedirect(form.redirect));
}
Expand Down

0 comments on commit 22a409b

Please sign in to comment.