This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MyPluginApi } from './types'; | |
import { DiscoveryApi } from '@backstage/core-plugin-api'; | |
export class MyPluginBackendClient implements MyPluginApi { | |
private readonly discoveryApi: DiscoveryApi; | |
constructor(options: { | |
discoveryApi: DiscoveryApi; | |
}) { | |
this.discoveryApi = options.discoveryApi; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { useEntity } from '@backstage/plugin-catalog-react'; | |
import { useMyPluginObjects } from '../../hooks/useMyPluginObjects' | |
export const ExampleComponent = () => { | |
const { entity } = useEntity(); | |
const { error, loading, status } = useMyPluginObjects(); | |
if (loading) { | |
return <div>Loading</div>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
import { useApi } from '@backstage/core-plugin-api'; | |
import { myPluginApiRef } from '../api/types'; | |
export const useMyPluginObjects = () => { | |
const [loading, setLoading] = useState<boolean>(true); | |
const [status, setStatus] = useState<string>(''); | |
const [error, setError] = useState<boolean>(false); | |
const myPluginApi = useApi(myPluginApiRef); | |
const getObjects = async () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Entity } from '@backstage/catalog-model'; | |
import { EntityProvider } from '@backstage/plugin-catalog-react'; | |
import { createDevApp } from '@backstage/dev-utils'; | |
import { TestApiProvider } from '@backstage/test-utils'; | |
import { myPluginPlugin, EntityMyPluginContent } from '../src/plugin'; | |
import { MyPluginApi, myPluginApiRef } from '../src'; | |
const mockEntity: Entity = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export { myPluginPlugin, EntityMyPluginContent } from './plugin'; | |
export * from './api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type { MyPluginApi } from './types'; | |
export { myPluginApiRef } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createApiRef } from '@backstage/core-plugin-api'; | |
export interface MyPluginApi { | |
getHealth(): Promise<{ status: string; }>; | |
} | |
export const myPluginApiRef = createApiRef<MyPluginApi>({ | |
id: 'plugin.my-plugin.service', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { useEntity } from '@backstage/plugin-catalog-react'; | |
export const ExampleComponent = () => { | |
const { entity } = useEntity(); | |
return <div>Hello {entity.metadata.name}</div>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Entity } from '@backstage/catalog-model'; | |
import { EntityProvider } from '@backstage/plugin-catalog-react'; | |
import { createDevApp } from '@backstage/dev-utils'; | |
import { myPluginPlugin, EntityMyPluginContent } from '../src/plugin'; | |
const mockEntity: Entity = { | |
apiVersion: 'backstage.io/v1alpha1', | |
kind: 'Component', | |
metadata: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { createDevApp } from '@backstage/dev-utils'; | |
import { myPluginPlugin, EntityMyPluginContent } from '../src/plugin'; | |
createDevApp() | |
.registerPlugin(myPluginPlugin) | |
.addPage({ | |
element: <EntityMyPluginContent />, | |
title: 'Root Page', | |
path: '/my-plugin' |