Repository navigation
Add supported stack sort controls to the Svelte UI #2278
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
Open
Copilot
wants to merge
12
commits into
main
Choose a base branch
from
copilot/make-more-columns-sortable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+256
−6
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dabcd1b
Initial plan
Copilot 854bb63
Enable stack and session duration column sorting
Copilot f498fdc
Fix stack sorting UI contract
niemyjski efef7d6
Fix stack sort test portability
niemyjski fa4a078
Remove unsupported first occurrence stack sort
niemyjski 58d6587
Persist stack sort selection
niemyjski c179f92
Preserve legacy stack view sorting
niemyjski 07f054e
Preserve stack sort selection and legacy saved views
niemyjski fdca014
Merge remote-tracking branch 'origin/main' into HEAD
niemyjski 4034984
Preserve explicit legacy stack sort aliases
niemyjski 6d294c7
Merge remote-tracking branch 'origin/main' into HEAD
niemyjski dc8a2be
Align stack sorting browser tests with root routes
niemyjski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
src/Exceptionless.Web/ClientApp/e2e/tests/stack-sorting.e2e.ts
This file contains hidden or 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,122 @@ | ||
| import type { Page, Response } from '@playwright/test'; | ||
|
|
||
| import { expect, test } from '../fixtures/e2e-test'; | ||
| import { ExceptionlessE2EJourney } from '../support/exceptionless-journey'; | ||
|
|
||
| test('stack sort survives reload and resets pagination and selection without sending an API sort parameter', async ({ e2eApi, e2eScenario, page }) => { | ||
| await ExceptionlessE2EJourney.fromScenario(page, e2eApi, e2eScenario).submitRepresentativeEvent(); | ||
| const requests: URL[] = []; | ||
| page.on('request', (request) => { | ||
| const url = new URL(request.url()); | ||
| if (isStackRequest(url)) { | ||
| requests.push(url); | ||
| } | ||
| }); | ||
|
|
||
| const initialResponse = waitForStackMode(page, 'stack_frequent'); | ||
| await page.goto(`/stack?project=${e2eScenario.projectId}&page=2`); | ||
| expect((await initialResponse).ok()).toBe(true); | ||
| await expect(page.getByRole('button', { name: 'Sort by Events descending' })).toHaveAttribute('aria-pressed', 'true'); | ||
| await expect(page.getByRole('button', { name: /Sort by First/ })).toHaveCount(0); | ||
|
|
||
| const recentResponse = waitForStackMode(page, 'stack_recent'); | ||
| await page.getByRole('button', { name: 'Sort by Last descending' }).click(); | ||
| expect((await recentResponse).ok()).toBe(true); | ||
| await expect(page).toHaveURL(/[?&]sort=stack_recent(?:&|$)/); | ||
| await expect(page).not.toHaveURL(/[?&]page=2(?:&|$)/); | ||
|
|
||
| const reloadResponse = waitForStackMode(page, 'stack_recent'); | ||
| await page.reload(); | ||
| expect((await reloadResponse).ok()).toBe(true); | ||
| await expect(page.getByRole('button', { name: 'Sort by Last descending' })).toHaveAttribute('aria-pressed', 'true'); | ||
|
|
||
| await page.getByRole('checkbox', { name: 'Select row' }).first().click(); | ||
| await expect(page.getByRole('checkbox', { checked: true, name: 'Select row' })).toHaveCount(1); | ||
| await page.getByRole('button', { name: 'Sort by Events descending' }).click(); | ||
| await expect(page).not.toHaveURL(/[?&]sort=/); | ||
| await expect(page.getByRole('button', { name: 'Sort by Events descending' })).toHaveAttribute('aria-pressed', 'true'); | ||
| await expect(page.getByRole('checkbox', { checked: true })).toHaveCount(0); | ||
| expect(requests.length).toBeGreaterThanOrEqual(3); | ||
| expect(requests.every((url) => !url.searchParams.has('sort'))).toBe(true); | ||
| }); | ||
|
|
||
| for (const [sort, label, mode, explicitSort] of [ | ||
| ['-events', 'Events', 'stack_frequent', false], | ||
| ['-last', 'Last', 'stack_recent', false], | ||
| ['-events', 'Events', 'stack_frequent', true], | ||
| ['-last', 'Last', 'stack_recent', true] | ||
| ] as const) { | ||
| test(`legacy ${sort} stack views ${explicitSort ? 'with an explicit URL sort ' : ''}preserve their sort through reset and save`, async ({ | ||
| e2eScenario, | ||
| page, | ||
| request | ||
| }) => { | ||
| const headers = { Authorization: `Bearer ${e2eScenario.userToken}` }; | ||
| const slug = `sort-${label.toLowerCase()}`; | ||
| const createResponse = await request.post(`/api/v2/organizations/${e2eScenario.organizationId}/saved-views`, { | ||
| data: { | ||
| filter: 'type:error', | ||
| name: `Sort ${label}`, | ||
| organization_id: e2eScenario.organizationId, | ||
| slug, | ||
| sort, | ||
| view_type: 'stacks' | ||
| }, | ||
| headers | ||
| }); | ||
| expect(createResponse.status()).toBe(201); | ||
| const savedView = (await createResponse.json()) as { id: string }; | ||
|
|
||
| const initialResponse = waitForStackMode(page, mode); | ||
| await page.goto(`/stack/${slug}${explicitSort ? `?sort=${sort}` : ''}`); | ||
| expect((await initialResponse).ok()).toBe(true); | ||
| await expect(page.getByRole('button', { name: `Sort by ${label} descending` })).toHaveAttribute('aria-pressed', 'true'); | ||
| await expect(page.getByLabel('Unsaved view changes')).toHaveCount(0); | ||
|
|
||
| await page.getByRole('button', { name: /^View/ }).filter({ visible: true }).first().click(); | ||
| await page.getByRole('menuitemcheckbox', { exact: true, name: 'Chart' }).click(); | ||
| const displaySaveResponse = page.waitForResponse( | ||
| (response) => response.url().includes(`/saved-views/${savedView.id}`) && response.request().method() === 'PATCH' | ||
| ); | ||
| await page.getByRole('menuitem', { exact: true, name: 'Save' }).click(); | ||
| const displayResponse = await displaySaveResponse; | ||
| expect(displayResponse.ok()).toBe(true); | ||
| expect(displayResponse.request().postDataJSON().sort).toBe(sort); | ||
| await expect(page.getByLabel('Unsaved view changes')).toHaveCount(0); | ||
|
|
||
| const otherLabel = label === 'Events' ? 'Last' : 'Events'; | ||
| const otherMode = mode === 'stack_frequent' ? 'stack_recent' : 'stack_frequent'; | ||
| await page.getByRole('button', { name: `Sort by ${otherLabel} descending` }).click(); | ||
| await expect(page.getByLabel('Unsaved view changes')).toBeVisible(); | ||
| await page.getByRole('button', { name: /^View/ }).filter({ visible: true }).first().click(); | ||
| await page.getByRole('menuitem', { name: 'Reset to Saved' }).click(); | ||
| await expect(page.getByRole('button', { name: `Sort by ${label} descending` })).toHaveAttribute('aria-pressed', 'true'); | ||
| await expect(page.getByLabel('Unsaved view changes')).toHaveCount(0); | ||
|
|
||
| await page.getByRole('button', { name: `Sort by ${otherLabel} descending` }).click(); | ||
| await page.getByRole('button', { name: /^View/ }).filter({ visible: true }).first().click(); | ||
| const saveResponse = page.waitForResponse( | ||
| (response) => response.url().includes(`/saved-views/${savedView.id}`) && response.request().method() === 'PATCH' | ||
| ); | ||
| await page.getByRole('menuitem', { exact: true, name: 'Save' }).click(); | ||
| const response = await saveResponse; | ||
| expect(response.ok()).toBe(true); | ||
| expect(response.request().postDataJSON().sort).toBe(otherMode); | ||
| await expect(page.getByLabel('Unsaved view changes')).toHaveCount(0); | ||
|
|
||
| await page.goto(`/stack/${slug}`); | ||
| await expect(page.getByRole('button', { name: `Sort by ${otherLabel} descending` })).toHaveAttribute('aria-pressed', 'true'); | ||
| await expect(page.getByLabel('Unsaved view changes')).toHaveCount(0); | ||
| }); | ||
| } | ||
|
|
||
| function isStackRequest(url: URL): boolean { | ||
| return url.pathname.endsWith('/events') && url.searchParams.get('mode')?.startsWith('stack_') === true; | ||
| } | ||
|
|
||
| function waitForStackMode(page: Page, mode: string): Promise<Response> { | ||
| return page.waitForResponse((response) => { | ||
| const url = new URL(response.url()); | ||
| return isStackRequest(url) && url.searchParams.get('mode') === mode; | ||
| }); | ||
| } | ||
This file contains hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
...ptionless.Web/ClientApp/src/lib/features/events/components/table/stack-sort-header.svelte
This file contains hidden or 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,19 @@ | ||
| <script lang="ts"> | ||
| import { Button } from '$comp/ui/button'; | ||
| import ArrowDown from '@lucide/svelte/icons/arrow-down'; | ||
|
|
||
| interface Props { | ||
| active: boolean; | ||
| label: string; | ||
| onclick: () => void; | ||
| } | ||
|
|
||
| let { active, label, onclick }: Props = $props(); | ||
| </script> | ||
|
|
||
| <Button aria-label={`Sort by ${label} descending`} aria-pressed={active} class="h-8" {onclick} variant="ghost"> | ||
| {label} | ||
| {#if active} | ||
| <ArrowDown aria-hidden="true" /> | ||
| {/if} | ||
| </Button> |
24 changes: 24 additions & 0 deletions
24
...s.Web/ClientApp/src/lib/features/events/components/table/stack-sort-header.svelte.test.ts
This file contains hidden or 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,24 @@ | ||
| import { fireEvent, render, screen } from '@testing-library/svelte'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import StackSortHeader from './stack-sort-header.svelte'; | ||
|
|
||
| describe('StackSortHeader', () => { | ||
| it('exposes the active descending sort and handles selection', async () => { | ||
| const onclick = vi.fn(); | ||
| render(StackSortHeader, { active: true, label: 'Events', onclick }); | ||
|
|
||
| const button = screen.getByRole('button', { name: 'Sort by Events descending' }); | ||
| expect(button.getAttribute('aria-pressed')).toBe('true'); | ||
|
|
||
| await fireEvent.click(button); | ||
|
|
||
| expect(onclick).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it('does not mark inactive sort modes as selected', () => { | ||
| render(StackSortHeader, { active: false, label: 'Last', onclick: vi.fn() }); | ||
|
|
||
| expect(screen.getByRole('button', { name: 'Sort by Last descending' }).getAttribute('aria-pressed')).toBe('false'); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each entry in this loop becomes a separate Playwright test, so
e2eScenarioprovisions and deletes an organization and project four times; with one worker per browser shard, these variants serialize the same reset/save journey and add repeated service setup to the CI critical path. Keep one representative browser journey and move the alias matrix to Vitest, or exercise the variants withtest.stepunder a single fixture.AGENTS.md reference: src/Exceptionless.Web/ClientApp/AGENTS.md:L27-L29
Useful? React with 👍 / 👎.