Skip to content
Open
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
1 change: 1 addition & 0 deletions dashboard/e2e/e2e-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export const HARDWARE_LISTING_SELECTORS = {
branchSelector: '[data-test-id="hardware-branch-selector"]',
revisionSelector: '[data-test-id="hardware-revision-selector"]',
clearSelection: '[data-test-id="hardware-selection-clear"]',
filterLabel: '[data-test-id="hardware-filter-label"]',
} as const;
45 changes: 45 additions & 0 deletions dashboard/e2e/hardware-listing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,49 @@ test.describe('Hardware Listing Page Tests', () => {
).toContainText('Select tree');
await expect(clearButton).toBeHidden();
});

test('filter label updates with query params', async ({ page }) => {
const filterLabel = page.locator(HARDWARE_LISTING_SELECTORS.filterLabel);
await expect(filterLabel).toBeVisible();
await expect(filterLabel).toContainText(
/Showing latest checkout for trees updated in the last \d+ days/,
);

const url = new URL(page.url());

url.searchParams.set('days', '2');
await page.goto(url.toString());
await expect(filterLabel).toContainText('last 2 days');

url.searchParams.set('days', '7');
await page.goto(url.toString());
await expect(filterLabel).toContainText('last 7 days');
});

test('selecting a revision toggles filter label', async ({ page }) => {
const filterLabel = page.locator(HARDWARE_LISTING_SELECTORS.filterLabel);
await expect(filterLabel).toBeVisible();

await selectComboboxOption(page, HARDWARE_LISTING_SELECTORS.treeSelector);
await expect(filterLabel).toBeHidden();

await page.locator(HARDWARE_LISTING_SELECTORS.clearSelection).click();
await expect(filterLabel).toBeVisible();
});

test('loading URL with revision does not show filter label', async ({
page,
}) => {
await selectComboboxOption(page, HARDWARE_LISTING_SELECTORS.treeSelector);
const urlWithRevision = page.url();
await expect(urlWithRevision).toMatch(/[?&]ch=/);

await page.goto(urlWithRevision);

const filterLabel = page.locator(HARDWARE_LISTING_SELECTORS.filterLabel);
await expect(filterLabel).toBeHidden();

await page.locator(HARDWARE_LISTING_SELECTORS.clearSelection).click();
await expect(filterLabel).toBeVisible();
});
});
16 changes: 16 additions & 0 deletions dashboard/src/components/FilterLabel/FilterLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { JSX } from 'react';
import { FormattedMessage } from 'react-intl';

export function FilterLabel({ days }: { days: number }): JSX.Element {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth to add a new component, just for a a formatted message?

return (
<p
className="text-dim-gray text-left text-xs"
data-test-id="hardware-filter-label"
>
<FormattedMessage
id="hardwareListing.latestCheckoutFilterLabel"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially now, that we are adding this component on tree listing, the hardwareListing prefix might make us believe this component is only used in hardware page.

values={{ days }}
/>
</p>
);
}
19 changes: 13 additions & 6 deletions dashboard/src/components/TreeListingPage/TreeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { usePaginationState } from '@/hooks/usePaginationState';
import BaseTable, { TableHead } from '@/components/Table/BaseTable';
import { TableBody, TableCell, TableRow } from '@/components/ui/table';
import { ConditionalTableCell } from '@/components/Table/ConditionalTableCell';
import { FilterLabel } from '@/components/FilterLabel/FilterLabel';

import { BaseGroupedStatusWithLink } from '@/components/Status/Status';
import { TableHeader } from '@/components/Table/TableHeader';
Expand All @@ -50,6 +51,7 @@ import QuerySwitcher from '@/components/QuerySwitcher/QuerySwitcher';
import { MemoizedSectionError } from '@/components/DetailsPages/SectionError';

import type { TreeListingRoutesMap } from '@/utils/constants/treeListing';
import { DEFAULT_TIME_SEARCH } from '@/utils/constants/general';

