Skip to content

Commit

Permalink
Merge pull request #4941 from erdoganoksuz/bug-fix/locale-case
Browse files Browse the repository at this point in the history
use local version of all case conversion methods
  • Loading branch information
freben committed Mar 17, 2021
2 parents b5fc764 + 12d5dd4 commit a0098ba
Show file tree
Hide file tree
Showing 31 changed files with 85 additions and 45 deletions.
21 changes: 21 additions & 0 deletions .changeset/pink-knives-obey.md
@@ -0,0 +1,21 @@
---
'@backstage/core': patch
'@backstage/create-app': patch
'@backstage/plugin-api-docs': patch
'@backstage/plugin-bitrise': patch
'@backstage/plugin-catalog': patch
'@backstage/plugin-catalog-import': patch
'@backstage/plugin-catalog-react': patch
'@backstage/plugin-circleci': patch
'@backstage/plugin-cloudbuild': patch
'@backstage/plugin-explore': patch
'@backstage/plugin-github-actions': patch
'@backstage/plugin-jenkins': patch
'@backstage/plugin-kubernetes': patch
'@backstage/plugin-lighthouse': patch
'@backstage/plugin-org': patch
'@backstage/plugin-scaffolder': patch
'@backstage/plugin-search': patch
---

use local version of lowerCase and upperCase methods
2 changes: 1 addition & 1 deletion packages/app/src/components/catalog/EntityPage.tsx
Expand Up @@ -500,7 +500,7 @@ const DomainEntityPage = ({ entity }: { entity: Entity }) => (
export const EntityPage = () => {
const { entity } = useEntity();

switch (entity?.kind?.toLowerCase()) {
switch (entity?.kind?.toLocaleLowerCase('en-US')) {
case 'component':
return <ComponentEntityPage entity={entity} />;
case 'api':
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/api-wrappers/createApp.tsx
Expand Up @@ -58,7 +58,10 @@ export const defaultConfigLoader: AppConfigLoader = async (
const configs = (appConfig.slice() as unknown) as AppConfig[];

// Avoiding this string also being replaced at runtime
if (runtimeConfigJson !== '__app_injected_runtime_config__'.toUpperCase()) {
if (
runtimeConfigJson !==
'__app_injected_runtime_config__'.toLocaleUpperCase('en-US')
) {
try {
const data = JSON.parse(runtimeConfigJson) as JsonObject;
if (Array.isArray(data)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/Table/Table.stories.tsx
Expand Up @@ -213,8 +213,8 @@ export const SubvalueTable = () => {
row: any, // Only needed if you want subvalue searchable
) =>
`${row.col1} ${row.subvalue}`
.toUpperCase()
.includes(query.toUpperCase()),
.toLocaleUpperCase('en-US')
.includes(query.toLocaleUpperCase('en-US')),
field: 'col1',
highlight: true,
render: (row: any): React.ReactNode => (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/WarningPanel/WarningPanel.tsx
Expand Up @@ -81,7 +81,7 @@ type Props = {
};

const capitalize = (s: string) => {
return s.charAt(0).toUpperCase() + s.slice(1);
return s.charAt(0).toLocaleUpperCase('en-US') + s.slice(1);
};

/**
Expand Down
Expand Up @@ -184,7 +184,7 @@ const ApiEntityPage = ({ entity }: { entity: Entity }) => (
export const EntityPage = () => {
const { entity } = useEntity();

switch (entity?.kind?.toLowerCase()) {
switch (entity?.kind?.toLocaleLowerCase('en-US')) {
case 'component':
return <ComponentEntityPage entity={entity} />;
case 'api':
Expand Down
Expand Up @@ -74,7 +74,8 @@ export const ConsumedApisCard = ({ variant = 'gridItem' }: Props) => {
emptyContent={
<div style={{ textAlign: 'center' }}>
<Typography variant="body1">
This {entity.kind.toLowerCase()} does not consume any APIs.
This {entity.kind.toLocaleLowerCase('en-US')} does not consume any
APIs.
</Typography>
<Typography variant="body2">
<Link to="https://backstage.io/docs/features/software-catalog/descriptor-format#specconsumesapis-optional">
Expand Down
3 changes: 2 additions & 1 deletion plugins/api-docs/src/components/ApisCards/HasApisCard.tsx
Expand Up @@ -78,7 +78,8 @@ export const HasApisCard = ({ variant = 'gridItem' }: Props) => {
emptyContent={
<div style={{ textAlign: 'center' }}>
<Typography variant="body1">
This {entity.kind.toLowerCase()} does not contain any APIs.
This {entity.kind.toLocaleLowerCase('en-US')} does not contain any
APIs.
</Typography>
<Typography variant="body2">
<Link to="https://backstage.io/docs/features/software-catalog/descriptor-format#kind-api">
Expand Down
Expand Up @@ -74,7 +74,8 @@ export const ProvidedApisCard = ({ variant = 'gridItem' }: Props) => {
emptyContent={
<div style={{ textAlign: 'center' }}>
<Typography variant="body1">
This {entity.kind.toLowerCase()} does not provide any APIs.
This {entity.kind.toLocaleLowerCase('en-US')} does not provide any
APIs.
</Typography>
<Typography variant="body2">
<Link to="https://backstage.io/docs/features/software-catalog/descriptor-format#specprovidesapis-optional">
Expand Down
Expand Up @@ -162,8 +162,8 @@ export const BitriseBuildsTable = ({
title: 'Branch',
customFilterAndSearch: (query, row: any) =>
`${row.message} ${row.workflow}`
.toUpperCase()
.includes(query.toUpperCase()),
.toLocaleUpperCase('en-US')
.includes(query.toLocaleUpperCase('en-US')),
field: 'message',
width: 'auto',
highlight: true,
Expand Down
Expand Up @@ -54,7 +54,7 @@ function sortEntities(entities: Array<EntityName | Entity>) {
}

function getEntityIcon(entity: { kind: string }): React.ReactElement {
switch (entity.kind.toLowerCase()) {
switch (entity.kind.toLocaleLowerCase('en-US')) {
case 'api':
return <ExtensionIcon />;

Expand Down
Expand Up @@ -48,11 +48,12 @@ export const EntityRefLink = forwardRef<any, EntityRefLinkProps>(
name = entityRef.name;
}

kind = kind.toLowerCase();
kind = kind.toLocaleLowerCase('en-US');

const routeParams = {
kind,
namespace: namespace?.toLowerCase() ?? ENTITY_DEFAULT_NAMESPACE,
namespace:
namespace?.toLocaleLowerCase('en-US') ?? ENTITY_DEFAULT_NAMESPACE,
name,
};

Expand Down
8 changes: 4 additions & 4 deletions plugins/catalog/src/components/AboutCard/AboutContent.tsx
Expand Up @@ -39,10 +39,10 @@ type Props = {

export const AboutContent = ({ entity }: Props) => {
const classes = useStyles();
const isSystem = entity.kind.toLowerCase() === 'system';
const isDomain = entity.kind.toLowerCase() === 'domain';
const isResource = entity.kind.toLowerCase() === 'resource';
const isComponent = entity.kind.toLowerCase() === 'component';
const isSystem = entity.kind.toLocaleLowerCase('en-US') === 'system';
const isDomain = entity.kind.toLocaleLowerCase('en-US') === 'domain';
const isResource = entity.kind.toLocaleLowerCase('en-US') === 'resource';
const isComponent = entity.kind.toLocaleLowerCase('en-US') === 'component';
const partOfSystemRelations = getEntityRelations(entity, RELATION_PART_OF, {
kind: 'system',
});
Expand Down
4 changes: 2 additions & 2 deletions plugins/catalog/src/components/EntityLayout/EntityLayout.tsx
Expand Up @@ -69,10 +69,10 @@ const headerProps = (
: ''
}`,
headerType: (() => {
let t = kind.toLowerCase();
let t = kind.toLocaleLowerCase('en-US');
if (entity && entity.spec && 'type' in entity.spec) {
t += ' — ';
t += (entity.spec as { type: string }).type.toLowerCase();
t += (entity.spec as { type: string }).type.toLocaleLowerCase('en-US');
}
return t;
})(),
Expand Down
Expand Up @@ -88,10 +88,10 @@ const headerProps = (
: ''
}`,
headerType: (() => {
let t = kind.toLowerCase();
let t = kind.toLocaleLowerCase('en-US');
if (entity && entity.spec && 'type' in entity.spec) {
t += ' — ';
t += (entity.spec as { type: string }).type.toLowerCase();
t += (entity.spec as { type: string }).type.toLocaleLowerCase('en-US');
}
return t;
})(),
Expand Down
3 changes: 2 additions & 1 deletion plugins/catalog/src/components/Router.tsx
Expand Up @@ -63,7 +63,8 @@ const EntityPageSwitch = ({ EntityPage }: { EntityPage: ComponentType }) => {
const OldEntityRouteRedirect = () => {
const { optionalNamespaceAndName, '*': rest } = useParams() as any;
const [name, namespace] = optionalNamespaceAndName.split(':').reverse();
const namespaceLower = namespace?.toLowerCase() ?? ENTITY_DEFAULT_NAMESPACE;
const namespaceLower =
namespace?.toLocaleLowerCase('en-US') ?? ENTITY_DEFAULT_NAMESPACE;
const restWithSlash = rest ? `/${rest}` : '';
return (
<Navigate
Expand Down
Expand Up @@ -79,7 +79,7 @@ export type CITableBuildInfo = {

// retried, canceled, infrastructure_fail, timedout, not_run, running, failed, queued, scheduled, not_running, no_tests, fixed, success
const getStatusComponent = (status: string | undefined = '') => {
switch (status.toLowerCase()) {
switch (status.toLocaleLowerCase('en-US')) {
case 'queued':
case 'scheduled':
return <StatusPending />;
Expand Down
Expand Up @@ -29,7 +29,7 @@ export const WorkflowRunStatus = ({
status: string | undefined;
}) => {
if (status === undefined) return null;
switch (status.toLowerCase()) {
switch (status.toLocaleLowerCase('en-US')) {
case 'queued':
return (
<>
Expand Down
4 changes: 2 additions & 2 deletions plugins/explore/src/components/ToolCard/ToolCard.tsx
Expand Up @@ -76,13 +76,13 @@ export const ToolCard = ({ card, objectFit }: Props) => {
<CardContent>
<Typography paragraph variant="h5">
{title}{' '}
{lifecycle && lifecycle.toLowerCase() !== 'ga' && (
{lifecycle && lifecycle.toLocaleLowerCase('en-US') !== 'ga' && (
<Chip
size="small"
label={lifecycle}
className={classNames(
classes.lifecycle,
classes[lifecycle.toLowerCase()],
classes[lifecycle.toLocaleLowerCase('en-US')],
)}
/>
)}
Expand Down
Expand Up @@ -88,8 +88,8 @@ const StepView = ({ step }: { step: Step }) => {
</TableCell>
<TableCell>
<WorkflowRunStatus
status={step.status.toUpperCase()}
conclusion={step.conclusion?.toUpperCase()}
status={step.status.toLocaleUpperCase('en-US')}
conclusion={step.conclusion?.toLocaleUpperCase('en-US')}
/>
</TableCell>
</TableRow>
Expand Down
Expand Up @@ -32,7 +32,7 @@ export const WorkflowRunStatus = ({
conclusion: string | undefined;
}) => {
if (status === undefined) return null;
switch (status.toLowerCase()) {
switch (status.toLocaleLowerCase('en-US')) {
case 'queued':
return (
<>
Expand All @@ -46,7 +46,7 @@ export const WorkflowRunStatus = ({
</>
);
case 'completed':
switch (conclusion?.toLowerCase()) {
switch (conclusion?.toLocaleLowerCase('en-US')) {
case 'skipped' || 'canceled':
return (
<>
Expand Down
Expand Up @@ -30,7 +30,7 @@ export const JenkinsRunStatus = ({
status: string | undefined;
}) => {
if (status === undefined) return null;
switch (status.toLowerCase()) {
switch (status.toLocaleLowerCase('en-US')) {
case 'queued':
case 'scheduled':
return (
Expand Down
Expand Up @@ -18,7 +18,8 @@ import React from 'react';
import { KubernetesDrawer } from '../KubernetesDrawer/KubernetesDrawer';
import { Typography, Grid } from '@material-ui/core';

const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
const capitalize = (str: string) =>
str.charAt(0).toLocaleUpperCase('en-US') + str.slice(1);

export const DefaultCustomResourceDrawer = ({
customResource,
Expand Down
Expand Up @@ -106,7 +106,7 @@ export const AuditListTable = ({ items }: { items: Website[] }) => {
lastReport: (
<>
<AuditStatusIcon audit={website.lastAudit} />{' '}
<span>{website.lastAudit.status.toUpperCase()}</span>
<span>{website.lastAudit.status.toLocaleUpperCase('en-US')}</span>
</>
),
lastAuditTriggered: formatTime(website.lastAudit.timeCreated),
Expand Down
Expand Up @@ -59,7 +59,7 @@ const LighthouseCategoryScoreStatus = ({ score }: { score: number }) => {
const LighthouseAuditStatus = ({ audit }: { audit: Audit }) => (
<>
<AuditStatusIcon audit={audit} />
{audit.status.toUpperCase()}
{audit.status.toLocaleUpperCase('en-US')}
</>
);

Expand Down
Expand Up @@ -130,7 +130,8 @@ export const MembersListCard = (_props: {
member?.relations?.some(
r =>
r.type === RELATION_MEMBER_OF &&
r.target.name.toLowerCase() === groupName.toLowerCase(),
r.target.name.toLocaleLowerCase('en-US') ===
groupName.toLocaleLowerCase('en-US'),
),
);
return groupMembersList;
Expand Down
Expand Up @@ -100,7 +100,9 @@ describe('Results Filter', () => {
);
for (const category of categories) {
expect(
await findByText(category.charAt(0).toUpperCase() + category.slice(1)),
await findByText(
category.charAt(0).toLocaleUpperCase('en-US') + category.slice(1),
),
).toBeInTheDocument();
}
});
Expand Down
Expand Up @@ -107,7 +107,10 @@ export const ResultsFilter = ({ availableCategories }: Props) => {
/>
<ListItemText
id={labelId}
primary={category.charAt(0).toUpperCase() + category.slice(1)}
primary={
category.charAt(0).toLocaleUpperCase('en-US') +
category.slice(1)
}
/>
</ListItem>
);
Expand Down
Expand Up @@ -105,16 +105,16 @@ export const ScaffolderPageContents = () => {
);

const matchesQuery = (metadata: EntityMeta, query: string) =>
`${metadata.title}`.toUpperCase().includes(query) ||
metadata.tags?.join('').toUpperCase().indexOf(query) !== -1;
`${metadata.title}`.toLocaleUpperCase('en-US').includes(query) ||
metadata.tags?.join('').toLocaleUpperCase('en-US').indexOf(query) !== -1;

useEffect(() => {
if (search.length === 0) {
return setMatchingEntities(filteredEntities);
}
return setMatchingEntities(
filteredEntities.filter(template =>
matchesQuery(template.metadata, search.toUpperCase()),
matchesQuery(template.metadata, search.toLocaleUpperCase('en-US')),
),
);
}, [search, filteredEntities]);
Expand Down
4 changes: 3 additions & 1 deletion plugins/search/src/components/SearchPage/SearchPage.tsx
Expand Up @@ -56,7 +56,9 @@ export const SearchPage = () => {
/>
</Grid>
<Grid item xs={12}>
<SearchResult searchQuery={(queryString ?? '').toLowerCase()} />
<SearchResult
searchQuery={(queryString ?? '').toLocaleLowerCase('en-US')}
/>
</Grid>
</Grid>
</Content>
Expand Down
8 changes: 5 additions & 3 deletions plugins/search/src/components/SearchResult/SearchResult.tsx
Expand Up @@ -158,11 +158,13 @@ export const SearchResult = ({ searchQuery }: SearchResultProps) => {
if (searchQuery) {
withFilters = withFilters.filter(
(result: Result) =>
result.name?.toLowerCase().includes(searchQuery) ||
result.name?.toLocaleLowerCase('en-US').includes(searchQuery) ||
result.name
?.toLowerCase()
?.toLocaleLowerCase('en-US')
.includes(searchQuery.split(' ').join('-')) ||
result.description?.toLowerCase().includes(searchQuery),
result.description
?.toLocaleLowerCase('en-US')
.includes(searchQuery),
);
}

Expand Down

0 comments on commit a0098ba

Please sign in to comment.