Skip to content

Commit 5ee8ef1

Browse files
committed
Use common formatName function
Signed-off-by: Trung Nguyen <[email protected]>
1 parent a0d9b58 commit 5ee8ef1

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

src/extension/ui/src/components/tile/Modal.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
Typography,
2626
useTheme,
2727
} from '@mui/material';
28-
import { capitalize } from 'lodash-es';
2928
import { useEffect, useState } from 'react';
3029

3130
import { ASSIGNED_SECRET_PLACEHOLDER, MCP_POLICY_NAME } from '../../Constants';
@@ -34,6 +33,7 @@ import { useConfig } from '../../queries/useConfig';
3433
import { useSecrets } from '../../queries/useSecrets';
3534
import { CatalogItemRichened } from '../../types/catalog';
3635
import ConfigEditor from './ConfigEditor';
36+
import { formatName } from '../../formatName';
3737

3838
interface TabPanelProps {
3939
children?: React.ReactNode;
@@ -154,15 +154,7 @@ const ConfigurationModal = ({
154154
borderRadius: 1,
155155
}}
156156
/>
157-
{
158-
// Lodash doesn't have a capitalize function that works with strings
159-
catalogItem.name
160-
.replace(/-/g, ' ')
161-
.replace(/_/g, ' ')
162-
.split(' ')
163-
.map(capitalize)
164-
.join(' ')
165-
}
157+
{formatName(catalogItem.name)}
166158

167159
<Tooltip
168160
placement="right"

src/extension/ui/src/components/tile/Top.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Avatar, CardHeader, Switch, Tooltip, Typography } from '@mui/material';
2-
import { capitalize } from 'lodash-es';
32

43
import { CatalogItemRichened } from '../../types/catalog';
4+
import { formatName } from '../../formatName';
55

66
type TopProps = {
77
onToggleRegister: (checked: boolean) => void;
@@ -26,15 +26,7 @@ export default function Top({ item, onToggleRegister }: TopProps) {
2626
}
2727
title={
2828
<Typography sx={{ justifySelf: 'flex-start', fontWeight: 'bold' }}>
29-
{
30-
// Lodash doesn't have a capitalize function that works with strings
31-
item.name
32-
.replace(/-/g, ' ')
33-
.replace(/_/g, ' ')
34-
.split(' ')
35-
.map(capitalize)
36-
.join(' ')
37-
}
29+
{formatName(item.name)}
3830
</Typography>
3931
}
4032
action={

src/extension/ui/src/formatName.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { capitalize } from 'lodash-es';
2+
3+
// This function is used to format the name of a catalog item, as this name isn't always presentable
4+
export function formatName(name: string): string {
5+
// Lodash doesn't have a capitalize function that works with strings
6+
return name
7+
.replace(/-/g, ' ')
8+
.replace(/_/g, ' ')
9+
.split(' ')
10+
.map(capitalize)
11+
.join(' ');
12+
}

0 commit comments

Comments
 (0)