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

yarn 4 prettier command #14

Merged
merged 2 commits into from
May 4, 2024
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
2 changes: 1 addition & 1 deletion .github/labeler.yaml → .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ cicd:

documentation:
- docs/**/*
- README.md
- README.md
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ If applicable, please link any related issues. Use "Closes" keyword to automatic

- [ ] I have included or updated unit tests for my changes.
- [ ] I would like some help writing tests.
- [ ] These changes do not require tests.
- [ ] These changes do not require tests.
6 changes: 3 additions & 3 deletions .github/workflows/labeler-workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Pull Request Labeler"
name: 'Pull Request Labeler'
on:
- pull_request_target
- pull_request_target

jobs:
labeler:
Expand All @@ -9,4 +9,4 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
- uses: actions/labeler@v5
5 changes: 2 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ jobs:
yarn lint:all
yarn prettier:check

- name: Run Tests
run: yarn test:all

# - name: Run Tests
# run: yarn test:all
7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enableGlobalCache: true

httpTimeout: 300000

nodeLinker: node-modules

npmRegistryServer: 'https://registry.npmjs.org/'
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"fix": "backstage-cli repo fix",
"lint": "backstage-cli repo lint --since origin/master",
"lint:all": "backstage-cli repo lint",
"prettier:write": "prettier --write .",
"prettier:check": "prettier --check .",
"new": "backstage-cli new --scope internal"
},
Expand Down Expand Up @@ -54,5 +55,6 @@
"*.{json,md}": [
"prettier --write"
]
}
},
"packageManager": "[email protected]"
}
9 changes: 6 additions & 3 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
import { RequirePermission } from '@backstage/plugin-permission-react';
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
import { githubAuthApiRef } from '@backstage/core-plugin-api';
import { OpenFeedbackModal, OpenFeedbackPage } from '@internal/backstage-plugin-open-feedback';
import {
OpenFeedbackModal,
OpenFeedbackPage,
} from '@internal/backstage-plugin-open-feedback';

