deprecate EntityName, introduce CompoundEntityRef

deprecate getEntityName, introduce getCompoundEntityRef

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-03-02 21:26:22 +01:00
parent 80d2674a31
commit 36aa63022b
84 changed files with 393 additions and 268 deletions
+8 -6
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { EntityName } from '@backstage/catalog-model';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { TechDocsEntityMetadata, TechDocsMetadata } from './types';
import { createApiRef } from '@backstage/core-plugin-api';
@@ -55,14 +55,14 @@ export interface TechDocsStorageApi {
getApiOrigin(): Promise<string>;
getStorageUrl(): Promise<string>;
getBuilder(): Promise<string>;
getEntityDocs(entityId: EntityName, path: string): Promise<string>;
getEntityDocs(entityId: CompoundEntityRef, path: string): Promise<string>;
syncEntityDocs(
entityId: EntityName,
entityId: CompoundEntityRef,
logHandler?: (line: string) => void,
): Promise<SyncResult>;
getBaseUrl(
oldBaseUrl: string,
entityId: EntityName,
entityId: CompoundEntityRef,
path: string,
): Promise<string>;
}
@@ -77,6 +77,8 @@ export interface TechDocsApi {
* Set to techdocs.requestUrl as the URL for techdocs-backend API.
*/
getApiOrigin(): Promise<string>;
getTechDocsMetadata(entityId: EntityName): Promise<TechDocsMetadata>;
getEntityMetadata(entityId: EntityName): Promise<TechDocsEntityMetadata>;
getTechDocsMetadata(entityId: CompoundEntityRef): Promise<TechDocsMetadata>;
getEntityMetadata(
entityId: CompoundEntityRef,
): Promise<TechDocsEntityMetadata>;
}
+11 -6
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { EntityName } from '@backstage/catalog-model';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import {
DiscoveryApi,
@@ -62,7 +62,9 @@ export class TechDocsClient implements TechDocsApi {
*
* @param entityId - Object containing entity data like name, namespace, etc.
*/
async getTechDocsMetadata(entityId: EntityName): Promise<TechDocsMetadata> {
async getTechDocsMetadata(
entityId: CompoundEntityRef,
): Promise<TechDocsMetadata> {
const { kind, namespace, name } = entityId;
const apiOrigin = await this.getApiOrigin();
@@ -84,7 +86,7 @@ export class TechDocsClient implements TechDocsApi {
* @param entityId - Object containing entity data like name, namespace, etc.
*/
async getEntityMetadata(
entityId: EntityName,
entityId: CompoundEntityRef,
): Promise<TechDocsEntityMetadata> {
const { kind, namespace, name } = entityId;
@@ -149,7 +151,10 @@ export class TechDocsStorageClient implements TechDocsStorageApi {
* @returns HTML content of the docs page as string
* @throws Throws error when the page is not found.
*/
async getEntityDocs(entityId: EntityName, path: string): Promise<string> {
async getEntityDocs(
entityId: CompoundEntityRef,
path: string,
): Promise<string> {
const { kind, namespace, name } = entityId;
const storageUrl = await this.getStorageUrl();
@@ -190,7 +195,7 @@ export class TechDocsStorageClient implements TechDocsStorageApi {
* @throws Throws error on error from sync endpoint in Techdocs Backend
*/
async syncEntityDocs(
entityId: EntityName,
entityId: CompoundEntityRef,
logHandler: (line: string) => void = () => {},
): Promise<SyncResult> {
const { kind, namespace, name } = entityId;
@@ -243,7 +248,7 @@ export class TechDocsStorageClient implements TechDocsStorageApi {
async getBaseUrl(
oldBaseUrl: string,
entityId: EntityName,
entityId: CompoundEntityRef,
path: string,
): Promise<string> {
const { kind, namespace, name } = entityId;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Entity, EntityName } from '@backstage/catalog-model';
import { Entity, CompoundEntityRef } from '@backstage/catalog-model';
/**
* Generic representing the metadata structure for a docs table row.
@@ -26,6 +26,6 @@ export type DocsTableRow = {
resolved: {
docsUrl: string;
ownedByRelationsTitle: string;
ownedByRelations: EntityName[];
ownedByRelations: CompoundEntityRef[];
};
};
@@ -34,7 +34,7 @@ import {
alpha,
} from '@material-ui/core';
import { EntityName } from '@backstage/catalog-model';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { useApi, configApiRef } from '@backstage/core-plugin-api';
import { scmIntegrationsApiRef } from '@backstage/integration-react';
import { BackstageTheme } from '@backstage/theme';
@@ -68,7 +68,7 @@ import { useReaderState } from './useReaderState';
* @public
*/
export type ReaderProps = {
entityRef: EntityName;
entityRef: CompoundEntityRef;
withSearch?: boolean;
onReady?: () => void;
};
@@ -95,7 +95,7 @@ const TechDocsReaderContext = createContext<TechDocsReaderValue>(
const TechDocsReaderProvider = ({
children,
entityRef,
}: PropsWithChildren<{ entityRef: EntityName }>) => {
}: PropsWithChildren<{ entityRef: CompoundEntityRef }>) => {
const { '*': path } = useParams();
const { kind, namespace, name } = entityRef;
const value = useReaderState(kind, namespace, name, path);
@@ -116,7 +116,7 @@ const TechDocsReaderProvider = ({
* @internal
*/
export const withTechDocsReaderProvider =
<T extends {}>(Component: ComponentType<T>, entityRef: EntityName) =>
<T extends {}>(Component: ComponentType<T>, entityRef: CompoundEntityRef) =>
(props: T) =>
(
<TechDocsReaderProvider entityRef={entityRef}>
@@ -157,7 +157,9 @@ const headings: TypographyHeadingsKeys[] = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
* todo: Make public or stop exporting (see others: "altReaderExperiments")
* @internal
*/
export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
export const useTechDocsReaderDom = (
entityRef: CompoundEntityRef,
): Element | null => {
const navigate = useNavigate();
const theme = useTheme<BackstageTheme>();
const techdocsStorageApi = useApi(techdocsStorageApiRef);
@@ -322,7 +324,7 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
--md-source-version-icon: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M2.5 7.775V2.75a.25.25 0 0 1 .25-.25h5.025a.25.25 0 0 1 .177.073l6.25 6.25a.25.25 0 0 1 0 .354l-5.025 5.025a.25.25 0 0 1-.354 0l-6.25-6.25a.25.25 0 0 1-.073-.177zm-1.5 0V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 0 1 0 2.474l-5.026 5.026a1.75 1.75 0 0 1-2.474 0l-6.25-6.25A1.75 1.75 0 0 1 1 7.775zM6 5a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>');
--md-version-icon: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="m310.6 246.6-127.1 128c-7.1 6.3-15.3 9.4-23.5 9.4s-16.38-3.125-22.63-9.375l-127.1-128C.224 237.5-2.516 223.7 2.438 211.8S19.07 192 32 192h255.1c12.94 0 24.62 7.781 29.58 19.75s3.12 25.75-6.08 34.85z"/></svg>');
}
:host > * {
/* CODE */
--md-code-fg-color: ${theme.palette.text.primary};
@@ -438,7 +440,7 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
.md-main__inner {
margin-top: 0;
}
.md-sidebar {
height: calc(100% - 100px);
position: fixed;
@@ -450,13 +452,13 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
.md-sidebar--secondary {
right: ${theme.spacing(3)}px;
}
.md-content {
max-width: calc(100% - 16rem * 2);
margin-left: 16rem;
margin-bottom: 50px;
}
.md-footer {
position: fixed;
bottom: 0px;
@@ -471,7 +473,7 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
.md-dialog {
background-color: unset;
}
@media screen and (max-width: 76.1875em) {
.md-nav {
transition: none !important;
@@ -567,7 +569,7 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
}),
injectCss({
// Typeset
css: `
css: `
.md-typeset {
font-size: var(--md-typeset-font-size);
}
@@ -600,11 +602,11 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
.md-typeset .md-content__button {
color: var(--md-default-fg-color);
}
.md-typeset hr {
border-bottom: 0.05rem dotted ${theme.palette.divider};
}
.md-typeset details {
font-size: var(--md-typeset-font-size) !important;
}
@@ -621,7 +623,7 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
.md-typeset details[open] > summary:after {
transform: rotate(90deg) translateX(-50%) !important;
}
.md-typeset blockquote {
color: var(--md-default-fg-color--light);
border-left: 0.2rem solid var(--md-default-fg-color--light);
@@ -667,13 +669,13 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
.highlight .md-clipboard:after {
content: unset;
}
.highlight .nx {
color: ${isDarkTheme ? '#ff53a3' : '#ec407a'};
}
/* CODE HILITE */
.codehilite .gd {
.codehilite .gd {
background-color: ${
isDarkTheme ? 'rgba(248,81,73,0.65)' : '#fdd'
};
@@ -21,12 +21,12 @@ import useAsync from 'react-use/lib/useAsync';
import { techdocsApiRef } from '../../api';
import { LegacyTechDocsPage } from './LegacyTechDocsPage';
import { TechDocsEntityMetadata, TechDocsMetadata } from '../../types';
import { EntityName } from '@backstage/catalog-model';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { useApi, useApp } from '@backstage/core-plugin-api';
import { Page } from '@backstage/core-components';
/**
* Helper function that gives the children of {@link TechDocsReaderPage} acccess to techdocs and entity metadata
* Helper function that gives the children of {@link TechDocsReaderPage} access to techdocs and entity metadata
*
* @public
*/
@@ -37,7 +37,7 @@ export type TechDocsReaderPageRenderFunction = ({
}: {
techdocsMetadataValue?: TechDocsMetadata | undefined;
entityMetadataValue?: TechDocsEntityMetadata | undefined;
entityRef: EntityName;
entityRef: CompoundEntityRef;
onReady: () => void;
}) => JSX.Element;
@@ -19,7 +19,7 @@ import CodeIcon from '@material-ui/icons/Code';
import { useRouteRef } from '@backstage/core-plugin-api';
import { Header, HeaderLabel } from '@backstage/core-components';
import { EntityName, RELATION_OWNED_BY } from '@backstage/catalog-model';
import { CompoundEntityRef, RELATION_OWNED_BY } from '@backstage/catalog-model';
import {
EntityRefLink,
EntityRefLinks,
@@ -35,7 +35,7 @@ import { TechDocsEntityMetadata, TechDocsMetadata } from '../../types';
* @public
*/
export type TechDocsReaderPageHeaderProps = PropsWithChildren<{
entityRef: EntityName;
entityRef: CompoundEntityRef;
entityMetadata?: TechDocsEntityMetadata;
techDocsMetadata?: TechDocsMetadata;
}>;
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { EntityName } from '@backstage/catalog-model';
import { CompoundEntityRef } from '@backstage/catalog-model';
import useAsyncRetry from 'react-use/lib/useAsyncRetry';
import { AsyncState } from 'react-use/lib/useAsync';
import { techdocsStorageApiRef } from '../../api';
@@ -22,7 +22,7 @@ import { useApi } from '@backstage/core-plugin-api';
export type RawPage = {
content: string;
path: string;
entityId: EntityName;
entityId: CompoundEntityRef;
};
export function useRawPage(
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { EntityName } from '@backstage/catalog-model';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { TechDocsStorageApi } from '../../api';
import type { Transformer } from './transformer';
type AddBaseUrlOptions = {
techdocsStorageApi: TechDocsStorageApi;
entityId: EntityName;
entityId: CompoundEntityRef;
path: string;
};
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { EntityName } from '@backstage/catalog-model';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { SearchContextProvider, useSearch } from '@backstage/plugin-search';
import {
makeStyles,
@@ -42,7 +42,7 @@ const useStyles = makeStyles({
* @public
*/
export type TechDocsSearchProps = {
entityId: EntityName;
entityId: CompoundEntityRef;
debounceTime?: number;
};