Skip to content

Commit

Permalink
feedback @jaalah-akamai
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Oct 4, 2024
1 parent 526fedd commit 8f5f1a1
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 74 deletions.
52 changes: 26 additions & 26 deletions packages/manager/src/routes/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,90 @@ export const ProfileRoutes = () => {
);
};

const ProfileRoute = createRoute({
const profileRoute = createRoute({
getParentRoute: () => rootRoute,
path: 'profile',
}).lazy(() =>
import('src/features/Profile/Profile').then((m) => m.ProfileLazyRoute)
);

const ProfileDisplaySettingsRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileDisplaySettingsRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'display',
}).lazy(() =>
import('src/features/Profile/DisplaySettings/DisplaySettings').then(
(m) => m.displaySettingsLazyRoute
)
);

const ProfileAuthenticationSettingsRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileAuthenticationSettingsRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'auth',
}).lazy(() =>
import(
'src/features/Profile/AuthenticationSettings/AuthenticationSettings'
).then((m) => m.authenticationSettingsLazyRoute)
);

const ProfileSSHKeysRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileSSHKeysRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'keys',
}).lazy(() =>
import('src/features/Profile/SSHKeys/SSHKeys').then((m) => m.SSHKeysLazyRoute)
);

const ProfileLishSettingsRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileLishSettingsRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'lish',
}).lazy(() =>
import('src/features/Profile/LishSettings/LishSettings').then(
(m) => m.lishSettingsLazyRoute
)
);

const ProfileAPITokensRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileAPITokensRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'tokens',
}).lazy(() =>
import('src/features/Profile/APITokens/APITokens').then(
(m) => m.APITokensLazyRoute
)
);

const ProfileOAuthClientsRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileOAuthClientsRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'clients',
}).lazy(() =>
import('src/features/Profile/OAuthClients/OAuthClients').then(
(m) => m.OAuthClientsLazyRoute
)
);

const ProfileReferralsRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileReferralsRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'referrals',
}).lazy(() =>
import('src/features/Profile/Referrals/Referrals').then(
(m) => m.ReferralsLazyRoute
)
);

