Merge pull request #5676 from jrusso1020/jrusso/remove-circular-dependencies

Remove circular dependencies
This commit is contained in:
Fredrik Adelöw
2021-05-17 18:01:04 +02:00
committed by GitHub
78 changed files with 395 additions and 275 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ import {
rootRouteRef,
rootDocsRouteRef,
rootCatalogDocsRouteRef,
} from './plugin';
} from './routes';
import { TechDocsHome } from './home/components/TechDocsHome';
import { TechDocsPage } from './reader/components/TechDocsPage';
import { EntityPageDocs } from './EntityPageDocs';
@@ -21,7 +21,7 @@ import { Entity } from '@backstage/catalog-model';
import { Button, ItemCardGrid, ItemCardHeader } from '@backstage/core';
import { Card, CardActions, CardContent, CardMedia } from '@material-ui/core';
import { rootDocsRouteRef } from '../../plugin';
import { rootDocsRouteRef } from '../../routes';
export const DocsCardGrid = ({
entities,
@@ -22,7 +22,7 @@ import { IconButton, Tooltip } from '@material-ui/core';
import ShareIcon from '@material-ui/icons/Share';
import { Table, EmptyState, Button, SubvalueCell, Link } from '@backstage/core';
import { Entity } from '@backstage/catalog-model';
import { rootDocsRouteRef } from '../../plugin';
import { rootDocsRouteRef } from '../../routes';
export const DocsTable = ({
entities,
+5 -16
View File
@@ -20,27 +20,16 @@ import {
createComponentExtension,
createPlugin,
createRoutableExtension,
createRouteRef,
discoveryApiRef,
identityApiRef,
} from '@backstage/core';
import { techdocsApiRef, techdocsStorageApiRef } from './api';
import { TechDocsClient, TechDocsStorageClient } from './client';
export const rootRouteRef = createRouteRef({
path: '',
title: 'TechDocs Landing Page',
});
export const rootDocsRouteRef = createRouteRef({
path: ':namespace/:kind/:name/*',
title: 'Docs',
});
export const rootCatalogDocsRouteRef = createRouteRef({
path: '*',
title: 'Docs',
});
import {
rootDocsRouteRef,
rootRouteRef,
rootCatalogDocsRouteRef,
} from './routes';
export const techdocsPlugin = createPlugin({
id: 'techdocs',
@@ -23,7 +23,7 @@ import React, { useEffect, useRef, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useAsync } from 'react-use';
import { techdocsStorageApiRef } from '../../api';
import transformer, {
import {
addBaseUrl,
addGitFeedbackLink,
addLinkClickListener,
@@ -33,6 +33,7 @@ import transformer, {
rewriteDocLinks,
sanitizeDOM,
simplifyMkdocsFooter,
transform as transformer,
} from '../transformers';
import { TechDocsNotFound } from './TechDocsNotFound';
import TechDocsProgressBar from './TechDocsProgressBar';
@@ -18,7 +18,7 @@ import { TechDocsPageHeader } from './TechDocsPageHeader';
import { act } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { entityRouteRef } from '@backstage/plugin-catalog-react';
import { rootRouteRef } from '../../plugin';
import { rootRouteRef } from '../../routes';
describe('<TechDocsPageHeader />', () => {
it('should render a techdocs page header', async () => {
@@ -24,7 +24,7 @@ import {
import CodeIcon from '@material-ui/icons/Code';
import React from 'react';
import { AsyncState } from 'react-use/lib/useAsync';
import { rootRouteRef } from '../../plugin';
import { rootRouteRef } from '../../routes';
import { TechDocsMetadata } from '../../types';
type TechDocsPageHeaderProps = {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { EntityName } from '@backstage/catalog-model';
import type { Transformer } from './index';
import type { Transformer } from './transformer';
import { TechDocsStorageApi } from '../../api';
type AddBaseUrlOptions = {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Transformer } from './index';
import type { Transformer } from './transformer';
type AddLinkClickListenerOptions = {
baseUrl: string;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import transform, { Transformer } from './index';
import { Transformer, transform } from './transformer';
describe('transform', () => {
it('calls the transformers', () => {
@@ -23,30 +23,4 @@ export * from './simplifyMkdocsFooter';
export * from './onCssReady';
export * from './sanitizeDOM';
export * from './injectCss';
// TODO(freben): move all of this out of index
export type Transformer = (dom: Element) => Element;
function transform(
html: string | Element,
transformers: Transformer[],
): Element {
let dom: Element;
if (typeof html === 'string') {
dom = new DOMParser().parseFromString(html, 'text/html').documentElement;
} else if (html instanceof Element) {
dom = html;
} else {
throw new Error('dom is not a recognized type');
}
transformers.forEach(transformer => {
dom = transformer(dom);
});
return dom;
}
export default transform;
export * from './transformer';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Transformer } from './index';
import type { Transformer } from './transformer';
type InjectCssOptions = {
css: string;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Transformer } from './index';
import type { Transformer } from './transformer';
type OnCssReadyOptions = {
docStorageUrl: Promise<string>;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Transformer } from './index';
import type { Transformer } from './transformer';
export const removeMkdocsHeader = (): Transformer => {
return dom => {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Transformer } from './index';
import type { Transformer } from './transformer';
export const rewriteDocLinks = (): Transformer => {
return dom => {
@@ -16,7 +16,7 @@
// @ts-ignore
import sanitizeHtml from 'sanitize-html';
import type { Transformer } from '../index';
import type { Transformer } from '../transformer';
import { TECHDOCS_ALLOWED_TAGS } from './tags';
import { TECHDOCS_ALLOWED_ATTRIBUTES } from './attributes';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Transformer } from './index';
import type { Transformer } from './transformer';
export const simplifyMkdocsFooter = (): Transformer => {
return dom => {
@@ -0,0 +1,38 @@
/*
* Copyright 2020 Spotify AB
*
* 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 type Transformer = (dom: Element) => Element;
export const transform = (
html: string | Element,
transformers: Transformer[],
): Element => {
let dom: Element;
if (typeof html === 'string') {
dom = new DOMParser().parseFromString(html, 'text/html').documentElement;
} else if (html instanceof Element) {
dom = html;
} else {
throw new Error('dom is not a recognized type');
}
transformers.forEach(transformer => {
dom = transformer(dom);
});
return dom;
};
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright 2020 Spotify AB
*
* 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 { createRouteRef } from '@backstage/core';
export const rootRouteRef = createRouteRef({
path: '',
title: 'TechDocs Landing Page',
});
export const rootDocsRouteRef = createRouteRef({
path: ':namespace/:kind/:name/*',
title: 'Docs',
});
export const rootCatalogDocsRouteRef = createRouteRef({
path: '*',
title: 'Docs',
});
+1 -1
View File
@@ -14,8 +14,8 @@
* limitations under the License.
*/
import transformer from '../reader/transformers';
import type { Transformer } from '../reader/transformers';
import { transform as transformer } from '../reader/transformers';
export type CreateTestShadowDomOptions = {
preTransformers: Transformer[];