Skip to content

Commit

Permalink
Enhance survey and copilot seat components by updating survey URL for…
Browse files Browse the repository at this point in the history
…mat in comments; rename hoursSpent to timeSpent for clarity; adjust routing for survey component
  • Loading branch information
austenstone committed Nov 20, 2024
1 parent 0d50926 commit db9f925
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 3 additions & 1 deletion backend/src/controllers/survey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { Request, Response } from 'express';
import { Survey } from '../models/survey.model.js';
import setup from '../services/setup.js';
import logger from '../services/logger.js';
import settingsService from 'services/settings.service.js';

class SurveyController {
async createSurvey(req: Request, res: Response): Promise<void> {
try {
const survey = await Survey.create(req.body);
res.status(201).json(survey);
try {
const surveyUrl = new URL(`copilot/surveys/${survey.id}`, settingsService.baseUrl);
const octokit = await setup.getOctokit();
const comments = await octokit.rest.issues.listComments({
owner: survey.owner,
Expand All @@ -25,7 +27,7 @@ class SurveyController {
owner: survey.owner,
repo: survey.repo,
comment_id: comment.id,
body: `Thanks for filling out the copilot survey @${survey.userId}!`
body: `Thanks for filling out the [copilot survey](${surveyUrl.toString()}) @${survey.userId}!`
});
} else {
logger.info(`No comment found for survey from ${setup.installation?.slug}`)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const routes: Routes = [
{ path: 'copilot/seats/:id', component: CopilotSeatComponent, title: 'Seat' },
{ path: 'copilot/calculator', component: CopilotCalculatorComponent, title: 'Calculator' },
{ path: 'copilot/surveys', component: CopilotSurveysComponent, title: 'Surveys' },
{ path: 'copilot/surveys/:id', component: CopilotSurveyComponent, title: 'Survey' },
{ path: 'copilot/surveys/new', component: NewCopilotSurveyComponent, title: 'New Survey' },
{ path: 'copilot/surveys/:id', component: CopilotSurveyComponent, title: 'Survey' },
{ path: 'settings', component: SettingsComponent, title: 'Settings' },
{ path: '', redirectTo: 'copilot', pathMatch: 'full' }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>
<p><strong>Last Active: </strong>{{ seat.last_activity_at | date: 'medium' }}</p>
<p><strong>Editor: </strong>{{ seat.last_activity_editor }}</p>
<p><strong>Site Admin: </strong>{{ seat.assignee.site_admin ? 'Yes' : 'No' }}</p>
<p><strong>Copilot Usage: </strong>{{ hoursSpent }}</p>
<p><strong>Copilot Usage: </strong>{{ timeSpent }}</p>
</mat-card-content>
</mat-card>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class CopilotSeatComponent implements OnInit {
id?: number;
seat?: Seat;
seatActivity?: Seat[];
hoursSpent?: string;
timeSpent?: string;

constructor(
private copilotSeatService: SeatService,
Expand All @@ -81,13 +81,10 @@ export class CopilotSeatComponent implements OnInit {
...this.chartOptions,
...this._chartOptions
};
const totalTime = (this.chartOptions.series as Highcharts.SeriesGanttOptions[])?.reduce((acc, series) => {
return acc += series.data?.reduce((acc: number, data) => {
return acc += (data.end || 0) - (data.start || 0);
}, 0) || 0;
}, 0);
this.hoursSpent = dayjs.duration({
milliseconds: totalTime
this.timeSpent = dayjs.duration({
milliseconds: (this.chartOptions.series as Highcharts.SeriesGanttOptions[])?.reduce((total, series) => {
return total += series.data?.reduce((dataTotal, data) => dataTotal += (data.end || 0) - (data.start || 0), 0) || 0;
}, 0)
}).humanize();
this.updateFlag = true;
this.cdr.detectChanges();
Expand Down

0 comments on commit db9f925

Please sign in to comment.