-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Add details to the monitor > pepr view ## Related Issue Resolve #35 \
- Loading branch information
1 parent
34e7e6c
commit a4ed8cd
Showing
8 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
ui/src/routes/monitor/pepr/[[stream]]/(details)/denied-details/DeniedDetails.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!-- SPDX-License-Identifier: Apache-2.0 --> | ||
<!-- SPDX-FileCopyrightText: 2024-Present The UDS Authors --> | ||
|
||
<script lang="ts"> | ||
import type { PeprDetails } from '$lib/types' | ||
export let details: PeprDetails | ||
</script> | ||
|
||
<span class="whitespace-nowrap relative group py-4 flex items-center"> | ||
<span class="text-blue-400">Details</span> | ||
<div class="tooltip tooltip-left"> | ||
{#each details.messages || [] as msg} | ||
<div class="text-red-400">{msg}</div> | ||
{/each} | ||
</div> | ||
</span> |
25 changes: 25 additions & 0 deletions
25
ui/src/routes/monitor/pepr/[[stream]]/(details)/denied-details/comonent.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { render } from '@testing-library/svelte' | ||
|
||
import type { SvelteComponent } from 'svelte' | ||
import DeniedDetails from './DeniedDetails.svelte' | ||
|
||
// Mock the carbon-icons-svelte module | ||
|
||
const comp = vi.fn().mockImplementation(() => ({ | ||
$$: { | ||
on_mount: [], | ||
on_destroy: [], | ||
before_update: [], | ||
after_update: [], | ||
}, | ||
})) as unknown as SvelteComponent | ||
|
||
describe('Denied Details', () => { | ||
test('renders denied messages', () => { | ||
const peprDetails = { component: comp, messages: ['Authorized: test', 'Found: test'] } | ||
const { getByText } = render(DeniedDetails, { props: { details: peprDetails } }) | ||
expect(getByText('Details')).toBeInTheDocument() | ||
expect(getByText(peprDetails.messages[0])).toBeInTheDocument() | ||
expect(getByText(peprDetails.messages[1])).toBeInTheDocument() | ||
}) | ||
}) |
34 changes: 34 additions & 0 deletions
34
ui/src/routes/monitor/pepr/[[stream]]/(details)/mutated-details/MutatedDetails.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- SPDX-License-Identifier: Apache-2.0 --> | ||
<!-- SPDX-FileCopyrightText: 2024-Present The UDS Authors --> | ||
|
||
<script lang="ts"> | ||
import type { PeprDetails } from '$lib/types' | ||
export let details: PeprDetails | ||
</script> | ||
|
||
<div class="whitespace-nowrap relative group py-4 flex"> | ||
<span class="text-blue-400">Details</span> | ||
<div class="tooltip tooltip-left"> | ||
{#each Object.entries(details.operations || {}) as [key, ops], index} | ||
{#if index > 0} | ||
<br /> | ||
{/if} | ||
<h3 class="font-bold">{key}:</h3> | ||
{#each ops as op} | ||
<p class="text-pretty tooltip-w"> | ||
{op.path} | ||
{#if op.value} | ||
<span class="text-blue-400">={JSON.stringify(op.value)}</span> | ||
{/if} | ||
</p> | ||
{/each} | ||
{/each} | ||
</div> | ||
</div> | ||
|
||
<style> | ||
.tooltip-w { | ||
width: 496px; | ||
} | ||
</style> |
32 changes: 32 additions & 0 deletions
32
ui/src/routes/monitor/pepr/[[stream]]/(details)/mutated-details/comonent.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { render, screen } from '@testing-library/svelte' | ||
|
||
import type { SvelteComponent } from 'svelte' | ||
import MutatedDetails from './MutatedDetails.svelte' | ||
|
||
// Mock the carbon-icons-svelte module | ||
|
||
const comp = vi.fn().mockImplementation(() => ({ | ||
$$: { | ||
on_mount: [], | ||
on_destroy: [], | ||
before_update: [], | ||
after_update: [], | ||
}, | ||
})) as unknown as SvelteComponent | ||
|
||
describe('Denied Details', () => { | ||
test('renders exemption title', () => { | ||
const peprDetails = { | ||
component: comp, | ||
operations: { | ||
ADDED: [{ op: 'add', path: '/path', value: 'value' }], | ||
REPLACED: [{ op: 'add', path: '/path', value: 'value' }], | ||
REMOVED: [{ op: 'add', path: '/path', value: '' }], | ||
}, | ||
} | ||
render(MutatedDetails, { props: { details: peprDetails } }) | ||
|
||
expect(screen.getByText('Details')).toBeInTheDocument() | ||
//todo: figure out assertions for split up text | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { PatchOperation, PeprDetails, PeprEvent } from '$lib/types' | ||
import type { SvelteComponent } from 'svelte' | ||
import DeniedDetails from './(details)/denied-details/DeniedDetails.svelte' | ||
import MutatedDetails from './(details)/mutated-details/MutatedDetails.svelte' | ||
|
||
// Utility function to decode base64 | ||
function decodeBase64(base64String: string) { | ||
try { | ||
return atob(base64String) | ||
} catch (e) { | ||
console.error('Failed to decode base64 string:', e) | ||
return '' | ||
} | ||
} | ||
|
||
export function getDetails(payload: PeprEvent): PeprDetails | undefined { | ||
if (!payload.res) { | ||
return undefined | ||
} | ||
|
||
if (payload.event === 'DENIED') { | ||
if (payload.res) { | ||
const status = payload.res.status as Record<string, string> | ||
const split = status.message.split(' Authorized: ') | ||
|
||
// No "Authorized" or "Found" in the message | ||
if (split.length !== 2) { | ||
return { component: DeniedDetails as unknown as SvelteComponent, messages: split } | ||
} | ||
|
||
const authorized = `Authorized: ${split[1].split(' Found: ')[0]}` | ||
const found = `Found: ${split[1].split(' Found:')[1]}` | ||
return { component: DeniedDetails as unknown as SvelteComponent, messages: [authorized, found] } | ||
} | ||
} | ||
|
||
if (payload.event === 'MUTATED') { | ||
if (payload.res.patch) { | ||
const decodedPatch = decodeBase64(payload.res.patch as string) | ||
const parsedPatch = JSON.parse(decodedPatch) | ||
|
||
const opMap: { [key: string]: string } = { | ||
add: 'ADDED', | ||
remove: 'REMOVED', | ||
replace: 'REPLACED', | ||
} | ||
|
||
// Group by operation type | ||
const groups: { [key: string]: PatchOperation[] } = {} | ||
for (const op of parsedPatch) { | ||
if (!groups[opMap[op.op]]) { | ||
groups[opMap[op.op]] = [] | ||
} | ||
groups[opMap[op.op]].push(op) | ||
} | ||
|
||
return { component: MutatedDetails as unknown as SvelteComponent, operations: groups } | ||
} | ||
} | ||
|
||
return undefined | ||
} |