chore: refactoring xlate a little bit
Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -14,11 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { MarkdownContent } from '@backstage/core-components';
|
||||
import {
|
||||
TranslationFunction,
|
||||
TranslationRef,
|
||||
useTranslationRef,
|
||||
} from '@backstage/core-plugin-api/alpha';
|
||||
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
||||
import Box from '@material-ui/core/Box';
|
||||
import Chip from '@material-ui/core/Chip';
|
||||
import Collapse from '@material-ui/core/Collapse';
|
||||
@@ -48,6 +44,7 @@ import {
|
||||
import { FC, JSX, cloneElement, Fragment } from 'react';
|
||||
import { scaffolderTranslationRef } from '../../translation';
|
||||
import { SchemaRenderContext, SchemaRenderStrategy } from './types';
|
||||
import { TranslationMessages } from '../TemplatingExtensionsPage/types';
|
||||
|
||||
const getTypes = (properties: JSONSchema7) => {
|
||||
if (!properties.type) {
|
||||
@@ -149,13 +146,9 @@ type RenderColumn = (
|
||||
context: SchemaRenderContext,
|
||||
) => JSX.Element;
|
||||
|
||||
type Xlate<R> = R extends TranslationRef<any, infer M>
|
||||
? TranslationFunction<M>
|
||||
: never;
|
||||
|
||||
type Column = {
|
||||
key: string;
|
||||
title: (t: Xlate<typeof scaffolderTranslationRef>) => string;
|
||||
title: (t: TranslationMessages<typeof scaffolderTranslationRef>) => string;
|
||||
render: RenderColumn;
|
||||
className?: keyof ReturnType<typeof useColumnStyles>;
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ import { Expanded, RenderSchema, SchemaRenderContext } from '../RenderSchema';
|
||||
import { ScaffolderUsageExamplesTable } from '../ScaffolderUsageExamplesTable';
|
||||
import { inspectFunctionArgSchema } from './functionArgs';
|
||||
import { Extension, renderFragment } from './navigation';
|
||||
import { StyleClasses, Xlate } from './types';
|
||||
import { StyleClasses, TranslationMessages } from './types';
|
||||
|
||||
const FilterDetailContent = ({
|
||||
t,
|
||||
@@ -40,7 +40,7 @@ const FilterDetailContent = ({
|
||||
name,
|
||||
filter,
|
||||
}: {
|
||||
t: Xlate<typeof scaffolderTranslationRef>;
|
||||
t: TranslationMessages<typeof scaffolderTranslationRef>;
|
||||
classes: ClassNameMap;
|
||||
name: string;
|
||||
filter: TemplateFilter;
|
||||
@@ -144,7 +144,7 @@ export const TemplateFilters = ({
|
||||
baseLink,
|
||||
selectedItem,
|
||||
}: {
|
||||
t: Xlate<typeof scaffolderTranslationRef>;
|
||||
t: TranslationMessages<typeof scaffolderTranslationRef>;
|
||||
classes: StyleClasses;
|
||||
filters: ListTemplatingExtensionsResponse['filters'];
|
||||
baseLink: ReactElement<Parameters<typeof Link>[0]>;
|
||||
|
||||
@@ -32,7 +32,7 @@ import { Expanded, RenderSchema, SchemaRenderContext } from '../RenderSchema';
|
||||
import { ScaffolderUsageExamplesTable } from '../ScaffolderUsageExamplesTable';
|
||||
import { inspectFunctionArgSchema } from './functionArgs';
|
||||
import { Extension, renderFragment } from './navigation';
|
||||
import { Xlate } from './types';
|
||||
import { TranslationMessages } from './types';
|
||||
|
||||
const FunctionDetailContent = ({
|
||||
classes,
|
||||
@@ -43,13 +43,13 @@ const FunctionDetailContent = ({
|
||||
classes: ClassNameMap;
|
||||
name: string;
|
||||
fn: TemplateGlobalFunction;
|
||||
t: Xlate<typeof scaffolderTranslationRef>;
|
||||
t: TranslationMessages<typeof scaffolderTranslationRef>;
|
||||
}) => {
|
||||
const expanded = useState<Expanded>({});
|
||||
if (!Object.keys(fn).length) {
|
||||
return (
|
||||
<Typography style={{ fontStyle: 'italic' }}>
|
||||
Function metadata unavailable
|
||||
{t('templatingExtensions.content.functions.notAvailable')}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
@@ -134,7 +134,7 @@ export const TemplateGlobalFunctions = ({
|
||||
}: {
|
||||
classes: ClassNameMap;
|
||||
functions: ListTemplatingExtensionsResponse['globals']['functions'];
|
||||
t: Xlate<typeof scaffolderTranslationRef>;
|
||||
t: TranslationMessages<typeof scaffolderTranslationRef>;
|
||||
baseLink: ReactElement<Parameters<typeof Link>[0]>;
|
||||
selectedItem: Extension | null;
|
||||
}) => {
|
||||
@@ -185,7 +185,7 @@ export const TemplateGlobalValues = ({
|
||||
selectedItem,
|
||||
}: {
|
||||
classes: ClassNameMap;
|
||||
t: Xlate<typeof scaffolderTranslationRef>;
|
||||
t: TranslationMessages<typeof scaffolderTranslationRef>;
|
||||
values: ListTemplatingExtensionsResponse['globals']['values'];
|
||||
baseLink: ReactElement<Parameters<typeof Link>[0]>;
|
||||
selectedItem: Extension | null;
|
||||
|
||||
@@ -23,6 +23,6 @@ export type StyleClasses = ClassNameMap<
|
||||
'code' | 'codeRequired' | 'argRequired' | 'link'
|
||||
>;
|
||||
|
||||
export type Xlate<R> = R extends TranslationRef<any, infer M>
|
||||
export type TranslationMessages<R> = R extends TranslationRef<any, infer M>
|
||||
? TranslationFunction<M>
|
||||
: never;
|
||||
|
||||
Reference in New Issue
Block a user