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

Remove usage of RegExp #1051

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
40 changes: 0 additions & 40 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { useQuery } from '@tanstack/react-query';
import { MarkdownText } from 'MarkdownTest';
import { fetchUserProfile } from 'api/requests';
import useSblAuth from 'api/useSblAuth';
import classNames from 'classnames';
import FooterCfGovWrapper from 'components/FooterCfGovWrapper';
import { Link } from 'components/Link';
import { LoadingApp, LoadingContent } from 'components/Loading';
import ScrollToTop from 'components/ScrollToTop';
import { Alert, PageHeader, SkipNav } from 'design-system-react';
Expand Down Expand Up @@ -77,44 +75,6 @@ if (import.meta.env.DEV) {
// eslint-disable-next-line no-console
if (!isRoutingEnabled) console.warn('Routing is disabled!');

/**
* Determine if the current provided URL (href) is the current page
* @param href string
* @returns string
*/
const deriveClassname = (href: string): string => {
let cname = 'nav-item';
const pattern = `${href}$`;

const regex = new RegExp(pattern);
if (regex.test(window.location.href)) {
cname += ' selected';
}

return cname;
};

interface NavItemProperties {
className: string;
href: string;
label: string;
}

export function NavItem({
href,
label,
className,
}: NavItemProperties): JSX.Element {
return (
<Link
{...{ href }}
className={classNames(deriveClassname(href), className)}
>
{label}
</Link>
);
}

function BasicLayout(): Promise<void> | ReactElement {
const headerLinks = [...useHeaderAuthLinks()];
const location = useLocation();
Expand Down
6 changes: 3 additions & 3 deletions src/components/Link.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
if (internalProtocols.includes(parsed.protocol)) return false;

// Any subdomain of consumerfinance.gov or the current host
const isInternalDomain = new RegExp(
`([\\S]*\\.)?(consumerfinance\\.gov|${window.location.host})`,
).test(parsed.host);
const isInternalDomain =
parsed.host.endsWith('consumerfinance.gov') ||
Fixed Show fixed Hide fixed
parsed.host === window.location.host;

return !isInternalDomain;
};
Expand Down
4 changes: 1 addition & 3 deletions src/pages/Filing/FilingApp/FilingSteps.helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { FilingStatusAsNumber } from 'types/filingTypes';
// Does the current browser URL correspond to this Step?
const isStepCurrent = (stepPath: string): boolean => {
const { pathname } = window.location;
const matcher = new RegExp(stepPath);
if (matcher.test(pathname)) return true;
return false;
return pathname.includes(stepPath);
};

const getUploadStatus = (
Expand Down
Loading