Skip to content
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

refactor: [M3-9053] - Reroute Longview #11490

Merged
merged 10 commits into from
Jan 14, 2025
Merged
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
15 changes: 11 additions & 4 deletions packages/manager/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module.exports = {
// for each new features added to the migration router, add its directory here
'src/features/Betas/**/*',
'src/features/Domains/**/*',
'src/features/Longview/**/*',
'src/features/Volumes/**/*',
],
rules: {
Expand Down Expand Up @@ -119,14 +120,20 @@ module.exports = {
'withRouter',
],
message:
'Please use routing utilities from @tanstack/react-router.',
'Please use routing utilities intended for @tanstack/react-router.',
name: 'react-router-dom',
},
{
importNames: ['renderWithTheme'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of test are just fine to keep running with renderWithTheme - only the ones relying on some form of routing need to start using renderWithThemeAndRouter

importNames: ['TabLinkList'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now need to make sure to use TanStackTabLinkList.tsx for Tabs under the tanstack routing

Eventually those "Tanstack" naming conventions will be going away, however for the time of the migration it si very helpful for utils and components to be semantically dissociated.

message:
'Please use the wrapWithThemeAndRouter helper function for testing components being migrated to TanStack Router.',
name: 'src/utilities/testHelpers',
'Please use the TanStackTabLinkList component for components being migrated to TanStack Router.',
name: 'src/components/Tabs/TabLinkList',
},
{
importNames: ['OrderBy', 'default'],
message:
'Please use useOrderV2 hook for components being migrated to TanStack Router.',
name: 'src/components/OrderBy',
},
],
},
Expand Down
2 changes: 0 additions & 2 deletions packages/manager/src/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ const SupportTicketDetail = React.lazy(() =>
})
)
);
const Longview = React.lazy(() => import('src/features/Longview'));
const Managed = React.lazy(() => import('src/features/Managed/ManagedLanding'));
const Help = React.lazy(() =>
import('./features/Help/index').then((module) => ({
Expand Down Expand Up @@ -339,7 +338,6 @@ export const MainContent = () => {
path="/nodebalancers"
/>
<Route component={Managed} path="/managed" />
<Route component={Longview} path="/longview" />
<Route component={Images} path="/images" />
<Route
component={StackScripts}
Expand Down
39 changes: 39 additions & 0 deletions packages/manager/src/components/Tabs/TanStackTabLinkList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Link as TanstackLink } from '@tanstack/react-router';
import * as React from 'react';

import { Tab } from 'src/components/Tabs/Tab';
import { TabList } from 'src/components/Tabs/TabList';

import type { Tab as TanstackTab } from 'src/hooks/useTabs';

export interface Tab {
chip?: React.JSX.Element | null;
routeName: string;
title: string;
}

interface TabLinkListProps {
noLink?: boolean;
tabs: TanstackTab[];
}

export const TanStackTabLinkList = ({ noLink, tabs }: TabLinkListProps) => {
return (
<TabList>
{tabs.map((tab, _index) => {
return (
<Tab
// @ts-expect-error - Tab accepts 'as' prop at runtime but it's not in the types
as={noLink ? undefined : TanstackLink}
key={`tab-${_index}`}
preload={noLink ? undefined : 'intent'}
to={noLink ? undefined : tab.to}
>
{tab.title}
{tab.chip}
</Tab>
);
})}
</TabList>
);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is essentially a copy of the old one except it uses the new Link under the hood

I made a new one to avoid going into a Typescript whack-a-mole

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as React from 'react';
import { ActionsPanel } from 'src/components/ActionsPanel/ActionsPanel';
import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog';
import { DocumentTitleSegment } from 'src/components/DocumentTitle';
// eslint-disable-next-line no-restricted-imports
import OrderBy from 'src/components/OrderBy';
import Paginate from 'src/components/Paginate';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';

import { longviewPortFactory } from 'src/factories/longviewService';
import { renderWithTheme } from 'src/utilities/testHelpers';
import { renderWithThemeAndRouter } from 'src/utilities/testHelpers';

import { ActiveConnections } from './ActiveConnections';

import type { TableProps } from './ActiveConnections';

const mockConnections = longviewPortFactory.buildList(10);
Expand All @@ -14,31 +15,31 @@ const props: TableProps = {
};

describe('ActiveConnections (and by extension ListeningServices)', () => {
it('should render a table with one row per active connection', () => {
const { queryAllByTestId } = renderWithTheme(
it('should render a table with one row per active connection', async () => {
const { queryAllByTestId } = await renderWithThemeAndRouter(
<ActiveConnections {...props} />
);
expect(queryAllByTestId('longview-connection-row')).toHaveLength(
mockConnections.length
);
});

it('should render a loading state', () => {
const { getByTestId } = renderWithTheme(
it('should render a loading state', async () => {
const { getByTestId } = await renderWithThemeAndRouter(
<ActiveConnections {...props} connectionsLoading={true} />
);
getByTestId('table-row-loading');
});

it('should render an empty state', () => {
const { getByTestId } = renderWithTheme(
it('should render an empty state', async () => {
const { getByTestId } = await renderWithThemeAndRouter(
<ActiveConnections {...props} connections={[]} />
);
getByTestId('table-row-empty');
});

it('should render an error state', () => {
const { getByTestId, getByText } = renderWithTheme(
it('should render an error state', async () => {
const { getByTestId, getByText } = await renderWithThemeAndRouter(
<ActiveConnections
{...props}
connectionsError={'an error'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useTheme } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';
import * as React from 'react';

import OrderBy from 'src/components/OrderBy';
import Paginate from 'src/components/Paginate';
import { PaginationFooter } from 'src/components/PaginationFooter/PaginationFooter';
import { Table } from 'src/components/Table';
Expand All @@ -14,6 +13,7 @@ import { TableRowEmpty } from 'src/components/TableRowEmpty/TableRowEmpty';
import { TableRowError } from 'src/components/TableRowError/TableRowError';
import { TableRowLoading } from 'src/components/TableRowLoading/TableRowLoading';
import { TableSortCell } from 'src/components/TableSortCell';
import { useOrderV2 } from 'src/hooks/useOrderV2';

import { ConnectionRow } from './ConnectionRow';

Expand Down Expand Up @@ -54,77 +54,86 @@ export const ActiveConnections = (props: TableProps) => {
export const ConnectionsTable = (props: TableProps) => {
const { connections, connectionsError, connectionsLoading } = props;

const {
handleOrderChange,
order,
orderBy,
sortedData,
} = useOrderV2<LongviewPort>({
data: connections,
initialRoute: {
defaultOrder: {
order: 'asc',
orderBy: 'process',
},
from: '/longview/clients/$id/overview',
},
preferenceKey: 'active-connections',
prefix: 'active-connections',
});

return (
<OrderBy
data={connections}
order={'asc'}
orderBy={'process'}
preferenceKey={'active-connections'}
>
{({ data: orderedData, handleOrderChange, order, orderBy }) => (
<Paginate data={orderedData} pageSize={25}>
{({
count,
data: paginatedData,
handlePageChange,
handlePageSizeChange,
page,
pageSize,
}) => (
<>
<Table spacingTop={16}>
<TableHead>
<TableRow>
<TableSortCell
active={orderBy === 'name'}
data-qa-table-header="Name"
direction={order}
handleClick={handleOrderChange}
label="name"
>
Name
</TableSortCell>
<TableSortCell
active={orderBy === 'user'}
data-qa-table-header="User"
direction={order}
handleClick={handleOrderChange}
label="user"
>
User
</TableSortCell>
<TableSortCell
active={orderBy === 'count'}
data-qa-table-header="Count"
direction={order}
handleClick={handleOrderChange}
label="count"
>
Count
</TableSortCell>
</TableRow>
</TableHead>
<TableBody>
{renderLoadingErrorData(
connectionsLoading,
paginatedData,
connectionsError
)}
</TableBody>
</Table>
<PaginationFooter
count={count}
eventCategory="Longview active connections"
handlePageChange={handlePageChange}
handleSizeChange={handlePageSizeChange}
page={page}
pageSize={pageSize}
/>
</>
)}
</Paginate>
<Paginate data={sortedData ?? []} pageSize={25}>
{({
count,
data: paginatedData,
handlePageChange,
handlePageSizeChange,
page,
pageSize,
}) => (
<>
<Table spacingTop={16}>
<TableHead>
<TableRow>
<TableSortCell
active={orderBy === 'name'}
data-qa-table-header="Name"
direction={order}
handleClick={handleOrderChange}
label="name"
>
Name
</TableSortCell>
<TableSortCell
active={orderBy === 'user'}
data-qa-table-header="User"
direction={order}
handleClick={handleOrderChange}
label="user"
>
User
</TableSortCell>
<TableSortCell
active={orderBy === 'count'}
data-qa-table-header="Count"
direction={order}
handleClick={handleOrderChange}
label="count"
>
Count
</TableSortCell>
</TableRow>
</TableHead>
<TableBody>
{renderLoadingErrorData(
connectionsLoading,
paginatedData ?? [],
connectionsError
)}
</TableBody>
</Table>
<PaginationFooter
count={count}
eventCategory="Longview active connections"
handlePageChange={handlePageChange}
handleSizeChange={handlePageSizeChange}
page={page}
pageSize={pageSize}
/>
</>
)}
</OrderBy>
</Paginate>
);
};

Expand Down
Loading
Loading