catalog-react: add initial legacy converters
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -59,6 +59,7 @@
|
||||
"dependencies": {
|
||||
"@backstage/catalog-client": "workspace:^",
|
||||
"@backstage/catalog-model": "workspace:^",
|
||||
"@backstage/core-compat-api": "workspace:^",
|
||||
"@backstage/core-components": "workspace:^",
|
||||
"@backstage/core-plugin-api": "workspace:^",
|
||||
"@backstage/errors": "workspace:^",
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { compatWrapper } from '@backstage/core-compat-api';
|
||||
import { getComponentData } from '@backstage/core-plugin-api';
|
||||
import { ExtensionDefinition } from '@backstage/frontend-plugin-api';
|
||||
import kebabCase from 'lodash/kebabCase';
|
||||
import React, { ComponentType } from 'react';
|
||||
import { EntityCardBlueprint } from '../blueprints';
|
||||
|
||||
/** @alpha */
|
||||
export function convertLegacyEntityCardExtension(
|
||||
LegacyExtension: ComponentType<{}>,
|
||||
overrides?: {
|
||||
name?: string;
|
||||
filter?:
|
||||
| typeof EntityCardBlueprint.dataRefs.filterFunction.T
|
||||
| typeof EntityCardBlueprint.dataRefs.filterExpression.T;
|
||||
},
|
||||
): ExtensionDefinition<any> {
|
||||
const element = <LegacyExtension />;
|
||||
|
||||
const extName = getComponentData<string>(element, 'core.extensionName');
|
||||
if (!extName) {
|
||||
throw new Error('Extension has no name');
|
||||
}
|
||||
|
||||
const match = extName.match(/^Entity(.*)Card$/);
|
||||
const name = match?.[1] ?? extName;
|
||||
const kebabName = kebabCase(name);
|
||||
|
||||
return EntityCardBlueprint.make({
|
||||
name: overrides?.name ?? kebabName,
|
||||
params: {
|
||||
filter: overrides?.filter,
|
||||
loader: async () => compatWrapper(element),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
compatWrapper,
|
||||
convertLegacyRouteRef,
|
||||
} from '@backstage/core-compat-api';
|
||||
import {
|
||||
getComponentData,
|
||||
RouteRef as LegacyRouteRef,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { ExtensionDefinition } from '@backstage/frontend-plugin-api';
|
||||
import kebabCase from 'lodash/kebabCase';
|
||||
import startCase from 'lodash/startCase';
|
||||
import React, { ComponentType } from 'react';
|
||||
import { EntityContentBlueprint } from '../blueprints';
|
||||
|
||||
/** @alpha */
|
||||
export function convertLegacyEntityContentExtension(
|
||||
LegacyExtension: ComponentType<{}>,
|
||||
overrides?: {
|
||||
name?: string;
|
||||
filter?:
|
||||
| typeof EntityContentBlueprint.dataRefs.filterFunction.T
|
||||
| typeof EntityContentBlueprint.dataRefs.filterExpression.T;
|
||||
defaultPath?: string;
|
||||
defaultTitle?: string;
|
||||
},
|
||||
): ExtensionDefinition<any> {
|
||||
const element = <LegacyExtension />;
|
||||
|
||||
const extName = getComponentData<string>(element, 'core.extensionName');
|
||||
if (!extName) {
|
||||
throw new Error('Extension has no name');
|
||||
}
|
||||
|
||||
const mountPoint = getComponentData<LegacyRouteRef>(
|
||||
element,
|
||||
'core.mountPoint',
|
||||
);
|
||||
|
||||
const match = extName.match(/^Entity(.*)Content$/);
|
||||
const name = match?.[1] ?? extName;
|
||||
const kebabName = kebabCase(name);
|
||||
|
||||
return EntityContentBlueprint.make({
|
||||
name: overrides?.name ?? kebabName,
|
||||
params: {
|
||||
filter: overrides?.filter,
|
||||
defaultPath: overrides?.defaultPath ?? `/${kebabName}`,
|
||||
defaultTitle: overrides?.defaultTitle ?? startCase(name),
|
||||
routeRef: mountPoint && convertLegacyRouteRef(mountPoint),
|
||||
loader: async () => compatWrapper(element),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { convertLegacyEntityCardExtension } from './convertLegacyEntityCardExtension';
|
||||
export { convertLegacyEntityContentExtension } from './convertLegacyEntityContentExtension';
|
||||
@@ -13,5 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './blueprints';
|
||||
export * from './extensions';
|
||||
export * from './converters';
|
||||
|
||||
@@ -5918,6 +5918,7 @@ __metadata:
|
||||
"@backstage/catalog-model": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/core-app-api": "workspace:^"
|
||||
"@backstage/core-compat-api": "workspace:^"
|
||||
"@backstage/core-components": "workspace:^"
|
||||
"@backstage/core-plugin-api": "workspace:^"
|
||||
"@backstage/errors": "workspace:^"
|
||||
|
||||
Reference in New Issue
Block a user