const ProfileSettingsRoute = createRoute({
getParentRoute: () => ProfileRoute,
const profileSettingsRoute = createRoute({
getParentRoute: () => profileRoute,
path: 'settings',
}).lazy(() =>
import('src/features/Profile/Settings/Settings').then(
(m) => m.SettingsLazyRoute
)
);

export const profileRouteTree = ProfileRoute.addChildren([
ProfileAuthenticationSettingsRoute,
ProfileDisplaySettingsRoute,
ProfileSSHKeysRoute,
ProfileLishSettingsRoute,
ProfileAPITokensRoute,
ProfileOAuthClientsRoute,
ProfileReferralsRoute,
ProfileSettingsRoute,
export const profileRouteTree = profileRoute.addChildren([
profileAuthenticationSettingsRoute,
profileDisplaySettingsRoute,
profileSSHKeysRoute,
profileLishSettingsRoute,
profileAPITokensRoute,
profileOAuthClientsRoute,
profileReferralsRoute,
profileSettingsRoute,
]);
15 changes: 6 additions & 9 deletions packages/manager/src/routes/routes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ import {
import { waitFor } from '@testing-library/react';
import React from 'react';

import { accountSettingsFactory } from 'src/factories';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { allPaths } from './utils/allPaths';
import { routeTree } from './index';
import { allPaths } from './utils/allPaths';

import type { RouterContext } from './types';

// Mock any context or dependencies your routes might need
const mockContext = {
accountSettings: {},
app: {
features: {},
flags: {},
notifications: [],
},
const mockContext: RouterContext = {
accountSettings: accountSettingsFactory.build(),
isACLPEnabled: false,
isDatabasesEnabled: false,
isPlacementGroupsEnabled: false,
selfServeBetas: false,
};

// Helper function to create a test router
Expand Down
40 changes: 20 additions & 20 deletions packages/manager/src/routes/stackscripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,71 @@ export const StackScriptsRoutes = () => {
);
};

const StackScriptsRoute = createRoute({
const stackScriptsRoute = createRoute({
component: StackScriptsRoutes,
getParentRoute: () => rootRoute,
path: 'stackscripts',
});

const StackScriptsLandingRoute = createRoute({
getParentRoute: () => StackScriptsRoute,
const stackScriptsLandingRoute = createRoute({
getParentRoute: () => stackScriptsRoute,
path: '/',
}).lazy(() =>
import('src/features/StackScripts/StackScriptsLanding').then(
(m) => m.stackScriptsLandingLazyRoute
)
);

const StackScriptsAccountRoute = createRoute({
getParentRoute: () => StackScriptsRoute,
const stackScriptsAccountRoute = createRoute({
getParentRoute: () => stackScriptsRoute,
path: 'account',
}).lazy(() =>
import('src/features/StackScripts/StackScriptsLanding').then(
(m) => m.stackScriptsLandingLazyRoute
)
);

const StackScriptsCommunityRoute = createRoute({
getParentRoute: () => StackScriptsRoute,
const stackScriptsCommunityRoute = createRoute({
getParentRoute: () => stackScriptsRoute,
path: 'community',
}).lazy(() =>
import('src/features/StackScripts/StackScriptsLanding').then(
(m) => m.stackScriptsLandingLazyRoute
)
);

const StackScriptsCreateRoute = createRoute({
const stackScriptsCreateRoute = createRoute({
// TODO: TanStack Router - broken, perhaps due to being a class component.
component: () => <StackScriptCreate mode="create" />,
getParentRoute: () => StackScriptsRoute,
getParentRoute: () => stackScriptsRoute,
path: 'create',
});

const StackScriptsDetailRoute = createRoute({
const stackScriptsDetailRoute = createRoute({
// TODO: TanStack Router - broken, perhaps due to being a class component.
component: () => <StackScriptDetail />,
getParentRoute: () => StackScriptsRoute,
getParentRoute: () => stackScriptsRoute,
parseParams: (params) => ({
stackScriptID: Number(params.stackScriptID),
}),
path: '$stackScriptID',
});

const StackScriptsEditRoute = createRoute({
const stackScriptsEditRoute = createRoute({
// TODO: TanStack Router - broken, perhaps due to being a class component.
component: () => <StackScriptCreate mode="edit" />,
getParentRoute: () => StackScriptsRoute,
getParentRoute: () => stackScriptsRoute,
parseParams: (params) => ({
stackScriptID: Number(params.stackScriptID),
}),
path: '$stackScriptID/edit',
});

export const stackScriptsRouteTree = StackScriptsRoute.addChildren([
StackScriptsLandingRoute,
StackScriptsAccountRoute,
StackScriptsCommunityRoute,
StackScriptsCreateRoute,
StackScriptsDetailRoute,
StackScriptsEditRoute,
export const stackScriptsRouteTree = stackScriptsRoute.addChildren([
stackScriptsLandingRoute,
stackScriptsAccountRoute,
stackScriptsCommunityRoute,
stackScriptsCreateRoute,
stackScriptsDetailRoute,
stackScriptsEditRoute,
]);
26 changes: 13 additions & 13 deletions packages/manager/src/routes/support.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ export const SupportTicketsRoutes = () => {
);
};

const SupportRoute = createRoute({
const supportRoute = createRoute({
// TODO: TanStackRouter - got to handle the MainContent.tsx `globalErrors.account_unactivated` logic.
component: SupportTicketsRoutes,
getParentRoute: () => rootRoute,
path: 'support',
});

const SupportLandingRoute = createRoute({
getParentRoute: () => SupportRoute,
const supportLandingRoute = createRoute({
getParentRoute: () => supportRoute,
path: '/',
}).lazy(() =>
import('src/features/Help/HelpLanding').then((m) => m.helpLandingLazyRoute)
);

const SupportTicketsRoute = createRoute({
getParentRoute: () => SupportRoute,
const supportTicketsRoute = createRoute({
getParentRoute: () => supportRoute,
path: 'tickets',
}).lazy(() =>
import('src/features/Support/SupportTickets/SupportTicketsLanding').then(
(m) => m.supportTicketsLandingLazyRoute
)
);

const SupportTicketDetailRoute = createRoute({
getParentRoute: () => SupportRoute,
const supportTicketDetailRoute = createRoute({
getParentRoute: () => supportRoute,
parseParams: (params) => ({
ticketId: Number(params.ticketId),
}),
Expand All @@ -50,17 +50,17 @@ const SupportTicketDetailRoute = createRoute({
)
);

const SupportSearchLandingRoute = createRoute({
getParentRoute: () => SupportRoute,
const supportSearchLandingRoute = createRoute({
getParentRoute: () => supportRoute,
path: 'search',
}).lazy(() =>
import('src/features/Help/SupportSearchLanding/SupportSearchLanding').then(
(m) => m.supportSearchLandingLazyRoute
)
);

export const supportRouteTree = SupportRoute.addChildren([
SupportLandingRoute,
SupportTicketsRoute.addChildren([SupportTicketDetailRoute]),
SupportSearchLandingRoute,
export const supportRouteTree = supportRoute.addChildren([
supportLandingRoute,
supportTicketsRoute.addChildren([supportTicketDetailRoute]),
supportSearchLandingRoute,
]);
5 changes: 3 additions & 2 deletions packages/manager/src/routes/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO: TanStackRouter - type this better
import type { AccountSettings } from '@linode/api-v4';

export type RouterContext = {
accountSettings?: any;
accountSettings?: AccountSettings;
globalErrors?: {
account_unactivated?: boolean;
};
Expand Down
13 changes: 9 additions & 4 deletions packages/manager/src/routes/utils/allPaths.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import { routeTree } from '..';

import type { AnyRoute } from '@tanstack/react-router';

/**
* This function is meant to be used for testing purposes only.
* It allows us to generate a list of all unique @tanstack/router paths defined in the routing factory.
*
* We import this util in cypress to loop through all routes and test them.
* It probably should not be used for anything else.
*/
export const getAllRoutePaths = (route: any, parentPath = ''): string[] => {
export const getAllRoutePaths = (
route: AnyRoute,
parentPath = ''
): string[] => {
let currentPath = parentPath
? `${parentPath}/${route.path || ''}`
: route.path || '';

// Remove leading and trailing slashes
currentPath = currentPath.replace(/^\/+|\/+$/g, '');

const paths: Set<string> = new Set();
const paths = new Set<string>();

// Check if the current path is valid
if (currentPath && currentPath !== '//') {
paths.add('/' + currentPath);
}

if (route.children) {
route.children.forEach((childRoute: any) => {
if (route.children && Array.isArray(route.children)) {
route.children.forEach((childRoute) => {
getAllRoutePaths(childRoute, currentPath).forEach((path) =>
paths.add(path)
);
Expand Down

0 comments on commit 8f5f1a1

Please sign in to comment.