From ae499a55ff7a1c7d2edf7f6b8ac3feeb37ee0e6d Mon Sep 17 00:00:00 2001 From: Sebastian Qvarfordt Date: Thu, 8 Oct 2020 16:59:30 +0200 Subject: [PATCH] Use new url scheme for techdocs --- plugins/techdocs-backend/src/service/router.ts | 4 ++-- .../src/techdocs/stages/publish/local.test.ts | 2 +- .../src/techdocs/stages/publish/local.ts | 2 +- plugins/techdocs/src/EntityPageDocs.tsx | 2 +- plugins/techdocs/src/api.test.ts | 4 ++-- plugins/techdocs/src/api.ts | 12 +++--------- plugins/techdocs/src/plugin.ts | 2 +- .../techdocs/src/reader/components/TechDocsHome.tsx | 6 +++--- .../techdocs/src/reader/components/TechDocsPage.tsx | 3 +-- 9 files changed, 15 insertions(+), 22 deletions(-) diff --git a/plugins/techdocs-backend/src/service/router.ts b/plugins/techdocs-backend/src/service/router.ts index 365534b9d0..f2317f749e 100644 --- a/plugins/techdocs-backend/src/service/router.ts +++ b/plugins/techdocs-backend/src/service/router.ts @@ -78,7 +78,7 @@ export async function createRouter({ } }); - router.get('/metadata/entity/:kind/:namespace/:name', async (req, res) => { + router.get('/metadata/entity/:namespace/:kind/:name', async (req, res) => { const baseUrl = config.getString('backend.baseUrl'); const { kind, namespace, name } = req.params; @@ -101,7 +101,7 @@ export async function createRouter({ } }); - router.get('/docs/:kind/:namespace/:name/*', async (req, res) => { + router.get('/docs/:namespace/:kind/:name/*', async (req, res) => { const storageUrl = config.getString('techdocs.storageUrl'); const { kind, namespace, name } = req.params; diff --git a/plugins/techdocs-backend/src/techdocs/stages/publish/local.test.ts b/plugins/techdocs-backend/src/techdocs/stages/publish/local.test.ts index 55e0a547e9..64edc5c294 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/publish/local.test.ts +++ b/plugins/techdocs-backend/src/techdocs/stages/publish/local.test.ts @@ -53,7 +53,7 @@ describe('local publisher', () => { const resultDir = path.resolve( __dirname, - `../../../../static/docs/${mockEntity.kind}/default/${mockEntity.metadata.name}`, + `../../../../static/docs/default/${mockEntity.kind}/${mockEntity.metadata.name}`, ); expect(fs.existsSync(resultDir)).toBeTruthy(); diff --git a/plugins/techdocs-backend/src/techdocs/stages/publish/local.ts b/plugins/techdocs-backend/src/techdocs/stages/publish/local.ts index f328443965..6d655d4632 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/publish/local.ts +++ b/plugins/techdocs-backend/src/techdocs/stages/publish/local.ts @@ -42,8 +42,8 @@ export class LocalPublish implements PublisherBase { const publishDir = resolvePackagePath( '@backstage/plugin-techdocs-backend', 'static/docs', - entity.kind, entityNamespace, + entity.kind, entity.metadata.name, ); diff --git a/plugins/techdocs/src/EntityPageDocs.tsx b/plugins/techdocs/src/EntityPageDocs.tsx index d10c7a5932..544c2cdadd 100644 --- a/plugins/techdocs/src/EntityPageDocs.tsx +++ b/plugins/techdocs/src/EntityPageDocs.tsx @@ -23,7 +23,7 @@ export const EntityPageDocs = ({ entity }: { entity: Entity }) => { diff --git a/plugins/techdocs/src/api.test.ts b/plugins/techdocs/src/api.test.ts index f7c52f8a7d..132976e280 100644 --- a/plugins/techdocs/src/api.test.ts +++ b/plugins/techdocs/src/api.test.ts @@ -28,7 +28,7 @@ describe('TechDocsStorageApi', () => { const storageApi = new TechDocsStorageApi({ apiOrigin: DOC_STORAGE_URL }); expect(storageApi.getBaseUrl('test.js', mockEntity, '')).toEqual( - `${DOC_STORAGE_URL}/docs/${mockEntity.kind}/${mockEntity.namespace}/${mockEntity.name}/test.js`, + `${DOC_STORAGE_URL}/docs/${mockEntity.namespace}/${mockEntity.kind}/${mockEntity.name}/test.js`, ); }); @@ -36,7 +36,7 @@ describe('TechDocsStorageApi', () => { const storageApi = new TechDocsStorageApi({ apiOrigin: DOC_STORAGE_URL }); expect(storageApi.getBaseUrl('test/', mockEntity, '')).toEqual( - `${DOC_STORAGE_URL}/docs/${mockEntity.kind}/${mockEntity.namespace}/${mockEntity.name}/test/`, + `${DOC_STORAGE_URL}/docs/${mockEntity.namespace}/${mockEntity.kind}/${mockEntity.name}/test/`, ); }); }); diff --git a/plugins/techdocs/src/api.ts b/plugins/techdocs/src/api.ts index 87a0a56a01..31e4a10e4c 100644 --- a/plugins/techdocs/src/api.ts +++ b/plugins/techdocs/src/api.ts @@ -51,9 +51,7 @@ export class TechDocsApi implements TechDocs { async getMetadata(metadataType: string, entityId: ParsedEntityId) { const { kind, namespace, name } = entityId; - const requestUrl = `${this.apiOrigin}/metadata/${metadataType}/${kind}/${ - namespace ? namespace : 'default' - }/${name}`; + const requestUrl = `${this.apiOrigin}/metadata/${metadataType}/${namespace}/${kind}/${name}`; const request = await fetch(`${requestUrl}`); const res = await request.json(); @@ -72,9 +70,7 @@ export class TechDocsStorageApi implements TechDocsStorage { async getEntityDocs(entityId: ParsedEntityId, path: string) { const { kind, namespace, name } = entityId; - const url = `${this.apiOrigin}/docs/${kind}/${ - namespace ? namespace : 'default' - }/${name}/${path}`; + const url = `${this.apiOrigin}/docs/${namespace}/${kind}/${name}/${path}`; const request = await fetch( `${url.endsWith('/') ? url : `${url}/`}index.html`, @@ -96,9 +92,7 @@ export class TechDocsStorageApi implements TechDocsStorage { return new URL( oldBaseUrl, - `${this.apiOrigin}/docs/${kind}/${ - namespace ? namespace : 'default' - }/${name}/${path}`, + `${this.apiOrigin}/docs/${namespace}/${kind}/${name}/${path}`, ).toString(); } } diff --git a/plugins/techdocs/src/plugin.ts b/plugins/techdocs/src/plugin.ts index b197bdfb76..ee2cab60fa 100644 --- a/plugins/techdocs/src/plugin.ts +++ b/plugins/techdocs/src/plugin.ts @@ -48,7 +48,7 @@ export const rootRouteRef = createRouteRef({ }); export const rootDocsRouteRef = createRouteRef({ - path: ':entityId/*', + path: ':namespace/:kind/:name/*', title: 'Docs', }); diff --git a/plugins/techdocs/src/reader/components/TechDocsHome.tsx b/plugins/techdocs/src/reader/components/TechDocsHome.tsx index c478a52127..cbef46f6c1 100644 --- a/plugins/techdocs/src/reader/components/TechDocsHome.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsHome.tsx @@ -84,9 +84,9 @@ export const TechDocsHome = () => { onClick={() => navigate( generatePath(rootDocsRouteRef.path, { - entityId: `${entity.kind}:${ - entity.metadata.namespace ?? '' - }:${entity.metadata.name}`, + namespace: entity.metadata.namespace ?? 'default', + kind: entity.kind, + name: entity.metadata.name, }), ) } diff --git a/plugins/techdocs/src/reader/components/TechDocsPage.tsx b/plugins/techdocs/src/reader/components/TechDocsPage.tsx index a70ce76191..3c4005762e 100644 --- a/plugins/techdocs/src/reader/components/TechDocsPage.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsPage.tsx @@ -24,8 +24,7 @@ import { techdocsApiRef } from '../../api'; export const TechDocsPage = () => { const [documentReady, setDocumentReady] = useState(false); - const { entityId } = useParams(); - const [kind, namespace, name] = entityId.split(':'); + const { namespace, kind, name } = useParams(); const techDocsApi = useApi(techdocsApiRef);