techdocs: Use EntityName from catalog-model as Entity type
This commit is contained in:
@@ -13,9 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ParsedEntityId } from '../src/types';
|
||||
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
import { TechDocsStorage } from '../src/api';
|
||||
|
||||
export class TechDocsDevStorageApi implements TechDocsStorage {
|
||||
@@ -25,7 +23,7 @@ export class TechDocsDevStorageApi implements TechDocsStorage {
|
||||
this.apiOrigin = apiOrigin;
|
||||
}
|
||||
|
||||
async getEntityDocs(entityId: ParsedEntityId, path: string) {
|
||||
async getEntityDocs(entityId: EntityName, path: string) {
|
||||
const { name } = entityId;
|
||||
|
||||
const url = `${this.apiOrigin}/${name}/${path}`;
|
||||
@@ -41,11 +39,7 @@ export class TechDocsDevStorageApi implements TechDocsStorage {
|
||||
return request.text();
|
||||
}
|
||||
|
||||
getBaseUrl(
|
||||
oldBaseUrl: string,
|
||||
entityId: ParsedEntityId,
|
||||
path: string,
|
||||
): string {
|
||||
getBaseUrl(oldBaseUrl: string, entityId: EntityName, path: string): string {
|
||||
const { name } = entityId;
|
||||
return new URL(oldBaseUrl, `${this.apiOrigin}/${name}/${path}`).toString();
|
||||
}
|
||||
|
||||
+12
-20
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { createApiRef } from '@backstage/core';
|
||||
import { ParsedEntityId } from './types';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
|
||||
export const techdocsStorageApiRef = createApiRef<TechDocsStorageApi>({
|
||||
id: 'plugin.techdocs.storageservice',
|
||||
@@ -28,17 +28,13 @@ export const techdocsApiRef = createApiRef<TechDocsApi>({
|
||||
});
|
||||
|
||||
export interface TechDocsStorage {
|
||||
getEntityDocs(entityId: ParsedEntityId, path: string): Promise<string>;
|
||||
getBaseUrl(
|
||||
oldBaseUrl: string,
|
||||
entityId: ParsedEntityId,
|
||||
path: string,
|
||||
): string;
|
||||
getEntityDocs(entityId: EntityName, path: string): Promise<string>;
|
||||
getBaseUrl(oldBaseUrl: string, entityId: EntityName, path: string): string;
|
||||
}
|
||||
|
||||
export interface TechDocs {
|
||||
getTechDocsMetadata(entityId: ParsedEntityId): Promise<string>;
|
||||
getEntityMetadata(entityId: ParsedEntityId): Promise<string>;
|
||||
getTechDocsMetadata(entityId: EntityName): Promise<string>;
|
||||
getEntityMetadata(entityId: EntityName): Promise<string>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +56,9 @@ export class TechDocsApi implements TechDocs {
|
||||
* static files. It includes necessary data about the docs site. This method requests techdocs-backend
|
||||
* which retrieves the TechDocs metadata.
|
||||
*
|
||||
* @param {ParsedEntityId} entityId Object containing entity data like name, namespace, etc.
|
||||
* @param {EntityName} entityId Object containing entity data like name, namespace, etc.
|
||||
*/
|
||||
async getTechDocsMetadata(entityId: ParsedEntityId) {
|
||||
async getTechDocsMetadata(entityId: EntityName) {
|
||||
const { kind, namespace, name } = entityId;
|
||||
|
||||
const requestUrl = `${this.apiOrigin}/metadata/techdocs/${namespace}/${kind}/${name}`;
|
||||
@@ -79,9 +75,9 @@ export class TechDocsApi implements TechDocs {
|
||||
* This method requests techdocs-backend which uses the catalog APIs to respond with filtered
|
||||
* information required here.
|
||||
*
|
||||
* @param {ParsedEntityId} entityId Object containing entity data like name, namespace, etc.
|
||||
* @param {EntityName} entityId Object containing entity data like name, namespace, etc.
|
||||
*/
|
||||
async getEntityMetadata(entityId: ParsedEntityId) {
|
||||
async getEntityMetadata(entityId: EntityName) {
|
||||
const { kind, namespace, name } = entityId;
|
||||
|
||||
const requestUrl = `${this.apiOrigin}/metadata/entity/${namespace}/${kind}/${name}`;
|
||||
@@ -108,12 +104,12 @@ export class TechDocsStorageApi implements TechDocsStorage {
|
||||
/**
|
||||
* Fetch HTML content as text for an individual docs page in an entity's docs site.
|
||||
*
|
||||
* @param {ParsedEntityId} entityId Object containing entity data like name, namespace, etc.
|
||||
* @param {EntityName} entityId Object containing entity data like name, namespace, etc.
|
||||
* @param {string} path The unique path to an individual docs page e.g. overview/what-is-new
|
||||
* @returns {string} HTML content of the docs page as string
|
||||
* @throws {Error} Throws error when the page is not found.
|
||||
*/
|
||||
async getEntityDocs(entityId: ParsedEntityId, path: string) {
|
||||
async getEntityDocs(entityId: EntityName, path: string) {
|
||||
const { kind, namespace, name } = entityId;
|
||||
|
||||
const url = `${this.apiOrigin}/docs/${namespace}/${kind}/${name}/${path}`;
|
||||
@@ -135,11 +131,7 @@ export class TechDocsStorageApi implements TechDocsStorage {
|
||||
return request.text();
|
||||
}
|
||||
|
||||
getBaseUrl(
|
||||
oldBaseUrl: string,
|
||||
entityId: ParsedEntityId,
|
||||
path: string,
|
||||
): string {
|
||||
getBaseUrl(oldBaseUrl: string, entityId: EntityName, path: string): string {
|
||||
const { kind, namespace, name } = entityId;
|
||||
|
||||
return new URL(
|
||||
|
||||
@@ -13,16 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useApi } from '@backstage/core';
|
||||
import { useShadowDom } from '..';
|
||||
import { useAsync } from 'react-use';
|
||||
import { techdocsStorageApiRef } from '../../api';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { ParsedEntityId } from '../../types';
|
||||
import { useTheme } from '@material-ui/core';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
import { useApi } from '@backstage/core';
|
||||
import { BackstageTheme } from '@backstage/theme';
|
||||
import { useShadowDom } from '..';
|
||||
import { techdocsStorageApiRef } from '../../api';
|
||||
import TechDocsProgressBar from './TechDocsProgressBar';
|
||||
|
||||
import transformer, {
|
||||
@@ -39,7 +38,7 @@ import transformer, {
|
||||
import { TechDocsNotFound } from './TechDocsNotFound';
|
||||
|
||||
type Props = {
|
||||
entityId: ParsedEntityId;
|
||||
entityId: EntityName;
|
||||
onReady?: () => void;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import CodeIcon from '@material-ui/icons/Code';
|
||||
import { Header, HeaderLabel, Link } from '@backstage/core';
|
||||
import { CircularProgress } from '@material-ui/core';
|
||||
import { ParsedEntityId } from '../../types';
|
||||
import { AsyncState } from 'react-use/lib/useAsync';
|
||||
import { CircularProgress } from '@material-ui/core';
|
||||
import CodeIcon from '@material-ui/icons/Code';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
import { Header, HeaderLabel, Link } from '@backstage/core';
|
||||
|
||||
type TechDocsPageHeaderProps = {
|
||||
entityId: ParsedEntityId;
|
||||
entityId: EntityName;
|
||||
metadataRequest: {
|
||||
entity: AsyncState<any>;
|
||||
techdocs: AsyncState<any>;
|
||||
|
||||
@@ -13,14 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
import type { Transformer } from './index';
|
||||
import { TechDocsStorage } from '../../api';
|
||||
import { ParsedEntityId } from '../../types';
|
||||
|
||||
type AddBaseUrlOptions = {
|
||||
techdocsStorageApi: TechDocsStorage;
|
||||
entityId: ParsedEntityId;
|
||||
entityId: EntityName;
|
||||
path: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* To uniquely identify an entity in Backstage.
|
||||
* @property {string} kind
|
||||
* @property {string} namespace
|
||||
* @property {string} name
|
||||
*/
|
||||
export type ParsedEntityId = {
|
||||
kind: string;
|
||||
namespace?: string;
|
||||
name: string;
|
||||
};
|
||||
Reference in New Issue
Block a user