mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(vendors): truncate long locations in table
This commit is contained in:
parent
40ce66fbb3
commit
2a42f97d60
2 changed files with 60 additions and 1 deletions
|
|
@ -51,6 +51,28 @@ function stopPropagation(event: MouseEvent): void {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function VendorLocation({ value }: { value: string }) {
|
||||||
|
const hasLocation = value !== "—";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip title={hasLocation ? value : ""} placement="top" arrow describeChild>
|
||||||
|
<Box
|
||||||
|
component="span"
|
||||||
|
tabIndex={hasLocation ? 0 : undefined}
|
||||||
|
sx={{
|
||||||
|
display: "block",
|
||||||
|
maxWidth: "100%",
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
</Box>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
interface VendorTableRowProps {
|
interface VendorTableRowProps {
|
||||||
row: VendorListItem;
|
row: VendorListItem;
|
||||||
onOpenDetail: (row: VendorListItem) => void;
|
onOpenDetail: (row: VendorListItem) => void;
|
||||||
|
|
@ -108,7 +130,9 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>{locationText}</TableCell>
|
<TableCell sx={{ color: "var(--color-muted-foreground)", overflow: "hidden" }}>
|
||||||
|
<VendorLocation value={locationText} />
|
||||||
|
</TableCell>
|
||||||
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>
|
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>
|
||||||
{primaryTrade === "—" ? (
|
{primaryTrade === "—" ? (
|
||||||
"—"
|
"—"
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,41 @@ describe("VendorsListPage", () => {
|
||||||
expect(screen.queryByText(/555-0198/)).not.toBeInTheDocument();
|
expect(screen.queryByText(/555-0198/)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps a long address inside the Location column and reveals the full value", async () => {
|
||||||
|
setupDefaults();
|
||||||
|
const longAddress = "New York, NY, Estados Unidos, 123 Long Address Avenue";
|
||||||
|
const fallbackVendor: VendorListItem = {
|
||||||
|
...activeVendor,
|
||||||
|
id: 4,
|
||||||
|
address: longAddress,
|
||||||
|
city: "",
|
||||||
|
state: "",
|
||||||
|
};
|
||||||
|
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
||||||
|
if (params.pageSize === 1) return result([], 1);
|
||||||
|
return params.isActive ? result([fallbackVendor], 1) : result([], 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
||||||
|
|
||||||
|
const locationCell = screen.getByRole("cell", { name: longAddress });
|
||||||
|
const locationText = within(locationCell).getByText(longAddress);
|
||||||
|
expect(locationCell).toHaveStyle({ overflow: "hidden" });
|
||||||
|
expect(locationText).toHaveStyle({
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
});
|
||||||
|
|
||||||
|
await userEvent.hover(locationText);
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(longAddress);
|
||||||
|
|
||||||
|
await userEvent.unhover(locationText);
|
||||||
|
locationText.focus();
|
||||||
|
expect(locationText).toHaveFocus();
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(longAddress);
|
||||||
|
});
|
||||||
|
|
||||||
it("reports the filtered totalCount in the footer when page rows are fewer than total", () => {
|
it("reports the filtered totalCount in the footer when page rows are fewer than total", () => {
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
const pageVendors = Array.from({ length: 3 }, (_, index) => ({
|
const pageVendors = Array.from({ length: 3 }, (_, index) => ({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue