techdocs: add extensions for techdocs addons (#28644)

* techdocs: add extensions for techdocs addons

Signed-off-by: Jackson Chen <jacksonc@spotify.com>

* techdocs: add blueprint extension for techdocs addons

Signed-off-by: Jackson Chen <jacksonc@spotify.com>

* techdocs: move addons blueprint to alpha

Signed-off-by: Jackson Chen <jacksonc@spotify.com>

* techdocs: add addon extensions for new frontend system and add docs

Signed-off-by: Jackson Chen <jacksonc@spotify.com>

* techdocs: fix addon modules naming patterns

Signed-off-by: Jackson Chen <jacksonc@spotify.com>

* techdocs: update test utils with entity presentation api

Signed-off-by: Jackson Chen <jacksonc@spotify.com>

---------

Signed-off-by: Jackson Chen <jacksonc@spotify.com>
This commit is contained in:
Jackson Chen
2025-02-21 16:39:45 -05:00
committed by GitHub
parent b8ef3783fb
commit b5a82087a7
20 changed files with 589 additions and 30 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ export const TechDocsAddons: React.ComponentType<
attachComponentData(TechDocsAddons, TECHDOCS_ADDONS_WRAPPER_KEY, true);
const getDataKeyByName = (name: string) => {
export const getDataKeyByName = (name: string) => {
return `${TECHDOCS_ADDONS_KEY}.${name.toLocaleLowerCase('en-US')}`;
};
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright 2025 The Backstage Authors
*
* 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 { TechDocsAddonOptions } from './types';
import { attachComponentData } from '@backstage/core-plugin-api';
import { ComponentType } from 'react';
import { getDataKeyByName, TECHDOCS_ADDONS_KEY } from './addons';
import {
createExtensionBlueprint,
createExtensionDataRef,
} from '@backstage/frontend-plugin-api';
/** @alpha */
export type { TechDocsAddonOptions, TechDocsAddonLocations } from './types';
/** @alpha */
export const techDocsAddonDataRef =
createExtensionDataRef<TechDocsAddonOptions>().with({
id: 'techdocs.addon',
});
/**
* Creates an extension to add addons to the TechDocs standalone reader and entity pages.
* @alpha
*/
export const AddonBlueprint = createExtensionBlueprint({
kind: 'addon',
attachTo: [
{ id: 'page:techdocs/reader', input: 'addons' },
{ id: 'entity-content:techdocs', input: 'addons' },
],
output: [techDocsAddonDataRef],
factory: (params: TechDocsAddonOptions) => [techDocsAddonDataRef(params)],
dataRefs: {
addon: techDocsAddonDataRef,
},
});
/** @alpha */
export const attachTechDocsAddonComponentData = <P>(
techDocsAddon: ComponentType<P>,
data: TechDocsAddonOptions,
) => {
attachComponentData(techDocsAddon, TECHDOCS_ADDONS_KEY, data);
attachComponentData(techDocsAddon, getDataKeyByName(data.name), true);
};