Skip to content

Commit 506223d

Browse files
committed
chore: convert UUID regex to a function
1 parent c313439 commit 506223d

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

site/src/pages/DeploymentSettingsPage/IdpOrgSyncPage/OrganizationPills.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "components/Popover/Popover";
88
import type { FC } from "react";
99
import { cn } from "utils/cn";
10-
import { UUID } from "utils/uuid";
10+
import { isUUID } from "utils/uuid";
1111

1212
interface OrganizationPillsProps {
1313
organizations: readonly string[];
@@ -18,7 +18,7 @@ export const OrganizationPills: FC<OrganizationPillsProps> = ({
1818
}) => {
1919
const orgs = organizations.map((org) => ({
2020
name: org,
21-
isUUID: UUID.test(org),
21+
isUUID: isUUID(org),
2222
}));
2323

2424
return (

site/src/pages/ManagementSettingsPage/IdpSyncPage/IdpPillList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
PopoverTrigger,
88
} from "components/Popover/Popover";
99
import type { FC } from "react";
10-
import { UUID } from "utils/uuid";
10+
import { isUUID } from "utils/uuid";
1111

1212
interface PillListProps {
1313
roles: readonly string[];
@@ -17,7 +17,7 @@ export const IdpPillList: FC<PillListProps> = ({ roles }) => {
1717
return (
1818
<Stack direction="row" spacing={1}>
1919
{roles.length > 0 ? (
20-
<Pill css={UUID.test(roles[0]) ? styles.errorPill : styles.pill}>
20+
<Pill css={isUUID(roles[0]) ? styles.errorPill : styles.pill}>
2121
{roles[0]}
2222
</Pill>
2323
) : (
@@ -77,7 +77,7 @@ const OverflowPill: FC<OverflowPillProps> = ({ roles }) => {
7777
{roles.map((role) => (
7878
<Pill
7979
key={role}
80-
css={UUID.test(role) ? styles.errorPill : styles.pill}
80+
css={isUUID(role) ? styles.errorPill : styles.pill}
8181
>
8282
{role}
8383
</Pill>

site/src/utils/uuid.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
export const UUID =
2-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1+
export const isUUID = (text:string) => {
2+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
3+
return UUID.test(text);
4+
}
5+

0 commit comments

Comments
 (0)