Skip to content

Commit

Permalink
design Pr bad practice component and activity dashboard(#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-flo committed Jan 2, 2025
1 parent 9e0925a commit 3c67209
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="flex flex-col items-center">
<div class="grid grid-cols-1 xl:grid-cols-4 gap-y-4 xl:gap-8">
<div class="grid grid-cols-1 xl:grid-cols-5 gap-y-4 xl:gap-8">
<div class="space-y-2 col-span-1">
<div class="flex flex-col gap-2 mb-4">
<h1 class="text-xl font-semibold">Activities</h1>
Expand All @@ -9,16 +9,16 @@ <h1 class="text-xl font-semibold">Activities</h1>
</p>
</div>
</div>
<div class="col-span-2">
<div class="col-span-3">
<div class="flex flex-col justify-between gap-2">
<span class="flex flex-row justify-between items-center">
<h1 class="text-xl font-semibold">Your open pull requests</h1>
<button hlmBtn aria-describedby=">Detect bad practices" class="gap-2" (click)="this.detectBadPractices()">
<button hlmBtn variant="outline" aria-describedby=">Detect bad practices" class="gap-2" (click)="this.detectBadPractices()">
<lucide-angular [img]="RefreshCcw" class="size-4" />
<span>Detect bad practices</span>
</button>
</span>
<div class="flex flex-col gap-2 m-1 mr-3">
<div class="flex flex-col gap-4">
@if (query.data()?.pullRequests) {
@for (pullRequest of query.data()?.pullRequests; track pullRequest.id) {
<app-pull-request-bad-practice-card
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<a class="shadow-sm">
<div class="flex flex-row justify-start items-center gap-2">
<div>
@if (resolved()) {
<ng-icon [svg]="octCheck" size="24" class="text-github-success-foreground" />
} @else {
<ng-icon [svg]="octX" size="24" class="text-github-danger-foreground" />
}
</div>
<div class="flex flex-col">
<h1 class="text-lg font-semibold">{{ title() }}</h1>
<div class="text-sm">{{ description() }}</div>
<p class="text-sm">{{ description() }}</p>
</div>
</a>
</div>
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { Component, input } from '@angular/core';
import { HlmCardModule } from '@spartan-ng/ui-card-helm';
import { NgIcon } from '@ng-icons/core';
import { octCheck, octX } from '@ng-icons/octicons';

@Component({
selector: 'app-bad-practice-card',
standalone: true,
imports: [HlmCardModule],
imports: [HlmCardModule, NgIcon],
templateUrl: './bad-practice-card.component.html',
styles: ``
})
export class BadPracticeCardComponent {
protected readonly octCheck = octCheck;
protected readonly octX = octX;

title = input<string>();
description = input<string>();
repositoryName = input<string>();
number = input<number>();
resolved = input<boolean>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export const Default: Story = {
args: {
title: 'Avoid using any type',
description: 'Using the any type defeats the purpose of TypeScript.',
repositoryName: 'Hepheastus',
number: 200
resolved: false
}
};
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
<brn-collapsible>
<button brnCollapsibleTrigger>
<a hlmCard variant="profile">
<div hlmCardHeader>
<div class="flex justify-between items-center text-sm text-github-muted-foreground">
<span class="font-medium flex justify-center items-center space-x-1">
@if (isLoading()) {
<hlm-skeleton class="size-5 bg-green-500/30"></hlm-skeleton>
<hlm-skeleton class="h-4 w-16 lg:w-36"></hlm-skeleton>
} @else {
<ng-icon [svg]="issueIconAndColor().icon" size="18" [class]="'mr-1 ' + issueIconAndColor().color"></ng-icon>
{{ repositoryName() }} #{{ number() }} on {{ displayCreated().format('MMM D') }}
}
</span>
<span class="flex items-center space-x-2">
@if (isLoading()) {
<hlm-skeleton class="h-4 w-8 bg-green-500/30"></hlm-skeleton>
<hlm-skeleton class="h-4 w-8 bg-destructive/20"></hlm-skeleton>
} @else {
<span class="text-github-success-foreground font-bold">+{{ additions() }}</span>
<span class="text-github-danger-foreground font-bold">-{{ deletions() }}</span>
}
</span>
</div>
<span class="flex justify-between font-medium">
<a hlmCard variant="profile">
<div hlmCardHeader>
<div class="flex justify-between items-center text-sm text-github-muted-foreground">
<span class="font-medium flex justify-center items-center space-x-1">
@if (isLoading()) {
<hlm-skeleton class="size-5 bg-green-500/30"></hlm-skeleton>
<hlm-skeleton class="h-4 w-16 lg:w-36"></hlm-skeleton>
} @else {
<ng-icon [svg]="issueIconAndColor().icon" size="18" [class]="'mr-1 ' + issueIconAndColor().color"></ng-icon>
{{ repositoryName() }} #{{ number() }} on {{ displayCreated().format('MMM D') }}
}
</span>
<span class="font-medium flex justify-center items-center gap-1">
@if (isLoading()) {
<hlm-skeleton class="h-4 w-16 lg:w-36"></hlm-skeleton>
<hlm-skeleton class="size-5"></hlm-skeleton>
} @else {
<span> {{ badPractices()?.length }} bad practices detected </span>
<button brnCollapsibleTrigger hlmBtn variant="ghost">
<ng-icon [svg]="octFold" size="18" class="text-github-muted-foreground"></ng-icon>
</button>
}
</span>
</div>
<div class="flex justify-between font-medium">
<span>
@if (isLoading()) {
<hlm-skeleton class="h-6 w-3/4"></hlm-skeleton>
} @else {
<div [innerHTML]="displayTitle()" class="truncate"></div>
}
</span>
<span>
<div class="text-left">You have {{ badPractices()?.length }} bad practices in this pull request.</div>
<span class="flex items-center space-x-2">
@if (isLoading()) {
<hlm-skeleton class="h-4 w-8 bg-green-500/30"></hlm-skeleton>
<hlm-skeleton class="h-4 w-8 bg-destructive/20"></hlm-skeleton>
} @else {
<span class="text-github-success-foreground font-bold">+{{ additions() }}</span>
<span class="text-github-danger-foreground font-bold">-{{ deletions() }}</span>
}
</span>
</div>
@if (!isLoading()) {
<div hlmCardContent class="gap-2 p-0 space-x-0 pl-6 text-left">
<brn-collapsible-content>
@for (badpractice of badPractices(); track badpractice.title) {
<brn-separator hlmSeparator />
<app-bad-practice-card [title]="badpractice.title" [description]="badpractice.description"></app-bad-practice-card>
}
</brn-collapsible-content>
<div class="flex flex-wrap gap-2 p-0 space-x-0">
@for (label of pullRequestLabels(); track label.name) {
<app-github-label [label]="label"></app-github-label>
}
</div>
}
</a>
</button>
</div>
@if (!isLoading()) {
<div hlmCardContent class="gap-2 p-0 space-x-0 pl-6 text-left">
<brn-collapsible-content>
@for (badpractice of badPractices(); track badpractice.title) {
<brn-separator hlmSeparator />
<app-bad-practice-card [title]="badpractice.title" [description]="badpractice.description" [resolved]="false"></app-bad-practice-card>
}
</brn-collapsible-content>
</div>
}
</a>
</brn-collapsible>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, computed, input } from '@angular/core';
import { PullRequestInfo, LabelInfo, PullRequestBadPractice } from '@app/core/modules/openapi';
import { NgIcon } from '@ng-icons/core';
import { octCheck, octComment, octFileDiff, octGitPullRequest, octGitPullRequestClosed, octGitPullRequestDraft, octGitMerge, octX } from '@ng-icons/octicons';
import { octCheck, octComment, octFileDiff, octGitPullRequest, octGitPullRequestClosed, octGitPullRequestDraft, octGitMerge, octX, octFold } from '@ng-icons/octicons';
import { HlmCardModule } from '@spartan-ng/ui-card-helm';
import { HlmSkeletonComponent } from '@spartan-ng/ui-skeleton-helm';

Expand All @@ -10,6 +10,9 @@ import { BadPracticeCardComponent } from '@app/user/bad-practice-card/bad-practi
import { BrnSeparatorComponent } from '@spartan-ng/ui-separator-brain';
import { HlmSeparatorDirective } from '@spartan-ng/ui-separator-helm';
import { BrnCollapsibleComponent, BrnCollapsibleContentComponent, BrnCollapsibleTriggerDirective } from '@spartan-ng/ui-collapsible-brain';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';
import { GithubLabelComponent } from '@app/ui/github-label/github-label.component';
import { cn } from '@app/utils';

@Component({
selector: 'app-pull-request-bad-practice-card',
Expand All @@ -23,7 +26,9 @@ import { BrnCollapsibleComponent, BrnCollapsibleContentComponent, BrnCollapsible
HlmSeparatorDirective,
BrnCollapsibleComponent,
BrnCollapsibleContentComponent,
BrnCollapsibleTriggerDirective
BrnCollapsibleTriggerDirective,
HlmButtonDirective,
GithubLabelComponent
],
standalone: true
})
Expand All @@ -32,6 +37,7 @@ export class PullRequestBadPracticeCardComponent {
protected readonly octX = octX;
protected readonly octComment = octComment;
protected readonly octFileDiff = octFileDiff;
protected readonly octFold = octFold;

isLoading = input(false);
class = input('');
Expand All @@ -50,6 +56,7 @@ export class PullRequestBadPracticeCardComponent {

displayCreated = computed(() => dayjs(this.createdAt()));
displayTitle = computed(() => (this.title() ?? '').replace(/`([^`]+)`/g, '<code class="textCode">$1</code>'));
computedClass = computed(() => cn('w-full', !this.isLoading() ? 'hover:bg-accent/50 cursor-pointer' : '', this.class()));

issueIconAndColor = computed(() => {
var icon: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ export const Default: Story = {
]
}
};

export const isLoading: Story = {
args: {
title: 'Add feature X',
number: 12,
additions: 10,
deletions: 5,
htmlUrl: 'http://example.com',
state: 'OPEN',
isDraft: false,
isMerged: false,
repositoryName: 'Artemis',
createdAt: '2024-01-01',
pullRequestLabels: [
{ id: 1, name: 'bug', color: 'f00000' },
{ id: 2, name: 'enhancement', color: '008000' }
],
badPractices: [
{
title: 'Avoid using any type',
description: 'Using the any type defeats the purpose of TypeScript.'
},
{
title: 'Unchecked checkbox in description',
description: 'Unchecked checkboxes in the description are not allowed.'
}
],
isLoading: true
}
};

0 comments on commit 3c67209

Please sign in to comment.