Merge pull request #7150 from backstage/rugvip/api-docs

Introduce API Reference
This commit is contained in:
Patrik Oldsberg
2021-09-13 16:20:23 +02:00
committed by GitHub
96 changed files with 818 additions and 3682 deletions
+6 -5
View File
@@ -105,9 +105,6 @@ jobs:
run: git diff --quiet origin/master HEAD -- yarn.lock
continue-on-error: true
- name: verify doc links
run: node scripts/verify-links.js
- name: prettier
run: yarn prettier:check '!ADOPTERS.md'
@@ -123,8 +120,12 @@ jobs:
- name: type checking and declarations
run: yarn tsc:full
- name: check api reports
run: yarn build:api-reports:only --ci
# We need to generate the API references as well, so that we can verify the doc links
- name: check api reports and generate API reference
run: yarn build:api-reports:only --ci --docs
- name: verify doc links
run: node scripts/verify-links.js
- name: build changed packages
if: ${{ steps.yarn-lock.outcome == 'success' }}
@@ -27,9 +27,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: verify doc links
run: node scripts/verify-links.js
# Skip caching of microsite dependencies, it keeps the global cache size
# smaller, which make Windows builds a lot faster for the rest of the project.
- name: yarn install
@@ -4,12 +4,6 @@ on:
push:
branches:
- master
paths:
- '.github/workflows/microsite-with-storybook-deploy.yml'
- 'packages/storybook/**'
- 'packages/core-components/src/**'
- 'microsite/**'
- 'docs/**'
jobs:
deploy-microsite-and-storybook:
@@ -41,6 +35,9 @@ jobs:
run: yarn install --frozen-lockfile
working-directory: microsite
- name: build API reference
run: yarn build:api-docs
- name: build microsite
run: yarn build
working-directory: microsite
+2
View File
@@ -0,0 +1,2 @@
# This is generated by build:api-docs in the root
reference
+106 -71
View File
@@ -12,25 +12,32 @@ however always be a need for plugins to communicate outside of its boundaries,
both with other plugins and the app itself.
Backstage provides two primary methods for plugins to communicate across their
boundaries in client-side code. The first one being the `createPlugin` API and
the registration hooks passed to the `register` method, and the second one being
Utility APIs. While the `createPlugin` API is focused on the initialization
plugins and the app, the Utility APIs provide ways for plugins to communicate
during their entire life cycle.
boundaries in client-side code. The first one being the
[createPlugin](../reference/core-plugin-api.createplugin.md) API along with the
extensions that it can provide, and the second one being Utility APIs. While the
[createPlugin](../reference/core-plugin-api.createplugin.md) API is focused on
the initialization plugins and the app, the Utility APIs provide ways for
plugins to communicate during their entire life cycle.
## Consuming APIs
Each Utility API is tied to an `ApiRef` instance, which is a global singleton
object without any additional state or functionality, its only purpose is to
reference Utility APIs. `ApiRef`s are created using `createApiRef`, which is
exported by `@backstage/core-plugin-api`. There are many
[predefined Utility APIs](../reference/utility-apis/README.md) defined in
`@backstage/core-plugin-api`, and they're all exported with a name of the
pattern `*ApiRef`, for example `errorApiRef`.
Each Utility API is tied to an [ApiRef](../reference/core-plugin-api.apiref.md)
instance, which is a global singleton object without any additional state or
functionality, its only purpose is to reference Utility APIs.
[ApiRef](../reference/core-plugin-api.apiref.md)s are created using
[createApiRef](../reference/core-plugin-api.createapiref.md), which is exported
by [@backstage/core-plugin-api](../reference/core-plugin-api.md). There are also
many predefined Utility APIs in
[@backstage/core-plugin-api](../reference/core-plugin-api.md), and they're all
exported with a name of the pattern `*ApiRef`, for example
[errorApiRef](../reference/core-plugin-api.errorapiref.md).
To access one of the Utility APIs inside a React component, use the `useApi`
hook exported by `@backstage/core-plugin-api`, or the `withApis` HOC if you
prefer class components. For example, the `ErrorApi` can be accessed like this:
To access one of the Utility APIs inside a React component, use the
[useApi](../reference/core-plugin-api.useapi.md) hook exported by
[@backstage/core-plugin-api](../reference/core-plugin-api.md), or the
[withApis](../reference/core-plugin-api.withapis.md) HOC if you prefer class
components. For example, the
[ErrorApi](../reference/core-plugin-api.errorapi.md) can be accessed like this:
```tsx
import React from 'react';
@@ -48,24 +55,31 @@ export const MyComponent = () => {
};
```
Note that there is no explicit type given for `ErrorApi`. This is because the
`errorApiRef` has the type embedded, and `useApi` is able to infer the type.
Note that there is no explicit type given for
[ErrorApi](../reference/core-plugin-api.errorapi.md). This is because the
[errorApiRef](../reference/core-plugin-api.errorapiref.md) has the type
embedded, and [useApi](../reference/core-plugin-api.useapi.md) is able to infer
the type.
Also note that consuming Utility APIs is not limited to plugins, it can be done
from any component inside Backstage, including the ones in
`@backstage/core-plugin-api`. The only requirement is that they are beneath the
`AppProvider` in the react tree.
[@backstage/core-plugin-api](../reference/core-plugin-api.md). The only
requirement is that they are beneath the `AppProvider` in the react tree.
## Supplying APIs
### API Factories
APIs are registered in the form of `ApiFactories`, which encapsulate the process
of instantiating an API. It is a collection of three things: the `ApiRef` of the
API to instantiate, a list of all required dependencies, and a factory function
that returns a new API instance.
APIs are registered in the form of
[ApiFactories](../reference/core-plugin-api.apifactory.md), which encapsulate
the process of instantiating an API. It is a collection of three things: the
[ApiRef](../reference/core-plugin-api.apiref.md) of the API to instantiate, a
list of all required dependencies, and a factory function that returns a new API
instance.
For example, this is the default `ApiFactory` for the `ErrorApi`:
For example, this is the default
[ApiFactory](../reference/core-plugin-api.apifactory.md) for the
[ErrorApi](../reference/core-plugin-api.errorapi.md):
```ts
createApiFactory({
@@ -79,18 +93,25 @@ createApiFactory({
});
```
In this example the `errorApiRef` is our API, which encapsulates the `ErrorApi`
type. The `alertApiRef` is our single dependency, which we give the name
`alertApi`, and is then passed on to the factory function, which returns an
implementation of the `ErrorApi`.
In this example the [errorApiRef](../reference/core-plugin-api.errorapiref.md)
is our API, which encapsulates the
[ErrorApi](../reference/core-plugin-api.errorapi.md) type. The
[alertApiRef](../reference/core-plugin-api.alertapiref.md) is our single
dependency, which we give the name `alertApi`, and is then passed on to the
factory function, which returns an implementation of the
[ErrorApi](../reference/core-plugin-api.errorapi.md).
The `createApiFactory` function is a thin wrapper that enables TypeScript type
inference. You may notice that there are no type annotations in the above
example, and that is because we're able to infer all types from the `ApiRef`s.
TypeScript will make sure that the return value of the `factory` function
matches the type embedded in `api`'s `ApiRef`, in this case the `ErrorApi`. It
will also match the types between the `deps` and the parameters of the `factory`
function, again using the type embedded within the `ApiRef`s.
The [createApiFactory](../reference/core-plugin-api.createapifactory.md)
function is a thin wrapper that enables TypeScript type inference. You may
notice that there are no type annotations in the above example, and that is
because we're able to infer all types from the
[ApiRef](../reference/core-plugin-api.apiref.md)s. TypeScript will make sure
that the return value of the `factory` function matches the type embedded in
`api`'s [ApiRef](../reference/core-plugin-api.apiref.md), in this case the
[ErrorApi](../reference/core-plugin-api.errorapi.md). It will also match the
types between the `deps` and the parameters of the `factory` function, again
using the type embedded within the
[ApiRef](../reference/core-plugin-api.apiref.md)s.
## Registering API Factories
@@ -102,24 +123,27 @@ app, and the app itself.
Starting with the Backstage core library, it provides implementations for all of
the core APIs. The core APIs are the ones exported by
`@backstage/core-plugin-api`, such as the `errorApiRef` and `configApiRef`. You
can find a full list of them [here](../reference/utility-apis/README.md).
[@backstage/core-plugin-api](../reference/core-plugin-api.md), such as the
[errorApiRef](../reference/core-plugin-api.errorapiref.md) and
[configApiRef](../reference/core-plugin-api.configapiref.md).
The core APIs are loaded for any app created with `createApp` from
`@backstage/core-plugin-api`, which means that there is no step that needs to be
taken to include these APIs in an app.
The core APIs are loaded for any app created with
[createApp](../reference/core-app-api.createapp.md) from
[@backstage/core-plugin-api](../reference/core-plugin-api.md), which means that
there is no step that needs to be taken to include these APIs in an app.
### Plugin APIs
In addition to the core APIs, plugins can define and export their own APIs.
While doing so they should usually also provide default implementations of their
own APIs, for example, the `catalog` plugin exports `catalogApiRef`, and also
supplies a default `ApiFactory` of that API using the `CatalogClient`. There is
one restriction to plugin-provided API Factories: plugins may not supply
factories for core APIs, trying to do so will cause the app to refuse to start.
supplies a default [ApiFactory](../reference/core-plugin-api.apifactory.md) of
that API using the `CatalogClient`. There is one restriction to plugin-provided
API Factories: plugins may not supply factories for core APIs, trying to do so
will cause the app to refuse to start.
Plugins supply their APIs through the `apis` option of `createPlugin`, for
example:
Plugins supply their APIs through the `apis` option of
[createPlugin](../reference/core-plugin-api.createplugin.md), for example:
```ts
export const techdocsPlugin = createPlugin({
@@ -144,7 +168,8 @@ Lastly, the app itself is the final point where APIs can be added, and what has
the final say in what APIs will be loaded at runtime. The app may override the
factories for any of the core or plugin APIs, with the exception of the config,
app theme, and identity APIs. These are static APIs that are tied into the
`createApp` implementation, and therefore not possible to override.
[createApp](../reference/core-app-api.createapp.md) implementation, and
therefore not possible to override.
Overriding APIs is useful for apps that want to switch out behavior to tailor it
to their environment. In some cases plugins may also export multiple
@@ -206,16 +231,19 @@ const app = createApp({
```
Note that the above line will cause an error if `IgnoreErrorApi` does not fully
implement the `ErrorApi`, as it is checked by the type embedded in the
`errorApiRef` at compile time.
implement the [ErrorApi](../reference/core-plugin-api.errorapi.md), as it is
checked by the type embedded in the
[errorApiRef](../reference/core-plugin-api.errorapiref.md) at compile time.
## Defining custom Utility APIs
Plugins are free to define their own Utility APIs. Simply define the TypeScript
interface for the API, and create an `ApiRef` using `createApiRef` exported from
`@backstage/core-plugin-api`. Also be sure to provide at least one
implementation of the API, and to declare a default factory for the API in
`createPlugin`.
interface for the API, and create an
[ApiRef](../reference/core-plugin-api.apiref.md) using
[createApiRef](../reference/core-plugin-api.createapiref.md) exported from
[@backstage/core-plugin-api](../reference/core-plugin-api.md). Also be sure to
provide at least one implementation of the API, and to declare a default factory
for the API in [createPlugin](../reference/core-plugin-api.createplugin.md).
Custom Utility APIs can be either public or private, which is up to the plugin
to choose. Private APIs do not expose an external API surface, and it's
@@ -226,15 +254,18 @@ plugin to override the API in the app. It is however important to maintain
backwards compatibility of public APIs, as you may otherwise break apps that are
using your plugin.
To make an API public, simply export the `ApiRef` of the API, and any associated
types. To make an API private, just avoid exporting the `ApiRef`, but still be
sure to supply a default factory to `createPlugin`.
To make an API public, simply export the
[ApiRef](../reference/core-plugin-api.apiref.md) of the API, and any associated
types. To make an API private, just avoid exporting the
[ApiRef](../reference/core-plugin-api.apiref.md), but still be sure to supply a
default factory to [createPlugin](../reference/core-plugin-api.createplugin.md).
Private APIs are useful for plugins that want to depend on other APIs outside of
React components, but not have to expose an entire API surface to maintain. When
using private APIs, it is fine to use the `typeof` of an implementing class as
the type parameter passed to `createApiRef`, while public APIs should always
define a separate TypeScript interface type.
the type parameter passed to
[createApiRef](../reference/core-plugin-api.createapiref.md), while public APIs
should always define a separate TypeScript interface type.
Plugins may depend on APIs from other plugins, both in React components and as
dependencies to API factories. Do however be sure to not cause circular
@@ -242,13 +273,14 @@ dependencies between plugins.
## Architecture
The `ApiRef` instances mentioned above provide a point of indirection between
consumers and producers of Utility APIs. It allows for plugins and components to
depend on APIs in a type-safe way, without having a direct reference to a
concrete implementation of the APIs. The Apps are also given a lot of
flexibility in what implementations to provide. As long as they adhere to the
contract established by an `ApiRef`, they are free to choose any implementation
they want.
The [ApiRef](../reference/core-plugin-api.apiref.md) instances mentioned above
provide a point of indirection between consumers and producers of Utility APIs.
It allows for plugins and components to depend on APIs in a type-safe way,
without having a direct reference to a concrete implementation of the APIs. The
Apps are also given a lot of flexibility in what implementations to provide. As
long as they adhere to the contract established by an
[ApiRef](../reference/core-plugin-api.apiref.md), they are free to choose any
implementation they want.
The figure below shows the relationship between
<span style="color: #82b366">different Apps</span>, that provide
@@ -271,14 +303,17 @@ directly tied to React.
The indirection provided by Utility APIs also makes it straightforward to test
components that depend on APIs, and to provide a standard common development
environment for plugins. A proper test wrapper with mocked API implementations
is not yet ready, but it will be provided as a part of `@backstage/test-utils`.
It will provide mocked variants of APIs, with additional methods for asserting a
component's interaction with the API.
is not yet ready, but it will be provided as a part of
[@backstage/test-utils](../reference/test-utils.md). It will provide mocked
variants of APIs, with additional methods for asserting a component's
interaction with the API.
The common development environment for plugins is included in
`@backstage/dev-utils`, where the exported `createDevApp` function creates an
[@backstage/dev-utils](../reference/dev-utils.md), where the exported
[createDevApp](../reference/dev-utils.createdevapp.md) function creates an
application with implementations for all core APIs already present. Contrary to
the method for wiring up Utility API implementations in an app created with
`createApp`, `createDevApp` uses automatic dependency injection. This is to make
it possible to replace any API implementation, and having that be reflected in
dependents of that API.
[createApp](../reference/core-app-api.createapp.md),
[createDevApp](../reference/dev-utils.createdevapp.md) uses automatic dependency
injection. This is to make it possible to replace any API implementation, and
having that be reflected in dependents of that API.
+2 -3
View File
@@ -60,9 +60,8 @@ small update to show this provider as a login option. The `SignInPage` component
handles this, and takes either a `provider` or `providers` (array) prop of
`SignInProviderConfig` definitions.
These reference the [ApiRef](../reference/utility-apis/README.md) exported by
the provider. Again, an example using GitHub that can be adapted to any of the
built-in providers:
These reference the `ApiRef` exported by the provider. Again, an example using
GitHub that can be adapted to any of the built-in providers:
```diff
# packages/app/src/App.tsx
+2 -1
View File
@@ -28,7 +28,8 @@ OAuth helps in that regard.
The method with which frontend plugins request access to third party services is
through [Utility APIs](../api/utility-apis.md) for each service provider. For a
full list of providers, see the
[Utility API References](../reference/utility-apis/README.md).
[@backstage/core-plugin-api](../reference/core-plugin-api.md#variables)
reference.
### Identity - WIP
+2 -2
View File
@@ -7,7 +7,7 @@ description: Documentation on Reading Backstage Configuration
## Config API
There's a common configuration API for by both frontend and backend plugins. An
API reference can be found [here](../reference/utility-apis/Config.md).
API reference can be found [here](../reference/config.config.md).
The configuration API is tailored towards failing fast in case of missing or bad
config. That's because configuration errors can always be considered programming
@@ -110,7 +110,7 @@ example `getString`. These will throw an error if there is no value available.
## Accessing ConfigApi in Frontend Plugins
The [ConfigApi](../reference/utility-apis/Config.md) in the frontend is a
The [ConfigApi](../reference/core-plugin-api.configapi.md) in the frontend is a
[UtilityApi](../api/utility-apis.md). It's accessible as usual via the
`configApiRef` exported from `@backstage/core-plugin-api`:
+2 -2
View File
@@ -82,8 +82,8 @@ export const ExamplePage = examplePlugin.provide(
This is where the plugin is created and where it creates and exports extensions
that can be imported and used the app. See reference docs for
[createPlugin](../reference/createPlugin.md) or introduction to the new
[Composability System](./composability.md).
[createPlugin](../reference/core-plugin-api.createplugin.md) or introduction to
the new [Composability System](./composability.md).
## Components
@@ -1,44 +0,0 @@
---
id: createPlugin-feature-flags
title: createPlugin - feature flags
description: Documentation on createPlugin - feature flags
---
The `featureFlags` object passed to the `register` function makes it possible
for plugins to register Feature Flags in Backstage for users to opt into. You
can use this to split out logic in your code for manual A/B testing, etc.
Here's a code sample:
```typescript
import { createPlugin } from '@backstage/core-plugin-api';
export default createPlugin({
id: 'plugin-name',
register({ featureFlags }) {
featureFlags.register('enable-example-feature');
},
});
```
## Using with useApi
To inspect the state of a feature flag inside your plugin, you can use the
`FeatureFlagsApi`, accessed via the `featureFlagsApiRef`. For example:
```tsx
import React from 'react';
import { Button } from '@material-ui/core';
import { featureFlagsApiRef, useApi } from '@backstage/core-plugin-api';
const ExamplePage = () => {
const featureFlags = useApi(featureFlagsApiRef);
return (
<div>
<MyPluginWidget>
{ featureFlags.isActive('enable-example-feature') && <ExperimentalPluginWidget> }
</div>
);
};
```
-41
View File
@@ -1,41 +0,0 @@
---
id: createPlugin
title: createPlugin
description: Documentation on createPlugin
---
Takes a plugin config as an argument and returns a new plugin.
## Plugin Config
```typescript
function createPlugin(config: PluginConfig): BackstagePlugin;
type PluginConfig = {
id: string;
register?(hooks: PluginHooks): void;
};
type PluginHooks = {
featureFlags: FeatureFlagsHooks;
};
```
- [Read more about feature flags here](createPlugin-feature-flags.md)
## Example Uses
### Creating a basic plugin
Showcasing adding a feature flag.
```jsx
import { createPlugin } from '@backstage/core-plugin-api';
export default createPlugin({
id: 'new-plugin',
register({ router, featureFlags }) {
featureFlags.register('enable-example-component');
},
});
```
-114
View File
@@ -1,114 +0,0 @@
# AlertApi
The AlertApi type is defined at
[packages/core-api/src/apis/definitions/AlertApi.ts:29](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/AlertApi.ts#L29).
The following Utility API implements this type: [alertApiRef](./README.md#alert)
## Members
### post()
Post an alert for handling by the application.
<pre>
post(alert: <a href="#alertmessage">AlertMessage</a>): void
</pre>
### alert\$()
Observe alerts posted by other parts of the application.
<pre>
alert$(): <a href="#observable">Observable</a>&lt;<a href="#alertmessage">AlertMessage</a>&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### AlertMessage
<pre>
export type AlertMessage = {
message: string;
// Severity will default to success since that is what material ui defaults the value to.
severity?: 'success' | 'info' | 'warning' | 'error';
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/AlertApi.ts:19](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/AlertApi.ts#L19).
Referenced by: [post](#post), [alert\$](#alert).
### Observable
Observable sequence of values and errors, see TC39.
https://github.com/tc39/proposal-observable
This is used as a common return type for observable values and can be created
using many different observable implementations, such as zen-observable or
RxJS 5.
<pre>
export type Observable&lt;T&gt; = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: <a href="#observer">Observer</a>&lt;T&gt;): <a href="#subscription">Subscription</a>;
subscribe(
onNext: (value: T) =&gt; void,
onError?: (error: Error) =&gt; void,
onComplete?: () =&gt; void,
): <a href="#subscription">Subscription</a>;
}
</pre>
Defined at
[packages/core-api/src/types.ts:53](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L53).
Referenced by: [alert\$](#alert).
### Observer
This file contains non-react related core types used throughout Backstage.
Observer interface for consuming an Observer, see TC39.
<pre>
export type Observer&lt;T&gt; = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
}
</pre>
Defined at
[packages/core-api/src/types.ts:24](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L24).
Referenced by: [Observable](#observable).
### Subscription
Subscription returned when subscribing to an Observable, see TC39.
<pre>
export type Subscription = {
/**
* Cancels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
}
</pre>
Defined at
[packages/core-api/src/types.ts:33](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L33).
Referenced by: [Observable](#observable).
-271
View File
@@ -1,271 +0,0 @@
# AppThemeApi
The AppThemeApi type is defined at
[packages/core-api/src/apis/definitions/AppThemeApi.ts:56](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/AppThemeApi.ts#L56).
The following Utility API implements this type:
[appThemeApiRef](./README.md#apptheme)
## Members
### getInstalledThemes()
Get a list of available themes.
<pre>
getInstalledThemes(): <a href="#apptheme">AppTheme</a>[]
</pre>
### activeThemeId\$()
Observe the currently selected theme. A value of undefined means no specific
theme has been selected.
<pre>
activeThemeId$(): <a href="#observable">Observable</a>&lt;string | undefined&gt;
</pre>
### getActiveThemeId()
Get the current theme ID. Returns undefined if no specific theme is selected.
<pre>
getActiveThemeId(): string | undefined
</pre>
### setActiveThemeId()
Set a specific theme to use in the app, overriding the default theme selection.
Clear the selection by passing in undefined.
<pre>
setActiveThemeId(themeId?: string): void
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### AppTheme
Describes a theme provided by the app.
<pre>
export type AppTheme = {
/**
* ID used to remember theme selections.
*/
id: string;
/**
* Title of the theme
*/
title: string;
/**
* Theme variant
*/
variant: 'light' | 'dark';
/**
* The specialized MaterialUI theme instance.
*/
theme: <a href="#backstagetheme">BackstageTheme</a>;
/**
* An Icon for the theme mode setting.
*/
icon?: React.ReactElement&lt;SvgIconProps&gt;;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/AppThemeApi.ts:25](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/AppThemeApi.ts#L25).
Referenced by: [getInstalledThemes](#getinstalledthemes).
### BackstagePalette
<pre>
export type BackstagePalette = Palette &amp; <a href="#paletteadditions">PaletteAdditions</a>
</pre>
Defined at
[packages/theme/src/types.ts:74](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/theme/src/types.ts#L74).
Referenced by: [BackstageTheme](#backstagetheme).
### BackstageTheme
<pre>
export interface BackstageTheme extends Theme {
palette: <a href="#backstagepalette">BackstagePalette</a>;
page: <a href="#pagetheme">PageTheme</a>;
getPageTheme: ({ themeId }: <a href="#pagethemeselector">PageThemeSelector</a>) =&gt; <a href="#pagetheme">PageTheme</a>;
}
</pre>
Defined at
[packages/theme/src/types.ts:81](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/theme/src/types.ts#L81).
Referenced by: [AppTheme](#apptheme).
### Observable
Observable sequence of values and errors, see TC39.
https://github.com/tc39/proposal-observable
This is used as a common return type for observable values and can be created
using many different observable implementations, such as zen-observable or
RxJS 5.
<pre>
export type Observable&lt;T&gt; = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: <a href="#observer">Observer</a>&lt;T&gt;): <a href="#subscription">Subscription</a>;
subscribe(
onNext: (value: T) =&gt; void,
onError?: (error: Error) =&gt; void,
onComplete?: () =&gt; void,
): <a href="#subscription">Subscription</a>;
}
</pre>
Defined at
[packages/core-api/src/types.ts:53](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L53).
Referenced by: [activeThemeId\$](#activethemeid).
### Observer
This file contains non-react related core types used throughout Backstage.
Observer interface for consuming an Observer, see TC39.
<pre>
export type Observer&lt;T&gt; = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
}
</pre>
Defined at
[packages/core-api/src/types.ts:24](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L24).
Referenced by: [Observable](#observable).
### PageTheme
<pre>
export type PageTheme = {
colors: string[];
shape: string;
backgroundImage: string;
}
</pre>
Defined at
[packages/theme/src/types.ts:103](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/theme/src/types.ts#L103).
Referenced by: [BackstageTheme](#backstagetheme).
### PageThemeSelector
<pre>
export type PageThemeSelector = {
themeId: string;
}
</pre>
Defined at
[packages/theme/src/types.ts:77](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/theme/src/types.ts#L77).
Referenced by: [BackstageTheme](#backstagetheme).
### PaletteAdditions
<pre>
type PaletteAdditions = {
status: {
ok: string;
warning: string;
error: string;
pending: string;
running: string;
aborted: string;
};
border: string;
textContrast: string;
textVerySubtle: string;
textSubtle: string;
highlight: string;
errorBackground: string;
warningBackground: string;
infoBackground: string;
errorText: string;
infoText: string;
warningText: string;
linkHover: string;
link: string;
gold: string;
navigation: {
background: string;
indicator: string;
color: string;
selectedColor: string;
};
tabbar: {
indicator: string;
};
bursts: {
fontColor: string;
slackChannelText: string;
backgroundColor: {
default: string;
};
};
pinSidebarButton: {
icon: string;
background: string;
};
banner: {
info: string;
error: string;
text: string;
link: string;
};
}
</pre>
Defined at
[packages/theme/src/types.ts:23](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/theme/src/types.ts#L23).
Referenced by: [BackstagePalette](#backstagepalette).
### Subscription
Subscription returned when subscribing to an Observable, see TC39.
<pre>
export type Subscription = {
/**
* Cancels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
}
</pre>
Defined at
[packages/core-api/src/types.ts:33](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L33).
Referenced by: [Observable](#observable).
@@ -1,100 +0,0 @@
# BackstageIdentityApi
The BackstageIdentityApi type is defined at
[packages/core-api/src/apis/definitions/auth.ts:134](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L134).
The following Utility APIs implement this type:
- [auth0AuthApiRef](./README.md#auth0auth)
- [githubAuthApiRef](./README.md#githubauth)
- [gitlabAuthApiRef](./README.md#gitlabauth)
- [googleAuthApiRef](./README.md#googleauth)
- [microsoftAuthApiRef](./README.md#microsoftauth)
- [oauth2ApiRef](./README.md#oauth2)
- [oidcAuthApiRef](./README.md#oidcauth)
- [oktaAuthApiRef](./README.md#oktaauth)
- [oneloginAuthApiRef](./README.md#oneloginauth)
- [samlAuthApiRef](./README.md#samlauth)
## Members
### getBackstageIdentity()
Get the user's identity within Backstage. This should normally not be called
directly, use the @IdentityApi instead.
If the optional flag is not set, a session is guaranteed to be returned, while
if the optional flag is set, the session may be undefined. See
@AuthRequestOptions for more details.
<pre>
getBackstageIdentity(
options?: <a href="#authrequestoptions">AuthRequestOptions</a>,
): Promise&lt;<a href="#backstageidentity">BackstageIdentity</a> | undefined&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### AuthRequestOptions
<pre>
export type AuthRequestOptions = {
/**
* If this is set to true, the user will not be prompted to log in,
* and an empty response will be returned if there is no existing session.
*
* This can be used to perform a check whether the user is logged in, or if you don't
* want to force a user to be logged in, but provide functionality if they already are.
*
* @default false
*/
optional?: boolean;
/**
* If this is set to true, the request will bypass the regular oauth login modal
* and open the login popup directly.
*
* The method must be called synchronously from a user action for this to work in all browsers.
*
* @default false
*/
instantPopup?: boolean;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:40](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L40).
Referenced by: [getBackstageIdentity](#getbackstageidentity).
### BackstageIdentity
<pre>
export type BackstageIdentity = {
/**
* The backstage user ID.
*/
id: string;
/**
* An ID token that can be used to authenticate the user within Backstage.
*/
idToken: string;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:147](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L147).
Referenced by: [getBackstageIdentity](#getbackstageidentity).
-187
View File
@@ -1,187 +0,0 @@
# Config
The Config type is defined at
[packages/config/src/types.ts:32](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/config/src/types.ts#L32).
The following Utility API implements this type:
[configApiRef](./README.md#config)
## Members
### has()
<pre>
has(key: string): boolean
</pre>
### keys()
<pre>
keys(): string[]
</pre>
### get()
<pre>
get(key?: string): <a href="#jsonvalue">JsonValue</a>
</pre>
### getOptional()
<pre>
getOptional(key?: string): <a href="#jsonvalue">JsonValue</a> | undefined
</pre>
### getConfig()
<pre>
getConfig(key: string): <a href="#config">Config</a>
</pre>
### getOptionalConfig()
<pre>
getOptionalConfig(key: string): <a href="#config">Config</a> | undefined
</pre>
### getConfigArray()
<pre>
getConfigArray(key: string): <a href="#config">Config</a>[]
</pre>
### getOptionalConfigArray()
<pre>
getOptionalConfigArray(key: string): <a href="#config">Config</a>[] | undefined
</pre>
### getNumber()
<pre>
getNumber(key: string): number
</pre>
### getOptionalNumber()
<pre>
getOptionalNumber(key: string): number | undefined
</pre>
### getBoolean()
<pre>
getBoolean(key: string): boolean
</pre>
### getOptionalBoolean()
<pre>
getOptionalBoolean(key: string): boolean | undefined
</pre>
### getString()
<pre>
getString(key: string): string
</pre>
### getOptionalString()
<pre>
getOptionalString(key: string): string | undefined
</pre>
### getStringArray()
<pre>
getStringArray(key: string): string[]
</pre>
### getOptionalStringArray()
<pre>
getOptionalStringArray(key: string): string[] | undefined
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### Config
<pre>
export type Config = {
has(key: string): boolean;
keys(): string[];
get(key?: string): <a href="#jsonvalue">JsonValue</a>;
getOptional(key?: string): <a href="#jsonvalue">JsonValue</a> | undefined;
getConfig(key: string): Config;
getOptionalConfig(key: string): <a href="#config">Config</a> | undefined;
getConfigArray(key: string): <a href="#config">Config</a>[];
getOptionalConfigArray(key: string): <a href="#config">Config</a>[] | undefined;
getNumber(key: string): number;
getOptionalNumber(key: string): number | undefined;
getBoolean(key: string): boolean;
getOptionalBoolean(key: string): boolean | undefined;
getString(key: string): string;
getOptionalString(key: string): string | undefined;
getStringArray(key: string): string[];
getOptionalStringArray(key: string): string[] | undefined;
}
</pre>
Defined at
[packages/config/src/types.ts:32](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/config/src/types.ts#L32).
Referenced by: [getConfig](#getconfig), [getOptionalConfig](#getoptionalconfig),
[getConfigArray](#getconfigarray),
[getOptionalConfigArray](#getoptionalconfigarray), [Config](#config).
### JsonArray
<pre>
export type JsonArray = <a href="#jsonvalue">JsonValue</a>[]
</pre>
Defined at
[packages/config/src/types.ts:18](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/config/src/types.ts#L18).
Referenced by: [JsonValue](#jsonvalue).
### JsonObject
<pre>
export type JsonObject = { [key in string]?: <a href="#jsonvalue">JsonValue</a> }
</pre>
Defined at
[packages/config/src/types.ts:17](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/config/src/types.ts#L17).
Referenced by: [JsonValue](#jsonvalue).
### JsonValue
<pre>
export type JsonValue =
| <a href="#jsonobject">JsonObject</a>
| <a href="#jsonarray">JsonArray</a>
| number
| string
| boolean
| null
</pre>
Defined at
[packages/config/src/types.ts:19](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/config/src/types.ts#L19).
Referenced by: [get](#get), [getOptional](#getoptional),
[JsonObject](#jsonobject), [JsonArray](#jsonarray), [Config](#config).
@@ -1,24 +0,0 @@
# DiscoveryApi
The DiscoveryApi type is defined at
[packages/core-api/src/apis/definitions/DiscoveryApi.ts:30](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/DiscoveryApi.ts#L30).
The following Utility API implements this type:
[discoveryApiRef](./README.md#discovery)
## Members
### getBaseUrl()
Returns the HTTP base backend URL for a given plugin, without a trailing slash.
This method must always be called just before making a request, as opposed to
fetching the URL when constructing an API client. That is to ensure that more
flexible routing patterns can be supported.
For example, asking for the URL for `auth` may return something like
`https://backstage.example.com/api/auth`
<pre>
getBaseUrl(pluginId: string): Promise&lt;string&gt;
</pre>
-134
View File
@@ -1,134 +0,0 @@
# ErrorApi
The ErrorApi type is defined at
[packages/core-api/src/apis/definitions/ErrorApi.ts:53](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/ErrorApi.ts#L53).
The following Utility API implements this type: [errorApiRef](./README.md#error)
## Members
### post()
Post an error for handling by the application.
<pre>
post(error: <a href="#error">Error</a>, context?: <a href="#errorcontext">ErrorContext</a>): void
</pre>
### error\$()
Observe errors posted by other parts of the application.
<pre>
error$(): <a href="#observable">Observable</a>&lt;{ error: <a href="#error">Error</a>; context?: <a href="#errorcontext">ErrorContext</a> }&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### Error
Mirrors the JavaScript Error class, for the purpose of providing documentation
and optional fields.
<pre>
type Error = {
name: string;
message: string;
stack?: string;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/ErrorApi.ts:24](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/ErrorApi.ts#L24).
Referenced by: [post](#post), [error\$](#error).
### ErrorContext
Provides additional information about an error that was posted to the
application.
<pre>
export type ErrorContext = {
// If set to true, this error should not be displayed to the user. Defaults to false.
hidden?: boolean;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/ErrorApi.ts:33](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/ErrorApi.ts#L33).
Referenced by: [post](#post), [error\$](#error).
### Observable
Observable sequence of values and errors, see TC39.
https://github.com/tc39/proposal-observable
This is used as a common return type for observable values and can be created
using many different observable implementations, such as zen-observable or
RxJS 5.
<pre>
export type Observable&lt;T&gt; = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: <a href="#observer">Observer</a>&lt;T&gt;): <a href="#subscription">Subscription</a>;
subscribe(
onNext: (value: T) =&gt; void,
onError?: (error: Error) =&gt; void,
onComplete?: () =&gt; void,
): <a href="#subscription">Subscription</a>;
}
</pre>
Defined at
[packages/core-api/src/types.ts:53](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L53).
Referenced by: [error\$](#error).
### Observer
This file contains non-react related core types used throughout Backstage.
Observer interface for consuming an Observer, see TC39.
<pre>
export type Observer&lt;T&gt; = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
}
</pre>
Defined at
[packages/core-api/src/types.ts:24](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L24).
Referenced by: [Observable](#observable).
### Subscription
Subscription returned when subscribing to an Observable, see TC39.
<pre>
export type Subscription = {
/**
* Cancels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
}
</pre>
Defined at
[packages/core-api/src/types.ts:33](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L33).
Referenced by: [Observable](#observable).
@@ -1,113 +0,0 @@
# FeatureFlagsApi
The FeatureFlagsApi type is defined at
[packages/core-api/src/apis/definitions/FeatureFlagsApi.ts:60](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/FeatureFlagsApi.ts#L60).
The following Utility API implements this type:
[featureFlagsApiRef](./README.md#featureflags)
## Members
### registerFlag()
Registers a new feature flag. Once a feature flag has been registered it can be
toggled by users, and read back to enable or disable features.
<pre>
registerFlag(flag: <a href="#featureflag">FeatureFlag</a>): void
</pre>
### getRegisteredFlags()
Get a list of all registered flags.
<pre>
getRegisteredFlags(): <a href="#featureflag">FeatureFlag</a>[]
</pre>
### isActive()
Whether the feature flag with the given name is currently activated for the
user.
<pre>
isActive(name: string): boolean
</pre>
### save()
Save the user's choice of feature flag states.
<pre>
save(options: <a href="#featureflagssaveoptions">FeatureFlagsSaveOptions</a>): void
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### FeatureFlag
The feature flags API is used to toggle functionality to users across plugins
and Backstage.
Plugins can use this API to register feature flags that they have available for
users to enable/disable, and this API will centralize the current user's state
of which feature flags they would like to enable.
This is ideal for Backstage plugins, as well as your own App, to trial
incomplete or unstable upcoming features. Although there will be a common
interface for users to enable and disable feature flags, this API acts as
another way to enable/disable.
<pre>
export type FeatureFlag = {
name: string;
pluginId: string;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/FeatureFlagsApi.ts:31](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/FeatureFlagsApi.ts#L31).
Referenced by: [registerFlag](#registerflag),
[getRegisteredFlags](#getregisteredflags).
### FeatureFlagState
<pre>
export enum FeatureFlagState {
None = 0,
Active = 1,
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/FeatureFlagsApi.ts:36](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/FeatureFlagsApi.ts#L36).
Referenced by: [FeatureFlagsSaveOptions](#featureflagssaveoptions).
### FeatureFlagsSaveOptions
Options to use when saving feature flags.
<pre>
export type FeatureFlagsSaveOptions = {
/**
* The new feature flag states to save.
*/
states: Record&lt;string, <a href="#featureflagstate">FeatureFlagState</a>&gt;;
/**
* Whether the saves states should be merged into the existing ones, or replace them.
*
* Defaults to false.
*/
merge?: boolean;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/FeatureFlagsApi.ts:44](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/FeatureFlagsApi.ts#L44).
Referenced by: [save](#save).
@@ -1,81 +0,0 @@
# IdentityApi
The IdentityApi type is defined at
[packages/core-api/src/apis/definitions/IdentityApi.ts:22](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/IdentityApi.ts#L22).
The following Utility API implements this type:
[identityApiRef](./README.md#identity)
## Members
### getUserId()
The ID of the signed in user. This ID is not meant to be presented to the user,
but used as an opaque string to pass on to backends or use in frontend logic.
TODO: The intention of the user ID is to be able to tie the user to an identity
that is known by the catalog and/or identity backend. It should for example be
possible to fetch all owned components using this ID.
<pre>
getUserId(): string
</pre>
### getProfile()
The profile of the signed in user.
<pre>
getProfile(): <a href="#profileinfo">ProfileInfo</a>
</pre>
### getIdToken()
An OpenID Connect ID Token which proves the identity of the signed in user.
The ID token will be undefined if the signed in user does not have a verified
identity, such as a demo user or mocked user for e2e tests.
<pre>
getIdToken(): Promise&lt;string | undefined&gt;
</pre>
### signOut()
Sign out the current user
<pre>
signOut(): Promise&lt;void&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### ProfileInfo
Profile information of the user.
<pre>
export type ProfileInfo = {
/**
* Email ID.
*/
email?: string;
/**
* Display name that can be presented to the user.
*/
displayName?: string;
/**
* URL to an avatar image of the user.
*/
picture?: string;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:162](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L162).
Referenced by: [getProfile](#getprofile).
-117
View File
@@ -1,117 +0,0 @@
# OAuthApi
The OAuthApi type is defined at
[packages/core-api/src/apis/definitions/auth.ts:67](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L67).
The following Utility APIs implement this type:
- [githubAuthApiRef](./README.md#githubauth)
- [gitlabAuthApiRef](./README.md#gitlabauth)
- [googleAuthApiRef](./README.md#googleauth)
- [microsoftAuthApiRef](./README.md#microsoftauth)
- [oauth2ApiRef](./README.md#oauth2)
- [oidcAuthApiRef](./README.md#oidcauth)
- [oktaAuthApiRef](./README.md#oktaauth)
- [oneloginAuthApiRef](./README.md#oneloginauth)
## Members
### getAccessToken()
Requests an OAuth 2 Access Token, optionally with a set of scopes. The access
token allows you to make requests on behalf of the user, and the copes may grant
you broader access, depending on the auth provider.
Each auth provider has separate handling of scope, so you need to look at the
documentation for each one to know what scope you need to request.
This method is cheap and should be called each time an access token is used. Do
not for example store the access token in React component state, as that could
cause the token to expire. Instead fetch a new access token for each request.
Be sure to include all required scopes when requesting an access token. When
testing your implementation it is best to log out the Backstage session and then
visit your plugin page directly, as you might already have some required scopes
in your existing session. Not requesting the correct scopes can lead to 403 or
other authorization errors, which can be tricky to debug.
If the user has not yet granted access to the provider and the set of requested
scopes, the user will be prompted to log in. The returned promise will not
resolve until the user has successfully logged in. The returned promise can be
rejected, but only if the user rejects the login request.
<pre>
getAccessToken(
scope?: <a href="#oauthscope">OAuthScope</a>,
options?: <a href="#authrequestoptions">AuthRequestOptions</a>,
): Promise&lt;string&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### AuthRequestOptions
<pre>
export type AuthRequestOptions = {
/**
* If this is set to true, the user will not be prompted to log in,
* and an empty response will be returned if there is no existing session.
*
* This can be used to perform a check whether the user is logged in, or if you don't
* want to force a user to be logged in, but provide functionality if they already are.
*
* @default false
*/
optional?: boolean;
/**
* If this is set to true, the request will bypass the regular oauth login modal
* and open the login popup directly.
*
* The method must be called synchronously from a user action for this to work in all browsers.
*
* @default false
*/
instantPopup?: boolean;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:40](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L40).
Referenced by: [getAccessToken](#getaccesstoken).
### OAuthScope
This file contains declarations for common interfaces of auth-related APIs. The
declarations should be used to signal which type of authentication and
authorization methods each separate auth provider supports.
For example, a Google OAuth provider that supports OAuth 2 and OpenID Connect,
would be declared as follows:
const googleAuthApiRef = createApiRef<OAuthApi & OpenIDConnectApi>({ ... })
An array of scopes, or a scope string formatted according to the auth provider,
which is typically a space separated list.
See the documentation for each auth provider for the list of scopes supported by
each provider.
<pre>
export type OAuthScope = string | string[]
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:38](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L38).
Referenced by: [getAccessToken](#getaccesstoken).
@@ -1,233 +0,0 @@
# OAuthRequestApi
The OAuthRequestApi type is defined at
[packages/core-api/src/apis/definitions/OAuthRequestApi.ts:99](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/OAuthRequestApi.ts#L99).
The following Utility API implements this type:
[oauthRequestApiRef](./README.md#oauthrequest)
## Members
### createAuthRequester()
A utility for showing login popups or similar things, and merging together
multiple requests for different scopes into one request that includes all
scopes.
The passed in options provide information about the login provider, and how to
handle auth requests.
The returned AuthRequester function is used to request login with new scopes.
These requests are merged together and forwarded to the auth handler, as soon as
a consumer of auth requests triggers an auth flow.
See AuthRequesterOptions, AuthRequester, and handleAuthRequests for more info.
<pre>
createAuthRequester&lt;AuthResponse&gt;(
options: <a href="#authrequesteroptions">AuthRequesterOptions</a>&lt;AuthResponse&gt;,
): <a href="#authrequester">AuthRequester</a>&lt;AuthResponse&gt;
</pre>
### authRequest\$()
Observers pending auth requests. The returned observable will emit all current
active auth request, at most one for each created auth requester.
Each request has its own info about the login provider, forwarded from the auth
requester options.
Depending on user interaction, the request should either be rejected, or used to
trigger the auth handler. If the request is rejected, all pending AuthRequester
calls will fail with a "RejectedError". If a auth is triggered, and the auth
handler resolves successfully, then all currently pending AuthRequester calls
will resolve to the value returned by the onAuthRequest call.
<pre>
authRequest$(): <a href="#observable">Observable</a>&lt;<a href="#pendingauthrequest">PendingAuthRequest</a>[]&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### AuthProvider
Information about the auth provider that we're requesting a login towards.
This should be shown to the user so that they can be informed about what login
is being requested before a popup is shown.
<pre>
export type AuthProvider = {
/**
* Title for the auth provider, for example "GitHub"
*/
title: string;
/**
* Icon for the auth provider.
*/
icon: IconComponent;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/OAuthRequestApi.ts:27](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/OAuthRequestApi.ts#L27).
Referenced by: [AuthRequesterOptions](#authrequesteroptions),
[PendingAuthRequest](#pendingauthrequest).
### AuthRequester
Function used to trigger new auth requests for a set of scopes.
The returned promise will resolve to the same value returned by the
onAuthRequest in the AuthRequesterOptions. Or rejected, if the request is
rejected.
This function can be called multiple times before the promise resolves. All
calls will be merged into one request, and the scopes forwarded to the
onAuthRequest will be the union of all requested scopes.
<pre>
export type AuthRequester&lt;AuthResponse&gt; = (
scopes: Set&lt;string&gt;,
) =&gt; Promise&lt;AuthResponse&gt;
</pre>
Defined at
[packages/core-api/src/apis/definitions/OAuthRequestApi.ts:66](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/OAuthRequestApi.ts#L66).
Referenced by: [createAuthRequester](#createauthrequester).
### AuthRequesterOptions
Describes how to handle auth requests. Both how to show them to the user, and
what to do when the user accesses the auth request.
<pre>
export type AuthRequesterOptions&lt;AuthResponse&gt; = {
/**
* Information about the auth provider, which will be forwarded to auth requests.
*/
provider: <a href="#authprovider">AuthProvider</a>;
/**
* Implementation of the auth flow, which will be called synchronously when
* trigger() is called on an auth requests.
*/
onAuthRequest(scopes: Set&lt;string&gt;): Promise&lt;AuthResponse&gt;;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/OAuthRequestApi.ts:43](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/OAuthRequestApi.ts#L43).
Referenced by: [createAuthRequester](#createauthrequester).
### Observable
Observable sequence of values and errors, see TC39.
https://github.com/tc39/proposal-observable
This is used as a common return type for observable values and can be created
using many different observable implementations, such as zen-observable or
RxJS 5.
<pre>
export type Observable&lt;T&gt; = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: <a href="#observer">Observer</a>&lt;T&gt;): <a href="#subscription">Subscription</a>;
subscribe(
onNext: (value: T) =&gt; void,
onError?: (error: Error) =&gt; void,
onComplete?: () =&gt; void,
): <a href="#subscription">Subscription</a>;
}
</pre>
Defined at
[packages/core-api/src/types.ts:53](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L53).
Referenced by: [authRequest\$](#authrequest).
### Observer
This file contains non-react related core types used throughout Backstage.
Observer interface for consuming an Observer, see TC39.
<pre>
export type Observer&lt;T&gt; = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
}
</pre>
Defined at
[packages/core-api/src/types.ts:24](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L24).
Referenced by: [Observable](#observable).
### PendingAuthRequest
An pending auth request for a single auth provider. The request will remain in
this pending state until either reject() or trigger() is called.
Any new requests for the same provider are merged into the existing pending
request, meaning there will only ever be a single pending request for a given
provider.
<pre>
export type PendingAuthRequest = {
/**
* Information about the auth provider, as given in the AuthRequesterOptions
*/
provider: <a href="#authprovider">AuthProvider</a>;
/**
* Rejects the request, causing all pending AuthRequester calls to fail with "RejectedError".
*/
reject: () =&gt; void;
/**
* Trigger the auth request to continue the auth flow, by for example showing a popup.
*
* Synchronously calls onAuthRequest with all scope currently in the request.
*/
trigger(): Promise&lt;void&gt;;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/OAuthRequestApi.ts:77](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/OAuthRequestApi.ts#L77).
Referenced by: [authRequest\$](#authrequest).
### Subscription
Subscription returned when subscribing to an Observable, see TC39.
<pre>
export type Subscription = {
/**
* Cancels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
}
</pre>
Defined at
[packages/core-api/src/types.ts:33](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L33).
Referenced by: [Observable](#observable).
@@ -1,75 +0,0 @@
# OpenIdConnectApi
The OpenIdConnectApi type is defined at
[packages/core-api/src/apis/definitions/auth.ts:99](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L99).
The following Utility APIs implement this type:
- [auth0AuthApiRef](./README.md#auth0auth)
- [googleAuthApiRef](./README.md#googleauth)
- [microsoftAuthApiRef](./README.md#microsoftauth)
- [oauth2ApiRef](./README.md#oauth2)
- [oidcAuthApiRef](./README.md#oidcauth)
- [oktaAuthApiRef](./README.md#oktaauth)
- [oneloginAuthApiRef](./README.md#oneloginauth)
## Members
### getIdToken()
Requests an OpenID Connect ID Token.
This method is cheap and should be called each time an ID token is used. Do not
for example store the id token in React component state, as that could cause the
token to expire. Instead fetch a new id token for each request.
If the user has not yet logged in to Google inside Backstage, the user will be
prompted to log in. The returned promise will not resolve until the user has
successfully logged in. The returned promise can be rejected, but only if the
user rejects the login request.
<pre>
getIdToken(options?: <a href="#authrequestoptions">AuthRequestOptions</a>): Promise&lt;string&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### AuthRequestOptions
<pre>
export type AuthRequestOptions = {
/**
* If this is set to true, the user will not be prompted to log in,
* and an empty response will be returned if there is no existing session.
*
* This can be used to perform a check whether the user is logged in, or if you don't
* want to force a user to be logged in, but provide functionality if they already are.
*
* @default false
*/
optional?: boolean;
/**
* If this is set to true, the request will bypass the regular oauth login modal
* and open the login popup directly.
*
* The method must be called synchronously from a user action for this to work in all browsers.
*
* @default false
*/
instantPopup?: boolean;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:40](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L40).
Referenced by: [getIdToken](#getidtoken).
@@ -1,104 +0,0 @@
# ProfileInfoApi
The ProfileInfoApi type is defined at
[packages/core-api/src/apis/definitions/auth.ts:117](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L117).
The following Utility APIs implement this type:
- [auth0AuthApiRef](./README.md#auth0auth)
- [githubAuthApiRef](./README.md#githubauth)
- [gitlabAuthApiRef](./README.md#gitlabauth)
- [googleAuthApiRef](./README.md#googleauth)
- [microsoftAuthApiRef](./README.md#microsoftauth)
- [oauth2ApiRef](./README.md#oauth2)
- [oidcAuthApiRef](./README.md#oidcauth)
- [oktaAuthApiRef](./README.md#oktaauth)
- [oneloginAuthApiRef](./README.md#oneloginauth)
- [samlAuthApiRef](./README.md#samlauth)
## Members
### getProfile()
Get profile information for the user as supplied by this auth provider.
If the optional flag is not set, a session is guaranteed to be returned, while
if the optional flag is set, the session may be undefined. See
@AuthRequestOptions for more details.
<pre>
getProfile(options?: <a href="#authrequestoptions">AuthRequestOptions</a>): Promise&lt;<a href="#profileinfo">ProfileInfo</a> | undefined&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### AuthRequestOptions
<pre>
export type AuthRequestOptions = {
/**
* If this is set to true, the user will not be prompted to log in,
* and an empty response will be returned if there is no existing session.
*
* This can be used to perform a check whether the user is logged in, or if you don't
* want to force a user to be logged in, but provide functionality if they already are.
*
* @default false
*/
optional?: boolean;
/**
* If this is set to true, the request will bypass the regular oauth login modal
* and open the login popup directly.
*
* The method must be called synchronously from a user action for this to work in all browsers.
*
* @default false
*/
instantPopup?: boolean;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:40](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L40).
Referenced by: [getProfile](#getprofile).
### ProfileInfo
Profile information of the user.
<pre>
export type ProfileInfo = {
/**
* Email ID.
*/
email?: string;
/**
* Display name that can be presented to the user.
*/
displayName?: string;
/**
* URL to an avatar image of the user.
*/
picture?: string;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:162](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L162).
Referenced by: [getProfile](#getprofile).
-202
View File
@@ -1,202 +0,0 @@
# Backstage Core Utility APIs
The following is a list of all Utility APIs defined by `@backstage/core`. They
are available to use by plugins and components, and can be accessed using the
`useApi` hook, also provided by `@backstage/core`. For more information, see
https://github.com/backstage/backstage/blob/master/docs/api/utility-apis.md.
### alert
Used to report alerts and forward them to the app
Implemented type: [AlertApi](./AlertApi.md)
ApiRef:
[alertApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/AlertApi.ts#L41)
### appTheme
API Used to configure the app theme, and enumerate options
Implemented type: [AppThemeApi](./AppThemeApi.md)
ApiRef:
[appThemeApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/AppThemeApi.ts#L80)
### auth0Auth
Provides authentication towards Auth0 APIs
Implemented types: [OpenIdConnectApi](./OpenIdConnectApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[auth0AuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L275)
### config
Used to access runtime configuration
Implemented type: [Config](./Config.md)
ApiRef:
[configApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/ConfigApi.ts#L25)
### discovery
Provides service discovery of backend plugins
Implemented type: [DiscoveryApi](./DiscoveryApi.md)
ApiRef:
[discoveryApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/DiscoveryApi.ts#L44)
### error
Used to report errors and forward them to the app
Implemented type: [ErrorApi](./ErrorApi.md)
ApiRef:
[errorApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/ErrorApi.ts#L65)
### featureFlags
Used to toggle functionality in features across Backstage
Implemented type: [FeatureFlagsApi](./FeatureFlagsApi.md)
ApiRef:
[featureFlagsApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/FeatureFlagsApi.ts#L83)
### githubAuth
Provides authentication towards GitHub APIs
Implemented types: [OAuthApi](./OAuthApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[githubAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L232)
### gitlabAuth
Provides authentication towards GitLab APIs
Implemented types: [OAuthApi](./OAuthApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[gitlabAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L262)
### googleAuth
Provides authentication towards Google APIs and identities
Implemented types: [OAuthApi](./OAuthApi.md),
[OpenIdConnectApi](./OpenIdConnectApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[googleAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L215)
### identity
Provides access to the identity of the signed in user
Implemented type: [IdentityApi](./IdentityApi.md)
ApiRef:
[identityApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/IdentityApi.ts#L53)
### microsoftAuth
Provides authentication towards Microsoft APIs and identities
Implemented types: [OAuthApi](./OAuthApi.md),
[OpenIdConnectApi](./OpenIdConnectApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[microsoftAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L289)
### oauth2
Example of how to use oauth2 custom provider
Implemented types: [OAuthApi](./OAuthApi.md),
[OpenIdConnectApi](./OpenIdConnectApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[oauth2ApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L303)
### oauthRequest
An API for implementing unified OAuth flows in Backstage
Implemented type: [OAuthRequestApi](./OAuthRequestApi.md)
ApiRef:
[oauthRequestApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/OAuthRequestApi.ts#L130)
### oidcAuth
Example of how to use oidc custom provider
Implemented types: [OAuthApi](./OAuthApi.md),
[OpenIdConnectApi](./OpenIdConnectApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[oidcAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L317)
### oktaAuth
Provides authentication towards Okta APIs
Implemented types: [OAuthApi](./OAuthApi.md),
[OpenIdConnectApi](./OpenIdConnectApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[oktaAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L245)
### oneloginAuth
Provides authentication towards OneLogin APIs and identities
Implemented types: [OAuthApi](./OAuthApi.md),
[OpenIdConnectApi](./OpenIdConnectApi.md),
[ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[oneloginAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L338)
### samlAuth
Example of how to use SAML custom provider
Implemented types: [ProfileInfoApi](./ProfileInfoApi.md),
[BackstageIdentityApi](./BackstageIdentityApi.md), [SessionApi](./SessionApi.md)
ApiRef:
[samlAuthApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L331)
### storage
Provides the ability to store data which is unique to the user
Implemented type: [StorageApi](./StorageApi.md)
ApiRef:
[storageApiRef](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/StorageApi.ts#L68)
-144
View File
@@ -1,144 +0,0 @@
# SessionApi
The SessionApi type is defined at
[packages/core-api/src/apis/definitions/auth.ts:190](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L190).
The following Utility APIs implement this type:
- [auth0AuthApiRef](./README.md#auth0auth)
- [githubAuthApiRef](./README.md#githubauth)
- [gitlabAuthApiRef](./README.md#gitlabauth)
- [googleAuthApiRef](./README.md#googleauth)
- [microsoftAuthApiRef](./README.md#microsoftauth)
- [oauth2ApiRef](./README.md#oauth2)
- [oidcAuthApiRef](./README.md#oidcauth)
- [oktaAuthApiRef](./README.md#oktaauth)
- [oneloginAuthApiRef](./README.md#oneloginauth)
- [samlAuthApiRef](./README.md#samlauth)
## Members
### signIn()
Sign in with a minimum set of permissions.
<pre>
signIn(): Promise&lt;void&gt;
</pre>
### signOut()
Sign out from the current session. This will reload the page.
<pre>
signOut(): Promise&lt;void&gt;
</pre>
### sessionState\$()
Observe the current state of the auth session. Emits the current state on
subscription.
<pre>
sessionState$(): <a href="#observable">Observable</a>&lt;<a href="#sessionstate">SessionState</a>&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### Observable
Observable sequence of values and errors, see TC39.
https://github.com/tc39/proposal-observable
This is used as a common return type for observable values and can be created
using many different observable implementations, such as zen-observable or
RxJS 5.
<pre>
export type Observable&lt;T&gt; = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: <a href="#observer">Observer</a>&lt;T&gt;): <a href="#subscription">Subscription</a>;
subscribe(
onNext: (value: T) =&gt; void,
onError?: (error: Error) =&gt; void,
onComplete?: () =&gt; void,
): <a href="#subscription">Subscription</a>;
}
</pre>
Defined at
[packages/core-api/src/types.ts:53](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L53).
Referenced by: [sessionState\$](#sessionstate).
### Observer
This file contains non-react related core types used throughout Backstage.
Observer interface for consuming an Observer, see TC39.
<pre>
export type Observer&lt;T&gt; = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
}
</pre>
Defined at
[packages/core-api/src/types.ts:24](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L24).
Referenced by: [Observable](#observable).
### SessionState
Session state values passed to subscribers of the SessionApi.
<pre>
export enum SessionState {
SignedIn = 'SignedIn',
SignedOut = 'SignedOut',
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:182](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/auth.ts#L182).
Referenced by: [sessionState\$](#sessionstate).
### Subscription
Subscription returned when subscribing to an Observable, see TC39.
<pre>
export type Subscription = {
/**
* Cancels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
}
</pre>
Defined at
[packages/core-api/src/types.ts:33](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L33).
Referenced by: [Observable](#observable).
@@ -1,119 +0,0 @@
# SessionStateApi
The SessionStateApi type is defined at
[packages/core-api/src/apis/definitions/auth.ts:201](https://github.com/backstage/backstage/blob/82d329555c16af46db9b4e5cd2f44a3cc006a52e/packages/core-api/src/apis/definitions/auth.ts#L201).
The following Utility APIs implement this type:
- [auth0AuthApiRef](./README.md#auth0auth)
- [githubAuthApiRef](./README.md#githubauth)
- [gitlabAuthApiRef](./README.md#gitlabauth)
- [googleAuthApiRef](./README.md#googleauth)
- [microsoftAuthApiRef](./README.md#microsoftauth)
- [oauth2ApiRef](./README.md#oauth2)
- [oktaAuthApiRef](./README.md#oktaauth)
## Members
### sessionState\$()
<pre>
sessionState$(): <a href="#observable">Observable</a>&lt;<a href="#sessionstate">SessionState</a>&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### Observable
Observable sequence of values and errors, see TC39.
https://github.com/tc39/proposal-observable
This is used as a common return type for observable values and can be created
using many different observable implementations, such as zen-observable or
RxJS 5.
<pre>
export type Observable&lt;T&gt; = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: <a href="#observer">Observer</a>&lt;T&gt;): <a href="#subscription">Subscription</a>;
subscribe(
onNext: (value: T) =&gt; void,
onError?: (error: Error) =&gt; void,
onComplete?: () =&gt; void,
): <a href="#subscription">Subscription</a>;
}
</pre>
Defined at
[packages/core-api/src/types.ts:53](https://github.com/backstage/backstage/blob/82d329555c16af46db9b4e5cd2f44a3cc006a52e/packages/core-api/src/types.ts#L53).
Referenced by: [sessionState\$](#sessionstate).
### Observer
This file contains non-react related core types used through Backstage.
Observer interface for consuming an Observer, see TC39.
<pre>
export type Observer&lt;T&gt; = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
}
</pre>
Defined at
[packages/core-api/src/types.ts:24](https://github.com/backstage/backstage/blob/82d329555c16af46db9b4e5cd2f44a3cc006a52e/packages/core-api/src/types.ts#L24).
Referenced by: [Observable](#observable).
### SessionState
Session state values passed to subscribers of the SessionStateApi.
<pre>
export enum SessionState {
SignedIn = 'SignedIn',
SignedOut = 'SignedOut',
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/auth.ts:192](https://github.com/backstage/backstage/blob/82d329555c16af46db9b4e5cd2f44a3cc006a52e/packages/core-api/src/apis/definitions/auth.ts#L192).
Referenced by: [sessionState\$](#sessionstate).
### Subscription
Subscription returned when subscribing to an Observable, see TC39.
<pre>
export type Subscription = {
/**
* Cancels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
}
</pre>
Defined at
[packages/core-api/src/types.ts:33](https://github.com/backstage/backstage/blob/82d329555c16af46db9b4e5cd2f44a3cc006a52e/packages/core-api/src/types.ts#L33).
Referenced by: [Observable](#observable).
-186
View File
@@ -1,186 +0,0 @@
# StorageApi
The StorageApi type is defined at
[packages/core-api/src/apis/definitions/StorageApi.ts:31](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/StorageApi.ts#L31).
The following Utility API implements this type:
[storageApiRef](./README.md#storage)
## Members
### forBucket()
Create a bucket to store data in.
<pre>
forBucket(name: string): <a href="#storageapi">StorageApi</a>
</pre>
### get()
Get the current value for persistent data, use observe\$ to be notified of
updates.
<pre>
get&lt;T&gt;(key: string): T | undefined
</pre>
### remove()
Remove persistent data.
<pre>
remove(key: string): Promise&lt;void&gt;
</pre>
### set()
Save persistent data, and emit messages to anyone that is using observe\$ for
this key
<pre>
set(key: string, data: any): Promise&lt;void&gt;
</pre>
### observe\$()
Observe changes on a particular key in the bucket
<pre>
observe$&lt;T&gt;(key: string): <a href="#observable">Observable</a>&lt;<a href="#storagevaluechange">StorageValueChange</a>&lt;T&gt;&gt;
</pre>
## Supporting types
These types are part of the API declaration, but may not be unique to this API.
### Observable
Observable sequence of values and errors, see TC39.
https://github.com/tc39/proposal-observable
This is used as a common return type for observable values and can be created
using many different observable implementations, such as zen-observable or
RxJS 5.
<pre>
export type Observable&lt;T&gt; = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: <a href="#observer">Observer</a>&lt;T&gt;): <a href="#subscription">Subscription</a>;
subscribe(
onNext: (value: T) =&gt; void,
onError?: (error: Error) =&gt; void,
onComplete?: () =&gt; void,
): <a href="#subscription">Subscription</a>;
}
</pre>
Defined at
[packages/core-api/src/types.ts:53](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L53).
Referenced by: [observe\$](#observe), [StorageApi](#storageapi).
### Observer
This file contains non-react related core types used throughout Backstage.
Observer interface for consuming an Observer, see TC39.
<pre>
export type Observer&lt;T&gt; = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
}
</pre>
Defined at
[packages/core-api/src/types.ts:24](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L24).
Referenced by: [Observable](#observable).
### StorageApi
<pre>
export interface StorageApi {
/**
* Create a bucket to store data in.
* @param {String} name Namespace for the storage to be stored under,
* will inherit previous namespaces too
*/
forBucket(name: string): StorageApi;
/**
* Get the current value for persistent data, use observe$ to be notified of updates.
*
* @param {String} key Unique key associated with the data.
* @return {Object} data The data that should is stored.
*/
get&lt;T&gt;(key: string): T | undefined;
/**
* Remove persistent data.
*
* @param {String} key Unique key associated with the data.
*/
remove(key: string): Promise&lt;void&gt;;
/**
* Save persistent data, and emit messages to anyone that is using observe$ for this key
*
* @param {String} key Unique key associated with the data.
*/
set(key: string, data: any): Promise&lt;void&gt;;
/**
* Observe changes on a particular key in the bucket
* @param {String} key Unique key associated with the data
*/
observe$&lt;T&gt;(key: string): <a href="#observable">Observable</a>&lt;<a href="#storagevaluechange">StorageValueChange</a>&lt;T&gt;&gt;;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/StorageApi.ts:31](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/StorageApi.ts#L31).
Referenced by: [forBucket](#forbucket).
### StorageValueChange
<pre>
export type StorageValueChange&lt;T = any&gt; = {
key: string;
newValue?: T;
}
</pre>
Defined at
[packages/core-api/src/apis/definitions/StorageApi.ts:21](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/apis/definitions/StorageApi.ts#L21).
Referenced by: [observe\$](#observe), [StorageApi](#storageapi).
### Subscription
Subscription returned when subscribing to an Observable, see TC39.
<pre>
export type Subscription = {
/**
* Cancels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
}
</pre>
Defined at
[packages/core-api/src/types.ts:33](https://github.com/backstage/backstage/blob/a4dbd8353cfa4d4d4334473e2c33afcda64e130d/packages/core-api/src/types.ts#L33).
Referenced by: [Observable](#observable).
+7 -4
View File
@@ -28,15 +28,18 @@ try {
}
const errors = [];
const ids = Object.keys(metadata);
for (let id of ids) {
// reference/index is generated, so make sure this goes through even if it's not there
const knownIds = new Set([...Object.keys(metadata), 'reference/index']);
for (const id in metadata) {
const { next, previous } = metadata[id];
if (next && !ids.includes(next)) {
if (next && !knownIds.has(next)) {
errors.push(`Next ${next} does not exist in ${id}.`);
}
if (previous && !ids.includes(previous)) {
if (previous && !knownIds.has(previous)) {
errors.push(`Previous ${previous} does not exist in ${id}.`);
}
}
+5 -10
View File
@@ -234,21 +234,16 @@
"dls/contributing-to-storybook",
"dls/figma"
],
"API references": [
"API Reference": [
{
"type": "subcategory",
"label": "TypeScript API",
"ids": [
"api/utility-apis",
"reference/utility-apis/README",
"reference/createPlugin",
"reference/createPlugin-feature-flags"
]
"label": "Guides",
"ids": ["api/utility-apis"]
},
{
"type": "subcategory",
"label": "Backend APIs",
"ids": ["api/backend"]
"label": "API Reference",
"ids": ["reference/index"]
}
],
"Tutorials": [
+2 -7
View File
@@ -156,14 +156,9 @@ nav:
- Design: 'dls/design.md'
- Contributing to Storybook: 'dls/contributing-to-storybook.md'
- Figma: 'dls/figma.md'
- API references:
- TypeScript API:
- API Reference:
- Guides:
- Utility APIs: 'api/utility-apis.md'
- reference/utility-apis/README: 'reference/utility-apis/README.md'
- createPlugin: 'reference/createPlugin.md'
- createPlugin -feature flags: 'reference/createPlugin-feature-flags.md'
- Backend APIs:
- Backend: 'api/backend.md'
- Tutorials:
- Future developer journey: 'tutorials/journey.md'
- Migrating away from @backstage/core: 'tutorials/migrating-away-from-core.md'
+4 -3
View File
@@ -54,9 +54,10 @@
},
"version": "1.0.0",
"dependencies": {
"@microsoft/api-documenter": "^7.13.30",
"@microsoft/api-extractor": "^7.18.1",
"@microsoft/api-extractor-model": "^7.13.3"
"@microsoft/api-documenter": "^7.13.47",
"@microsoft/api-extractor": "^7.18.7",
"@microsoft/api-extractor-model": "^7.13.5",
"@microsoft/tsdoc": "^0.13.2"
},
"devDependencies": {
"@types/webpack": "^5.28.0",
File diff suppressed because it is too large Load Diff
@@ -22,7 +22,7 @@ import { AlertMessage, useApi, alertApiRef } from '@backstage/core-plugin-api';
import pluralize from 'pluralize';
// TODO: improve on this and promote to a shared component for use by all apps.
export const AlertDisplay = () => {
export function AlertDisplay(_props: {}) {
const [messages, setMessages] = useState<Array<AlertMessage>>([]);
const alertApi = useApi(alertApiRef);
@@ -73,4 +73,4 @@ export const AlertDisplay = () => {
</Alert>
</Snackbar>
);
};
}
@@ -41,7 +41,8 @@ export type AvatarProps = {
customStyles?: CSSProperties;
};
export const Avatar = ({ displayName, picture, customStyles }: AvatarProps) => {
export function Avatar(props: AvatarProps) {
const { displayName, picture, customStyles } = props;
const classes = useStyles();
return (
<MaterialAvatar
@@ -56,4 +57,4 @@ export const Avatar = ({ displayName, picture, customStyles }: AvatarProps) => {
{displayName && extractInitials(displayName)}
</MaterialAvatar>
);
};
}
@@ -23,10 +23,19 @@ import { Link, LinkProps } from '../Link';
type Props = MaterialButtonProps & Omit<LinkProps, 'variant' | 'color'>;
declare function ButtonType(props: Props): JSX.Element;
/**
* Thin wrapper on top of material-ui's Button component
* Makes the Button to utilise react-router
*/
export const Button = React.forwardRef<any, Props>((props, ref) => (
const ActualButton = React.forwardRef<any, Props>((props, ref) => (
<MaterialButton ref={ref} component={Link} {...props} />
));
)) as { (props: Props): JSX.Element };
// TODO(Rugvip): We use this as a workaround to make the exported type be a
// function, which makes our API reference docs much nicer.
// The first type to be exported gets priority, but it will
// be thrown away when compiling to JS.
// @ts-ignore
export { ButtonType as Button, ActualButton as Button };
@@ -225,13 +225,8 @@ const indexer = (
};
}, {});
export const CheckboxTree = ({
subCategories,
label,
selected,
onChange,
triggerReset,
}: CheckboxTreeProps) => {
export function CheckboxTree(props: CheckboxTreeProps) {
const { subCategories, label, selected, onChange, triggerReset } = props;
const classes = useStyles();
const [state, dispatch] = useReducer(reducer, indexer(subCategories));
@@ -355,4 +350,4 @@ export const CheckboxTree = ({
</List>
</div>
);
};
}
@@ -30,14 +30,15 @@ type Props = {
customStyle?: any;
};
export const CodeSnippet = ({
text,
language,
showLineNumbers = false,
showCopyCodeButton = false,
highlightedNumbers,
customStyle,
}: Props) => {
export const CodeSnippet = (props: Props) => {
const {
text,
language,
showLineNumbers = false,
showCopyCodeButton = false,
highlightedNumbers,
customStyle,
} = props;
const theme = useTheme<BackstageTheme>();
const mode = theme.palette.type === 'dark' ? dark : docco;
const highlightColor = theme.palette.type === 'dark' ? '#256bf3' : '#e6ffed';
@@ -47,7 +47,7 @@ const defaultProps = {
tooltipText: 'Text copied to clipboard',
};
export const CopyTextButton = (props: Props) => {
export function CopyTextButton(props: Props) {
const { text, tooltipDelay, tooltipText } = {
...defaultProps,
...props,
@@ -84,7 +84,7 @@ export const CopyTextButton = (props: Props) => {
</Tooltip>
</>
);
};
}
// Type check for the JS files using this core component
CopyTextButton.propTypes = {
@@ -24,7 +24,8 @@ type CreateButtonProps = {
title: string;
} & Partial<Pick<LinkProps, 'to'>>;
export const CreateButton = ({ title, to }: CreateButtonProps) => {
export function CreateButton(props: CreateButtonProps) {
const { title, to } = props;
const isXSScreen = useMediaQuery<BackstageTheme>(theme =>
theme.breakpoints.down('xs'),
);
@@ -48,4 +49,4 @@ export const CreateButton = ({ title, to }: CreateButtonProps) => {
{title}
</Button>
);
};
}
@@ -60,27 +60,28 @@ export type DependencyGraphProps = React.SVGProps<SVGSVGElement> & {
const WORKSPACE_ID = 'workspace';
export function DependencyGraph({
edges,
nodes,
renderNode,
direction = Direction.TOP_BOTTOM,
align,
nodeMargin = 50,
edgeMargin = 10,
rankMargin = 50,
paddingX = 0,
paddingY = 0,
acyclicer,
ranker = Ranker.NETWORK_SIMPLEX,
labelPosition = LabelPosition.RIGHT,
labelOffset = 10,
edgeRanks = 1,
edgeWeight = 1,
renderLabel,
defs,
...svgProps
}: DependencyGraphProps) {
export function DependencyGraph(props: DependencyGraphProps) {
const {
edges,
nodes,
renderNode,
direction = Direction.TOP_BOTTOM,
align,
nodeMargin = 50,
edgeMargin = 10,
rankMargin = 50,
paddingX = 0,
paddingY = 0,
acyclicer,
ranker = Ranker.NETWORK_SIMPLEX,
labelPosition = LabelPosition.RIGHT,
labelOffset = 10,
edgeRanks = 1,
edgeWeight = 1,
renderLabel,
defs,
...svgProps
} = props;
const theme: BackstageTheme = useTheme();
const [containerWidth, setContainerWidth] = React.useState<number>(100);
const [containerHeight, setContainerHeight] = React.useState<number>(100);
@@ -70,12 +70,8 @@ type Props = {
fixed?: boolean;
};
export const DismissableBanner = ({
variant,
message,
id,
fixed = false,
}: Props) => {
export const DismissableBanner = (props: Props) => {
const { variant, message, id, fixed = false } = props;
const classes = useStyles();
const storageApi = useApi(storageApiRef);
const notificationsStore = storageApi.forBucket('notifications');
@@ -38,7 +38,8 @@ type Props = {
action?: JSX.Element;
};
export const EmptyState = ({ title, description, missing, action }: Props) => {
export function EmptyState(props: Props) {
const { title, description, missing, action } = props;
const classes = useStyles();
return (
<Grid
@@ -67,4 +68,4 @@ export const EmptyState = ({ title, description, missing, action }: Props) => {
</Grid>
</Grid>
);
};
}
@@ -45,7 +45,8 @@ const useStyles = makeStyles<BackstageTheme>(theme => ({
},
}));
export const MissingAnnotationEmptyState = ({ annotation }: Props) => {
export function MissingAnnotationEmptyState(props: Props) {
const { annotation } = props;
const classes = useStyles();
const description = (
<>
@@ -84,4 +85,4 @@ export const MissingAnnotationEmptyState = ({ annotation }: Props) => {
}
/>
);
};
}
@@ -92,12 +92,8 @@ export type ErrorPanelProps = {
/**
* Renders a warning panel as the effect of an error.
*/
export const ErrorPanel = ({
title,
error,
defaultExpanded,
children,
}: PropsWithChildren<ErrorPanelProps>) => {
export function ErrorPanel(props: PropsWithChildren<ErrorPanelProps>) {
const { title, error, defaultExpanded, children } = props;
return (
<WarningPanel
severity="error"
@@ -112,4 +108,4 @@ export const ErrorPanel = ({
/>
</WarningPanel>
);
};
}
@@ -93,12 +93,8 @@ type Placement = {
textWidth: number;
};
export const FeatureCalloutCircular = ({
featureId,
title,
description,
children,
}: PropsWithChildren<Props>) => {
export function FeatureCalloutCircular(props: PropsWithChildren<Props>) {
const { featureId, title, description, children } = props;
const { show, hide } = useShowCallout(featureId);
const portalElement = usePortal('core.callout');
const wrapperRef = useRef<HTMLDivElement>(null);
@@ -196,4 +192,4 @@ export const FeatureCalloutCircular = ({
)}
</>
);
};
}
@@ -31,7 +31,8 @@ type Props = {
links: IconLinkVerticalProps[];
};
export const HeaderIconLinkRow = ({ links }: Props) => {
export function HeaderIconLinkRow(props: Props) {
const { links } = props;
const classes = useStyles();
return (
<nav className={classes.links}>
@@ -40,4 +41,4 @@ export const HeaderIconLinkRow = ({ links }: Props) => {
))}
</nav>
);
};
}
@@ -181,7 +181,7 @@ function useSmoothScroll(
return setScrollTarget;
}
export const HorizontalScrollGrid = (props: PropsWithChildren<Props>) => {
export function HorizontalScrollGrid(props: PropsWithChildren<Props>) {
const {
scrollStep = 100,
scrollSpeed = 50,
@@ -244,4 +244,4 @@ export const HorizontalScrollGrid = (props: PropsWithChildren<Props>) => {
)}
</div>
);
};
}
@@ -38,7 +38,7 @@ const useStyles = makeStyles({
},
});
export const Lifecycle = (props: Props) => {
export function Lifecycle(props: Props) {
const classes = useStyles(props);
const { shorthand, alpha } = props;
return shorthand ? (
@@ -53,4 +53,4 @@ export const Lifecycle = (props: Props) => {
{alpha ? 'Alpha' : 'Beta'}
</span>
);
};
}
@@ -31,11 +31,13 @@ export type LinkProps = MaterialLinkProps &
component?: ElementType<any>;
};
declare function LinkType(props: LinkProps): JSX.Element;
/**
* Thin wrapper on top of material-ui's Link component
* Makes the Link to utilise react-router
*/
export const Link = React.forwardRef<any, LinkProps>((props, ref) => {
const ActualLink = React.forwardRef<any, LinkProps>((props, ref) => {
const to = String(props.to);
const external = isExternalUri(to);
const newWindow = external && !!/^https?:/.exec(to);
@@ -52,3 +54,10 @@ export const Link = React.forwardRef<any, LinkProps>((props, ref) => {
<MaterialLink ref={ref} component={RouterLink} {...props} />
);
});
// TODO(Rugvip): We use this as a workaround to make the exported type be a
// function, which makes our API reference docs much nicer.
// The first type to be exported gets priority, but it will
// be thrown away when compiling to JS.
// @ts-ignore
export { LinkType as Link, ActualLink as Link };
@@ -76,7 +76,8 @@ const renderers = {
* Renders markdown with the default dialect [gfm - GitHub flavored Markdown](https://github.github.com/gfm/) to backstage theme styled HTML.
* If you just want to render to plain [CommonMark](https://commonmark.org/), set the dialect to `'common-mark'`
*/
export const MarkdownContent = ({ content, dialect = 'gfm' }: Props) => {
export function MarkdownContent(props: Props) {
const { content, dialect = 'gfm' } = props;
const classes = useStyles();
return (
<ReactMarkdown
@@ -86,4 +87,4 @@ export const MarkdownContent = ({ content, dialect = 'gfm' }: Props) => {
renderers={renderers}
/>
);
};
}
@@ -44,7 +44,7 @@ const useStyles = makeStyles<Theme>(theme => ({
},
}));
export const OAuthRequestDialog = () => {
export function OAuthRequestDialog(_props: {}) {
const classes = useStyles();
const [busy, setBusy] = useState(false);
const oauthRequestApi = useApi(oauthRequestApiRef);
@@ -86,4 +86,4 @@ export const OAuthRequestDialog = () => {
</DialogActions>
</Dialog>
);
};
}
@@ -32,7 +32,7 @@ const useStyles = makeStyles({
},
});
export const OverflowTooltip = (props: Props) => {
export function OverflowTooltip(props: Props) {
const [hover, setHover] = useState(false);
const classes = useStyles();
@@ -54,4 +54,4 @@ export const OverflowTooltip = (props: Props) => {
/>
</Tooltip>
);
};
}
@@ -17,7 +17,7 @@
import React, { useState, useEffect, PropsWithChildren } from 'react';
import { LinearProgress, LinearProgressProps } from '@material-ui/core';
export const Progress = (props: PropsWithChildren<LinearProgressProps>) => {
export function Progress(props: PropsWithChildren<LinearProgressProps>) {
const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
@@ -30,4 +30,4 @@ export const Progress = (props: PropsWithChildren<LinearProgressProps>) => {
) : (
<div style={{ display: 'none' }} />
);
};
}
@@ -77,7 +77,7 @@ export function getProgressColor(
return palette.status.ok;
}
export const Gauge = (props: Props) => {
export function Gauge(props: Props) {
const classes = useStyles(props);
const theme = useTheme<BackstageTheme>();
const { value, fractional, inverse, unit, max } = {
@@ -103,4 +103,4 @@ export const Gauge = (props: Props) => {
</div>
</div>
);
};
}
@@ -37,7 +37,7 @@ const useStyles = makeStyles({
},
});
export const GaugeCard = (props: Props) => {
export function GaugeCard(props: Props) {
const classes = useStyles(props);
const { title, subheader, progress, inverse, deepLink, variant } = props;
@@ -53,4 +53,4 @@ export const GaugeCard = (props: Props) => {
</InfoCard>
</div>
);
};
}
@@ -28,7 +28,8 @@ type Props = {
value: number;
};
export const LinearGauge = ({ value }: Props) => {
export function LinearGauge(props: Props) {
const { value } = props;
const theme = useTheme<BackstageTheme>();
if (isNaN(value)) {
return null;
@@ -50,4 +51,4 @@ export const LinearGauge = ({ value }: Props) => {
</span>
</Tooltip>
);
};
}
@@ -39,11 +39,8 @@ const useStyles = makeStyles(theme => ({
* Has special treatment for ResponseError errors, to display rich
* server-provided information about what happened.
*/
export const ResponseErrorPanel = ({
title,
error,
defaultExpanded,
}: ErrorPanelProps) => {
export function ResponseErrorPanel(props: ErrorPanelProps) {
const { title, error, defaultExpanded } = props;
const classes = useStyles();
if (error.name !== 'ResponseError') {
@@ -93,4 +90,4 @@ export const ResponseErrorPanel = ({
</>
</ErrorPanel>
);
};
}
@@ -106,15 +106,16 @@ export type SelectProps = {
triggerReset?: boolean;
};
export const SelectComponent = ({
multiple,
items,
label,
placeholder,
selected,
onChange,
triggerReset,
}: SelectProps) => {
export function SelectComponent(props: SelectProps) {
const {
multiple,
items,
label,
placeholder,
selected,
onChange,
triggerReset,
} = props;
const classes = useStyles();
const [value, setValue] = useState<Selection>(
selected || (multiple ? [] : ''),
@@ -228,4 +229,4 @@ export const SelectComponent = ({
</ClickAwayListener>
</div>
);
};
}
@@ -47,12 +47,8 @@ export interface StepperProps {
activeStep?: number;
}
export const SimpleStepper = ({
children,
elevated,
onStepChange,
activeStep = 0,
}: PropsWithChildren<StepperProps>) => {
export function SimpleStepper(props: PropsWithChildren<StepperProps>) {
const { children, elevated, onStepChange, activeStep = 0 } = props;
const [stepIndex, setStepIndex] = useState<number>(activeStep);
const [stepHistory, setStepHistory] = useState<number[]>([0]);
@@ -95,4 +91,4 @@ export const SimpleStepper = ({
{stepIndex >= Children.count(children) - 1 && endStep}
</>
);
};
}
@@ -30,13 +30,8 @@ const useStyles = makeStyles(theme => ({
},
}));
export const SimpleStepperStep = ({
title,
children,
end,
actions,
...muiProps
}: PropsWithChildren<StepProps>) => {
export function SimpleStepperStep(props: PropsWithChildren<StepProps>) {
const { title, children, end, actions, ...muiProps } = props;
const classes = useStyles();
// The end step is not a part of the stepper
@@ -58,4 +53,4 @@ export const SimpleStepperStep = ({
</StepContent>
</MuiStep>
);
};
}
@@ -63,7 +63,7 @@ const useStyles = makeStyles<BackstageTheme>(theme => ({
},
}));
export const StatusOK = (props: PropsWithChildren<{}>) => {
export function StatusOK(props: PropsWithChildren<{}>) {
const classes = useStyles(props);
return (
<span
@@ -73,9 +73,9 @@ export const StatusOK = (props: PropsWithChildren<{}>) => {
{...props}
/>
);
};
}
export const StatusWarning = (props: PropsWithChildren<{}>) => {
export function StatusWarning(props: PropsWithChildren<{}>) {
const classes = useStyles(props);
return (
<span
@@ -85,9 +85,9 @@ export const StatusWarning = (props: PropsWithChildren<{}>) => {
{...props}
/>
);
};
}
export const StatusError = (props: PropsWithChildren<{}>) => {
export function StatusError(props: PropsWithChildren<{}>) {
const classes = useStyles(props);
return (
<span
@@ -97,9 +97,9 @@ export const StatusError = (props: PropsWithChildren<{}>) => {
{...props}
/>
);
};
}
export const StatusPending = (props: PropsWithChildren<{}>) => {
export function StatusPending(props: PropsWithChildren<{}>) {
const classes = useStyles(props);
return (
<span
@@ -109,9 +109,9 @@ export const StatusPending = (props: PropsWithChildren<{}>) => {
{...props}
/>
);
};
}
export const StatusRunning = (props: PropsWithChildren<{}>) => {
export function StatusRunning(props: PropsWithChildren<{}>) {
const classes = useStyles(props);
return (
<span
@@ -121,9 +121,9 @@ export const StatusRunning = (props: PropsWithChildren<{}>) => {
{...props}
/>
);
};
}
export const StatusAborted = (props: PropsWithChildren<{}>) => {
export function StatusAborted(props: PropsWithChildren<{}>) {
const classes = useStyles(props);
return (
<span
@@ -133,4 +133,4 @@ export const StatusAborted = (props: PropsWithChildren<{}>) => {
{...props}
/>
);
};
}
@@ -153,11 +153,8 @@ type Props = {
options?: any;
};
export const StructuredMetadataTable = ({
metadata,
dense = true,
options,
}: Props) => {
export function StructuredMetadataTable(props: Props) {
const { metadata, dense = true, options } = props;
const metadataItems = mapToItems(metadata, options || {});
return <MetadataTable dense={dense}>{metadataItems}</MetadataTable>;
};
}
@@ -80,7 +80,8 @@ const SupportListItem = ({ item }: { item: SupportItem }) => {
);
};
export const SupportButton = ({ title, children }: SupportButtonProps) => {
export function SupportButton(props: SupportButtonProps) {
const { title, children } = props;
const { items } = useSupportConfig();
const [popoverOpen, setPopoverOpen] = useState(false);
@@ -160,4 +161,4 @@ export const SupportButton = ({ title, children }: SupportButtonProps) => {
</Popover>
</>
);
};
}
@@ -47,7 +47,8 @@ export function useSelectedSubRoute(subRoutes: SubRoute[]): {
};
}
export const RoutedTabs = ({ routes }: { routes: SubRoute[] }) => {
export function RoutedTabs(props: { routes: SubRoute[] }) {
const { routes } = props;
const navigate = useNavigate();
const { index, route, element } = useSelectedSubRoute(routes);
const headerTabs = useMemo(
@@ -80,4 +81,4 @@ export const RoutedTabs = ({ routes }: { routes: SubRoute[] }) => {
</Content>
</>
);
};
}
@@ -82,10 +82,10 @@ export function createSubRoutesFromChildren(
* </TabbedLayout>
* ```
*/
export const TabbedLayout = ({ children }: PropsWithChildren<{}>) => {
const routes = createSubRoutesFromChildren(children);
export function TabbedLayout(props: PropsWithChildren<{}>) {
const routes = createSubRoutesFromChildren(props.children);
return <RoutedTabs routes={routes} />;
};
}
TabbedLayout.Route = Route;
@@ -33,7 +33,8 @@ type SubvalueCellProps = {
subvalue: React.ReactNode;
};
export const SubvalueCell = ({ value, subvalue }: SubvalueCellProps) => {
export function SubvalueCell(props: SubvalueCellProps) {
const { value, subvalue } = props;
const classes = useSubvalueCellStyles();
return (
@@ -42,4 +43,4 @@ export const SubvalueCell = ({ value, subvalue }: SubvalueCellProps) => {
<div className={classes.subvalue}>{subvalue}</div>
</>
);
};
}
@@ -263,21 +263,21 @@ export function TableToolbar(toolbarProps: {
);
}
export function Table<T extends object = {}>({
columns,
options,
title,
subtitle,
filters,
initialState,
emptyContent,
onStateChange,
...props
}: TableProps<T>) {
export function Table<T extends object = {}>(props: TableProps<T>) {
const {
data,
columns,
options,
title,
subtitle,
filters,
initialState,
emptyContent,
onStateChange,
...restProps
} = props;
const tableClasses = useTableStyles();
const { data, ...propsWithoutData } = props;
const theme = useTheme<BackstageTheme>();
const calculatedInitialState = { ...defaultInitialState, ...initialState };
@@ -495,7 +495,7 @@ export function Table<T extends object = {}>({
}
data={typeof data === 'function' ? data : tableData}
style={{ width: '100%' }}
{...propsWithoutData}
{...restProps}
/>
</div>
);
@@ -58,7 +58,8 @@ const useStyles = makeStyles<BackstageTheme>(theme => ({
},
}));
export const Tabs = ({ tabs }: TabsProps) => {
export function Tabs(props: TabsProps) {
const { tabs } = props;
const classes = useStyles();
const [value, setValue] = useState([0, 0]); // [selectedChunkedNavIndex, selectedIndex]
const [navIndex, setNavIndex] = useState(0);
@@ -160,4 +161,4 @@ export const Tabs = ({ tabs }: TabsProps) => {
)}
</div>
);
};
}
@@ -32,10 +32,10 @@ function color(data: number[], theme: BackstageTheme): string | undefined {
return theme.palette.status.error;
}
export const TrendLine = (
export function TrendLine(
props: SparklinesProps &
Pick<SparklinesLineProps, 'color'> & { title?: string },
) => {
) {
const theme = useTheme<BackstageTheme>();
if (!props.data) return null;
@@ -45,4 +45,4 @@ export const TrendLine = (
<SparklinesLine color={props.color ?? color(props.data, theme)} />
</Sparklines>
);
};
}
@@ -137,13 +137,14 @@ const capitalize = (s: string) => {
* @param {Object} [children] Objects to provide context, such as a stack trace or detailed error reporting.
* Will be available inside an unfolded accordion.
*/
export const WarningPanel = ({
severity = 'warning',
title,
message,
children,
defaultExpanded,
}: WarningProps) => {
export function WarningPanel(props: WarningProps) {
const {
severity = 'warning',
title,
message,
children,
defaultExpanded,
} = props;
const classes = useStyles({ severity });
// If no severity or title provided, the heading will read simply "Warning"
@@ -184,4 +185,4 @@ export const WarningPanel = ({
)}
</Accordion>
);
};
}
+41 -20
View File
@@ -15,27 +15,48 @@
*/
import MuiBrokenImageIcon from '@material-ui/icons/BrokenImage';
import React from 'react';
import React, { ComponentProps } from 'react';
import { useApp, IconComponent } from '@backstage/core-plugin-api';
const overridableSystemIcon = (key: string): IconComponent => {
const Component: IconComponent = props => {
const app = useApp();
const Icon = app.getSystemIcon(key);
return Icon ? <Icon {...props} /> : <MuiBrokenImageIcon {...props} />;
};
return Component;
};
type IconComponentProps = ComponentProps<IconComponent>;
function useSystemIcon(key: string, props: IconComponentProps) {
const app = useApp();
const Icon = app.getSystemIcon(key);
return Icon ? <Icon {...props} /> : <MuiBrokenImageIcon {...props} />;
}
// Should match the list of overridable system icon keys in @backstage/core-app-api
export const BrokenImageIcon = overridableSystemIcon('brokenImage');
export const CatalogIcon = overridableSystemIcon('catalog');
export const ChatIcon = overridableSystemIcon('chat');
export const DashboardIcon = overridableSystemIcon('dashboard');
export const DocsIcon = overridableSystemIcon('docs');
export const EmailIcon = overridableSystemIcon('email');
export const GitHubIcon = overridableSystemIcon('github');
export const GroupIcon = overridableSystemIcon('group');
export const HelpIcon = overridableSystemIcon('help');
export const UserIcon = overridableSystemIcon('user');
export const WarningIcon = overridableSystemIcon('warning');
export function BrokenImageIcon(props: IconComponentProps) {
return useSystemIcon('brokenImage', props);
}
export function CatalogIcon(props: IconComponentProps) {
return useSystemIcon('catalog', props);
}
export function ChatIcon(props: IconComponentProps) {
return useSystemIcon('chat', props);
}
export function DashboardIcon(props: IconComponentProps) {
return useSystemIcon('dashboard', props);
}
export function DocsIcon(props: IconComponentProps) {
return useSystemIcon('docs', props);
}
export function EmailIcon(props: IconComponentProps) {
return useSystemIcon('email', props);
}
export function GitHubIcon(props: IconComponentProps) {
return useSystemIcon('github', props);
}
export function GroupIcon(props: IconComponentProps) {
return useSystemIcon('group', props);
}
export function HelpIcon(props: IconComponentProps) {
return useSystemIcon('help', props);
}
export function UserIcon(props: IconComponentProps) {
return useSystemIcon('user', props);
}
export function WarningIcon(props: IconComponentProps) {
return useSystemIcon('warning', props);
}
@@ -41,7 +41,8 @@ export type BottomLinkProps = {
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void;
};
export const BottomLink = ({ link, title, onClick }: BottomLinkProps) => {
export function BottomLink(props: BottomLinkProps) {
const { link, title, onClick } = props;
const classes = useStyles();
return (
@@ -59,4 +60,4 @@ export const BottomLink = ({ link, title, onClick }: BottomLinkProps) => {
</Link>
</div>
);
};
}
@@ -41,7 +41,8 @@ const StyledBox = withStyles({
},
})(Box);
export const Breadcrumbs = ({ children, ...props }: Props) => {
export function Breadcrumbs(props: Props) {
const { children, ...restProps } = props;
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(
null,
);
@@ -65,7 +66,7 @@ export const Breadcrumbs = ({ children, ...props }: Props) => {
const open = Boolean(anchorEl);
return (
<Fragment>
<MaterialBreadcrumbs aria-label="breadcrumb" {...props}>
<MaterialBreadcrumbs aria-label="breadcrumb" {...restProps}>
{childrenArray.length > 1 && <StyledBox clone>{firstPage}</StyledBox>}
{childrenArray.length > 2 && <StyledBox clone>{secondPage}</StyledBox>}
{hasHiddenBreadcrumbs && (
@@ -96,4 +97,4 @@ export const Breadcrumbs = ({ children, ...props }: Props) => {
</Popover>
</Fragment>
);
};
}
@@ -47,17 +47,12 @@ type Props = {
className?: string;
};
export const Content = ({
className,
stretch,
noPadding,
children,
...props
}: PropsWithChildren<Props>) => {
export function Content(props: PropsWithChildren<Props>) {
const { className, stretch, noPadding, children, ...restProps } = props;
const classes = useStyles();
return (
<article
{...props}
{...restProps}
className={classNames(classes.root, className, {
[classes.stretch]: stretch,
[classes.noPadding]: noPadding,
@@ -66,4 +61,4 @@ export const Content = ({
{children}
</article>
);
};
}
@@ -82,13 +82,14 @@ type ContentHeaderProps = {
textAlign?: 'left' | 'right' | 'center';
};
export const ContentHeader = ({
description,
title,
titleComponent: TitleComponent = undefined,
children,
textAlign = 'left',
}: PropsWithChildren<ContentHeaderProps>) => {
export function ContentHeader(props: PropsWithChildren<ContentHeaderProps>) {
const {
description,
title,
titleComponent: TitleComponent = undefined,
children,
textAlign = 'left',
} = props;
const classes = useStyles({ textAlign })();
const renderedTitle = TitleComponent ? (
@@ -112,4 +113,4 @@ export const ContentHeader = ({
</div>
</>
);
};
}
@@ -47,11 +47,8 @@ const useStyles = makeStyles<BackstageTheme>(theme => ({
},
}));
export const ErrorPage = ({
status,
statusMessage,
additionalInfo,
}: IErrorPageProps) => {
export function ErrorPage(props: IErrorPageProps) {
const { status, statusMessage, additionalInfo } = props;
const classes = useStyles();
const navigate = useNavigate();
const support = useSupportConfig();
@@ -82,4 +79,4 @@ export const ErrorPage = ({
</Grid>
</Grid>
);
};
}
@@ -172,16 +172,17 @@ const SubtitleFragment = ({ classes, subtitle }: SubtitleFragmentProps) => {
);
};
export const Header = ({
children,
pageTitleOverride,
style,
subtitle,
title,
tooltip,
type,
typeLink,
}: PropsWithChildren<Props>) => {
export function Header(props: PropsWithChildren<Props>) {
const {
children,
pageTitleOverride,
style,
subtitle,
title,
tooltip,
type,
typeLink,
} = props;
const classes = useStyles();
const configApi = useApi(configApiRef);
const appTitle = configApi.getOptionalString('app.title') || 'Backstage';
@@ -214,4 +215,4 @@ export const Header = ({
</header>
</>
);
};
}
@@ -66,7 +66,8 @@ export type HeaderActionMenuProps = {
actionItems: ActionItemProps[];
};
export const HeaderActionMenu = ({ actionItems }: HeaderActionMenuProps) => {
export function HeaderActionMenu(props: HeaderActionMenuProps) {
const { actionItems } = props;
const [open, setOpen] = React.useState(false);
const anchorElRef = React.useRef(null);
@@ -103,4 +104,4 @@ export const HeaderActionMenu = ({ actionItems }: HeaderActionMenuProps) => {
</Popover>
</Fragment>
);
};
}
@@ -51,7 +51,8 @@ type HeaderLabelProps = {
url?: string;
};
export const HeaderLabel = ({ label, value, url }: HeaderLabelProps) => {
export function HeaderLabel(props: HeaderLabelProps) {
const { label, value, url } = props;
const classes = useStyles();
const content = (
<HeaderLabelContent
@@ -67,4 +68,4 @@ export const HeaderLabel = ({ label, value, url }: HeaderLabelProps) => {
</span>
</Grid>
);
};
}
@@ -55,11 +55,8 @@ type HeaderTabsProps = {
onChange?: (index: number) => void;
selectedIndex?: number;
};
export const HeaderTabs = ({
tabs,
onChange,
selectedIndex,
}: HeaderTabsProps) => {
export function HeaderTabs(props: HeaderTabsProps) {
const { tabs, onChange, selectedIndex } = props;
const [selectedTab, setSelectedTab] = useState<number>(selectedIndex ?? 0);
const styles = useStyles();
@@ -101,4 +98,4 @@ export const HeaderTabs = ({
</Tabs>
</div>
);
};
}
@@ -67,7 +67,7 @@ function getTimes(configApi: ConfigApi) {
return clocks;
}
export const HomepageTimer = () => {
export function HomepageTimer(_props: {}) {
const configApi = useApi(configApiRef);
const defaultTimes: TimeObj[] = [];
@@ -99,4 +99,4 @@ export const HomepageTimer = () => {
);
}
return null;
};
}
@@ -128,26 +128,27 @@ type Props = {
titleTypographyProps?: object;
};
export const InfoCard = ({
title,
subheader,
divider = true,
deepLink,
slackChannel,
errorBoundaryProps,
variant,
children,
headerStyle,
headerProps,
action,
actionsClassName,
actions,
cardClassName,
actionsTopRight,
className,
noPadding,
titleTypographyProps,
}: Props): JSX.Element => {
export function InfoCard(props: Props): JSX.Element {
const {
title,
subheader,
divider = true,
deepLink,
slackChannel,
errorBoundaryProps,
variant,
children,
headerStyle,
headerProps,
action,
actionsClassName,
actions,
cardClassName,
actionsTopRight,
className,
noPadding,
titleTypographyProps,
} = props;
const classes = useStyles();
/**
* If variant is specified, we build up styles for that particular variant for both
@@ -214,4 +215,4 @@ export const InfoCard = ({
</ErrorBoundary>
</Card>
);
};
}
@@ -62,16 +62,9 @@ type ItemCardProps = {
* @deprecated Use plain MUI <Card> and composable helpers instead.
* @see https://material-ui.com/components/cards/
*/
export const ItemCard = ({
description,
tags,
title,
type,
subtitle,
label,
onClick,
href,
}: ItemCardProps) => {
export function ItemCard(props: ItemCardProps) {
const { description, tags, title, type, subtitle, label, onClick, href } =
props;
return (
<Card>
<CardMedia>
@@ -101,4 +94,4 @@ export const ItemCard = ({
</CardActions>
</Card>
);
};
}
@@ -51,7 +51,7 @@ export type ItemCardGridProps = Partial<WithStyles<typeof styles>> & {
* This can be useful for e.g. overriding gridTemplateColumns to adapt the
* minimum size of the cells to fit the content better.
*/
export const ItemCardGrid = (props: ItemCardGridProps) => {
export function ItemCardGrid(props: ItemCardGridProps) {
const { children, ...otherProps } = props;
const classes = useStyles(otherProps);
return (
@@ -59,4 +59,4 @@ export const ItemCardGrid = (props: ItemCardGridProps) => {
{children}
</div>
);
};
}
@@ -72,7 +72,7 @@ export type ItemCardHeaderProps = Partial<WithStyles<typeof styles>> & {
* <ItemCardHeader title="Hello" classes={{ root: myClassName }} />
* </code>
*/
export const ItemCardHeader = (props: ItemCardHeaderProps) => {
export function ItemCardHeader(props: ItemCardHeaderProps) {
const { title, subtitle, children } = props;
const classes = useStyles(props);
return (
@@ -90,4 +90,4 @@ export const ItemCardHeader = (props: ItemCardHeaderProps) => {
{children}
</div>
);
};
}
@@ -34,7 +34,8 @@ type Props = {
themeId: string;
};
export const Page = ({ themeId, children }: PropsWithChildren<Props>) => {
export function Page(props: PropsWithChildren<Props>) {
const { themeId, children } = props;
const classes = useStyles();
return (
<ThemeProvider
@@ -46,4 +47,4 @@ export const Page = ({ themeId, children }: PropsWithChildren<Props>) => {
<div className={classes.root}>{children}</div>
</ThemeProvider>
);
};
}
@@ -23,13 +23,12 @@ type PageWithHeaderProps = ComponentProps<typeof Header> & {
themeId: string;
};
export const PageWithHeader = ({
themeId,
children,
...props
}: PropsWithChildren<PageWithHeaderProps>) => (
<Page themeId={themeId}>
<Header {...props} />
{children}
</Page>
);
export function PageWithHeader(props: PropsWithChildren<PageWithHeaderProps>) {
const { themeId, children, ...restProps } = props;
return (
<Page themeId={themeId}>
<Header {...restProps} />
{children}
</Page>
);
}
@@ -74,11 +74,12 @@ type Props = {
closeDelayMs?: number;
};
export const Sidebar = ({
openDelayMs = sidebarConfig.defaultOpenDelayMs,
closeDelayMs = sidebarConfig.defaultCloseDelayMs,
children,
}: PropsWithChildren<Props>) => {
export function Sidebar(props: PropsWithChildren<Props>) {
const {
openDelayMs = sidebarConfig.defaultOpenDelayMs,
closeDelayMs = sidebarConfig.defaultCloseDelayMs,
children,
} = props;
const classes = useStyles();
const isSmallScreen = useMediaQuery<BackstageTheme>(theme =>
theme.breakpoints.down('md'),
@@ -149,4 +150,4 @@ export const Sidebar = ({
</SidebarContext.Provider>
</div>
);
};
}
@@ -74,7 +74,7 @@ type IntroCardProps = {
onClose: () => void;
};
export const IntroCard = (props: IntroCardProps) => {
export function IntroCard(props: IntroCardProps) {
const classes = useStyles();
const { text, onClose } = props;
const handleClose = () => onClose();
@@ -97,7 +97,7 @@ export const IntroCard = (props: IntroCardProps) => {
</div>
</div>
);
};
}
type SidebarIntroLocalStorage = {
starredItemsDismissed: boolean;
@@ -127,7 +127,7 @@ Keep an eye out for the little star icon (⭐) next to the plugin name and give
const recentlyViewedIntroText =
'And your recently viewed plugins will pop up here!';
export const SidebarIntro = () => {
export function SidebarIntro(_props: {}) {
const { isOpen } = useContext(SidebarContext);
const defaultValue = {
starredItemsDismissed: false,
@@ -177,4 +177,4 @@ export const SidebarIntro = () => {
)}
</>
);
};
}
@@ -282,7 +282,7 @@ type SidebarSearchFieldProps = {
to?: string;
};
export const SidebarSearchField = (props: SidebarSearchFieldProps) => {
export function SidebarSearchField(props: SidebarSearchFieldProps) {
const [input, setInput] = useState('');
const classes = useStyles();
@@ -334,7 +334,7 @@ export const SidebarSearchField = (props: SidebarSearchFieldProps) => {
</SidebarItem>
</div>
);
};
}
export const SidebarSpace = styled('div')({
flex: 1,
@@ -49,7 +49,7 @@ export const SidebarPinStateContext = createContext<SidebarPinStateContextType>(
},
);
export const SidebarPage = (props: PropsWithChildren<{}>) => {
export function SidebarPage(props: PropsWithChildren<{}>) {
const [isPinned, setIsPinned] = useState(() =>
LocalStorage.getSidebarPinState(),
);
@@ -71,4 +71,4 @@ export const SidebarPage = (props: PropsWithChildren<{}>) => {
<div className={classes.root}>{props.children}</div>
</SidebarPinStateContext.Provider>
);
};
}
@@ -192,10 +192,10 @@ export const SingleSignInPage = ({
);
};
export const SignInPage = (props: Props) => {
export function SignInPage(props: Props) {
if ('provider' in props) {
return <SingleSignInPage {...props} />;
}
return <MultiSignInPage {...props} />;
};
}
@@ -62,15 +62,16 @@ type Props = {
deepLink?: BottomLinkProps;
};
const TabbedCard = ({
slackChannel,
errorBoundaryProps,
children,
title,
deepLink,
value,
onChange,
}: PropsWithChildren<Props>) => {
export function TabbedCard(props: PropsWithChildren<Props>) {
const {
slackChannel,
errorBoundaryProps,
children,
title,
deepLink,
value,
onChange,
} = props;
const tabsClasses = useTabsStyles();
const [selectedIndex, selectIndex] = useState(0);
@@ -111,7 +112,7 @@ const TabbedCard = ({
</ErrorBoundary>
</Card>
);
};
}
const useCardTabStyles = makeStyles(theme => ({
root: {
@@ -135,10 +136,9 @@ type CardTabProps = TabProps & {
children: ReactNode;
};
const CardTab = ({ children, ...props }: PropsWithChildren<CardTabProps>) => {
export function CardTab(props: PropsWithChildren<CardTabProps>) {
const { children, ...restProps } = props;
const classes = useCardTabStyles();
return <Tab disableRipple classes={classes} {...props} />;
};
export { TabbedCard, CardTab };
return <Tab disableRipple classes={classes} {...restProps} />;
}
+40 -27
View File
@@ -3,11 +3,10 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
/// <reference types="react" />
import { BackstagePlugin } from '@backstage/core-plugin-api';
import { default } from 'react';
import { default as default_2 } from 'react';
import { ExternalRouteRef } from '@backstage/core-plugin-api';
import { RouteRef } from '@backstage/core-plugin-api';
import { TabProps } from '@material-ui/core';
@@ -15,25 +14,30 @@ import { TabProps } from '@material-ui/core';
// Warning: (ae-missing-release-tag) "catalogEntityRouteRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const catalogEntityRouteRef: ExternalRouteRef< {
name: string;
kind: string;
namespace: string;
}, false>;
export const catalogEntityRouteRef: ExternalRouteRef<
{
name: string;
kind: string;
namespace: string;
},
false
>;
// Warning: (ae-missing-release-tag) "DomainExplorerContent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const DomainExplorerContent: ({ title, }: {
title?: string | undefined;
export const DomainExplorerContent: ({
title,
}: {
title?: string | undefined;
}) => JSX.Element;
// Warning: (ae-missing-release-tag) "ExploreLayout" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const ExploreLayout: {
({ title, subtitle, children, }: ExploreLayoutProps): JSX.Element;
Route: (props: SubRoute) => null;
({ title, subtitle, children }: ExploreLayoutProps): JSX.Element;
Route: (props: SubRoute) => null;
};
// Warning: (ae-missing-release-tag) "ExplorePage" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
@@ -44,17 +48,23 @@ export const ExplorePage: () => JSX.Element;
// Warning: (ae-missing-release-tag) "explorePlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
const explorePlugin: BackstagePlugin< {
explore: RouteRef<undefined>;
}, {
catalogEntity: ExternalRouteRef< {
name: string;
kind: string;
namespace: string;
}, false>;
}>;
export { explorePlugin }
export { explorePlugin as plugin }
const explorePlugin: BackstagePlugin<
{
explore: RouteRef<undefined>;
},
{
catalogEntity: ExternalRouteRef<
{
name: string;
kind: string;
namespace: string;
},
false
>;
}
>;
export { explorePlugin };
export { explorePlugin as plugin };
// Warning: (ae-missing-release-tag) "exploreRouteRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@@ -64,15 +74,19 @@ export const exploreRouteRef: RouteRef<undefined>;
// Warning: (ae-missing-release-tag) "GroupsExplorerContent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const GroupsExplorerContent: ({ title, }: {
title?: string | undefined;
export const GroupsExplorerContent: ({
title,
}: {
title?: string | undefined;
}) => JSX.Element;
// Warning: (ae-missing-release-tag) "ToolExplorerContent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const ToolExplorerContent: ({ title }: {
title?: string | undefined;
export const ToolExplorerContent: ({
title,
}: {
title?: string | undefined;
}) => JSX.Element;
// Warnings were encountered during analysis:
@@ -81,5 +95,4 @@ export const ToolExplorerContent: ({ title }: {
// src/components/ExploreLayout/ExploreLayout.d.ts:30:5 - (ae-forgotten-export) The symbol "SubRoute" needs to be exported by the entry point index.d.ts
// (No @packageDocumentation comment for this package)
```
+145 -11
View File
@@ -31,8 +31,14 @@ import {
CompilerState,
ExtractorLogLevel,
} from '@microsoft/api-extractor';
import { DocNode, IDocNodeContainerParameters } from '@microsoft/tsdoc';
import { ApiPackage, ApiModel } from '@microsoft/api-extractor-model';
import { MarkdownDocumenter } from '@microsoft/api-documenter/lib/documenters/MarkdownDocumenter';
import {
IMarkdownDocumenterOptions,
MarkdownDocumenter,
} from '@microsoft/api-documenter/lib/documenters/MarkdownDocumenter';
import { CustomMarkdownEmitter } from '@microsoft/api-documenter/lib/markdown/CustomMarkdownEmitter';
import { IMarkdownEmitterContext } from '@microsoft/api-documenter/lib/markdown/MarkdownEmitter';
const tmpDir = resolvePath(__dirname, '../node_modules/.cache/api-extractor');
@@ -298,10 +304,13 @@ async function runApiExtraction({
}
}
function isComponentMember(member: any) {
// React components are annotated with @component, and we want to skip those
return Boolean(member.docComment.match(/\n\s*\**\s*@component/m));
}
/*
WARNING: Bring a blanket if you're gonna read the code below
There's some weird shit going on here, and it's because we cba
forking rushstash to modify the api-documenter markdown generation,
which otherwise is the recommended way to do customizations.
*/
async function buildDocs({
inputDir,
@@ -310,6 +319,8 @@ async function buildDocs({
inputDir: string;
outputDir: string;
}) {
// We start by constructing our own model from the files so that
// we get a change to modify them, as the model is otherwise read-only.
const parseFile = async (filename: string): Promise<any> => {
console.log(`Reading ${filename}`);
return fs.readJson(resolvePath(inputDir, filename));
@@ -324,9 +335,7 @@ async function buildDocs({
const newModel = new ApiModel();
for (const serialized of serializedPackages) {
serialized.members[0].members = serialized.members[0].members.filter(
member => !isComponentMember(member),
);
// Add any docs filtering logic here
const pkg = ApiPackage.deserialize(
serialized,
@@ -335,10 +344,132 @@ async function buildDocs({
newModel.addMember(pkg);
}
await fs.remove(outputDir);
await fs.ensureDir(outputDir);
// The doc AST need to be extended with custom nodes if we want to
// add any extra content.
// This one is for the YAML front matter that we need for the microsite.
class DocFrontMatter extends DocNode {
static kind = 'DocFrontMatter';
const documenter = new MarkdownDocumenter({
public readonly id: string;
public readonly title: string;
public readonly description: string;
public constructor(
parameters: IDocNodeContainerParameters & {
id: string;
title: string;
description: string;
},
) {
super(parameters);
this.id = parameters.id;
this.title = parameters.title;
this.description = parameters.description;
}
/** @override */
public get kind(): string {
return DocFrontMatter.kind;
}
}
// This is where we actually write the markdown and where we can hook
// in the rendering of our own nodes.
class CustomCustomMarkdownEmitter extends CustomMarkdownEmitter {
/** @override */
protected writeNode(
docNode: DocNode,
context: IMarkdownEmitterContext,
docNodeSiblings: boolean,
): void {
switch (docNode.kind) {
case DocFrontMatter.kind: {
const node = docNode as DocFrontMatter;
context.writer.writeLine('---');
context.writer.writeLine(`id: ${node.id}`);
context.writer.writeLine(`title: ${node.title}`);
context.writer.writeLine(`description: ${node.description}`);
context.writer.writeLine('---');
context.writer.writeLine();
break;
}
default:
super.writeNode(docNode, context, docNodeSiblings);
}
}
/** @override */
emit(stringBuilder, docNode, options) {
// Hack to get rid of the leading comment of each file, since
// we want the front matter to come first
stringBuilder._chunks.length = 0;
return super.emit(stringBuilder, docNode, options);
}
}
class CustomMarkdownDocumenter extends (MarkdownDocumenter as any) {
constructor(options: IMarkdownDocumenterOptions) {
super(options);
// It's a strict model, we gotta register the allowed usage of our new node
this._tsdocConfiguration.docNodeManager.registerDocNodes(
'@backstage/docs',
[{ docNodeKind: DocFrontMatter.kind, constructor: DocFrontMatter }],
);
this._tsdocConfiguration.docNodeManager.registerAllowableChildren(
'Paragraph',
[DocFrontMatter.kind],
);
this._markdownEmitter = new CustomCustomMarkdownEmitter(newModel);
}
// We don't really get many chances to modify the generated AST
// so we hook in wherever we can. In this case we add the front matter
// just before writing the breadcrumbs at the top.
/** @override */
_writeBreadcrumb(output, apiItem) {
let title;
let description;
const name = apiItem.getScopedNameWithinPackage();
if (name) {
title = name;
description = `API reference for ${apiItem.getScopedNameWithinPackage()}`;
} else if (apiItem.kind === 'Model') {
title = 'Package Index';
description = 'Index of all Backstage Packages';
} else {
title = apiItem.name;
description = `API Reference for ${apiItem.name}`;
}
// Add our front matter
output.appendNodeInParagraph(
new DocFrontMatter({
configuration: this._tsdocConfiguration,
id: this._getFilenameForApiItem(apiItem).slice(0, -3),
title,
description,
}),
);
// Now write the actual breadcrumbs
super._writeBreadcrumb(output, apiItem);
// We wanna ignore the header that always gets written after the breadcrumb
// This otherwise becomes more or less a duplicate of the title in the front matter
const oldAppendNode = output.appendNode;
output.appendNode = () => {
output.appendNode = oldAppendNode;
};
}
}
// This is root of the documentation generation, but it's not directly
// responsible for generating markdown, it just constructs an AST that
// is the consumed by an emitter to actually write the files.
const documenter = new CustomMarkdownDocumenter({
apiModel: newModel,
documenterConfig: {
outputTarget: 'markdown',
@@ -350,6 +481,9 @@ async function buildDocs({
outputFolder: outputDir,
});
// Clean up existing stuff and write ALL the docs!
await fs.remove(outputDir);
await fs.ensureDir(outputDir);
documenter.generateFiles();
}
+35 -35
View File
@@ -4540,45 +4540,45 @@
resolved "https://registry.npmjs.org/@mdx-js/util/-/util-1.6.22.tgz#219dfd89ae5b97a8801f015323ffa4b62f45718b"
integrity sha512-H1rQc1ZOHANWBvPcW+JpGwr+juXSxM8Q8YCkm3GhZd8REu1fHR3z99CErO1p9pkcfcxZnMdIZdIsXkOHY0NilA==
"@microsoft/api-documenter@^7.13.30":
version "7.13.30"
resolved "https://registry.npmjs.org/@microsoft/api-documenter/-/api-documenter-7.13.30.tgz#f4832b8747ad9f61b3a0d87eb61b6b1aca2aeb60"
integrity sha512-n91XihJptwcHp1g5FUIcrjDXhg/g2q6+Rj+nuPBkvsCAKQP/OwCLNVO3tYNpz+qa+lWrHPWL3Urc8G3th5cn7w==
"@microsoft/api-documenter@^7.13.47":
version "7.13.47"
resolved "https://registry.npmjs.org/@microsoft/api-documenter/-/api-documenter-7.13.47.tgz#0b7726634232b37f76c0e5e8353cdbb5b52d4ece"
integrity sha512-jk78Pf8cKL2WZf6CkKUUtwegdsTA1Jf0MfIzD50qpG7T257HLrqCi1t70ZA85VpRLR8oSeNHMayqNTWkdku9iA==
dependencies:
"@microsoft/api-extractor-model" "7.13.3"
"@microsoft/api-extractor-model" "7.13.5"
"@microsoft/tsdoc" "0.13.2"
"@rushstack/node-core-library" "3.39.0"
"@rushstack/ts-command-line" "4.8.0"
"@rushstack/node-core-library" "3.40.0"
"@rushstack/ts-command-line" "4.9.0"
colors "~1.2.1"
js-yaml "~3.13.1"
resolve "~1.17.0"
"@microsoft/api-extractor-model@7.13.3", "@microsoft/api-extractor-model@^7.13.3":
version "7.13.3"
resolved "https://registry.npmjs.org/@microsoft/api-extractor-model/-/api-extractor-model-7.13.3.tgz#ac01c064c5af520d3661c85d7e5ef95e1ca8ab92"
integrity sha512-uXilAhu2GcvyY/0NwVRk3AN7TFYjkPnjHLV2UywTTz9uglS+Af0YjNrCy+aaK8qXtfbFWdBzkH9N2XU8/YBeRQ==
"@microsoft/api-extractor-model@7.13.5", "@microsoft/api-extractor-model@^7.13.5":
version "7.13.5"
resolved "https://registry.npmjs.org/@microsoft/api-extractor-model/-/api-extractor-model-7.13.5.tgz#7836a81ba47b9a654062ed0361e4eee69afae51e"
integrity sha512-il6AebNltYo5hEtqXZw4DMvrwBPn6+F58TxwqmsLY+U+sSJNxaYn2jYksArrjErXVPR3gUgRMqD6zsdIkg+WEQ==
dependencies:
"@microsoft/tsdoc" "0.13.2"
"@microsoft/tsdoc-config" "~0.15.2"
"@rushstack/node-core-library" "3.39.0"
"@rushstack/node-core-library" "3.40.0"
"@microsoft/api-extractor@^7.18.1":
version "7.18.1"
resolved "https://registry.npmjs.org/@microsoft/api-extractor/-/api-extractor-7.18.1.tgz#61b39f972b646261dd49f2de9f5d448aa6497e7a"
integrity sha512-qljUF2Q0zAx1vJrjKkJVGN7OVbsXki+Pji99jywyl6L/FK3YZ7PpstUJYE6uBcLPy6rhNPWPAsHNTMpG/kHIsg==
"@microsoft/api-extractor@^7.18.7":
version "7.18.7"
resolved "https://registry.npmjs.org/@microsoft/api-extractor/-/api-extractor-7.18.7.tgz#851d2413a3c5d696f7cc914eb59de7a7882b2e8b"
integrity sha512-JhtV8LoyLuIecbgCPyZQg08G1kngIRWpai2UzwNil9mGVGYiDZVeeKx8c2phmlPcogmMDm4oQROxyuiYt5sJiw==
dependencies:
"@microsoft/api-extractor-model" "7.13.3"
"@microsoft/api-extractor-model" "7.13.5"
"@microsoft/tsdoc" "0.13.2"
"@microsoft/tsdoc-config" "~0.15.2"
"@rushstack/node-core-library" "3.39.0"
"@rushstack/rig-package" "0.2.12"
"@rushstack/ts-command-line" "4.8.0"
"@rushstack/node-core-library" "3.40.0"
"@rushstack/rig-package" "0.3.0"
"@rushstack/ts-command-line" "4.9.0"
colors "~1.2.1"
lodash "~4.17.15"
resolve "~1.17.0"
semver "~7.3.0"
source-map "~0.6.1"
typescript "~4.3.2"
typescript "~4.3.5"
"@microsoft/fetch-event-source@2.0.1":
version "2.0.1"
@@ -4600,7 +4600,7 @@
jju "~1.4.0"
resolve "~1.19.0"
"@microsoft/tsdoc@0.13.2":
"@microsoft/tsdoc@0.13.2", "@microsoft/tsdoc@^0.13.2":
version "0.13.2"
resolved "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.13.2.tgz#3b0efb6d3903bd49edb073696f60e90df08efb26"
integrity sha512-WrHvO8PDL8wd8T2+zBGKrMwVL5IyzR3ryWUsl0PXgEV0QHup4mTLi0QcATefGI6Gx9Anu7vthPyyyLpY0EpiQg==
@@ -5217,10 +5217,10 @@
estree-walker "^2.0.1"
picomatch "^2.2.2"
"@rushstack/node-core-library@3.39.0":
version "3.39.0"
resolved "https://registry.npmjs.org/@rushstack/node-core-library/-/node-core-library-3.39.0.tgz#38928946d15ae89b773386cf97433d0d1ec83b93"
integrity sha512-kgu3+7/zOBkZU0+NdJb1rcHcpk3/oTjn5c8cg5nUTn+JDjEw58yG83SoeJEcRNNdl11dGX0lKG2PxPsjCokZOQ==
"@rushstack/node-core-library@3.40.0":
version "3.40.0"
resolved "https://registry.npmjs.org/@rushstack/node-core-library/-/node-core-library-3.40.0.tgz#2551915ea34e34ec2abb7172b9d7f4546144d9d4"
integrity sha512-P6uMPI7cqTdawLSPAG5BQrBu1MHlGRPqecp7ruIRgyukIEzkmh0QAnje4jAL/l1r3hw0qe4e+Dz5ZSnukT/Egg==
dependencies:
"@types/node" "10.17.13"
colors "~1.2.1"
@@ -5232,18 +5232,18 @@
timsort "~0.3.0"
z-schema "~3.18.3"
"@rushstack/rig-package@0.2.12":
version "0.2.12"
resolved "https://registry.npmjs.org/@rushstack/rig-package/-/rig-package-0.2.12.tgz#c434d62b28e0418a040938226f8913971d0424c7"
integrity sha512-nbePcvF8hQwv0ql9aeQxcaMPK/h1OLAC00W7fWCRWIvD2MchZOE8jumIIr66HGrfG2X1sw++m/ZYI4D+BM5ovQ==
"@rushstack/rig-package@0.3.0":
version "0.3.0"
resolved "https://registry.npmjs.org/@rushstack/rig-package/-/rig-package-0.3.0.tgz#334ad2846797861361b3445d4cc9ae9164b1885c"
integrity sha512-Lj6noF7Q4BBm1hKiBDw94e6uZvq1xlBwM/d2cBFaPqXeGdV+G6r3qaCWfRiSXK0pcHpGGpV5Tb2MdfhVcO6G/g==
dependencies:
resolve "~1.17.0"
strip-json-comments "~3.1.1"
"@rushstack/ts-command-line@4.8.0":
version "4.8.0"
resolved "https://registry.npmjs.org/@rushstack/ts-command-line/-/ts-command-line-4.8.0.tgz#611accb931b9ac62ff4d078f68f95c47f6606724"
integrity sha512-nZ8cbzVF1VmFPfSJfy8vEohdiFAH/59Y/Y+B4nsJbn4SkifLJ8LqNZ5+LxCC2UR242EXFumxlsY1d6fPBxck5Q==
"@rushstack/ts-command-line@4.9.0":
version "4.9.0"
resolved "https://registry.npmjs.org/@rushstack/ts-command-line/-/ts-command-line-4.9.0.tgz#781ba42cff73cae097b6d5241b6441e7cc2fe6e0"
integrity sha512-kmT8t+JfnvphISF1C5WwY56RefjwgajhSjs9J4ckvAFXZDXR6F5cvF5/RTh7fGCzIomg8esy2PHO/b52zFoZvA==
dependencies:
"@types/argparse" "1.0.38"
argparse "~1.0.9"
@@ -26334,7 +26334,7 @@ typescript@^4.0.3, typescript@~4.2.3:
resolved "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
typescript@~4.3.2:
typescript@~4.3.5:
version "4.3.5"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==