chore: renamed formatEntityRefTitle to humanizeEnityRef

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-03-02 17:08:25 +01:00
parent 1c2755991d
commit c8222292bf
21 changed files with 53 additions and 53 deletions
@@ -21,7 +21,7 @@ import {
import { InfoCard, InfoCardVariants } from '@backstage/core-components';
import { useAnalytics, useRouteRef } from '@backstage/core-plugin-api';
import {
formatEntityRefTitle,
humanizeEntityRef,
useEntity,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
@@ -94,7 +94,7 @@ export const CatalogGraphCard = ({
});
analytics.captureEvent(
'click',
node.title ?? formatEntityRefTitle(nodeEntityName),
node.title ?? humanizeEntityRef(nodeEntityName),
{ attributes: { to: path } },
);
navigate(path);
@@ -24,7 +24,7 @@ import {
import { useAnalytics, useRouteRef } from '@backstage/core-plugin-api';
import {
entityRouteRef,
formatEntityRefTitle,
humanizeEntityRef,
} from '@backstage/plugin-catalog-react';
import { Grid, makeStyles, Paper, Typography } from '@material-ui/core';
import FilterListIcon from '@material-ui/icons/FilterList';
@@ -149,14 +149,14 @@ export const CatalogGraphPage = ({
analytics.captureEvent(
'click',
node.title ?? formatEntityRefTitle(nodeEntityName),
node.title ?? humanizeEntityRef(nodeEntityName),
{ attributes: { to: path } },
);
navigate(path);
} else {
analytics.captureEvent(
'click',
node.title ?? formatEntityRefTitle(nodeEntityName),
node.title ?? humanizeEntityRef(nodeEntityName),
);
setRootEntityNames([nodeEntityName]);
}
@@ -168,7 +168,7 @@ export const CatalogGraphPage = ({
<Page themeId="home">
<Header
title="Catalog Graph"
subtitle={rootEntityNames.map(e => formatEntityRefTitle(e)).join(', ')}
subtitle={rootEntityNames.map(e => humanizeEntityRef(e)).join(', ')}
/>
<Content stretch className={classes.content}>
<ContentHeader
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { DependencyGraphTypes } from '@backstage/core-components';
import { formatEntityRefTitle } from '@backstage/plugin-catalog-react';
import { humanizeEntityRef } from '@backstage/plugin-catalog-react';
import { BackstageTheme } from '@backstage/theme';
import { makeStyles } from '@material-ui/core/styles';
import classNames from 'classnames';
@@ -95,7 +95,7 @@ export function CustomNode({
const displayTitle =
title ??
(kind && name && namespace
? formatEntityRefTitle({ kind, name, namespace })
? humanizeEntityRef({ kind, name, namespace })
: id);
return (
@@ -18,7 +18,7 @@ import { Entity, EntityName } from '@backstage/catalog-model';
import { useApp } from '@backstage/core-plugin-api';
import {
EntityRefLink,
formatEntityRefTitle,
humanizeEntityRef,
} from '@backstage/plugin-catalog-react';
import {
Collapse,
@@ -43,7 +43,7 @@ const useStyles = makeStyles(theme => ({
function sortEntities(entities: Array<EntityName | Entity>) {
return entities.sort((a, b) =>
formatEntityRefTitle(a).localeCompare(formatEntityRefTitle(b)),
humanizeEntityRef(a).localeCompare(humanizeEntityRef(b)),
);
}
@@ -130,7 +130,7 @@ export const EntityListComponent = (props: EntityListComponentProps) => {
) ?? WorkIcon;
return (
<ListItem
key={formatEntityRefTitle(entity)}
key={humanizeEntityRef(entity)}
className={classes.nested}
{...(withLinks
? {
@@ -143,7 +143,7 @@ export const EntityListComponent = (props: EntityListComponentProps) => {
<ListItemIcon>
<Icon />
</ListItemIcon>
<ListItemText primary={formatEntityRefTitle(entity)} />
<ListItemText primary={humanizeEntityRef(entity)} />
</ListItem>
);
})}
@@ -19,7 +19,7 @@ import { errorApiRef, useApi } from '@backstage/core-plugin-api';
import { assertError } from '@backstage/errors';
import {
catalogApiRef,
formatEntityRefTitle,
humanizeEntityRef,
} from '@backstage/plugin-catalog-react';
import { Box, FormHelperText, Grid, Typography } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
@@ -139,7 +139,7 @@ export const StepPrepareCreatePullRequest = (
});
return groupEntities.items
.map(e => formatEntityRefTitle(e, { defaultKind: 'group' }))
.map(e => humanizeEntityRef(e, { defaultKind: 'group' }))
.sort();
});
@@ -31,7 +31,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { useEntityList } from '../../hooks/useEntityListProvider';
import { EntityOwnerFilter } from '../../filters';
import { getEntityRelations } from '../../utils';
import { formatEntityRefTitle } from '../EntityRefLink';
import { humanizeEntityRef } from '../EntityRefLink';
/** @public */
export type CatalogReactEntityOwnerPickerClassKey = 'input';
@@ -86,7 +86,7 @@ export const EntityOwnerPicker = () => {
backendEntities
.flatMap((e: Entity) =>
getEntityRelations(e, RELATION_OWNED_BY).map(o =>
formatEntityRefTitle(o, { defaultKind: 'group' }),
humanizeEntityRef(o, { defaultKind: 'group' }),
),
)
.filter(Boolean) as string[],
@@ -22,7 +22,7 @@ import {
} from '@backstage/catalog-model';
import React, { forwardRef } from 'react';
import { entityRouteRef } from '../../routes';
import { formatEntityRefTitle } from './format';
import { humanizeEntityRef } from './format';
import { Link, LinkProps } from '@backstage/core-components';
import { useRouteRef } from '@backstage/core-plugin-api';
import { Tooltip } from '@material-ui/core';
@@ -72,7 +72,7 @@ export const EntityRefLink = forwardRef<any, EntityRefLinkProps>(
namespace = namespace?.toLocaleLowerCase('en-US') ?? DEFAULT_NAMESPACE;
const routeParams = { kind, namespace, name };
const formattedEntityRefTitle = formatEntityRefTitle(
const formattedEntityRefTitle = humanizeEntityRef(
{ kind, namespace, name },
{ defaultKind },
);
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { formatEntityRefTitle } from './format';
import { humanizeEntityRef } from './humanize';
describe('formatEntityRefTitle', () => {
it('formats entity in default namespace', () => {
@@ -30,7 +30,7 @@ describe('formatEntityRefTitle', () => {
lifecycle: 'production',
},
};
const title = formatEntityRefTitle(entity);
const title = humanizeEntityRef(entity);
expect(title).toEqual('component:software');
});
@@ -48,7 +48,7 @@ describe('formatEntityRefTitle', () => {
lifecycle: 'production',
},
};
const title = formatEntityRefTitle(entity);
const title = humanizeEntityRef(entity);
expect(title).toEqual('component:test/software');
});
@@ -66,7 +66,7 @@ describe('formatEntityRefTitle', () => {
lifecycle: 'production',
},
};
const title = formatEntityRefTitle(entity, { defaultKind: 'Component' });
const title = humanizeEntityRef(entity, { defaultKind: 'Component' });
expect(title).toEqual('test/software');
});
@@ -76,7 +76,7 @@ describe('formatEntityRefTitle', () => {
namespace: 'default',
name: 'software',
};
const title = formatEntityRefTitle(entityName);
const title = humanizeEntityRef(entityName);
expect(title).toEqual('component:software');
});
@@ -87,7 +87,7 @@ describe('formatEntityRefTitle', () => {
name: 'software',
};
const title = formatEntityRefTitle(entityName);
const title = humanizeEntityRef(entityName);
expect(title).toEqual('component:test/software');
});
@@ -98,7 +98,7 @@ describe('formatEntityRefTitle', () => {
name: 'software',
};
const title = formatEntityRefTitle(entityName, {
const title = humanizeEntityRef(entityName, {
defaultKind: 'component',
});
expect(title).toEqual('test/software');
@@ -21,7 +21,7 @@ import {
} from '@backstage/catalog-model';
/** @public */
export function formatEntityRefTitle(
export function humanizeEntityRef(
entityRef: Entity | EntityName,
opts?: { defaultKind?: string },
) {
@@ -18,4 +18,4 @@ export { EntityRefLink } from './EntityRefLink';
export type { EntityRefLinkProps } from './EntityRefLink';
export { EntityRefLinks } from './EntityRefLinks';
export type { EntityRefLinksProps } from './EntityRefLinks';
export { formatEntityRefTitle } from './format';
export { humanizeEntityRef } from './format';
@@ -26,7 +26,7 @@ import { getEntityRelations } from '../../utils';
import {
EntityRefLink,
EntityRefLinks,
formatEntityRefTitle,
humanizeEntityRef,
} from '../EntityRefLink';
/** @public */
@@ -38,7 +38,7 @@ export const columnFactories = Object.freeze({
function formatContent(entity: T): string {
return (
entity.metadata?.title ||
formatEntityRefTitle(entity, {
humanizeEntityRef(entity, {
defaultKind,
})
);
@@ -87,7 +87,7 @@ export const columnFactories = Object.freeze({
function formatContent(entity: T): string {
return getRelations(entity)
.map(r => formatEntityRefTitle(r, { defaultKind }))
.map(r => humanizeEntityRef(r, { defaultKind }))
.join(', ');
}
@@ -33,7 +33,7 @@ import React, { useLayoutEffect, useRef, useState } from 'react';
import { useNavigate } from 'react-router';
import useAsync from 'react-use/lib/useAsync';
import { catalogApiRef } from '../../../api';
import { formatEntityRefTitle } from '../../../components/EntityRefLink/format';
import { humanizeEntityRef } from '../../../components/EntityRefLink/format';
import { entityRouteRef } from '../../../routes';
import { EntityKindIcon } from './EntityKindIcon';
@@ -132,7 +132,7 @@ function CustomNode({ node }: DependencyGraphTypes.RenderNodeProps<NodeType>) {
const displayTitle =
node.metadata.title ||
(node.kind && node.metadata.name && node.metadata.namespace
? formatEntityRefTitle({
? humanizeEntityRef({
kind: node.kind,
name: node.metadata.name,
namespace: node.metadata.namespace || '',
+2 -2
View File
@@ -15,7 +15,7 @@
*/
import { Entity, RELATION_OWNED_BY } from '@backstage/catalog-model';
import { formatEntityRefTitle } from './components/EntityRefLink';
import { humanizeEntityRef } from './components/EntityRefLink';
import { EntityFilter, UserListFilterKind } from './types';
import { getEntityRelations } from './utils';
@@ -107,7 +107,7 @@ export class EntityOwnerFilter implements EntityFilter {
filterEntity(entity: Entity): boolean {
return this.values.some(v =>
getEntityRelations(entity, RELATION_OWNED_BY).some(
o => formatEntityRefTitle(o, { defaultKind: 'group' }) === v,
o => humanizeEntityRef(o, { defaultKind: 'group' }) === v,
),
);
}
@@ -22,7 +22,7 @@ import {
import {
favoriteEntityIcon,
favoriteEntityTooltip,
formatEntityRefTitle,
humanizeEntityRef,
getEntityRelations,
useEntityList,
useStarredEntities,
@@ -132,16 +132,16 @@ export const CatalogTable = (props: CatalogTableProps) => {
return {
entity,
resolved: {
name: formatEntityRefTitle(entity, {
name: humanizeEntityRef(entity, {
defaultKind: 'Component',
}),
ownedByRelationsTitle: ownedByRelations
.map(r => formatEntityRefTitle(r, { defaultKind: 'group' }))
.map(r => humanizeEntityRef(r, { defaultKind: 'group' }))
.join(', '),
ownedByRelations,
partOfSystemRelationTitle: partOfSystemRelations
.map(r =>
formatEntityRefTitle(r, {
humanizeEntityRef(r, {
defaultKind: 'system',
}),
)
@@ -15,7 +15,7 @@
*/
import React from 'react';
import {
formatEntityRefTitle,
humanizeEntityRef,
EntityRefLink,
EntityRefLinks,
} from '@backstage/plugin-catalog-react';
@@ -34,7 +34,7 @@ export const columnFactories = Object.freeze({
function formatContent(entity: Entity): string {
return (
entity.metadata?.title ||
formatEntityRefTitle(entity, {
humanizeEntityRef(entity, {
defaultKind: options?.defaultKind,
})
);
@@ -31,7 +31,7 @@ import { configApiRef, useApi, useRouteRef } from '@backstage/core-plugin-api';
import {
catalogApiRef,
entityRouteRef,
formatEntityRefTitle,
humanizeEntityRef,
getEntityRelations,
} from '@backstage/plugin-catalog-react';
import { BackstageTheme } from '@backstage/theme';
@@ -193,7 +193,7 @@ export function GroupsDiagram() {
kind: catalogItem.kind,
name:
(catalogItem as GroupEntity).spec?.profile?.displayName ||
formatEntityRefTitle(catalogItem, { defaultKind: 'Group' }),
humanizeEntityRef(catalogItem, { defaultKind: 'Group' }),
});
// Edge to parent
@@ -23,7 +23,7 @@ import {
catalogApiRef,
EntityRefLink,
EntityRefLinks,
formatEntityRefTitle,
humanizeEntityRef,
getEntityRelations,
} from '@backstage/plugin-catalog-react';
import { Tooltip } from '@material-ui/core';
@@ -222,10 +222,10 @@ export const FossaPage = ({
return {
entity,
resolved: {
name: formatEntityRefTitle(entity),
name: humanizeEntityRef(entity),
ownedByRelations,
ownedByRelationsTitle: ownedByRelations
.map(r => formatEntityRefTitle(r, { defaultKind: 'group' }))
.map(r => humanizeEntityRef(r, { defaultKind: 'group' }))
.join(', '),
loading: summariesLoading,
details: summary,
@@ -25,7 +25,7 @@ import {
import { useApi, useRouteRef } from '@backstage/core-plugin-api';
import {
catalogApiRef,
formatEntityRefTitle,
humanizeEntityRef,
isOwnerOf,
useEntity,
} from '@backstage/plugin-catalog-react';
@@ -108,7 +108,7 @@ const getQueryParams = (
owner: Entity,
selectedEntity: EntityTypeProps,
): string => {
const ownerName = formatEntityRefTitle(owner, { defaultKind: 'group' });
const ownerName = humanizeEntityRef(owner, { defaultKind: 'group' });
const { kind, type } = selectedEntity;
const filters = {
kind,
@@ -16,7 +16,7 @@
import { useApi } from '@backstage/core-plugin-api';
import {
catalogApiRef,
formatEntityRefTitle,
humanizeEntityRef,
} from '@backstage/plugin-catalog-react';
import { TextField } from '@material-ui/core';
import FormControl from '@material-ui/core/FormControl';
@@ -58,7 +58,7 @@ export const EntityPicker = (
);
const entityRefs = entities?.items.map(e =>
formatEntityRefTitle(e, { defaultKind }),
humanizeEntityRef(e, { defaultKind }),
);
const onSelect = useCallback(
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import {
formatEntityRefTitle,
humanizeEntityRef,
useOwnedEntities,
} from '@backstage/plugin-catalog-react';
import { TextField } from '@material-ui/core';
@@ -50,7 +50,7 @@ export const OwnedEntityPicker = (
const { ownedEntities, loading } = useOwnedEntities(allowedKinds);
const entityRefs = ownedEntities?.items
.map(e => formatEntityRefTitle(e, { defaultKind }))
.map(e => humanizeEntityRef(e, { defaultKind }))
.filter(n => n);
const onSelect = (_: any, value: string | null) => {
@@ -20,7 +20,7 @@ import useCopyToClipboard from 'react-use/lib/useCopyToClipboard';
import { useRouteRef, useApi, configApiRef } from '@backstage/core-plugin-api';
import { Entity, RELATION_OWNED_BY } from '@backstage/catalog-model';
import {
formatEntityRefTitle,
humanizeEntityRef,
getEntityRelations,
} from '@backstage/plugin-catalog-react';
import { rootDocsRouteRef } from '../../../routes';
@@ -76,7 +76,7 @@ export const DocsTable = (props: DocsTableProps) => {
}),
ownedByRelations,
ownedByRelationsTitle: ownedByRelations
.map(r => formatEntityRefTitle(r, { defaultKind: 'group' }))
.map(r => humanizeEntityRef(r, { defaultKind: 'group' }))
.join(', '),
},
};