Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fab): add application listener and provider test plugins #318

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@red-hat-developer-hub/backstage-plugin-application-listener-test': patch
'@red-hat-developer-hub/backstage-plugin-application-provider-test': patch
---

Release the initial version of this test-plugin.
2 changes: 1 addition & 1 deletion workspaces/global-floating-action-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dev": "yarn workspaces foreach -A --include backend --include app --parallel -v -i run start",
"build:all": "backstage-cli repo build --all",
"build:api-reports": "yarn build:api-reports:only --tsc",
"build:api-reports:only": "backstage-repo-tools api-reports -o ae-wrong-input-file-type --validate-release-tags",
"build:api-reports:only": "backstage-repo-tools api-reports -o ae-wrong-input-file-type,ae-undocumented --validate-release-tags",
"clean": "backstage-cli repo clean",
"test": "backstage-cli repo test",
"test:all": "backstage-cli repo test --coverage",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# application-listener-test

Welcome to the application-listener-test plugin!

_This plugin was created through the Backstage CLI_

## Getting started

Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/application-listener-test](http://localhost:3000/application-listener-test).

You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test global-header components. this isn't implemented yet!
dynamicPlugins:
frontend:
red-hat-developer-hub.backstage-plugin-application-listener-test:
mountPoints:
- mountPoint: application/listener
importName: LocationListener
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Red Hat, Inc.
*
* 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 { createDevApp } from '@backstage/dev-utils';

import { applicationListenerTestPlugin, LocationListener } from '../src/plugin';

createDevApp()
.registerPlugin(applicationListenerTestPlugin)
.addPage({
element: <LocationListener />,
title: 'Page 1',
path: '/page-1',
})
.addPage({
element: <LocationListener />,
title: 'Page 2',
path: '/page-2',
})
.render();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Knip report

## Unused dependencies (1)

| Name | Location | Severity |
| :------------------------- | :----------- | :------- |
| @backstage/core-components | package.json | error |

## Unused devDependencies (5)

| Name | Location | Severity |
| :-------------------------- | :----------- | :------- |
| @testing-library/user-event | package.json | error |
| @backstage/core-app-api | package.json | error |
| @testing-library/react | package.json | error |
| @backstage/test-utils | package.json | error |
| msw | package.json | error |
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@red-hat-developer-hub/backstage-plugin-application-listener-test",
"version": "0.0.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/redhat-developer/rhdh-plugins",
"directory": "workspaces/global-floating-action-button/plugins/application-listener-test"
},
"backstage": {
"role": "frontend-plugin",
"pluginId": "application-listener-test",
"pluginPackages": [
"@red-hat-developer-hub/backstage-plugin-application-listener-test"
]
},
"sideEffects": false,
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build && yarn export-dynamic",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean && rm -rf dist-scalprum",
"prepack": "backstage-cli package prepack && yarn export-dynamic",
"postpack": "backstage-cli package postpack",
"export-dynamic": "janus-cli package export-dynamic-plugin --in-place"
},
"dependencies": {
"@backstage/core-components": "^0.15.1",
"@backstage/core-plugin-api": "^1.10.0"
},
"peerDependencies": {
"react": "16.13.1 || ^17.0.0 || ^18.0.0",
"react-router-dom": "^6.0.0"
},
"devDependencies": {
"@backstage/cli": "^0.28.0",
"@backstage/core-app-api": "^1.15.1",
"@backstage/dev-utils": "^1.1.2",
"@backstage/test-utils": "^1.7.0",
"@janus-idp/cli": "^2.0.0",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.0.0",
"msw": "^1.0.0",
"react": "^16.13.1 || ^17.0.0 || ^18.0.0"
},
"files": [
"app-config.dynamic.yaml",
"dist",
"dist-scalprum"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## API Report File for "@red-hat-developer-hub/backstage-plugin-application-listener-test"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts
import { BackstagePlugin } from '@backstage/core-plugin-api';

// @public (undocumented)
export const applicationListenerTestPlugin: BackstagePlugin<{}, {}, {}>;

// @public (undocumented)
export const LocationListener: () => null;

// (No @packageDocumentation comment for this package)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Red Hat, Inc.
*
* 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 { useLocation } from 'react-router-dom';

export const LocationListener = () => {
const loc = useLocation();
// eslint-disable-next-line no-console
console.log('LocationListener', loc);
return null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Red Hat, Inc.
*
* 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 * from './plugin';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Red Hat, Inc.
*
* 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 { applicationListenerTestPlugin } from './plugin';

describe('application-listener-test', () => {
it('should export plugin', () => {
expect(applicationListenerTestPlugin).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Red Hat, Inc.
*
* 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 {
createComponentExtension,
createPlugin,
} from '@backstage/core-plugin-api';

/**
* @public
*/
export const applicationListenerTestPlugin = createPlugin({
id: 'application-listener-test',
});

/**
* @public
*/
export const LocationListener = applicationListenerTestPlugin.provide(
createComponentExtension({
name: 'LocationListener',
component: {
lazy: () =>
import('./components/LocationListener').then(m => m.LocationListener),
},
}),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Red Hat, Inc.
*
* 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 '@testing-library/jest-dom';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# application-provider-test

Welcome to the application-provider-test plugin!

_This plugin was created through the Backstage CLI_

## Getting started

Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/application-provider-test](http://localhost:3000/application-provider-test).

You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# test global-header components. this isn't implemented yet!
dynamicPlugins:
frontend:
red-hat-developer-hub.backstage-plugin-application-provider-test:
dynamicRoutes:
- path: /countpage
importName: CountPage
mountPoints:
- mountPoint: application/provider
importName: CountProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Red Hat, Inc.
*
* 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 { Page, Content, Header } from '@backstage/core-components';
import { createDevApp } from '@backstage/dev-utils';

import Grid from '@mui/material/Grid';

import {
applicationProviderTestPlugin,
CountPage,
CountProvider,
CountCard,
} from '../src/plugin';

createDevApp()
.registerPlugin(applicationProviderTestPlugin)
.addPage({
element: (
<CountProvider>
<CountPage />
</CountProvider>
),
title: 'CountPage',
path: '/count-page',
})
.addPage({
element: (
<CountProvider>
<Page themeId="home">
<Header title="CountProvider" />
<Content>
<Grid container spacing={2}>
<Grid item>
<CountCard />
</Grid>
<Grid item>
<CountCard />
</Grid>
</Grid>
</Content>
</Page>
</CountProvider>
),
title: 'CountProvider',
path: '/count-provider',
})
.render();
Loading
Loading