import {
commonTreeTableColumns,
Expand Down Expand Up @@ -265,7 +267,7 @@ export function TreeTable({
isLoading?: boolean;
urlFromMap: TreeListingRoutesMap;
}): JSX.Element {
const { origin, listingSize } = useSearch({
const { origin, listingSize, intervalInDays } = useSearch({
from: urlFromMap.search,
});
const navigate = useNavigate({ from: urlFromMap.navigate });
Expand Down Expand Up @@ -395,11 +397,16 @@ export function TreeTable({
<TableBody>{tableBody}</TableBody>
</BaseTable>
</QuerySwitcher>
<PaginationInfo
table={table}
intlLabel="global.trees"
onPaginationChange={navigateWithPageSize}
/>
<div className="flex flex-wrap items-start justify-between gap-4">
<FilterLabel days={intervalInDays ?? DEFAULT_TIME_SEARCH} />
<div style={{ marginLeft: 'auto' }}>
<PaginationInfo
table={table}
intlLabel="global.trees"
onPaginationChange={navigateWithPageSize}
/>
</div>
</div>
</div>
);
}
2 changes: 2 additions & 0 deletions dashboard/src/locales/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export const messages = {
'hardwareListing.branchSelectorSearchPlaceholder': 'Search branch...',
'hardwareListing.clearSelection': 'Clear selection',
'hardwareListing.description': 'List of hardware from kernel tests',
'hardwareListing.latestCheckoutFilterLabel':
'Showing latest checkout for trees updated in the last {days} days',
'hardwareListing.notFound': 'No hardware information available',
'hardwareListing.revisionEmpty':
'The selected revision has no hardware rows yet. Data ingestion may still be in progress.',
Expand Down
23 changes: 17 additions & 6 deletions dashboard/src/pages/Hardware/HardwareTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import type {

import { sumStatus } from '@/utils/status';

import { REDUCED_TIME_SEARCH } from '@/utils/constants/general';

import { usePaginationState } from '@/hooks/usePaginationState';

import { zPossibleTabValidator } from '@/types/tree/TreeDetails';
Expand All @@ -61,6 +63,8 @@ import QuerySwitcher from '@/components/QuerySwitcher/QuerySwitcher';
import { MemoizedSectionError } from '@/components/DetailsPages/SectionError';
import { LoadingCircle } from '@/components/ui/loading-circle';

import { FilterLabel } from '@/components/FilterLabel/FilterLabel';

import { buildHardwareDetailsSearch } from './hardwareTableUtils';
import { HardwareRevisionSelectors } from './HardwareRevisionSelectors';
import type { HardwareRevisionSelectorValue } from './hardwareSelection';
Expand Down Expand Up @@ -390,7 +394,7 @@ export function HardwareTable({
onTreeChange = (): void => {},
onClearSelection = (): void => {},
}: IHardwareTable): JSX.Element {
const { listingSize } = useSearch({ strict: false });
const { listingSize, intervalInDays } = useSearch({ strict: false });
const navigate = useNavigate({ from: navigateFrom });

const [sorting, setSorting] = useState<SortingState>([]);
Expand Down Expand Up @@ -546,11 +550,18 @@ export function HardwareTable({
<TableBody>{tableBody}</TableBody>
</BaseTable>
</QuerySwitcher>
<PaginationInfo
table={table}
intlLabel="global.hardware"
onPaginationChange={navigateWithPageSize}
/>
<div className="flex flex-wrap items-start justify-between gap-4">
{!selection && (
<FilterLabel days={intervalInDays ?? REDUCED_TIME_SEARCH} />
)}
<div style={{ marginLeft: 'auto' }}>
<PaginationInfo
table={table}
intlLabel="global.hardware"
onPaginationChange={navigateWithPageSize}
/>
</div>
</div>
</div>
);
}
Loading