Skip to content

Commit 8a83097

Browse files
committed
feat(lesy-pilot-ui): add middlewares panel
1 parent 2f874ec commit 8a83097

File tree

13 files changed

+227
-7
lines changed

13 files changed

+227
-7
lines changed

packages/misc/pilot-ui/src/app/components/footer/footer.template.html

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@
5353
<i class="{{consolePosClassName}} leading-none text-xl"></i>
5454
</li>
5555
</ng-container>
56+
5657
<li class="flex items-center ml-auto">
58+
<a
59+
class="flex items-center p-3 cursor-pointer"
60+
[panel]="middlewareTpl"
61+
[popoverOn]="'CLICK'"
62+
>
63+
<i class="ri-mind-map leading-none text-xl mr-2"></i>
64+
</a>
65+
</li>
66+
<li class="flex items-center">
5767
<a
5868
class="flex items-center p-3 cursor-pointer"
5969
[popover]="shortcutsTpl"
@@ -75,6 +85,22 @@
7585
</li>
7686
</ul>
7787

88+
<ng-template #middlewareTpl let-toppy>
89+
<div class="bg-white h-full p-4 flex flex-col overflow-scroll">
90+
<div class="flex-1">
91+
<pilot-middlewares></pilot-middlewares>
92+
</div>
93+
<div class="flex justify-center">
94+
<button
95+
class="bg-gray-200 rounded-md p-5 text-center text-gray-800"
96+
(click)="toppy.close()"
97+
>
98+
Close
99+
</button>
100+
</div>
101+
</div>
102+
</ng-template>
103+
78104
<ng-template #shortcutsTpl>
79105
<div class="p-5">
80106
<div class="bg-white p-4 shadow-lg rounded-lg">
@@ -86,7 +112,7 @@
86112
<ul class="list-inline">
87113
<li
88114
*ngFor="let keys of getRegisteredHotKeys()"
89-
class="flex items-center"
115+
class="flex items-center mt-2"
90116
>
91117
<span
92118
class="font-bold text-yellow-900 bg-yellow-500 text-xs rounded px-2 py-1 mr-2 uppercase"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Component, OnInit, Input } from "@angular/core";
2+
import { Store } from "@ngxs/store";
3+
import { MiddlewaresModel, PilotState } from "../../pilot.models";
4+
5+
@Component({
6+
selector: "pilot-middlewares",
7+
templateUrl: "./middlewares.template.html",
8+
})
9+
export class MiddlewaresComponent implements OnInit {
10+
middlewares = {};
11+
constructor(private store: Store) {}
12+
ngOnInit() {
13+
const rawMiddlewares = this.store.selectSnapshot<any>(
14+
(state: PilotState) => state.middlewares,
15+
);
16+
this.middlewares = this.formatMiddlewaresShape(rawMiddlewares);
17+
}
18+
19+
private formatMiddlewaresShape(middlewares: MiddlewaresModel): any {
20+
const mw = [];
21+
const hookNames = Object.keys(middlewares);
22+
hookNames.forEach((hook) => {
23+
mw.push({
24+
hookName: hook,
25+
hooks: middlewares[hook],
26+
});
27+
});
28+
console.log("mw", mw);
29+
return mw;
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- <pre>{{middlewares|json}}</pre> -->
2+
<h3 class="font-display text-violet text-3xl mb-2">
3+
Middlewares
4+
</h3>
5+
6+
<ng-container *ngFor="let mw of middlewares">
7+
<ng-container *ngIf="mw.hooks.length">
8+
<div class="py-4">
9+
<h3 class="font-display text-gray-600 text-lg lowercase mb-2">
10+
{{mw.hookName}} ({{mw.hooks.length}})
11+
</h3>
12+
<div
13+
*ngFor="let hook of mw.hooks"
14+
class="bg-gray-100 p-2 mb-2 rounded-md"
15+
>
16+
<div class="text-lg text-gray-600">
17+
{{hook.description||'no desc'}}
18+
</div>
19+
<div class="ellipsize-left text-gray-700 text-sm">{{hook.source}}</div>
20+
</div>
21+
</div>
22+
</ng-container>
23+
</ng-container>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {
2+
Directive,
3+
ElementRef,
4+
HostListener,
5+
Input,
6+
OnInit,
7+
} from "@angular/core";
8+
import { Toppy, OutsidePlacement, SlidePlacement, SlidePosition } from "toppy";
9+
10+
@Directive({
11+
selector: "[panel]",
12+
})
13+
export class PanelDirective implements OnInit {
14+
private panelPosition;
15+
private panel;
16+
@Input("panel") panelContent;
17+
@Input() panelOn = "CLICK";
18+
19+
constructor(private toppy: Toppy) {}
20+
21+
ngOnInit() {
22+
this.panelPosition = new SlidePosition({
23+
placement: SlidePlacement.RIGHT,
24+
width: "30%",
25+
});
26+
this.panel = this.toppy
27+
.position(this.panelPosition)
28+
.config({
29+
backdrop: true,
30+
closeOnDocClick: this.panelOn === "CLICK",
31+
})
32+
.content(this.panelContent)
33+
.create();
34+
}
35+
36+
@HostListener("click") onClick() {
37+
if (this.panelOn === "CLICK") {
38+
this.panel.toggle();
39+
}
40+
}
41+
}

packages/misc/pilot-ui/src/app/pilot.main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import {
1313
SetConsolePanelHeight,
1414
ToggleConsolePanel,
1515
LoadConfig,
16+
ToggleConsolePosition,
1617
} from "./store/actions/common.actions";
1718
import { ToppyControl, Toppy, GlobalPosition, InsidePlacement } from "toppy";
1819
import { NotificationModel } from "./pilot.models";
1920
import { ToastComponent } from "./components";
2021
import { Hotkeys } from "./services/hotkeys.service";
2122
import { FetchDefaultProject } from "./store/actions/project.actions";
2223

23-
const HOTKEY = "`";
24-
2524
@Component({
2625
selector: "pilot-main",
2726
templateUrl: "./pilot.template.html",
@@ -67,8 +66,12 @@ export class PilotMain implements OnInit {
6766
});
6867

6968
this.hotkeys$
70-
.addShortcut(HOTKEY, "backquote", "Toggle console panel")
69+
.addShortcut("`", "backquote", "Toggle console panel")
7170
.subscribe(() => this.store.dispatch(new ToggleConsolePanel()));
71+
72+
this.hotkeys$
73+
.addShortcut("1", "one", "Toggle console position")
74+
.subscribe(() => this.store.dispatch(new ToggleConsolePosition()));
7275
}
7376
onDragEnd({ sizes: [, height] }) {
7477
this.store.dispatch(new SetConsolePanelHeight(height));

packages/misc/pilot-ui/src/app/pilot.models.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ export interface CommandModel {
1818
group: string;
1919
}
2020

21+
export interface MiddlewareModel {
22+
on: string;
23+
path: string;
24+
description: string;
25+
}
26+
27+
export interface MiddlewaresModel {
28+
[key: string]: MiddlewareModel;
29+
}
30+
2131
export interface ProjectModel {
2232
name: string;
2333
path: string;
@@ -62,10 +72,19 @@ export interface PilotState {
6272
projects: ProjectModel[];
6373
project: ProjectModel;
6474
commands: CommandModel[];
75+
middlewares: MiddlewaresModel;
6576
command: CommandModel;
6677
common: CommonModel;
6778
logs: LogsModel;
6879
notification: NotificationModel;
6980
prompt: PromptModel;
7081
runners: RunnerModel;
7182
}
83+
84+
export interface ShortcutKeyModel {
85+
key: string;
86+
name: string;
87+
description: string;
88+
}
89+
90+
export type ShortcutKeysModel = ShortcutKeyModel[];

packages/misc/pilot-ui/src/app/pilot.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MarkdownModule } from "ngx-markdown";
99

1010
/* Components */
1111
import { CommandComponent } from "./components/command/command.component";
12+
import { MiddlewaresComponent } from "./components/middlewares/middlewares.component";
1213
import { ConsoleComponent } from "./components/console/console.component";
1314
import { FooterComponent } from "./components/footer/footer.component";
1415
import { HeaderComponent } from "./components/header/header.component";
@@ -21,6 +22,7 @@ import { HeadingComponent } from "./components/heading/heading.component";
2122
/* Directives */
2223
import { TooltipDirective } from "./directives/tooltip/tooltip.directive";
2324
import { PopoverDirective } from "./directives/popover/popover.directive";
25+
import { PanelDirective } from "./directives/panel/panel.directive";
2426
import { CopyDirective } from "./directives/copy/copy.directive";
2527

2628
/* Pages */
@@ -36,6 +38,7 @@ import { ProjectsState } from "./store/states/projects.state";
3638
import { ProjectState } from "./store/states/project.state";
3739
import { CommandsState } from "./store/states/commands.state";
3840
import { CommandState } from "./store/states/command.state";
41+
import { MiddlewaresState } from "./store/states/middlewares.state";
3942
import { CommonState } from "./store/states/common.state";
4043
import { LogsState } from "./store/states/logs.state";
4144
import { NotificationState } from "./store/states/notification.state";
@@ -62,10 +65,12 @@ import { PilotMain } from "./pilot.main";
6265
HeaderComponent,
6366
HeadingComponent,
6467
CommandComponent,
68+
MiddlewaresComponent,
6569
ConsoleComponent,
6670
FooterComponent,
6771
TooltipDirective,
6872
PopoverDirective,
73+
PanelDirective,
6974
CopyDirective,
7075
SettingsPage,
7176
RunPage,
@@ -86,6 +91,7 @@ import { PilotMain } from "./pilot.main";
8691
ProjectState,
8792
CommandsState,
8893
CommandState,
94+
MiddlewaresState,
8995
CommonState,
9096
LogsState,
9197
NotificationState,

packages/misc/pilot-ui/src/app/services/hotkeys.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class Hotkeys {
2626
const event = `keydown.${merged.keys}`;
2727
this.registeredKeys.push([key, name, description]);
2828

29-
return new Observable(observer => {
30-
const handler = e => {
29+
return new Observable((observer) => {
30+
const handler = (e) => {
3131
e.preventDefault();
3232
observer.next(e);
3333
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Injectable } from "@angular/core";
2+
import { WsService } from "./ws.service";
3+
import { filter, take, map } from "rxjs/operators";
4+
import { Observable } from "rxjs";
5+
6+
@Injectable({ providedIn: "root" })
7+
export class MiddlewaresService {
8+
constructor(private wsService: WsService) {}
9+
10+
requestMiddlewares() {
11+
this.wsService.send("requestAllMiddlewares");
12+
}
13+
14+
onRequestMiddlewares(): Observable<any> {
15+
return this.wsService.listen().pipe(
16+
filter((a) => a && a.onRequestAllMiddlewares),
17+
take(1),
18+
map((req) => req.onRequestAllMiddlewares),
19+
);
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class LoadMiddlewares {
2+
static readonly type = "[Middlewares] Load middlewares";
3+
}
4+
5+
export class UpdateMiddlewares {
6+
static readonly type = "[Middlewares] Update middlewares";
7+
constructor(public middlewares: any) {}
8+
}

0 commit comments

Comments
 (0)