const app = createApp({
components: {
Expand Down Expand Up @@ -113,8 +116,8 @@ const routes = (
</Route>
<Route path="/settings" element={<UserSettingsPage />} />
<Route path="/catalog-graph" element={<CatalogGraphPage />} />
<Route path='/open-feedback' element={<OpenFeedbackPage />} />
<Route path='/open-feedback-dialog' element={<OpenFeedbackModal />} />
<Route path="/open-feedback" element={<OpenFeedbackPage />} />
<Route path="/open-feedback-dialog" element={<OpenFeedbackModal />} />
</FlatRoutes>
);

Expand Down
12 changes: 10 additions & 2 deletions packages/app/src/components/Root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,23 @@ export const Root = ({ children }: PropsWithChildren<{}>) => (
<SidebarGroup label="Search" icon={<SearchIcon />} to="/search">
<SidebarSearchModal />
</SidebarGroup>
<SidebarItem icon={ThumbUpAltIcon} to='open-feedback-dialog' text='OpenFeedbackModal' />
<SidebarItem
icon={ThumbUpAltIcon}
to="open-feedback-dialog"
text="OpenFeedbackModal"
/>
<SidebarDivider />
<SidebarGroup label="Menu" icon={<MenuIcon />}>
{/* Global nav, not org-specific */}
<SidebarItem icon={HomeIcon} to="catalog" text="Home" />
<SidebarItem icon={ExtensionIcon} to="api-docs" text="APIs" />
<SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
<SidebarItem icon={CreateComponentIcon} to="create" text="Create..." />
<SidebarItem icon={ThumbUpAltIcon} to='open-feedback' text='OpenFeedback' />
<SidebarItem
icon={ThumbUpAltIcon}
to="open-feedback"
text="OpenFeedback"
/>
{/* End global nav */}
<SidebarDivider />
<SidebarScrollWrapper>
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"@backstage/config": "^1.2.0",
"@backstage/plugin-app-backend": "^0.3.65",
"@backstage/plugin-auth-backend": "^0.22.4",
"@backstage/plugin-catalog-backend-module-github": "^0.5.4",
"@backstage/plugin-catalog-backend-module-github-org": "^0.1.8",
"@backstage/plugin-auth-backend-module-github-provider": "^0.1.14",
"@backstage/plugin-auth-backend-module-guest-provider": "^0.1.3",
"@backstage/plugin-auth-node": "^0.4.12",
"@backstage/plugin-catalog-backend": "^1.21.1",
"@backstage/plugin-catalog-backend-module-github": "^0.5.4",
"@backstage/plugin-catalog-backend-module-github-org": "^0.1.8",
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "^0.1.15",
"@backstage/plugin-permission-backend": "^0.5.41",
"@backstage/plugin-permission-backend-module-allow-all-policy": "^0.1.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ backend.add(import('@backstage/plugin-app-backend/alpha'));
backend.add(import('@backstage/plugin-proxy-backend/alpha'));
backend.add(import('@backstage/plugin-scaffolder-backend/alpha'));
backend.add(import('@backstage/plugin-techdocs-backend/alpha'));
backend.add(import('@internal/backstage-plugin-open-feedback-backend'))
backend.add(import('@internal/backstage-plugin-open-feedback-backend'));

// auth plugin
backend.add(import('@backstage/plugin-auth-backend'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
* @returns { Promise<void> }
*/
exports.up = function up(knex) {
return knex.schema.createTable('open_feedback', (table) => {
table.increments('id').primary();
table.string('userRef').notNullable();
table.string('rating').notNullable();
table.string('comment')
table.timestamp('created_at').defaultTo(knex.fn.now());
});

return knex.schema.createTable('open_feedback', table => {
table.increments('id').primary();
table.string('userRef').notNullable();
table.string('rating').notNullable();
table.string('comment');
table.timestamp('created_at').defaultTo(knex.fn.now());
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function down(knex) {
return knex.schema.dropTable('openfeedback');
return knex.schema.dropTable('openfeedback');
};
2 changes: 1 addition & 1 deletion plugins/open-feedback-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@internal/backstage-plugin-open-feedback-common": "0.1.0",
"@backstage/backend-common": "^0.21.7",
"@backstage/backend-defaults": "^0.2.17",
"@backstage/backend-plugin-api": "^0.6.17",
"@backstage/config": "^1.2.0",
"@internal/backstage-plugin-open-feedback-common": "0.1.0",
"@types/express": "*",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { resolvePackagePath } from '@backstage/backend-common';
import { Knex } from 'knex';
import { AppFeedback, SubmitFeedback } from '@internal/backstage-plugin-open-feedback-common';
import {
AppFeedback,
SubmitFeedback,
} from '@internal/backstage-plugin-open-feedback-common';

const migrationsDir = resolvePackagePath(
'@internal/backstage-plugin-open-feedback-backend',
Expand Down
9 changes: 1 addition & 8 deletions plugins/open-feedback-backend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ export const openFeedbackPlugin = createBackendPlugin({
auth: coreServices.auth,
httpAuth: coreServices.httpAuth,
},
async init({
database,
discovery,
logger,
httpRouter,
auth,
httpAuth,
}) {
async init({ database, discovery, logger, httpRouter, auth, httpAuth }) {
httpRouter.use(
await createRouter({
database,
Expand Down
64 changes: 40 additions & 24 deletions plugins/open-feedback-backend/src/service/router.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { errorHandler, PluginDatabaseManager, PluginEndpointDiscovery } from '@backstage/backend-common';
import { AuthService, HttpAuthService, LoggerService } from '@backstage/backend-plugin-api';
import {
errorHandler,
PluginDatabaseManager,
PluginEndpointDiscovery,
} from '@backstage/backend-common';
import {
AuthService,
HttpAuthService,
LoggerService,
} from '@backstage/backend-plugin-api';
import express, { Request, Response } from 'express';
import Router from 'express-promise-router';
import {body} from 'express-validator';
import { body } from 'express-validator';
import { DatabaseHandler } from '../database/DatabaseHandler';
import { SubmitFeedback } from '@internal/backstage-plugin-open-feedback-common';



export interface RouterOptions {
database: PluginDatabaseManager;
discovery: PluginEndpointDiscovery;
Expand All @@ -19,15 +25,15 @@ export interface RouterOptions {
const feedbackValidator = [
body('rating').isNumeric().notEmpty(),
body('comment').isString().notEmpty().withMessage('Comment must be a string'),
body('userRef').isString()
body('userRef').isString(),
];

export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
const { logger, database } = options;
const db = await database.getClient();
const dbHandler = await DatabaseHandler.create({ database: db });
const dbHandler = await DatabaseHandler.create({ database: db });

const router = Router();
router.use(express.json());
Expand All @@ -37,40 +43,50 @@ export async function createRouter(
response.json({ status: 'ok' });
});

router.post('/feedback/submit', feedbackValidator, async (req: Request, res: Response) => {
const { rating, comment, userRef } = req.body;

const feedback: SubmitFeedback = { userRef, rating, comment };

try {
await dbHandler.addFeedback(feedback);
logger.info(`Received feedback from ${userRef} with rating ${rating}`);
res.status(201).json({ status: 'ok', message: 'Feedback added'});
} catch (error) {
logger.error(`Failed to add feedback: ${error}`);
res.status(500).json({ status: 'error', message: 'Failed to add feedback' });
}
});
router.post(
'/feedback/submit',
feedbackValidator,
async (req: Request, res: Response) => {
const { rating, comment, userRef } = req.body;

const feedback: SubmitFeedback = { userRef, rating, comment };

try {
await dbHandler.addFeedback(feedback);
logger.info(`Received feedback from ${userRef} with rating ${rating}`);
res.status(201).json({ status: 'ok', message: 'Feedback added' });
} catch (error) {
logger.error(`Failed to add feedback: ${error}`);
res
.status(500)
.json({ status: 'error', message: 'Failed to add feedback' });
}
},
);

router.get('/feedback', async (_, res: Response) => {
try {
const feedback = await dbHandler.getFeedback();
res.status(200).json(feedback);
} catch (error) {
logger.error(`Failed to get feedback: ${error}`);
res.status(500).json({ status: 'error', message: 'Failed to get feedback' });
res
.status(500)
.json({ status: 'error', message: 'Failed to get feedback' });
}
});

router.delete('/feedback/:id', async (req: Request, res: Response) => {
const { id } = req.params;

try {
await dbHandler.removeFeedback(Number(id));
res.status(200).json({ status: 'ok', message: 'Feedback removed' });
} catch (error) {
logger.error(`Failed to remove feedback: ${error}`);
res.status(500).json({ status: 'error', message: 'Failed to remove feedback' });
res
.status(500)
.json({ status: 'error', message: 'Failed to remove feedback' });
}
});

Expand Down
4 changes: 2 additions & 2 deletions plugins/open-feedback-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export type AppFeedback = {
userRef: string;
rating: number;
comment: string;
}
};

export type SubmitFeedback = Omit<AppFeedback, 'id'>;
export type SubmitFeedback = Omit<AppFeedback, 'id'>;
10 changes: 5 additions & 5 deletions plugins/open-feedback-common/src/permissions/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export const openFeedbackReadPermission = createPermission({
});

export const openFeedbackCreatePermission = createPermission({
name: 'open.feedback.create',
attributes: { action: 'create' },
name: 'open.feedback.create',
attributes: { action: 'create' },
});

/**
* @public
*/

export const openFeedbackPermissions = [
openFeedbackReadPermission,
openFeedbackCreatePermission,
];
openFeedbackReadPermission,
openFeedbackCreatePermission,
];
2 changes: 1 addition & 1 deletion plugins/open-feedback/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@internal/backstage-plugin-open-feedback-common": "0.1.0",
"@backstage/core-components": "^0.14.4",
"@backstage/core-plugin-api": "^1.9.2",
"@backstage/theme": "^0.5.3",
"@internal/backstage-plugin-open-feedback-common": "0.1.0",
"@material-ui/core": "^4.9.13",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.61",
Expand Down
2 changes: 1 addition & 1 deletion plugins/open-feedback/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './openFeedbackBackendClient';
export * from './openFeedbackBackendClient';
Loading
Loading