clean up deprecations of techdocs plugin
Signed-off-by: Emma Indal <emma.indahl@gmail.com>
This commit is contained in:
@@ -49,9 +49,6 @@ export type SyncResult = 'cached' | 'updated';
|
||||
* @public
|
||||
*/
|
||||
export interface TechDocsStorageApi {
|
||||
/**
|
||||
* Set to techdocs.requestUrl as the URL for techdocs-backend API.
|
||||
*/
|
||||
getApiOrigin(): Promise<string>;
|
||||
getStorageUrl(): Promise<string>;
|
||||
getBuilder(): Promise<string>;
|
||||
@@ -73,9 +70,6 @@ export interface TechDocsStorageApi {
|
||||
* @public
|
||||
*/
|
||||
export interface TechDocsApi {
|
||||
/**
|
||||
* Set to techdocs.requestUrl as the URL for techdocs-backend API.
|
||||
*/
|
||||
getApiOrigin(): Promise<string>;
|
||||
getTechDocsMetadata(entityId: CompoundEntityRef): Promise<TechDocsMetadata>;
|
||||
getEntityMetadata(
|
||||
|
||||
@@ -47,10 +47,7 @@ export class TechDocsClient implements TechDocsApi {
|
||||
}
|
||||
|
||||
async getApiOrigin(): Promise<string> {
|
||||
return (
|
||||
this.configApi.getOptionalString('techdocs.requestUrl') ??
|
||||
(await this.discoveryApi.getBaseUrl('techdocs'))
|
||||
);
|
||||
return await this.discoveryApi.getBaseUrl('techdocs');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,10 +123,7 @@ export class TechDocsStorageClient implements TechDocsStorageApi {
|
||||
}
|
||||
|
||||
async getApiOrigin(): Promise<string> {
|
||||
return (
|
||||
this.configApi.getOptionalString('techdocs.requestUrl') ??
|
||||
(await this.discoveryApi.getBaseUrl('techdocs'))
|
||||
);
|
||||
return await this.discoveryApi.getBaseUrl('techdocs');
|
||||
}
|
||||
|
||||
async getStorageUrl(): Promise<string> {
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 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 { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
|
||||
import { screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { LegacyTechDocsHome } from './LegacyTechDocsHome';
|
||||
|
||||
import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
|
||||
import { ConfigApi, configApiRef } from '@backstage/core-plugin-api';
|
||||
import { rootDocsRouteRef } from '../../routes';
|
||||
|
||||
const mockCatalogApi = {
|
||||
getEntityByRef: jest.fn(),
|
||||
getEntities: async () => ({
|
||||
items: [
|
||||
{
|
||||
apiVersion: 'version',
|
||||
kind: 'User',
|
||||
metadata: {
|
||||
name: 'owned',
|
||||
namespace: 'default',
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
} as Partial<CatalogApi>;
|
||||
|
||||
describe('Legacy TechDocs Home', () => {
|
||||
const configApi: ConfigApi = new ConfigReader({
|
||||
organization: {
|
||||
name: 'My Company',
|
||||
},
|
||||
});
|
||||
|
||||
const apiRegistry = TestApiRegistry.from(
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[configApiRef, configApi],
|
||||
);
|
||||
|
||||
it('should render a TechDocs home page', async () => {
|
||||
await renderInTestApp(
|
||||
<ApiProvider apis={apiRegistry}>
|
||||
<LegacyTechDocsHome />
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/docs/:namespace/:kind/:name/*': rootDocsRouteRef,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
// Header
|
||||
expect(await screen.findByText('Documentation')).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByText(/Documentation available in My Company/i),
|
||||
).toBeInTheDocument();
|
||||
|
||||
// Explore Content
|
||||
expect(await screen.findByTestId('docs-explore')).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 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 React from 'react';
|
||||
import { PanelType, TechDocsCustomHome } from './TechDocsCustomHome';
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link TechDocsCustomHome} instead.
|
||||
*/
|
||||
export const LegacyTechDocsHome = () => {
|
||||
const tabsConfig = [
|
||||
{
|
||||
label: 'Overview',
|
||||
panels: [
|
||||
{
|
||||
title: 'Overview',
|
||||
description:
|
||||
'Explore your internal technical ecosystem through documentation.',
|
||||
panelType: 'DocsCardGrid' as PanelType,
|
||||
filterPredicate: () => true,
|
||||
},
|
||||
// uncomment this if you would like to have a secondary panel with owned documents
|
||||
// {
|
||||
// title: 'Owned',
|
||||
// description: 'Explore your owned internal documentation.',
|
||||
// panelType: 'DocsCardGrid' as PanelType,
|
||||
// filterPredicate: 'ownedByUser',
|
||||
// },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Owned Documents',
|
||||
panels: [
|
||||
{
|
||||
title: 'Owned documents',
|
||||
description: 'Access your documentation.',
|
||||
panelType: 'DocsTable' as PanelType,
|
||||
// ownedByUser filters out entities owned by signed in user
|
||||
filterPredicate: 'ownedByUser',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
return <TechDocsCustomHome tabsConfig={tabsConfig} />;
|
||||
};
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 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 React, { useCallback, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
import { techdocsApiRef } from '../../api';
|
||||
import { TechDocsNotFound } from './TechDocsNotFound';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { Page, Content } from '@backstage/core-components';
|
||||
import { Reader } from './Reader';
|
||||
import { TechDocsReaderPageHeader } from './TechDocsReaderPageHeader';
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link TechDocsReaderPage} instead.
|
||||
*/
|
||||
export const LegacyTechDocsPage = () => {
|
||||
const [documentReady, setDocumentReady] = useState<boolean>(false);
|
||||
const { namespace, kind, name } = useParams();
|
||||
|
||||
const techdocsApi = useApi(techdocsApiRef);
|
||||
|
||||
const { value: techdocsMetadataValue } = useAsync(() => {
|
||||
if (documentReady) {
|
||||
return techdocsApi.getTechDocsMetadata({ kind, namespace, name });
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
}, [kind, namespace, name, techdocsApi, documentReady]);
|
||||
|
||||
const { value: entityMetadataValue, error: entityMetadataError } =
|
||||
useAsync(() => {
|
||||
return techdocsApi.getEntityMetadata({ kind, namespace, name });
|
||||
}, [kind, namespace, name, techdocsApi]);
|
||||
|
||||
const onReady = useCallback(() => {
|
||||
setDocumentReady(true);
|
||||
}, [setDocumentReady]);
|
||||
|
||||
if (entityMetadataError) {
|
||||
return <TechDocsNotFound errorMessage={entityMetadataError.message} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Page themeId="documentation">
|
||||
<TechDocsReaderPageHeader
|
||||
techDocsMetadata={techdocsMetadataValue}
|
||||
entityMetadata={entityMetadataValue}
|
||||
entityRef={{
|
||||
kind,
|
||||
namespace,
|
||||
name,
|
||||
}}
|
||||
/>
|
||||
<Content data-testid="techdocs-content">
|
||||
<Reader
|
||||
onReady={onReady}
|
||||
entityRef={{
|
||||
kind,
|
||||
namespace,
|
||||
name,
|
||||
}}
|
||||
/>
|
||||
</Content>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
@@ -19,7 +19,6 @@ import { useOutlet } from 'react-router';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
import { techdocsApiRef } from '../../api';
|
||||
import { LegacyTechDocsPage } from './LegacyTechDocsPage';
|
||||
import { TechDocsEntityMetadata, TechDocsMetadata } from '../../types';
|
||||
import { CompoundEntityRef } from '@backstage/catalog-model';
|
||||
import { useApi, useApp } from '@backstage/core-plugin-api';
|
||||
@@ -79,7 +78,7 @@ export const TechDocsReaderPage = (props: TechDocsReaderPageProps) => {
|
||||
|
||||
if (entityMetadataError) return <NotFoundErrorPage />;
|
||||
|
||||
if (!children) return outlet || <LegacyTechDocsPage />;
|
||||
if (!children) return outlet;
|
||||
|
||||
return (
|
||||
<Page themeId="documentation">
|
||||
@@ -94,16 +93,3 @@ export const TechDocsReaderPage = (props: TechDocsReaderPageProps) => {
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated use {@link TechDocsReaderPage} instead
|
||||
*/
|
||||
export const TechDocsPage = TechDocsReaderPage;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated use {@link TechDocsReaderPageRenderFunction} instead
|
||||
*/
|
||||
|
||||
export type TechDocsPageRenderFunction = TechDocsReaderPageRenderFunction;
|
||||
|
||||
@@ -122,16 +122,3 @@ export const TechDocsReaderPageHeader = (
|
||||
</Header>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated use {@link TechDocsReaderPageHeader} instead
|
||||
*/
|
||||
export const TechDocsPageHeader = TechDocsReaderPageHeader;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated use {@link TechDocsReaderPageHeader} instead
|
||||
*/
|
||||
|
||||
export type TechDocsPageHeaderProps = TechDocsReaderPageHeaderProps;
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
export * from './Reader';
|
||||
export type {
|
||||
TechDocsReaderPageProps,
|
||||
TechDocsPageRenderFunction,
|
||||
TechDocsReaderPageRenderFunction,
|
||||
} from './TechDocsReaderPage';
|
||||
export { TechDocsPage } from './TechDocsReaderPage';
|
||||
export * from './TechDocsReaderPageHeader';
|
||||
export * from './TechDocsStateIndicator';
|
||||
|
||||
|
||||
@@ -101,9 +101,3 @@ export const TechDocsSearchResultListItem = (
|
||||
</LinkWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated use {@link TechDocsSearchResultListItem} instead
|
||||
*/
|
||||
export const DocsResultListItem = TechDocsSearchResultListItem;
|
||||
|
||||
Reference in New Issue
Block a user