Skip to content

Commit 2a64b13

Browse files
feat(rbac): add rbac frontend plugin (#859)
1 parent bf05ae8 commit 2a64b13

File tree

14 files changed

+192
-0
lines changed

14 files changed

+192
-0
lines changed

plugins/rbac/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);

plugins/rbac/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# rbac
2+
3+
Welcome to the rbac plugin!
4+
5+
_This plugin was created through the Backstage CLI_
6+
7+
## Getting started
8+
9+
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 [/rbac](http://localhost:3000/rbac).
10+
11+
You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
12+
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
13+
It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory.

plugins/rbac/dev/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
3+
import { createDevApp } from '@backstage/dev-utils';
4+
5+
import { RbacPage, rbacPlugin } from '../src/plugin';
6+
7+
createDevApp()
8+
.registerPlugin(rbacPlugin)
9+
.addPage({
10+
element: <RbacPage />,
11+
title: 'Administration',
12+
path: '/rbac',
13+
})
14+
.render();

plugins/rbac/package.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "@janus-idp/backstage-plugin-rbac",
3+
"version": "0.1.0",
4+
"main": "src/index.ts",
5+
"types": "src/index.ts",
6+
"license": "Apache-2.0",
7+
"publishConfig": {
8+
"access": "public",
9+
"main": "dist/index.esm.js",
10+
"types": "dist/index.d.ts"
11+
},
12+
"backstage": {
13+
"role": "frontend-plugin"
14+
},
15+
"scripts": {
16+
"start": "backstage-cli package start",
17+
"build": "backstage-cli package build",
18+
"tsc": "tsc",
19+
"lint": "backstage-cli package lint",
20+
"test": "backstage-cli package test --passWithNoTests --coverage",
21+
"clean": "backstage-cli package clean",
22+
"prepack": "backstage-cli package prepack",
23+
"postpack": "backstage-cli package postpack"
24+
},
25+
"dependencies": {
26+
"@backstage/core-components": "^0.13.6",
27+
"@backstage/core-plugin-api": "^1.7.0",
28+
"@backstage/theme": "^0.4.3",
29+
"@material-ui/core": "^4.9.13",
30+
"@material-ui/icons": "^4.11.3",
31+
"@material-ui/lab": "^4.0.0-alpha.45",
32+
"react-use": "^17.4.0"
33+
},
34+
"peerDependencies": {
35+
"react": "^16.13.1 || ^17.0.0"
36+
},
37+
"devDependencies": {
38+
"@backstage/cli": "0.23.0",
39+
"@backstage/core-app-api": "1.11.0",
40+
"@backstage/dev-utils": "1.0.22",
41+
"@backstage/test-utils": "1.4.4",
42+
"@testing-library/jest-dom": "5.17.0",
43+
"@testing-library/react": "12.1.5",
44+
"@testing-library/user-event": "14.5.1",
45+
"@types/node": "18.18.5",
46+
"msw": "1.3.2"
47+
},
48+
"files": [
49+
"dist"
50+
],
51+
"repository": "github:janus-idp/backstage-plugins",
52+
"keywords": [
53+
"backstage",
54+
"plugin"
55+
],
56+
"homepage": "https://janus-idp.io/",
57+
"bugs": "https://github.com/janus-idp/backstage-plugins/issues"
58+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
3+
import {
4+
renderInTestApp,
5+
setupRequestMockHandlers,
6+
} from '@backstage/test-utils';
7+
8+
import { screen } from '@testing-library/react';
9+
import { rest } from 'msw';
10+
import { setupServer } from 'msw/node';
11+
12+
import { RbacPage } from './RbacPage';
13+
14+
describe('RbacPage', () => {
15+
const server = setupServer();
16+
// Enable sane handlers for network requests
17+
setupRequestMockHandlers(server);
18+
19+
// setup mock response
20+
beforeEach(() => {
21+
server.use(
22+
rest.get('/*', (_, res, ctx) => res(ctx.status(200), ctx.json({}))),
23+
);
24+
});
25+
26+
it('should render', async () => {
27+
await renderInTestApp(<RbacPage />);
28+
expect(screen.getByText('Administration')).toBeInTheDocument();
29+
});
30+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
3+
import { Content, Header, InfoCard, Page } from '@backstage/core-components';
4+
5+
import { Grid, Typography } from '@material-ui/core';
6+
7+
export const RbacPage = () => (
8+
<Page themeId="tool">
9+
<Header title="Administration" />
10+
<Content>
11+
<Grid container spacing={3} direction="column">
12+
<Grid item>
13+
<InfoCard title="Information card">
14+
<Typography variant="body1">
15+
All content should be wrapped in a card like this.
16+
</Typography>
17+
</InfoCard>
18+
</Grid>
19+
</Grid>
20+
</Content>
21+
</Page>
22+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { RbacPage } from './RbacPage';

plugins/rbac/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { rbacPlugin, RbacPage } from './plugin';

plugins/rbac/src/plugin.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { rbacPlugin } from './plugin';
2+
3+
describe('rbac', () => {
4+
it('should export plugin', () => {
5+
expect(rbacPlugin).toBeDefined();
6+
});
7+
});

plugins/rbac/src/plugin.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
createPlugin,
3+
createRoutableExtension,
4+
} from '@backstage/core-plugin-api';
5+
6+
import { rootRouteRef } from './routes';
7+
8+
export const rbacPlugin = createPlugin({
9+
id: 'rbac',
10+
routes: {
11+
root: rootRouteRef,
12+
},
13+
});
14+
15+
export const RbacPage = rbacPlugin.provide(
16+
createRoutableExtension({
17+
name: 'RbacPage',
18+
component: () => import('./components/RbacPage').then(m => m.RbacPage),
19+
mountPoint: rootRouteRef,
20+
}),
21+
);

plugins/rbac/src/routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createRouteRef } from '@backstage/core-plugin-api';
2+
3+
export const rootRouteRef = createRouteRef({
4+
id: 'rbac',
5+
});

plugins/rbac/src/setupTests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

plugins/rbac/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@backstage/cli/config/tsconfig.json",
3+
"include": ["src", "dev", "migrations"],
4+
"exclude": ["node_modules"],
5+
"compilerOptions": {
6+
"outDir": "../../dist-types/plugins/rbac",
7+
"rootDir": "."
8+
}
9+
}

plugins/rbac/turbo.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": ["//"],
3+
"pipeline": {
4+
"tsc": {
5+
"outputs": ["../../dist-types/plugins/rbac/**"],
6+
"dependsOn": ["^tsc"]
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)