mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-19 22:47:48 +00:00
feat(frontend): Add persistant filtered detail navigation in the url (#12585)
* Add filtered detail navigation * Satisfy navigation lint checks * Fix missing Fragment import in PageDetail * Address detail navigation review feedback * Move detail navigation into breadcrumb bar * Address URL and layout review feedback * Address detail navigation review feedback * fix doclinks * test: update stock return validation assertion * fix: keep detail navigation actions stable * style: apply biome formatting * fix: use ActionIcon disabled state * test: use ActionIcon disabled state * fix: isolate detail navigation query params --------- Co-authored-by: Matthias Mair <code@mjmair.com> Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
11 files changed
+873
-77
No files matched your search
@@ -498,7 +498,7 @@ test('Stock - Return Items', async ({ browser }) => {
|
||||
await page.getByRole('textbox', { name: 'number-field-quantity' }).fill('0');
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
|
||||
await page.getByText('Errors exist for one or more form fields').waitFor();
|
||||
await page.getByRole('alert', { name: 'Form Error' }).waitFor();
|
||||
await page.getByText('Quantity must be greater than zero').first().waitFor();
|
||||
await page.getByText('This field is required.').first().waitFor();
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from './baseFixtures.js';
|
||||
import { stevenuser } from './defaults.js';
|
||||
import {
|
||||
@@ -136,6 +137,160 @@ test('Tables - Pagination', async ({ browser }) => {
|
||||
await page.getByText(/1 - 25 \/ \d+/).waitFor();
|
||||
});
|
||||
|
||||
test('Tables - Navigation query parameters', async ({ browser }) => {
|
||||
const page = await doCachedLogin(browser, {
|
||||
url: 'part/category/index/parts/'
|
||||
});
|
||||
|
||||
await clearTableFilters(page);
|
||||
|
||||
const navigationParams = new URLSearchParams({
|
||||
_na: 'p',
|
||||
_nq: 'search=530470',
|
||||
_ni: '0',
|
||||
_np: '69',
|
||||
_nf: 'pk'
|
||||
});
|
||||
|
||||
const waitForPartList = () =>
|
||||
page.waitForResponse((response) => {
|
||||
const url = new URL(response.url());
|
||||
|
||||
return (
|
||||
response.request().method() === 'GET' &&
|
||||
url.pathname === '/api/part/' &&
|
||||
url.searchParams.has('limit')
|
||||
);
|
||||
});
|
||||
|
||||
const navigationRequest = waitForPartList();
|
||||
await navigate(
|
||||
page,
|
||||
`part/category/index/parts/?${navigationParams.toString()}`
|
||||
);
|
||||
|
||||
const navigationRequestUrl = new URL((await navigationRequest).url());
|
||||
|
||||
for (const key of navigationParams.keys()) {
|
||||
expect(navigationRequestUrl.searchParams.has(key)).toBe(false);
|
||||
}
|
||||
|
||||
await expect(page.getByText('Custom table filters are active')).toHaveCount(
|
||||
0
|
||||
);
|
||||
await expect(page.getByLabel('table-select-filters')).toBeEnabled();
|
||||
|
||||
await setTableChoiceFilter(page, 'Assembly', 'Yes');
|
||||
|
||||
for (const [key, value] of navigationParams) {
|
||||
expect(new URL(page.url()).searchParams.get(key)).toBe(value);
|
||||
}
|
||||
|
||||
await clearTableFilters(page);
|
||||
|
||||
for (const [key, value] of navigationParams) {
|
||||
expect(new URL(page.url()).searchParams.get(key)).toBe(value);
|
||||
}
|
||||
|
||||
const searchParams = new URLSearchParams(navigationParams);
|
||||
searchParams.set('search', '530470');
|
||||
|
||||
const searchRequest = waitForPartList();
|
||||
await navigate(page, `part/category/index/parts/?${searchParams.toString()}`);
|
||||
|
||||
const searchRequestUrl = new URL((await searchRequest).url());
|
||||
expect(searchRequestUrl.searchParams.get('search')).toBe('530470');
|
||||
|
||||
for (const key of navigationParams.keys()) {
|
||||
expect(searchRequestUrl.searchParams.has(key)).toBe(false);
|
||||
}
|
||||
|
||||
await expect(page.getByRole('cell', { name: '530470210' })).toBeVisible();
|
||||
|
||||
const queryFilterAlert = page
|
||||
.getByRole('alert')
|
||||
.filter({ hasText: 'Custom table filters are active' });
|
||||
await expect(queryFilterAlert).toBeVisible();
|
||||
await expect(page.getByLabel('table-select-filters')).toBeDisabled();
|
||||
|
||||
await queryFilterAlert.getByRole('button').click();
|
||||
await expect(queryFilterAlert).toBeHidden();
|
||||
await expect
|
||||
.poll(() => new URL(page.url()).searchParams.has('search'))
|
||||
.toBe(false);
|
||||
|
||||
for (const [key, value] of navigationParams) {
|
||||
expect(new URL(page.url()).searchParams.get(key)).toBe(value);
|
||||
}
|
||||
|
||||
await expect(page.getByLabel('table-select-filters')).toBeEnabled();
|
||||
});
|
||||
|
||||
test('Tables - Detail navigation', async ({ browser }) => {
|
||||
const page = await doCachedLogin(browser, {
|
||||
url: 'part/category/index/parts/?search=530470'
|
||||
});
|
||||
|
||||
const firstRow = page.locator('tbody tr').first();
|
||||
await firstRow.waitFor();
|
||||
await firstRow.locator('td').nth(1).click();
|
||||
await page.waitForURL(/\/web\/part\/\d+(?:\/.*)?$/);
|
||||
|
||||
const position = page.getByText(/^\d+ of \d+$/).first();
|
||||
await expect(position).toHaveText('1 of 2');
|
||||
|
||||
const breadcrumbBar = page.getByTestId('breadcrumb-list');
|
||||
const detailNavigation = breadcrumbBar.getByTestId('detail-navigation');
|
||||
await expect(detailNavigation).toBeVisible();
|
||||
|
||||
const previous = page.getByLabel('Previous', { exact: true });
|
||||
await expect(previous).toBeVisible();
|
||||
await expect(previous.locator('svg')).toBeVisible();
|
||||
await expect(previous).toHaveAttribute('data-disabled', 'true');
|
||||
await expect(previous).not.toHaveAttribute('href');
|
||||
|
||||
const next = page.getByLabel('Next', { exact: true });
|
||||
await expect(next).toBeVisible();
|
||||
await expect(next.locator('svg')).toBeVisible();
|
||||
await expect(next).not.toHaveAttribute('data-disabled');
|
||||
|
||||
const nextHref = await next.getAttribute('href');
|
||||
expect(nextHref).toContain('_na=p');
|
||||
expect(nextHref).toContain('_ni=1');
|
||||
expect(nextHref).toContain('_np=');
|
||||
expect(nextHref).not.toContain('_nav_');
|
||||
expect(nextHref).not.toContain('_nf=');
|
||||
|
||||
const initialBreadcrumbHeight = (await breadcrumbBar.boundingBox())?.height;
|
||||
|
||||
await next.click();
|
||||
await expect(position).toHaveText('2 of 2');
|
||||
|
||||
const nextBreadcrumbHeight = (await breadcrumbBar.boundingBox())?.height;
|
||||
expect(initialBreadcrumbHeight).toBeDefined();
|
||||
expect(nextBreadcrumbHeight).toBeDefined();
|
||||
expect(
|
||||
Math.abs((nextBreadcrumbHeight ?? 0) - (initialBreadcrumbHeight ?? 0))
|
||||
).toBeLessThanOrEqual(1);
|
||||
|
||||
await expect(previous).toBeVisible();
|
||||
await expect(previous.locator('svg')).toBeVisible();
|
||||
await expect(previous).not.toHaveAttribute('data-disabled');
|
||||
await expect(previous).toHaveAttribute('href');
|
||||
|
||||
await expect(next).toBeVisible();
|
||||
await expect(next.locator('svg')).toBeVisible();
|
||||
await expect(next).toHaveAttribute('data-disabled', 'true');
|
||||
await expect(next).not.toHaveAttribute('href');
|
||||
|
||||
await previous.click();
|
||||
await expect(position).toHaveText('1 of 2');
|
||||
await expect(previous).toHaveAttribute('data-disabled', 'true');
|
||||
await expect(previous).not.toHaveAttribute('href');
|
||||
await expect(next).not.toHaveAttribute('data-disabled');
|
||||
await expect(next).toHaveAttribute('href');
|
||||
});
|
||||
|
||||
test('Tables - Columns', async ({ browser }) => {
|
||||
// Go to the "stock list" page
|
||||
const page = await doCachedLogin(browser, {
|
||||
|
||||
Reference in new issue
Block a user