Skip to content

Commit

Permalink
More keyboards shortcuts for Edit on detailviews; flash and table mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-smith authored Dec 16, 2024
2 parents fdbfe91 + 42d9a96 commit e9a5f4e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
4 changes: 4 additions & 0 deletions enterprise/frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
const flash = getFlash(page);
const toastStore = getToastStore();
import CommandPalette from '$lib/components/CommandPalette/CommandPalette.svelte';
import commandPaletteOpen from '$lib/components/CommandPalette/CommandPalette.svelte';
const toast = (message: string, options: Record<string, string>) => {
const t: ToastSettings = {
message: message,
Expand Down Expand Up @@ -112,6 +115,7 @@
<ParaglideJsProvider>
<Modal components={modalRegistry} />
<Toast />
<CommandPalette />
<slot />

{#if $flash}
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/lib/components/DetailView/DetailView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import List from '$lib/components/List/List.svelte';
import { SECURITY_OBJECTIVE_SCALE_MAP } from '$lib/utils/constants';
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
const modalStore: ModalStore = getModalStore();
const toastStore: ToastStore = getToastStore();
Expand Down Expand Up @@ -73,6 +76,25 @@
}
}
function handleKeydown(event: KeyboardEvent) {
if (event.metaKey || event.ctrlKey) return;
// Check if the pressed key is 'e' and the edit button should be displayed
if (event.key === 'e' && displayEditButton()) {
event.preventDefault();
goto(`${$page.url.pathname}/edit?next=${$page.url.pathname}`);
}
}
onMount(() => {
// Add event listener to the document
document.addEventListener('keydown', handleKeydown);
// Cleanup function to remove event listener
return () => {
document.removeEventListener('keydown', handleKeydown);
};
});
function modalCreateForm(model: Record<string, any>): void {
let modalComponent: ModalComponent = {
ref: CreateModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
});
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'ArrowRight' || event.key === 'l') {
if (event.key === 'n' || event.key === 'l') {
nextItem();
} else if (event.key === 'ArrowLeft' || event.key === 'h') {
} else if (event.key === 'p' || event.key === 'h') {
previousItem();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { breadcrumbObject } from '$lib/utils/stores';
import { displayOnlyAssessableNodes } from './store';
import { onMount } from 'svelte';
import type {
ModalComponent,
ModalSettings,
Expand Down Expand Up @@ -55,6 +57,29 @@
`change_${requirementAssessmentModel.name}`
);
function handleKeydown(event: KeyboardEvent) {
if (event.metaKey || event.ctrlKey) return;
// Check if the pressed key is 'e' and the edit button should be displayed
if (event.key === 'f') {
event.preventDefault();
goto(`${$page.url.pathname}/flash-mode`);
}
if (event.key === 't') {
event.preventDefault();
goto(`${$page.url.pathname}/table-mode`);
}
}
onMount(() => {
// Add event listener to the document
document.addEventListener('keydown', handleKeydown);
// Cleanup function to remove event listener
return () => {
document.removeEventListener('keydown', handleKeydown);
};
});
const countResults = (
node: Node,
resultCounts: Record<string, number> = {}
Expand Down

0 comments on commit e9a5f4e

Please sign in to comment.