Skip to content

Commit 3b4ade8

Browse files
fix sonarcloud issues
1 parent c9edbbb commit 3b4ade8

File tree

7 files changed

+71
-20
lines changed

7 files changed

+71
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# adoption-insights
1+
# Adoption Insights Plugin for Backstage
22

3-
Welcome to the adoption insights plugin!
4-
5-
This plugin helps gather user analytics data from Backstage and generates a dashboard that provides insights into the platform's adoption.
3+
The Adoption Insights plugin provides an interactive dashboard to visualize analytics data in Backstage. This frontend plugin integrates with the Adoption Insights backend to deliver insights into adoption trends and usage statistics.
64

75
## Getting started
86

@@ -11,3 +9,56 @@ Your plugin has been added to the example app in this repository, meaning you'll
119
You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
1210
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
1311
It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory.
12+
13+
## For Administrators
14+
15+
### Prerequisites
16+
17+
Before installing the frontend plugin, ensure that the Adoption Insights backend is integrated into your Backstage instance. Follow the [Adoption Insights backend plugin README](https://github.com/redhat-developer/rhdh-plugins/blob/main/workspaces/adoption-insights/plugins/adoption-insights-backend/README.md) for setup instructions.
18+
19+
### Installation
20+
21+
To install the Adoption Insights plugin, run the following command:
22+
23+
```sh
24+
yarn workspace app add @red-hat-developer-hub/backstage-plugin-adoption-insights
25+
```
26+
27+
### Configuration
28+
29+
1. Add the **Adoption Insights** page to your Backstage application by modifying `packages/app/src/App.tsx`:
30+
31+
```tsx
32+
import { AdoptionInsightsPage } from '@red-hat-developer-hub/backstage-plugin-adoption-insights';
33+
34+
<Route path="/adoption-insights" element={<AdoptionInsightsPage />} />;
35+
```
36+
37+
2. Add a navigation item to the Backstage sidebar by updating `packages/app/src/components/Root/Root.tsx`:
38+
39+
```tsx
40+
import QueryStatsIcon from '@mui/icons-material/QueryStats';
41+
42+
<SidebarItem
43+
icon={QueryStatsIcon}
44+
to="adoption-insights"
45+
text="Adoption Insights"
46+
/>;
47+
```
48+
49+
## For Users
50+
51+
### Using the Adoption Insights Plugin
52+
53+
The Adoption Insights plugin allows users to explore analytics data through an interactive dashboard.
54+
55+
#### Prerequisites
56+
57+
- A running Backstage application.
58+
- The Adoption Insights plugin is installed and configured. See [Installation](#installation) for setup instructions.
59+
60+
#### Accessing the Plugin
61+
62+
1. Open your Backstage application.
63+
2. Navigate to the **Adoption Insights** section from the sidebar.
64+
3. Explore and analyze adoption metrics using the interactive dashboard.

workspaces/adoption-insights/plugins/adoption-insights/dev/__data__/activeUsers.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { format, subDays, subHours, subMonths } from 'date-fns';
1818
export const generateHourlyData = () => {
1919
return Array.from({ length: 24 }, (_, i) => {
2020
const date = format(subHours(new Date(), i), 'yyyy-MM-dd HH:00');
21-
const new_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150;
22-
const returning_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150;
21+
const new_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150; // NOSONAR
22+
const returning_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150; // NOSONAR
2323
const total_users = new_users + returning_users;
2424
return { date, total_users, new_users, returning_users };
2525
}).reverse();
@@ -28,8 +28,8 @@ export const generateHourlyData = () => {
2828
export const generateDaysData = () => {
2929
return Array.from({ length: 7 }, (_, i) => {
3030
const date = format(subDays(new Date(), i), 'yyyy-MM-dd');
31-
const new_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150;
32-
const returning_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150;
31+
const new_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150; // NOSONAR
32+
const returning_users = Math.floor(Math.random() * (300 - 150 + 1)) + 150; // NOSONAR
3333
const total_users = new_users + returning_users;
3434
return { date, total_users, new_users, returning_users };
3535
}).reverse();
@@ -38,9 +38,9 @@ export const generateDaysData = () => {
3838
export const generateMonthsData = () => {
3939
return Array.from({ length: 9 }, (_, i) => {
4040
const date = format(subMonths(new Date(), i), 'yyyy-MM-dd');
41-
const new_users = Math.floor(Math.random() * (9000 - 4500 + 1)) + 4500;
41+
const new_users = Math.floor(Math.random() * (9000 - 4500 + 1)) + 4500; // NOSONAR
4242
const returning_users =
43-
Math.floor(Math.random() * (9000 - 4500 + 1)) + 4500;
43+
Math.floor(Math.random() * (9000 - 4500 + 1)) + 4500; // NOSONAR
4444
const total_users = new_users + returning_users;
4545
return { date, total_users, new_users, returning_users };
4646
}).reverse();

workspaces/adoption-insights/plugins/adoption-insights/dev/__data__/catalogEntities.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export const generateCatalogEntitiesData = (n: number): any[] => {
2323
name: names[i % names.length],
2424
kind: kinds[i % kinds.length],
2525
last_used: new Date(
26-
Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 10,
26+
Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 10, // NOSONAR
2727
).toISOString(),
28-
count: Math.floor(Math.random() * 3000),
28+
count: Math.floor(Math.random() * 3000), // NOSONAR
2929
namespace: namespaces[i % namespaces.length],
3030
}));
3131
};

workspaces/adoption-insights/plugins/adoption-insights/dev/__data__/plugins.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import { PluginTrend } from '../../src/types';
1919
export const generateHourlyData = () => {
2020
return Array.from({ length: 24 }, (_, i) => {
2121
const date = format(subHours(new Date(), i), 'yyyy-MM-dd HH:00');
22-
const count = Math.floor(Math.random() * (300 - 150 + 1)) + 150;
22+
const count = Math.floor(Math.random() * (300 - 150 + 1)) + 150; // NOSONAR
2323
return { date, count };
2424
}).reverse();
2525
};
2626

2727
export const generateLast30DaysData = () => {
2828
return Array.from({ length: 30 }, (_, i) => {
2929
const date = format(subDays(new Date(), i), 'yyyy-MM-dd');
30-
const count = Math.floor(Math.random() * (100 - 50 + 1)) + 50;
30+
const count = Math.floor(Math.random() * (100 - 50 + 1)) + 50; // NOSONAR
3131
return { date, count };
3232
}).reverse();
3333
};

workspaces/adoption-insights/plugins/adoption-insights/dev/__data__/searches.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ import { format, subDays, subMonths, subHours } from 'date-fns';
1818
export const generateHourlyData = () => {
1919
return Array.from({ length: 24 }, (_, i) => {
2020
const date = format(subHours(new Date(), i), 'yyyy-MM-dd HH:00');
21-
const count = Math.floor(Math.random() * (300 - 150 + 1)) + 150;
21+
const count = Math.floor(Math.random() * (300 - 150 + 1)) + 150; // NOSONAR
2222
return { date, count };
2323
}).reverse();
2424
};
2525

2626
export const generateDaysData = () => {
2727
return Array.from({ length: 12 }, (_, i) => {
2828
const date = format(subDays(new Date(), i), 'yyyy-MM-dd');
29-
const count = Math.floor(Math.random() * (300 - 150 + 1)) + 150;
29+
const count = Math.floor(Math.random() * (300 - 150 + 1)) + 150; // NOSONAR
3030
return { date, count };
3131
}).reverse();
3232
};
3333

3434
export const generateMonthsData = () => {
3535
return Array.from({ length: 12 }, (_, i) => {
3636
const date = format(subMonths(new Date(), i), 'yyyy-MM-dd');
37-
const count = Math.floor(Math.random() * (3000 - 1500 + 1)) + 1500;
37+
const count = Math.floor(Math.random() * (3000 - 1500 + 1)) + 1500; // NOSONAR
3838
return { date, count };
3939
}).reverse();
4040
};

workspaces/adoption-insights/plugins/adoption-insights/src/api/__tests__/index.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('AdoptionInsightsApiClient', () => {
2929

3030
beforeEach(() => {
3131
mockConfigApi = {
32-
getString: jest.fn().mockReturnValue('http://mock-backend'),
32+
getString: jest.fn().mockReturnValue('http://mock-backend'), // NOSONAR
3333
has: jest.fn().mockReturnValue(true),
3434
get: jest.fn(),
3535
getOptional: jest.fn(),
@@ -45,7 +45,7 @@ describe('AdoptionInsightsApiClient', () => {
4545

4646
test('getBaseUrl returns correct URL', async () => {
4747
await expect(apiClient.getBaseUrl()).resolves.toBe(
48-
'http://mock-backend/api/adoption-insights',
48+
'http://mock-backend/api/adoption-insights', // NOSONAR
4949
);
5050
});
5151

workspaces/adoption-insights/plugins/adoption-insights/src/utils/__tests__/utils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('getLastUsedDay', () => {
303303
});
304304

305305
it('should return formatted date for older dates', () => {
306-
expect(getLastUsedDay('2025-02-15T00:00:00Z')).toMatch(/\d{2} Feb 2024/);
306+
expect(getLastUsedDay('2025-02-15T00:00:00Z')).toMatch(/\d{2} Feb 2025/);
307307
});
308308
});
309309

0 commit comments

Comments
 (0)