Files
backstage/plugins/shortcuts
dependabot[bot] 24254fd433 build(deps): bump @testing-library/user-event from 13.5.0 to 14.0.0
Bumps [@testing-library/user-event](https://github.com/testing-library/user-event) from 13.5.0 to 14.0.0.
- [Release notes](https://github.com/testing-library/user-event/releases)
- [Changelog](https://github.com/testing-library/user-event/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testing-library/user-event/compare/v13.5.0...v14.0.0)

---
updated-dependencies:
- dependency-name: "@testing-library/user-event"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Johan Haals <johan.haals@gmail.com>
2022-04-05 10:19:52 +02:00
..
2021-06-18 20:26:42 +02:00
2022-03-22 12:28:03 +00:00

shortcuts

The shortcuts plugin allows a user to have easy access to pages within a Backstage app by storing them as "shortcuts" in the Sidebar.

Usage

Install the package:

yarn add @backstage/plugin-shortcuts

Register plugin:

This plugin requires explicit registration, so you will need to add it to your App's plugins.ts file:

// ...
export { shortcutsPlugin } from '@backstage/plugin-shortcuts';

If you don't have a plugins.ts file see: troubleshooting

Add the <Shortcuts /> component within your <Sidebar>:

Edit file packages/app/src/components/Root/Root.tsx

import {
  Sidebar,
  SidebarDivider,
  SidebarSpace,
} from '@backstage/core-components';
import { Shortcuts } from '@backstage/plugin-shortcuts';

export const SidebarComponent = () => (
  <Sidebar>
    {/* ... */}
    <SidebarDivider />
    <Shortcuts />
    <SidebarSpace />
  </Sidebar>
);

The plugin exports a shortcutApiRef but the plugin includes a default implementation of the ShortcutApi that uses localStorage to store each user's shortcuts.

To overwrite the default implementation add it to the App's apis.ts:

import { shortcutsApiRef } from '@backstage/plugin-shortcuts';
import { CustomShortcutsImpl } from '...';

export const apis = [
  // ...
  createApiFactory({
    api: shortcutsApiRef,
    deps: {},
    factory: () => new CustomShortcutsImpl(),
  }),
];

Troubleshooting

If you don't have a plugins.ts file, you can create it with the path packages/app/src/plugins.ts and then import it into your App.tsx:

+ import * as plugins from './plugins';

const app = createApp({
  apis,
+   plugins: Object.values(plugins),
  bindRoutes({ bind }) {
    /* ... */
  },
});

Or simply edit App.tsx with:

+ import { shortcutsPlugin } from '@backstage/plugin-shortcuts

const app = createApp({
  apis,
+   plugins: [shortcutsPlugin],
  bindRoutes({ bind }) {
    /* ... */
  },
});