diff --git a/.changeset/little-eggs-change.md b/.changeset/little-eggs-change.md new file mode 100644 index 0000000000..d19f17d665 --- /dev/null +++ b/.changeset/little-eggs-change.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-plugin-api': patch +--- + +Made the deprecated `icon` fields compatible with the `IconComponent` type from `@backstage/core` in order to smooth out the migration. diff --git a/.changeset/unlucky-lemons-sip.md b/.changeset/unlucky-lemons-sip.md new file mode 100644 index 0000000000..585d091e65 --- /dev/null +++ b/.changeset/unlucky-lemons-sip.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-api': patch +--- + +Made the `RouteRef*` types compatible with the ones exported from `@backstage/core-plugin-api`. diff --git a/packages/core-api/package.json b/packages/core-api/package.json index 6ecb942c28..99a9cd2b0f 100644 --- a/packages/core-api/package.json +++ b/packages/core-api/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "@backstage/config": "^0.1.4", + "@backstage/core-plugin-api": "^0.1.0", "@backstage/theme": "^0.2.6", "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", diff --git a/packages/core-api/src/routing/types.ts b/packages/core-api/src/routing/types.ts index 0089e29e4b..e88b2f748c 100644 --- a/packages/core-api/src/routing/types.ts +++ b/packages/core-api/src/routing/types.ts @@ -16,6 +16,7 @@ import { IconComponent } from '../icons/types'; import { getOrCreateGlobalSingleton } from '../lib/globalObject'; +import { RouteRef as NewRouteRef } from '@backstage/core-plugin-api'; export type AnyParams = { [param in string]: string } | undefined; export type ParamKeys = keyof Params extends never @@ -34,7 +35,11 @@ export type RouteFunc = ( ...[params]: Params extends undefined ? readonly [] : readonly [Params] ) => string; -export const routeRefType: unique symbol = getOrCreateGlobalSingleton( +type RouteRefType = Exclude< + keyof NewRouteRef, + 'params' | 'path' | 'title' | 'icon' +>; +export const routeRefType: RouteRefType = getOrCreateGlobalSingleton( 'route-ref-type', () => Symbol('route-ref-type'), ); diff --git a/packages/core-plugin-api/api-report.md b/packages/core-plugin-api/api-report.md index 339873cd85..dcf53d8aed 100644 --- a/packages/core-plugin-api/api-report.md +++ b/packages/core-plugin-api/api-report.md @@ -9,6 +9,7 @@ import { ComponentType } from 'react'; import { Config } from '@backstage/config'; import { default as React_2 } from 'react'; import { ReactNode } from 'react'; +import { SvgIconProps } from '@material-ui/core'; // @public export type AlertApi = { @@ -206,7 +207,7 @@ export function createRouteRef>; @@ -424,7 +425,7 @@ export type RouteRef = { readonly [routeRefType]: 'absolute'; params: ParamKeys; path: string; - icon?: IconComponent; + icon?: OldIconComponent; title?: string; }; diff --git a/packages/core-plugin-api/package.json b/packages/core-plugin-api/package.json index bb6dfdc4bd..cc0fe07872 100644 --- a/packages/core-plugin-api/package.json +++ b/packages/core-plugin-api/package.json @@ -31,6 +31,7 @@ "dependencies": { "@backstage/config": "^0.1.3", "@backstage/theme": "^0.2.3", + "@material-ui/core": "^4.11.0", "@types/react": "^16.9", "history": "^5.0.0", "prop-types": "^15.7.2", diff --git a/packages/core-plugin-api/src/icons/index.ts b/packages/core-plugin-api/src/icons/index.ts index 50e9534751..953c6ef1ed 100644 --- a/packages/core-plugin-api/src/icons/index.ts +++ b/packages/core-plugin-api/src/icons/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './types'; +export type { IconComponent } from './types'; diff --git a/packages/core-plugin-api/src/icons/types.ts b/packages/core-plugin-api/src/icons/types.ts index b0932bdb3a..53743edc59 100644 --- a/packages/core-plugin-api/src/icons/types.ts +++ b/packages/core-plugin-api/src/icons/types.ts @@ -15,6 +15,7 @@ */ import { ComponentType } from 'react'; +import { SvgIconProps } from '@material-ui/core'; /** * IconComponent is the common icon type used throughout Backstage when @@ -31,3 +32,10 @@ import { ComponentType } from 'react'; export type IconComponent = ComponentType<{ fontSize?: 'default' | 'small' | 'large'; }>; + +/** + * This exists for backwards compatibility with the old core package. + * It's used in some parts of this package in order to smooth out the + * migration, but it is not exported. + */ +export type OldIconComponent = ComponentType; diff --git a/packages/core-plugin-api/src/routing/RouteRef.ts b/packages/core-plugin-api/src/routing/RouteRef.ts index f6499ccc9f..fa4c936bff 100644 --- a/packages/core-plugin-api/src/routing/RouteRef.ts +++ b/packages/core-plugin-api/src/routing/RouteRef.ts @@ -21,13 +21,13 @@ import { ParamKeys, OptionalParams, } from './types'; -import { IconComponent } from '../icons/types'; +import { OldIconComponent } from '../icons/types'; // TODO(Rugvip): Remove this in the next breaking release, it's exported but unused export type RouteRefConfig = { params?: ParamKeys; path?: string; - icon?: IconComponent; + icon?: OldIconComponent; title: string; }; @@ -40,7 +40,7 @@ export class RouteRefImpl readonly params: ParamKeys, private readonly config: { path?: string; - icon?: IconComponent; + icon?: OldIconComponent; title?: string; }, ) {} @@ -79,7 +79,7 @@ export function createRouteRef< /** @deprecated Route refs no longer decide their own path */ path?: string; /** @deprecated Route refs no longer decide their own icon */ - icon?: IconComponent; + icon?: OldIconComponent; /** @deprecated Route refs no longer decide their own title */ title?: string; }): RouteRef> { diff --git a/packages/core-plugin-api/src/routing/types.ts b/packages/core-plugin-api/src/routing/types.ts index 0089e29e4b..0e1c817a39 100644 --- a/packages/core-plugin-api/src/routing/types.ts +++ b/packages/core-plugin-api/src/routing/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IconComponent } from '../icons/types'; +import { OldIconComponent } from '../icons/types'; import { getOrCreateGlobalSingleton } from '../lib/globalObject'; export type AnyParams = { [param in string]: string } | undefined; @@ -48,7 +48,7 @@ export type RouteRef = { /** @deprecated paths are no longer accessed directly from RouteRefs, use useRouteRef instead */ path: string; /** @deprecated icons are no longer accessed via RouteRefs */ - icon?: IconComponent; + icon?: OldIconComponent; /** @deprecated titles are no longer accessed via RouteRefs */ title?: string; };