Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More keyboards shortcuts for Edit on detailviews; flash and table mode #1192

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading