forked from backstage/backstage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request backstage#11404 from acierto/reconfigure
Make a possibility to configure existing components
- Loading branch information
Showing
90 changed files
with
616 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@backstage/core-plugin-api': patch | ||
--- | ||
|
||
Introduced a new experimental feature that allows you to declare plugin-wide options for your plugin by defining | ||
`__experimentalConfigure` in your `createPlugin` options. See https://backstage.io/docs/plugins/customization.md for more information. | ||
|
||
This is an experimental feature and it will have breaking changes in the future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
'@backstage/plugin-catalog': minor | ||
--- | ||
|
||
Plugin catalog has been modified to use an experimental feature where you can customize the title of the create button. | ||
|
||
You can modify it by doing: | ||
|
||
```typescript jsx | ||
import { catalogPlugin } from '@backstage/plugin-catalog'; | ||
|
||
catalogPlugin.__experimentalReconfigure({ | ||
createButtonTitle: 'New', | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
id: customization | ||
title: Customization | ||
description: Documentation on adding a customization logic to the plugin | ||
--- | ||
|
||
## Overview | ||
|
||
The Backstage core logic provides a possibility to make the component customizable in such a way that the application | ||
developer can redefine the labels, icons, elements or even completely replace the component. It's up to each plugin | ||
to decide what can be customized. | ||
|
||
## For a plugin developer | ||
|
||
When you are creating your plugin, you have a possibility to use a metadata field and define there all | ||
customizable elements. For example | ||
|
||
```typescript jsx | ||
const plugin = createPlugin({ | ||
id: 'my-plugin', | ||
__experimentalConfigure( | ||
options?: CatalogInputPluginOptions, | ||
): CatalogPluginOptions { | ||
const defaultOptions = { | ||
createButtonTitle: 'Create', | ||
}; | ||
return { ...defaultOptions, ...options }; | ||
}, | ||
}); | ||
``` | ||
|
||
And the rendering part of the exposed component can retrieve that metadata as: | ||
|
||
```typescript jsx | ||
export type CatalogPluginOptions = { | ||
createButtonTitle: string; | ||
}; | ||
|
||
export type CatalogInputPluginOptions = { | ||
createButtonTitle: string; | ||
}; | ||
|
||
export const useCatalogPluginOptions = () => | ||
usePluginOptions<CatalogPluginOptions>(); | ||
|
||
export function DefaultMyPluginWelcomePage() { | ||
const { createButtonTitle } = useCatalogPluginOptions(); | ||
|
||
return ( | ||
<div> | ||
<button>{createButtonTitle}</button> | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## For an application developer using the plugin | ||
|
||
The way to reconfigure the default values provided by the plugin you can do it via reconfigure method, defined on the | ||
plugin. Example: | ||
|
||
```typescript jsx | ||
import { myPlugin } from '@backstage/my-plugin'; | ||
|
||
myPlugin.__experimentalReconfigure({ | ||
createButtonTitle: 'New', | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2020 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export { usePluginOptions, PluginProvider } from './usePluginOptions'; | ||
export type { PluginOptionsProviderProps } from './usePluginOptions'; |
53 changes: 53 additions & 0 deletions
53
packages/core-plugin-api/src/plugin-options/usePluginOptions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2021 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { usePluginOptions, PluginProvider } from './usePluginOptions'; | ||
import { createPlugin } from '../plugin'; | ||
|
||
describe('usePluginOptions', () => { | ||
it('should provide a versioned value to hook', () => { | ||
type TestInputPluginOptions = { | ||
'key-1': string; | ||
}; | ||
|
||
type TestPluginOptions = { | ||
'key-1': string; | ||
'key-2': string; | ||
}; | ||
|
||
const plugin = createPlugin({ | ||
id: 'my-plugin', | ||
__experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { | ||
return { 'key-1': 'value-1', 'key-2': 'value-2' }; | ||
}, | ||
}); | ||
|
||
const rendered = renderHook(() => usePluginOptions(), { | ||
wrapper: ({ children }) => ( | ||
<PluginProvider plugin={plugin}>{children}</PluginProvider> | ||
), | ||
}); | ||
|
||
const config = rendered.result.current; | ||
|
||
expect(config).toEqual({ | ||
'key-1': 'value-1', | ||
'key-2': 'value-2', | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.