Merge branch 'master' of https://github.com/spotify/backstage into lintMod
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
import { ApiEntity } from '@backstage/catalog-model';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core';
|
||||
import { EntityProvider } from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
@@ -54,7 +55,7 @@ paths:
|
||||
get:
|
||||
summary: List all artists
|
||||
responses:
|
||||
"200":
|
||||
"200":
|
||||
description: Success
|
||||
`;
|
||||
const apiEntity: ApiEntity = {
|
||||
@@ -81,7 +82,9 @@ paths:
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ApiDefinitionCard apiEntity={apiEntity} />
|
||||
<EntityProvider entity={apiEntity}>
|
||||
<ApiDefinitionCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
@@ -110,7 +113,9 @@ paths:
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ApiDefinitionCard apiEntity={apiEntity} />
|
||||
<EntityProvider entity={apiEntity}>
|
||||
<ApiDefinitionCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { ApiEntity } from '@backstage/catalog-model';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
import { CardTab, TabbedCard, useApi } from '@backstage/core';
|
||||
import { Alert } from '@material-ui/lab';
|
||||
import React from 'react';
|
||||
@@ -22,29 +23,31 @@ import { apiDocsConfigRef } from '../../config';
|
||||
import { PlainApiDefinitionWidget } from '../PlainApiDefinitionWidget';
|
||||
|
||||
type Props = {
|
||||
/** @deprecated The entity is now grabbed from context instead */
|
||||
apiEntity?: ApiEntity;
|
||||
};
|
||||
|
||||
export const ApiDefinitionCard = ({ apiEntity }: Props) => {
|
||||
export const ApiDefinitionCard = (_: Props) => {
|
||||
const entity = useEntity().entity as ApiEntity;
|
||||
const config = useApi(apiDocsConfigRef);
|
||||
const { getApiDefinitionWidget } = config;
|
||||
|
||||
if (!apiEntity) {
|
||||
if (!entity) {
|
||||
return <Alert severity="error">Could not fetch the API</Alert>;
|
||||
}
|
||||
|
||||
const definitionWidget = getApiDefinitionWidget(apiEntity);
|
||||
const definitionWidget = getApiDefinitionWidget(entity);
|
||||
|
||||
if (definitionWidget) {
|
||||
return (
|
||||
<TabbedCard title={apiEntity.metadata.name}>
|
||||
<TabbedCard title={entity.metadata.name}>
|
||||
<CardTab label={definitionWidget.title} key="widget">
|
||||
{definitionWidget.component(apiEntity.spec.definition)}
|
||||
{definitionWidget.component(entity.spec.definition)}
|
||||
</CardTab>
|
||||
<CardTab label="Raw" key="raw">
|
||||
<PlainApiDefinitionWidget
|
||||
definition={apiEntity.spec.definition}
|
||||
language={definitionWidget.rawLanguage || apiEntity.spec.type}
|
||||
definition={entity.spec.definition}
|
||||
language={definitionWidget.rawLanguage || entity.spec.type}
|
||||
/>
|
||||
</CardTab>
|
||||
</TabbedCard>
|
||||
@@ -53,13 +56,13 @@ export const ApiDefinitionCard = ({ apiEntity }: Props) => {
|
||||
|
||||
return (
|
||||
<TabbedCard
|
||||
title={apiEntity.metadata.name}
|
||||
title={entity.metadata.name}
|
||||
children={[
|
||||
// Has to be an array, otherwise typescript doesn't like that this has only a single child
|
||||
<CardTab label={apiEntity.spec.type} key="raw">
|
||||
<CardTab label={entity.spec.type} key="raw">
|
||||
<PlainApiDefinitionWidget
|
||||
definition={apiEntity.spec.definition}
|
||||
language={apiEntity.spec.type}
|
||||
definition={entity.spec.definition}
|
||||
language={entity.spec.type}
|
||||
/>
|
||||
</CardTab>,
|
||||
]}
|
||||
|
||||
@@ -21,7 +21,11 @@ import {
|
||||
RELATION_PART_OF,
|
||||
} from '@backstage/catalog-model';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core';
|
||||
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import {
|
||||
CatalogApi,
|
||||
catalogApiRef,
|
||||
EntityProvider,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
@@ -68,7 +72,9 @@ describe('<ConsumedApisCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ConsumedApisCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ConsumedApisCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
@@ -134,7 +140,9 @@ describe('<ConsumedApisCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ConsumedApisCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ConsumedApisCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
Entity,
|
||||
RELATION_CONSUMES_API,
|
||||
} from '@backstage/catalog-model';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
import { EmptyState, InfoCard, Progress } from '@backstage/core';
|
||||
import React, { PropsWithChildren } from 'react';
|
||||
import { ApisTable } from './ApisTable';
|
||||
@@ -37,11 +38,13 @@ const ApisCard = ({
|
||||
};
|
||||
|
||||
type Props = {
|
||||
entity: Entity;
|
||||
/** @deprecated The entity is now grabbed from context instead */
|
||||
entity?: Entity;
|
||||
variant?: string;
|
||||
};
|
||||
|
||||
export const ConsumedApisCard = ({ entity, variant = 'gridItem' }: Props) => {
|
||||
export const ConsumedApisCard = ({ variant = 'gridItem' }: Props) => {
|
||||
const { entity } = useEntity();
|
||||
const { entities, loading, error } = useRelatedEntities(
|
||||
entity,
|
||||
RELATION_CONSUMES_API,
|
||||
|
||||
@@ -21,7 +21,11 @@ import {
|
||||
RELATION_PROVIDES_API,
|
||||
} from '@backstage/catalog-model';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core';
|
||||
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import {
|
||||
CatalogApi,
|
||||
catalogApiRef,
|
||||
EntityProvider,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
@@ -68,7 +72,9 @@ describe('<ProvidedApisCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ProvidedApisCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ProvidedApisCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
@@ -134,7 +140,9 @@ describe('<ProvidedApisCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ProvidedApisCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ProvidedApisCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
Entity,
|
||||
RELATION_PROVIDES_API,
|
||||
} from '@backstage/catalog-model';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
import { EmptyState, InfoCard, Progress } from '@backstage/core';
|
||||
import React, { PropsWithChildren } from 'react';
|
||||
import { ApisTable } from './ApisTable';
|
||||
@@ -37,11 +38,13 @@ const ApisCard = ({
|
||||
};
|
||||
|
||||
type Props = {
|
||||
entity: Entity;
|
||||
/** @deprecated The entity is now grabbed from context instead */
|
||||
entity?: Entity;
|
||||
variant?: string;
|
||||
};
|
||||
|
||||
export const ProvidedApisCard = ({ entity, variant = 'gridItem' }: Props) => {
|
||||
export const ProvidedApisCard = ({ variant = 'gridItem' }: Props) => {
|
||||
const { entity } = useEntity();
|
||||
const { entities, loading, error } = useRelatedEntities(
|
||||
entity,
|
||||
RELATION_PROVIDES_API,
|
||||
|
||||
@@ -21,7 +21,11 @@ import {
|
||||
RELATION_PART_OF,
|
||||
} from '@backstage/catalog-model';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core';
|
||||
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import {
|
||||
CatalogApi,
|
||||
catalogApiRef,
|
||||
EntityProvider,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
@@ -67,7 +71,9 @@ describe('<ConsumingComponentsCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ConsumingComponentsCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ConsumingComponentsCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
@@ -133,7 +139,9 @@ describe('<ConsumingComponentsCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ConsumingComponentsCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ConsumingComponentsCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
Entity,
|
||||
RELATION_API_CONSUMED_BY,
|
||||
} from '@backstage/catalog-model';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
import { EmptyState, InfoCard, Progress } from '@backstage/core';
|
||||
import React, { PropsWithChildren } from 'react';
|
||||
import { MissingConsumesApisEmptyState } from '../EmptyState';
|
||||
@@ -37,14 +38,13 @@ const ComponentsCard = ({
|
||||
};
|
||||
|
||||
type Props = {
|
||||
entity: Entity;
|
||||
/** @deprecated The entity is now grabbed from context instead */
|
||||
entity?: Entity;
|
||||
variant?: string;
|
||||
};
|
||||
|
||||
export const ConsumingComponentsCard = ({
|
||||
entity,
|
||||
variant = 'gridItem',
|
||||
}: Props) => {
|
||||
export const ConsumingComponentsCard = ({ variant = 'gridItem' }: Props) => {
|
||||
const { entity } = useEntity();
|
||||
const { entities, loading, error } = useRelatedEntities(
|
||||
entity,
|
||||
RELATION_API_CONSUMED_BY,
|
||||
|
||||
@@ -21,7 +21,11 @@ import {
|
||||
RELATION_PART_OF,
|
||||
} from '@backstage/catalog-model';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core';
|
||||
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import {
|
||||
CatalogApi,
|
||||
catalogApiRef,
|
||||
EntityProvider,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
@@ -67,7 +71,9 @@ describe('<ProvidingComponentsCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ProvidingComponentsCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ProvidingComponentsCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
@@ -133,7 +139,9 @@ describe('<ProvidingComponentsCard />', () => {
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<ProvidingComponentsCard entity={entity} />
|
||||
<EntityProvider entity={entity}>
|
||||
<ProvidingComponentsCard />
|
||||
</EntityProvider>
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
Entity,
|
||||
RELATION_API_PROVIDED_BY,
|
||||
} from '@backstage/catalog-model';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
import { EmptyState, InfoCard, Progress } from '@backstage/core';
|
||||
import React, { PropsWithChildren } from 'react';
|
||||
import { MissingProvidesApisEmptyState } from '../EmptyState';
|
||||
@@ -37,14 +38,13 @@ const ComponentsCard = ({
|
||||
};
|
||||
|
||||
type Props = {
|
||||
entity: Entity;
|
||||
/** @deprecated The entity is now grabbed from context instead */
|
||||
entity?: Entity;
|
||||
variant?: string;
|
||||
};
|
||||
|
||||
export const ProvidingComponentsCard = ({
|
||||
entity,
|
||||
variant = 'gridItem',
|
||||
}: Props) => {
|
||||
export const ProvidingComponentsCard = ({ variant = 'gridItem' }: Props) => {
|
||||
const { entity } = useEntity();
|
||||
const { entities, loading, error } = useRelatedEntities(
|
||||
entity,
|
||||
RELATION_API_PROVIDED_BY,
|
||||
|
||||
@@ -15,4 +15,13 @@
|
||||
*/
|
||||
|
||||
export * from './components';
|
||||
export { plugin } from './plugin';
|
||||
export {
|
||||
apiDocsPlugin,
|
||||
apiDocsPlugin as plugin,
|
||||
ApiExplorerPage,
|
||||
EntityApiDefinitionCard,
|
||||
EntityConsumedApisCard,
|
||||
EntityConsumingComponentsCard,
|
||||
EntityProvidedApisCard,
|
||||
EntityProvidingComponentsCard,
|
||||
} from './plugin';
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { plugin } from './plugin';
|
||||
import { apiDocsPlugin } from './plugin';
|
||||
|
||||
describe('api-docs', () => {
|
||||
it('should export plugin', () => {
|
||||
expect(plugin).toBeDefined();
|
||||
expect(apiDocsPlugin).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,14 +15,22 @@
|
||||
*/
|
||||
|
||||
import { ApiEntity } from '@backstage/catalog-model';
|
||||
import { createApiFactory, createPlugin } from '@backstage/core';
|
||||
import { ApiExplorerPage } from './components/ApiExplorerPage/ApiExplorerPage';
|
||||
import {
|
||||
createApiFactory,
|
||||
createPlugin,
|
||||
createRoutableExtension,
|
||||
createComponentExtension,
|
||||
} from '@backstage/core';
|
||||
import { ApiExplorerPage as Page } from './components/ApiExplorerPage/ApiExplorerPage';
|
||||
import { defaultDefinitionWidgets } from './components/ApiDefinitionCard';
|
||||
import { rootRoute } from './routes';
|
||||
import { apiDocsConfigRef } from './config';
|
||||
|
||||
export const plugin = createPlugin({
|
||||
export const apiDocsPlugin = createPlugin({
|
||||
id: 'api-docs',
|
||||
routes: {
|
||||
root: rootRoute,
|
||||
},
|
||||
apis: [
|
||||
createApiFactory({
|
||||
api: apiDocsConfigRef,
|
||||
@@ -38,6 +46,63 @@ export const plugin = createPlugin({
|
||||
}),
|
||||
],
|
||||
register({ router }) {
|
||||
router.addRoute(rootRoute, ApiExplorerPage);
|
||||
router.addRoute(rootRoute, Page);
|
||||
},
|
||||
});
|
||||
|
||||
export const ApiExplorerPage = apiDocsPlugin.provide(
|
||||
createRoutableExtension({
|
||||
component: () =>
|
||||
import('./components/ApiExplorerPage').then(m => m.ApiExplorerPage),
|
||||
mountPoint: rootRoute,
|
||||
}),
|
||||
);
|
||||
|
||||
export const EntityApiDefinitionCard = apiDocsPlugin.provide(
|
||||
createComponentExtension({
|
||||
component: {
|
||||
lazy: () =>
|
||||
import('./components/ApiDefinitionCard').then(m => m.ApiDefinitionCard),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
export const EntityConsumedApisCard = apiDocsPlugin.provide(
|
||||
createComponentExtension({
|
||||
component: {
|
||||
lazy: () =>
|
||||
import('./components/ApisCards').then(m => m.ConsumedApisCard),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
export const EntityConsumingComponentsCard = apiDocsPlugin.provide(
|
||||
createComponentExtension({
|
||||
component: {
|
||||
lazy: () =>
|
||||
import('./components/ComponentsCards').then(
|
||||
m => m.ConsumingComponentsCard,
|
||||
),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
export const EntityProvidedApisCard = apiDocsPlugin.provide(
|
||||
createComponentExtension({
|
||||
component: {
|
||||
lazy: () =>
|
||||
import('./components/ApisCards').then(m => m.ProvidedApisCard),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
export const EntityProvidingComponentsCard = apiDocsPlugin.provide(
|
||||
createComponentExtension({
|
||||
component: {
|
||||
lazy: () =>
|
||||
import('./components/ComponentsCards').then(
|
||||
m => m.ProvidingComponentsCard,
|
||||
),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user