Skip to content

Commit

Permalink
extra links palette and kbr shortcuts (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-smith authored Dec 25, 2024
2 parents cf00d7d + 2e307b4 commit cc6dfa5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 65 deletions.
88 changes: 27 additions & 61 deletions frontend/src/lib/components/CommandPalette/paletteData.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,35 @@
import * as m from '$paraglide/messages';
import { navData } from '../SideBar/navData';

export interface NavigationLink {
label: string;
href: string;
}
const flattenNavData = (navData) => {
const result = [];

export const navigationLinks: NavigationLink[] = [
{
label: 'analytics',
href: '/'
},
{
label: 'myAssignments',
href: '/my-assignments'
},
{
label: 'domains',
href: '/folders'
},
{
label: 'assets',
href: '/assets'
},
{
label: 'complianceAssessments',
href: '/compliance-assessments'
},
{
label: 'riskAssessments',
href: '/risk-assessments'
},
{
label: 'riskScenarios',
href: '/risk-scenarios'
},
{
label: 'ebiosRM',
href: '/ebios-rm'
},
{
label: 'actionPlan',
href: '/applied-controls'
},
{
label: 'evidences',
href: '/evidences'
},
{
label: 'xRays',
href: '/x-rays'
},
{
label: 'tpSolutions',
href: '/solutions'
},
{
label: 'libraries',
href: '/libraries'
},
{
label: 'myProfile',
href: '/my-profile'
},
{
label: 'settings',
href: '/settings'
// Handle potentially incomplete/malformed data
if (!navData?.items) return result;

for (const section of navData.items) {
if (!section.items) continue;

for (const item of section.items) {
if (item.name && item.href) {
result.push({
label: item.name,
href: item.href
});
}
}
}
];

return result;
};
export let navigationLinks: NavigationLink[] = flattenNavData(navData);
navigationLinks.push({
label: 'myProfile',
href: '/my-profile'
});

// wre can use the same trick later on for dynamic actions
10 changes: 6 additions & 4 deletions frontend/src/lib/components/DetailView/DetailView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
const modalStore: ModalStore = getModalStore();
const toastStore: ToastStore = getToastStore();
Expand Down Expand Up @@ -72,12 +73,13 @@
function handleKeydown(event: KeyboardEvent) {
if (event.metaKey || event.ctrlKey) return;
if (document.activeElement?.tagName !== 'BODY') 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}`);
//}
if (event.key === 'e' && displayEditButton()) {
event.preventDefault();
goto(`${$page.url.pathname}/edit?next=${$page.url.pathname}`);
}
}
onMount(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
function handleKeyDown(event: KeyboardEvent) {
if (event.metaKey || event.ctrlKey) return;
if (document.activeElement?.tagName !== 'BODY') return;
// Check if 'c' is pressed and no input fields are currently focused
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import { isDark } from '$lib/utils/helpers';
import Anchor from '$lib/components/Anchor/Anchor.svelte';
import { goto } from '$app/navigation';
import { onMount } from 'svelte';
export let data: PageData;
const user = $page.data.user;
Expand All @@ -26,6 +29,25 @@
$: classesCellText = (backgroundHexColor: string) => {
return isDark(backgroundHexColor) ? 'text-white' : '';
};
function handleKeydown(event: KeyboardEvent) {
if (event.metaKey || event.ctrlKey) return;
if (document.activeElement?.tagName !== 'BODY') return;
// Check if the pressed key is 'e' and the edit button should be displayed
if (event.key === 'e' && canEditObject) {
event.preventDefault();
goto(`${$page.url.pathname}/edit?next=${$page.url.pathname}`);
}
}
onMount(() => {
// Add event listener when component mounts
window.addEventListener('keydown', handleKeydown);
// Cleanup event listener when component is destroyed
return () => {
window.removeEventListener('keydown', handleKeydown);
};
});
</script>

<div class="flex flex-col space-y-3">
Expand Down

0 comments on commit cc6dfa5

Please sign in to comment.